Merge "Swap logging levels for command and its output"
diff --git a/jeepyb/cmd/close_pull_requests.py b/jeepyb/cmd/close_pull_requests.py
index b49bac3..e380f2f 100644
--- a/jeepyb/cmd/close_pull_requests.py
+++ b/jeepyb/cmd/close_pull_requests.py
@@ -44,6 +44,7 @@
 import logging
 import os
 
+import jeepyb.log as l
 import jeepyb.projects as p
 import jeepyb.utils as u
 
@@ -61,15 +62,13 @@
 
 def main():
 
-    logging.basicConfig(level=logging.ERROR,
-                        format='%(asctime)-6s: %(name)s - %(levelname)s'
-                               ' - %(message)s')
-
     parser = argparse.ArgumentParser()
+    l.setup_logging_arguments(parser)
     parser.add_argument('--message-file', dest='message_file', default=None,
                         help='The close pull request message')
 
     args = parser.parse_args()
+    l.configure_logging(args)
 
     if args.message_file:
         try:
diff --git a/jeepyb/cmd/create_hound_config.py b/jeepyb/cmd/create_hound_config.py
new file mode 100644
index 0000000..2fcc7fe
--- /dev/null
+++ b/jeepyb/cmd/create_hound_config.py
@@ -0,0 +1,59 @@
+#! /usr/bin/env python
+# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# create_hound_config.py reads the project config file called projects.yaml
+# and generates a hound configuration file.
+
+import json
+import os
+
+import jeepyb.utils as u
+
+
+PROJECTS_YAML = os.environ.get('PROJECTS_YAML', '/home/hound/projects.yaml')
+GIT_SERVER = os.environ.get('GIT_BASE', 'git.openstack.org')
+DATA_PATH = os.environ.get('DATA_PATH', 'data')
+
+
+def main():
+    registry = u.ProjectsRegistry(PROJECTS_YAML)
+    projects = [entry['project'] for entry in registry.configs_list]
+    repos = {}
+    for project in projects:
+        repos[os.path.basename(project)] = {
+            'url': "git://%(gitbase)s/%(project)s" % dict(
+                gitbase=GIT_SERVER, project=project),
+            'url-pattern': {
+                'base-url': "http://%(gitbase)s/cgit/%(project)s"
+                            "/tree/{path}{anchor}" % dict(gitbase=GIT_SERVER,
+                                                          project=project),
+                'anchor': '#n{line}',
+            }
+        }
+
+    config = {
+        "dbpath": "data",
+        "repos": repos
+    }
+    with open('config.json', 'w') as config_file:
+        config_file.write(
+            json.dumps(
+                config, indent=2,
+                separators=(',', ': '), sort_keys=False,
+                default=unicode))
+
+
+if __name__ == "__main__":
+    main()
diff --git a/jeepyb/cmd/expire_old_reviews.py b/jeepyb/cmd/expire_old_reviews.py
index ef67e3a..9ec1064 100644
--- a/jeepyb/cmd/expire_old_reviews.py
+++ b/jeepyb/cmd/expire_old_reviews.py
@@ -22,8 +22,9 @@
 import logging
 import paramiko
 
+import jeepyb.log as l
+
 logger = logging.getLogger('expire_reviews')
-logger.setLevel(logging.INFO)
 
 
 def expire_patch_set(ssh, patch_id, patch_subject):
@@ -49,16 +50,14 @@
     parser.add_argument('ssh_key', help='The gerrit admin SSH key file')
     parser.add_argument('--age', dest='age', default='1w',
                         help='The minimum age of a review to expire')
+    l.setup_logging_arguments(parser)
     options = parser.parse_args()
+    l.configure_logging(options)
 
     GERRIT_USER = options.user
     GERRIT_SSH_KEY = options.ssh_key
     EXPIRY_AGE = options.age
 
-    logging.basicConfig(format='%(asctime)-6s: %(name)s - %(levelname)s'
-                               ' - %(message)s',
-                        filename='/var/log/gerrit/expire_reviews.log')
-
     logger.info('Starting expire reviews')
     logger.info('Connecting to Gerrit')
 
diff --git a/jeepyb/cmd/manage_projects.py b/jeepyb/cmd/manage_projects.py
index 7fd8d16..f125975 100644
--- a/jeepyb/cmd/manage_projects.py
+++ b/jeepyb/cmd/manage_projects.py
@@ -64,6 +64,7 @@
 import github
 
 import jeepyb.gerritdb
