jenkins-bot has submitted this change and it was merged.

Change subject: Shuffle config usages around to be less of a jerk
......................................................................


Shuffle config usages around to be less of a jerk

The config global was a bad idea.  Try to back out of this mess.

Change-Id: I7516684a9f57a9969f91c2402851c7a388686e29
---
M database/db.py
M live_analysis/dump_tests.py
M mediawiki/api.py
M process/logging.py
M requirements.txt
M sftp/client.py
M silverpop_export/export.py
M silverpop_export/update.py
8 files changed, 44 insertions(+), 29 deletions(-)

Approvals:
  Ejegg: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/database/db.py b/database/db.py
index 92f229b..9340e27 100644
--- a/database/db.py
+++ b/database/db.py
@@ -8,7 +8,8 @@
 
 from signal import signal, SIGTERM, SIG_DFL
 from process.logging import Logger as log
-from process.globals import config
+import process.globals
+
 
 class Connection(object):
     def __init__(self, debug=False, **kw):
@@ -145,6 +146,8 @@
     '''Convenience'''
     global db_conn
 
+    config = process.globals.get_config()
+
     if not schema:
         schema = config.db_params.db
 
diff --git a/live_analysis/dump_tests.py b/live_analysis/dump_tests.py
index ba6599d..0497f95 100755
--- a/live_analysis/dump_tests.py
+++ b/live_analysis/dump_tests.py
@@ -6,12 +6,12 @@
 import csv
 import sys
 
-from process.logging import Logger as log
+import mediawiki.centralnotice.api
+
 from process.globals import load_config
+
 load_config("analysis")
 
-import mediawiki.centralnotice.api
-from process.globals import config
 
 def is_relevant(entry):
     '''
diff --git a/mediawiki/api.py b/mediawiki/api.py
index d8b9369..17a5ce5 100644
--- a/mediawiki/api.py
+++ b/mediawiki/api.py
@@ -2,13 +2,18 @@
 Dumb interface to the MediaWiki api.
 '''
 
-from process.globals import config
+import process.globals
 
 import json
 
-def mw_call(args, api=config.centralnotice_mw_api):
+
+def mw_call(args, api=None):
     import simplemediawiki
 
