Merge "Add global flag to control replication"
diff --git a/jeepyb/cmd/close_pull_requests.py b/jeepyb/cmd/close_pull_requests.py
index 70bc543..c1b6a1f 100644
--- a/jeepyb/cmd/close_pull_requests.py
+++ b/jeepyb/cmd/close_pull_requests.py
@@ -43,6 +43,7 @@
 import logging
 import os
 
+import jeepyb.projects as p
 import jeepyb.utils as u
 
 MESSAGE = """Thank you for contributing to %(project)s!
@@ -54,6 +55,8 @@
 and follow the instructions there to upload your change to Gerrit.
 """
 
+log = logging.getLogger("close_pull_requests")
+
 
 def main():
 
@@ -79,6 +82,10 @@
     for section in registry.configs_list:
         project = section['project']
 
+        # Make sure we're using GitHub for this project:
+        if not p.has_github(project):
+            continue
+
         # Make sure we're supposed to close pull requests for this project:
         if 'options' in section and 'has-pull-requests' in section['options']:
             continue
@@ -93,9 +100,8 @@
                 repo = org.get_repo(project_split[1])
             else:
                 repo = ghub.get_user().get_repo(project)
-        except KeyError:
-            continue
-        except github.GithubException:
+        except (KeyError, github.GithubException):
+            log.exception("Could not find project %s on GitHub." % project)
             continue
 
         # Close each pull request
diff --git a/jeepyb/cmd/openstackwatch.py b/jeepyb/cmd/openstackwatch.py
index 726912a..945674d 100644
--- a/jeepyb/cmd/openstackwatch.py
+++ b/jeepyb/cmd/openstackwatch.py
@@ -90,7 +90,7 @@
         print(msg)
 
 
-def get_javascript(project=None):
+def get_json(project=None):
     url = CONFIG['json_url']
     if project:
         url += "+project:" + project
@@ -99,8 +99,8 @@
     return ret
 
 
-def parse_javascript(javascript):
-    for row in javascript.splitlines():
+def parse_json(content):
+    for row in content.splitlines():
         try:
             json_row = json.loads(row)
         except(ValueError):
@@ -111,11 +111,7 @@
         yield json_row
 
 
-def upload_rss(xml, output_object):
-    if 'swift' not in CONFIG:
-        print(xml)
-        return
-
+def upload_to_swift(content, objectname):
     import swiftclient
     cfg = CONFIG['swift']
     client = swiftclient.Connection(cfg['auth_url'],
@@ -130,11 +126,11 @@
         # eventual consistenties
         time.sleep(1)
 
-    client.put_object(cfg['container'], output_object,
-                      cStringIO.StringIO(xml))
+    client.put_object(cfg['container'], objectname,
+                      cStringIO.StringIO(content))
 
 
-def generate_rss(javascript, project=""):
+def generate_rss(content, project=""):
     title = "OpenStack %s watch RSS feed" % (project)
     rss = PyRSS2Gen.RSS2(
         title=title,
@@ -143,7 +139,7 @@
                     "from Gerrit.",
         lastBuildDate=datetime.datetime.now()
     )
-    for row in parse_javascript(javascript):
+    for row in parse_json(content):
         author = row['owner']['name']
         author += " <%s>" % ('email' in row['owner'] and
                              row['owner']['email']
@@ -164,13 +160,19 @@
 
 def main():
     if CONFIG['output_mode'] == "combined":
-        upload_rss(generate_rss(get_javascript()),
-                   CONFIG['swift']['combined_output_object'])
+        content = generate_rss(get_json())
+        if 'swift' in CONFIG:
+            upload_to_swift(content, CONFIG['swift']['combined_output_object'])
+        else:
+            print(content)
     elif CONFIG['output_mode'] == "multiple":
         for project in CONFIG['projects']:
-            upload_rss(
-                generate_rss(get_javascript(project), project=project),
-                "%s.xml" % (os.path.basename(project)))
+            content = generate_rss(get_json(project), project=project)
+            if 'swift' in CONFIG:
+                objectname = "%s.xml" % os.path.basename(project)
+                upload_to_swift(content, objectname)
+            else:
+                print(content)
 
 if __name__ == '__main__':
     main()
diff --git a/jeepyb/projects.py b/jeepyb/projects.py
index 713072d..81db5ba 100644
--- a/jeepyb/projects.py
+++ b/jeepyb/projects.py
@@ -26,6 +26,8 @@
     - no-launchpad-blueprints
 """
 
+import ConfigParser
+
 import jeepyb.utils as u
 
 
@@ -56,6 +58,23 @@
     return _is_no_launchpad(project_full_name, 'blueprints')
 
 
+def has_github(project_full_name):
+    try:
+        if not registry.defaults.get('projects', 'has-github'):
+            # If the default is not to use GitHub...
+            try:
+                # ...then rely on the existence of a per-project option...
+                return 'has-github' in registry[project_full_name]['options']
+            except KeyError:
+                # ...and if it's not set, then still don't use it.
+                return False
+    # It's okay if the global option or even the section for this don't exist.
+    except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
+        pass
+    # If we got this far, we either explicitly or implicitly default to use it.
+    return True
+
+
 def is_direct_release(project_full_name):
     try:
         return 'direct-release' in registry[project_full_name]['options']