+import jeepyb.log as l
 import jeepyb.utils as u
 
 registry = u.ProjectsRegistry()
@@ -247,10 +248,10 @@
         with open(group_file, 'w') as fp:
             for group, uuid in uuids.items():
                 fp.write("%s\t%s\n" % (uuid, group))
-    status = git_command(repo_path, "add groups")
-    if status != 0:
-        log.error("Failed to add groups file for project: %s" % project)
-        raise CreateGroupException()
+        status = git_command(repo_path, "add groups")
+        if status != 0:
+            log.error("Failed to add groups file for project: %s" % project)
+            raise CreateGroupException()
 
 
 def make_ssh_wrapper(gerrit_user, gerrit_key):
@@ -528,28 +529,13 @@
 
 def main():
     parser = argparse.ArgumentParser(description='Manage projects')
-    parser.add_argument('-v', dest='verbose', action='store_true',
-                        help='verbose output')
-    parser.add_argument('-d', dest='debug', action='store_true',
-                        help='debug output')
+    l.setup_logging_arguments(parser)
     parser.add_argument('--nocleanup', action='store_true',
                         help='do not remove temp directories')
     parser.add_argument('projects', metavar='project', nargs='*',
                         help='name of project(s) to process')
     args = parser.parse_args()
-
-    if args.debug:
-        logging.basicConfig(level=logging.DEBUG,
-                            format='%(asctime)-6s: %(name)s - %(levelname)s'
-                                   ' - %(message)s')
-    elif args.verbose:
-        logging.basicConfig(level=logging.INFO,
-                            format='%(asctime)-6s: %(name)s - %(levelname)s'
-                                   ' - %(message)s')
-    else:
-        logging.basicConfig(level=logging.ERROR,
-                            format='%(asctime)-6s: %(name)s - %(levelname)s'
-                                   ' - %(message)s')
+    l.configure_logging(args)
 
     default_has_github = registry.get_defaults('has-github', True)
 
diff --git a/jeepyb/cmd/notify_impact.py b/jeepyb/cmd/notify_impact.py
index 029c5d2..db0d859 100644
--- a/jeepyb/cmd/notify_impact.py
+++ b/jeepyb/cmd/notify_impact.py
@@ -31,6 +31,7 @@
 from __future__ import print_function
 
 import argparse
+import logging
 import os
 import re
 import smtplib
@@ -43,6 +44,9 @@
 
 from jeepyb import projects
 
+
+logger = logging.getLogger('notify_impact')
+
 BASE_DIR = '/home/gerrit2/review_site'
 EMAIL_TEMPLATE = """
 Hi, I'd like you to take a look at this patch for potential
@@ -140,6 +144,11 @@
     author_class = None
 
     buginfo, buglink = actions.create(project, bug_title, bug_descr, args)
+    logger.info('Created a bug in project %(project)s with title "%(title)s": '
+                '%(buglink)s'
+                % {'project': project,
+                   'title': bug_title,
+                   'buglink': buglink})
 
     # If the author of the merging patch matches our configured
     # subscriber lists, then subscribe the configured victims.
@@ -154,10 +163,35 @@
         config = config.get('subscriber_map', {}).get(author_class, [])
         for subscriber in config:
             actions.subscribe(buginfo, subscriber)
+            logger.info('Subscribed %(subscriber)s to bug %(buglink)s'
+                        % {'subscriber': subscriber,
+                           'buglink': buglink})
 
     return buglink
 
 
+def smtp_connection(args):
+    """Create SMTP connection based on command line arguments, falling
+    back to sensible defaults if no arguments are provided.
+    """
+    conn = None
+    if args.smtp_ssl:
+        port = 465 if not args.smtp_port else args.smtp_port
+        conn = smtplib.SMTP_SSL(args.smtp_host, port)
+    else:
+        port = 25 if not args.smtp_port else args.smtp_port
+        conn = smtplib.SMTP(args.smtp_host, port)
+
+    if args.smtp_starttls:
+        conn.starttls()
+        conn.ehlo()
+
+    if args.smtp_user and args.smtp_pass:
+        conn.login(args.smtp_user, args.smtp_pass)
+
+    return conn
+
+
 def process_impact(git_log, args, config):
     """Process DocImpact flag.
 