+    if not api:
+        config = process.globals.get_config()
+        api = config.centralnotice_mw_api
+
     wiki = simplemediawiki.MediaWiki(
         api,
         user_agent='bot: fr-anal'
diff --git a/process/logging.py b/process/logging.py
index cdf23d0..f2268c4 100644
--- a/process/logging.py
+++ b/process/logging.py
@@ -33,12 +33,9 @@
         syslog.syslog(severity, message)
         syslog.closelog()
 
-        # TODO: Echo to stdout here since we can't log yet?
+        # FIXME: This late import is to cheat a circular dependency.
+        import process.globals
         config = process.globals.get_config()
         if sys.stdout.isatty() or (not hasattr(config, 'quiet') or not 
config.quiet):
             print(message)
             sys.stdout.flush()
-
-
-# FIXME: This late import is to cheat a circular dependency.
-import process.globals
diff --git a/requirements.txt b/requirements.txt
index e0957a4..4725ace 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -9,4 +9,5 @@
 PyYAML>=3.11
 redis
 # scipy - just use the package.
+simplemediawiki
 stompy
diff --git a/sftp/client.py b/sftp/client.py
index 831a714..e7c4df2 100644
--- a/sftp/client.py
+++ b/sftp/client.py
@@ -5,30 +5,31 @@
 import StringIO
 
 from process.logging import Logger as log
-from process.globals import config
+import process.globals
 
 
 class Client(object):
     def __init__(self):
         self.client = None
         self.connect()
+        self.config = process.globals.get_config()
 
     def __del__(self):
         if self.client:
             self.client.close()
 
     def connect(self):
-        log.info("Connecting to {host}".format(host=config.sftp.host))
-        transport = paramiko.Transport((config.sftp.host, 22))
+        log.info("Connecting to {host}".format(host=self.config.sftp.host))
+        transport = paramiko.Transport((self.config.sftp.host, 22))
         params = {
-            'username': config.sftp.username,
+            'username': self.config.sftp.username,
         }
-        if hasattr(config.sftp, 'host_key'):
-            params['hostkey'] = make_key(config.sftp.host_key)
-        if hasattr(config.sftp, 'password'):
-            params['password'] = config.sftp.password
-        if hasattr(config.sftp, 'private_key'):
-            params['pkey'] = make_key(config.sftp.private_key)
+        if hasattr(self.config.sftp, 'host_key'):
+            params['hostkey'] = make_key(self.config.sftp.host_key)
+        if hasattr(self.config.sftp, 'password'):
+            params['password'] = self.config.sftp.password
+        if hasattr(self.config.sftp, 'private_key'):
+            params['pkey'] = make_key(self.config.sftp.private_key)
         transport.connect(**params)
         self.client = paramiko.SFTPClient.from_transport(transport)
 
@@ -45,7 +46,7 @@
             raise
 
     def put(self, localpath, remotepath):
-        self.client.put(localpath, os.path.join(config.sftp.remote_root, 
remotepath))
+        self.client.put(localpath, os.path.join(self.config.sftp.remote_root, 
remotepath))
 
 
 class Crawler(object):
@@ -53,6 +54,8 @@
     def pull():
         '''Pull down new remote files'''
 
+        config = process.globals.get_config()
+
         # Check against both unprocessed and processed files to find new 
remote files
         local_paths = [
             config.incoming_path,
diff --git a/silverpop_export/export.py b/silverpop_export/export.py
index 370a79d..ec53199 100644
--- a/silverpop_export/export.py
+++ b/silverpop_export/export.py
@@ -6,9 +6,7 @@
 import time
 
 from process.logging import Logger as log
-from process.globals import load_config
-load_config('silverpop_export')
-from process.globals import config
+import process.globals
 
 from database.db import Connection as DbConnection, Query as DbQuery
 import process.lock as lock
@@ -18,6 +16,7 @@
 
 def export_and_upload():
     log.info("Begin Silverpop Export")
+    config = process.globals.get_config()
 
     make_sure_path_exists(config.working_path)
 
@@ -73,6 +72,8 @@
 
 
 def export_data(output_path=None):
+    config = process.globals.get_config()
+
     db = DbConnection(**config.silverpop_db)
 
     log.info("Starting full data export")
@@ -88,6 +89,8 @@
 
 
 def export_unsubscribes(output_path=None):
+    config = process.globals.get_config()
+
     db = DbConnection(**config.silverpop_db)
 
     log.info("Starting unsubscribe data export")
@@ -111,6 +114,8 @@
 
 
 def rotate_files():
+    config = process.globals.get_config()
+
     # Clean up after ourselves
     if config.days_to_keep_files:
         now = time.time()
@@ -138,6 +143,8 @@
 
 
 if __name__ == '__main__':
+    process.globals.load_config('silverpop_export')
+
     lock.begin()
 
     export_and_upload()
diff --git a/silverpop_export/update.py b/silverpop_export/update.py
index aed3177..d660dcf 100644
--- a/silverpop_export/update.py
+++ b/silverpop_export/update.py
@@ -4,9 +4,7 @@
 import os
 
 from process.logging import Logger as log
-from process.globals import load_config
-load_config('silverpop_export')
-from process.globals import config
+import process.globals
 
 from database.db import Connection as DbConnection
 import export
@@ -46,7 +44,8 @@
 
 
 if __name__ == '__main__':
-    global config
+    config = process.globals.load_config('silverpop_export')
+
     log.info("Begin Silverpop Update")
     lock.begin()
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7516684a9f57a9969f91c2402851c7a388686e29
Gerrit-PatchSet: 4
Gerrit-Project: wikimedia/fundraising/tools
Gerrit-Branch: master
Gerrit-Owner: Awight <awi...@wikimedia.org>
Gerrit-Reviewer: Awight <awi...@wikimedia.org>
Gerrit-Reviewer: Ejegg <eeggles...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to