Ottomata has submitted this change and it was merged.

Change subject: Add --schemas-path option to eventlogging-service
......................................................................


Add --schemas-path option to eventlogging-service

This removes the clunky SCHEMA_REPO_PATH environment var

Change-Id: I2776ea8bfd7273284de26a52fad49bf1b6dfa010
---
M bin/eventlogging-service
M eventlogging/schema.py
2 files changed, 31 insertions(+), 20 deletions(-)

Approvals:
  Ottomata: Verified; Looks good to me, approved



diff --git a/bin/eventlogging-service b/bin/eventlogging-service
index 45a5226..85553d3 100755
--- a/bin/eventlogging-service
+++ b/bin/eventlogging-service
@@ -3,6 +3,7 @@
 
 import argparse
 import logging
+import os
 import signal
 import textwrap
 
@@ -21,6 +22,19 @@
     default='8085',
     help='Port on which to listen for requests.',
 )
+
+
+ap.add_argument(
+    '--schemas-path',
+    default=os.path.join(
+        os.path.dirname(os.path.dirname(__file__)),
+        'config',
+        'schemas',
+        'jsonschema',
+    ),
+    help='Path to local schema repository',
+)
+
 
 ap.add_argument(
     '--topic-config',
@@ -43,15 +57,15 @@
     args = ap.parse_args()
 
     # Initialize topic_config and schema_cache with schemas from local files.
-    init_topic_config(args.config)
-    init_schema_cache()
+    init_topic_config(args.topic_config)
+    init_schema_cache(args.schemas_path)
 
     # Register a SIGHUP handler to reload all schemas
     # and topic_config on SIGHUP.
     def sighup_handler(signum, frame):
         logging.info('Got SIGHUP, reloading topic_config and local schemas...')
-        init_topic_config(args.config)
-        init_schema_cache()
+        init_topic_config(args.topic_config)
+        init_schema_cache(args.schemas_path)
     signal.signal(signal.SIGHUP, sighup_handler)
 
     # TODO: Remove.  This is a temporary hack to allow topic
diff --git a/eventlogging/schema.py b/eventlogging/schema.py
index 06e28cc..9f14c63 100644
--- a/eventlogging/schema.py
+++ b/eventlogging/schema.py
@@ -58,18 +58,6 @@
     SCHEMA_WIKI_API + '?action=jsonschema&title=%s&revid=%s&formatversion=2'
 )
 
-# Local file based jsonschemas will be loaded from SCHEMA_REPO_PATH.
-# This defaults to eventlogging/server/schemas/jsonschema, and
-# can be overridden by setting the SCHEMA_REPO_PATH environment variable.
-SCHEMA_REPO_PATH = os.environ.get(
-    'SCHEMA_REPO_PATH',
-    os.path.join(
-        os.path.dirname(os.path.dirname(__file__)),
-        'config',
-        'schemas',
-        'jsonschema'
-    )
-)
 
 # Use this to extract schemas from a local file name
 # File names look either like:
@@ -96,13 +84,15 @@
 schema_validator_cache = {}
 
 
-def init_schema_cache(schemas_path=SCHEMA_REPO_PATH):
+def init_schema_cache(schemas_path=None):
     """
-    Clears any cached schemas and then loads local schemas.
+    Clears any cached schemas and schema validators.
+    If schemas_path is provided, load_local_schemas is called.
     """
     schema_cache.clear()
     schema_validator_cache.clear()
-    load_local_schemas(schemas_path=schemas_path)
+    if schemas_path:
+        load_local_schemas(schemas_path=schemas_path)
 
 
 def get_schema(scid, encapsulate=False):
@@ -281,9 +271,16 @@
     schema_cache by calling get_schema with the
     scid extractd from the matched filename.
     """
-    # Loads all jsonschemas found in path into
+    # Loads all schemas found in path into
     # the in memory schema cache.
     logging.info("Loading local schemas from %s " % schemas_path)
+
+    if not os.path.isdir(schemas_path):
+        raise RuntimeError(
+            "Could not load local schemas. "
+            "%s is not a directory " % schemas_path
+        )
+
     for path, subdirs, files in os.walk(schemas_path):
         for f in files:
             file = os.path.join(path, f)

-- 
To view, visit https://gerrit.wikimedia.org/r/253460
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2776ea8bfd7273284de26a52fad49bf1b6dfa010
Gerrit-PatchSet: 1
Gerrit-Project: eventlogging
Gerrit-Branch: service
Gerrit-Owner: Ottomata <[email protected]>
Gerrit-Reviewer: Ottomata <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to