@@ -178,12 +212,11 @@
     msg = text.MIMEText(email_content)
     msg['Subject'] = '[%s] %s review request change %s' % \
         (args.project, args.impact, args.change)
-    msg['From'] = 'gerrit2@review.openstack.org'
+    msg['From'] = args.smtp_from
     msg['To'] = args.dest_address
 
-    s = smtplib.SMTP('localhost')
-    s.sendmail('gerrit2@review.openstack.org',
-               args.dest_address, msg.as_string())
+    s = smtp_connection(args)
+    s.sendmail(args.smtp_from, args.dest_address, msg.as_string())
     s.quit()
 
 
@@ -236,6 +269,22 @@
     parser.add_argument('--no-dryrun', dest='dryrun', action='store_false')
     parser.set_defaults(dryrun=False)
 
+    # SMTP configuration
+    parser.add_argument('--smtp-from', dest='smtp_from',
+                        default='gerrit2@review.openstack.org')
+
+    parser.add_argument('--smtp-host', dest='smtp_host', default="localhost")
+    parser.add_argument('--smtp-port', dest='smtp_port')
+
+    parser.add_argument('--smtp-ssl', dest='smtp_ssl', action='store_true')
+    parser.add_argument('--smtp-starttls', dest='smtp_starttls',
+                        action='store_true')
+
+    parser.add_argument('--smtp-user', dest='smtp_user',
+                        default=os.getenv('SMTP_USER'))
+    parser.add_argument('--smtp-pass', dest='smtp_pass',
+                        default=os.getenv('SMTP_PASS'))
+
     args = parser.parse_args()
 
     # NOTE(mikal): the basic idea here is to let people watch
diff --git a/jeepyb/cmd/openstackwatch.py b/jeepyb/cmd/openstackwatch.py
index 945674d..47add37 100644
--- a/jeepyb/cmd/openstackwatch.py
+++ b/jeepyb/cmd/openstackwatch.py
@@ -52,7 +52,7 @@
                                  section)
     if config.has_option(section, option):
         return config.get(section, option)
-    elif not default is None:
+    elif default is not None:
         return default
     else:
         raise ConfigurationError("Invalid configuration, missing "
@@ -105,7 +105,7 @@
             json_row = json.loads(row)
         except(ValueError):
             continue
-        if not json_row or not 'project' in json_row or \
+        if not json_row or 'project' not in json_row or \
                 json_row['project'] not in CONFIG['projects']:
             continue
         yield json_row
diff --git a/jeepyb/cmd/register_zanata_projects.py b/jeepyb/cmd/register_zanata_projects.py
new file mode 100644
index 0000000..6d64625
--- /dev/null
+++ b/jeepyb/cmd/register_zanata_projects.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import argparse
+import logging
+import os
+
+import jeepyb.log as l
+import jeepyb.projects as p
+import jeepyb.translations as t
+import jeepyb.utils as u
+
+PROJECTS_YAML = os.environ.get('PROJECTS_YAML', '/home/gerrit2/projects.yaml')
+ZANATA_URL = os.environ.get('ZANATA_URL')
+ZANATA_USER = os.environ.get('ZANATA_USER')
+ZANATA_KEY = os.environ.get('ZANATA_KEY')
+
+log = logging.getLogger('register_zanata_projects')
+
+
+def main():
+    parser = argparse.ArgumentParser(description='Register projects in Zanata')
+    l.setup_logging_arguments(parser)
+    args = parser.parse_args()
+    l.configure_logging(args)
+
+    registry = u.ProjectsRegistry(PROJECTS_YAML)
+    rest_service = t.ZanataRestService(ZANATA_URL, ZANATA_USER, ZANATA_KEY)
+    log.info("Registering projects in Zanata")
+    for entry in registry.configs_list:
+        project = entry['project']
+        if not p.has_translations(project):
+            continue
+        log.info("Processing project %s" % project)
+        (org, name) = project.split('/')
+        try:
+            translation_proect = t.TranslationProject(rest_service, name)
+            translation_proect.register()
+        except ValueError as e:
+            log.error(e)
+
+
+if __name__ == "__main__":
+    main()
diff --git a/jeepyb/cmd/trivial_rebase.py b/jeepyb/cmd/trivial_rebase.py
index 184ceb3..19e192b 100644
--- a/jeepyb/cmd/trivial_rebase.py
+++ b/jeepyb/cmd/trivial_rebase.py
@@ -113,7 +113,7 @@
                  "patch_sets.change_id = changes.change_id AND "
                  "patch_sets.patch_set_id = %s AND "
                  "changes.change_key = \'%s\'\"" % ((options.patchset - 1),
-                 options.changeId))
+                                                    options.changeId))
     revisions = GsqlQuery(sql_query, options)
 
     json_dict = json.loads(revisions[0], strict=False)
@@ -262,7 +262,7 @@
             approve_category = '--code-review'
         elif approval["category_id"] == "VRIF":
             # Don't re-add verifies
-            #approve_category = '--verified'
+            # approve_category = '--verified'
             continue
         elif approval["category_id"] == "SUBM":
             # We don't care about previous submit attempts
diff --git a/jeepyb/cmd/update_blueprint.py b/jeepyb/cmd/update_blueprint.py
index 1cff559..9e1f1ca 100644
--- a/jeepyb/cmd/update_blueprint.py
+++ b/jeepyb/cmd/update_blueprint.py
@@ -26,7 +26,7 @@
 
 from launchpadlib import launchpad
 from launchpadlib import uris
-import MySQLdb
+import PyMySQL
 
 from jeepyb import projects as p
 
@@ -132,7 +132,7 @@
 def main():
     parser = argparse.ArgumentParser()
     parser.add_argument('hook')
-    #common
+    # common
     parser.add_argument('--change', default=None)
     parser.add_argument('--change-url', default=None)
     parser.add_argument('--project', default=None)
@@ -140,7 +140,7 @@
     parser.add_argument('--commit', default=None)
     parser.add_argument('--topic', default=None)
     parser.add_argument('--change-owner', default=None)
-    #change-merged
+    # change-merged
     parser.add_argument('--submitter', default=None)
     # patchset-created
     parser.add_argument('--uploader', default=None)
@@ -154,8 +154,8 @@
         'Gerrit User Sync', uris.LPNET_SERVICE_ROOT, GERRIT_CACHE_DIR,
         credentials_file=GERRIT_CREDENTIALS, version='devel')
 
-    conn = MySQLdb.connect(
-        host=DB_HOST, user=DB_USER, passwd=DB_PASS, db=DB_DB)
+    conn = PyMySQL.connect(
+        host=DB_HOST, user=DB_USER, password=DB_PASS, db=DB_DB)
 
     find_specs(lpconn, conn, args)
 
diff --git a/jeepyb/cmd/update_bug.py b/jeepyb/cmd/update_bug.py
index 807aa46..43bd6c2 100644
--- a/jeepyb/cmd/update_bug.py
+++ b/jeepyb/cmd/update_bug.py
@@ -206,6 +206,7 @@
     """Apply changes to lp bug tasks, based on hook / branch."""
 
     bugtask = task.lp_task
+    series = None
 
     if args.hook == "change-abandoned":
         add_change_abandoned_message(bugtask, args.change_url,
@@ -223,11 +224,13 @@
                     set_fix_committed(bugtask)
         elif args.branch.startswith('proposed/'):
             release_fixcommitted(bugtask)
-        elif args.branch.startswith('stable/'):
-            series = args.branch[7:]
+        else:
+            series = args.branch.rsplit('/', 1)[-1]
+
+        if series:
             # Look for a related task matching the series.
             for reltask in bugtask.related_tasks:
-                if (reltask.bug_target_name.endswith("/" + series) and
+                if (reltask.bug_target_name.endswith(series) and
                         reltask.status != u'Fix Released' and
                         task.needs_change('set_fix_committed')):
                     set_fix_committed(reltask)
@@ -248,10 +251,13 @@
                     task.needs_change('set_in_progress')):
                 set_in_progress(bugtask, launchpad,
                                 args.uploader, args.change_url)
-        elif args.branch.startswith('stable/'):
-            series = args.branch[7:]
+        else:
+            series = args.branch.rsplit('/', 1)[-1]
+
+        if series:
+            # Look for a related task matching the series.
             for reltask in bugtask.related_tasks:
-                if (reltask.bug_target_name.endswith("/" + series) and
+                if (reltask.bug_target_name.endswith(series) and
                         task.needs_change('set_in_progress') and
                         reltask.status not in [u'Fix Committed',
                                                u'Fix Released']):
diff --git a/jeepyb/cmd/welcome_message.py b/jeepyb/cmd/welcome_message.py
index f4dbdf6..c8ed843 100644
--- a/jeepyb/cmd/welcome_message.py
+++ b/jeepyb/cmd/welcome_message.py
@@ -31,6 +31,7 @@
 import paramiko
 
 import jeepyb.gerritdb
+import jeepyb.log as l
 
 BASE_DIR = '/home/gerrit2/review_site'
 
@@ -79,12 +80,13 @@
     and resubmit a new change-set.
 
     Patches usually take 3 to 7 days to be reviewed so be patient and be
-    available on IRC to ask and answer questions about your work. The more you
-    participate in the community the more rewarding it is for you. You may also
-    notice that the more you get to know people and get to be known, the faster
-    your patches will be reviewed and eventually approved. Get to know others
-    and become known by doing code reviews: anybody can do it, and it's a
-    great way to learn the code base.
+    available on IRC to ask and answer questions about your work. Also it
+    takes generally at least a couple of weeks for cores to get around to
+    reviewing code. The more you participate in the community the more
+    rewarding it is for you. You may also notice that the more you get to know
+    people and get to be known, the faster your patches will be reviewed and
+    eventually approved. Get to know others and become known by doing code
+    reviews: anybody can do it, and it's a great way to learn the code base.
 
     Thanks again for supporting OpenStack, we look forward to working with you.
 
@@ -151,20 +153,12 @@
     # Don't actually post the message
     parser.add_argument('--dryrun', dest='dryrun', action='store_true')
     parser.add_argument('--no-dryrun', dest='dryrun', action='store_false')
-    parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
-                        help='verbose output')
     parser.set_defaults(dryrun=False)
+    l.setup_logging_arguments(parser)
 
     args = parser.parse_args()
 
-    if args.verbose:
-        logging.basicConfig(level=logging.DEBUG,
-                            format='%(asctime)-6s: %(name)s - %(levelname)s'
-                                   ' - %(message)s')
-    else:
-        logging.basicConfig(level=logging.ERROR,
-                            format='%(asctime)-6s: %(name)s - %(levelname)s'
-                                   ' - %(message)s')
+    l.configure_logging(args)
 
     # they're a first-timer, post the message on 1st patchset
     if is_newbie(args.uploader) and args.patchset == '1' and not args.dryrun:
diff --git a/jeepyb/gerritdb.py b/jeepyb/gerritdb.py
index 767991f..32ce3d9 100644
--- a/jeepyb/gerritdb.py
+++ b/jeepyb/gerritdb.py
@@ -52,10 +52,10 @@
         DB_PASS = secure_config.get("database", "password")
         DB_DB = gerrit_config.get("database", "database")
 
-        if DB_TYPE == "MYSQL":
-            import MySQLdb
-            db_connection = MySQLdb.connect(
-                host=DB_HOST, user=DB_USER, passwd=DB_PASS, db=DB_DB)
+        if DB_TYPE.upper() == "MYSQL":
+            import PyMySQL
+            db_connection = PyMySQL.connect(
+                host=DB_HOST, user=DB_USER, password=DB_PASS, db=DB_DB)
         else:
             import psycopg2
             db_connection = psycopg2.connect(
diff --git a/jeepyb/log.py b/jeepyb/log.py
new file mode 100644
index 0000000..86e3d39
--- /dev/null
+++ b/jeepyb/log.py
@@ -0,0 +1,37 @@
+# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+
+
+def setup_logging_arguments(parser):
+    """Sets up logging arguments, adds -d, -l and -v to the given parser."""
+    parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
+                        help='verbose output')
+    parser.add_argument('-d', dest='debug', action='store_true',
+                        help='debug output')
+    parser.add_argument('-l', dest='logfile', help='log file to use')
+
+
+def configure_logging(args):
+    if args.debug:
+        level = logging.DEBUG
+    elif args.verbose:
+        level = logging.INFO
+    else:
+        level = logging.ERROR
+    logging.basicConfig(level=level, filename=args.logfile,
+                        format='%(asctime)-6s: %(name)s - %(levelname)s'
+                               ' - %(message)s')
diff --git a/jeepyb/projects.py b/jeepyb/projects.py
index 81db5ba..5caaa66 100644
--- a/jeepyb/projects.py
+++ b/jeepyb/projects.py
@@ -75,6 +75,13 @@
     return True
 
 
+def has_translations(project_full_name):
+    try:
+        return 'translate' in registry[project_full_name]['options']
+    except KeyError:
+        return False
+
+
 def is_direct_release(project_full_name):
     try:
         return 'direct-release' in registry[project_full_name]['options']
diff --git a/jeepyb/translations.py b/jeepyb/translations.py
new file mode 100755
index 0000000..b814c74
--- /dev/null
+++ b/jeepyb/translations.py
@@ -0,0 +1,91 @@
+# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import json
+try:
+    from urllib.parse import urljoin
+except ImportError:
+    from urlparse import urljoin
+
+import requests
+
+
+class ZanataRestService:
+    def __init__(self, url, username, api_key, verify=False):
+        self.url = url
+        self.verify = verify
+        content_type = 'application/json;charset=utf8'
+        self.headers = {'Accept': content_type,
+                        'Content-Type': content_type,
+                        'X-Auth-User': username,
+                        'X-Auth-Token': api_key}
+
+    def _construct_url(self, url_fragment):
+        return urljoin(self.url, url_fragment)
+
+    def query(self, url_fragment):
+        request_url = self._construct_url(url_fragment)
+        try:
+            return requests.get(request_url, verify=self.verify,
+                                headers=self.headers)
+        except requests.exceptions.ConnectionError:
+            raise ValueError('Connection error')
+
+    def push(self, url_fragment, data):
+        request_url = self._construct_url(url_fragment)
+        try:
+            return requests.put(request_url, verify=self.verify,
+                                headers=self.headers, data=json.dumps(data))
+        except requests.exceptions.ConnectionError:
+            raise ValueError('Connection error')
+
+
+class TranslationProject:
+    def __init__(self, rest_service, project):
+        self.rest_service = rest_service
+        self.project = project
+
+    def is_registered(self):
+        r = self.rest_service.query('/rest/projects/p/%s' % self.project)
+        return r.status_code == 200
+
+    def has_master(self):
+        r = self.rest_service.query(
+            '/rest/projects/p/%s/iterations/i/master' % self.project)
+        return r.status_code == 200
+
+    def register_project(self):
+        project_data = {u'defaultType': u'Gettext', u'status': u'ACTIVE',
+                        u'id': self.project, u'name': self.project,
+                        u'description': self.project.title()}
+        r = self.rest_service.push('/rest/projects/p/%s' % self.project,
+                                   project_data)
+        return r.status_code in (200, 201)
+
+    def register_master_iteration(self):
+        iteration = {u'status': u'ACTIVE', u'projectType': u'Gettext',
+                     u'id': u'master'}
+        r = self.rest_service.push(
+            '/rest/projects/p/%s/iterations/i/master' % self.project,
+            iteration)
+        return r.status_code in (200, 201)
+
+    def register(self):
+        if not self.is_registered():
+            if not self.register_project():
+                raise ValueError('Failed to register project.')
+        if not self.has_master():
+            if not self.register_master_iteration():
+                raise ValueError('Failed to register master iteration.')
diff --git a/requirements.txt b/requirements.txt
index 32faa12..9390472 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,11 +2,12 @@
 
 argparse
 gerritlib>=0.3.0
-MySQL-python
+PyMySQL
 paramiko
 PyGithub
 pyyaml
 pkginfo
 PyRSS2Gen
 python-swiftclient
+requests>=2.5.2
 six>=1.7.0
diff --git a/setup.cfg b/setup.cfg
index 12e056e..8cc0e28 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -20,11 +20,13 @@
 console_scripts =
     close-pull-requests = jeepyb.cmd.close_pull_requests:main
     create-cgitrepos = jeepyb.cmd.create_cgitrepos:main
+    create-hound-config = jeepyb.cmd.create_hound_config:main
     expire-old-reviews = jeepyb.cmd.expire_old_reviews:main
     manage-projects = jeepyb.cmd.manage_projects:main
     notify-impact = jeepyb.cmd.notify_impact:main
     openstackwatch = jeepyb.cmd.openstackwatch:main
     process-cache = jeepyb.cmd.process_cache:main
+    register-zanata-projects = jeepyb.cmd.register_zanata_projects:main
     trivial-rebase = jeepyb.cmd.trivial_rebase:main
     update-blueprint = jeepyb.cmd.update_blueprint:main
     update-bug = jeepyb.cmd.update_bug:main