Allow importing the owner script.

This change modifies the usage of the script so that it can be imported by
the election module. It also fixes maketrans support for python3.

Change-Id: Ie3b602237625e11651825abc8feb38caa73e9632
This commit is contained in:
Tristan Cacqueray 2017-01-26 04:08:47 +00:00
parent f6d93be297
commit 31b9fc7ba3

View File

@ -94,12 +94,16 @@ import csv
import datetime
import json
import os
import string
import sys
import requests
import yaml
try:
from string import maketrans
except ImportError: # Python3
maketrans = bytes.maketrans
def dumper(data, stream):
"""Convenience wrapper to consistently set YAML formatting"""
@ -119,7 +123,7 @@ def normalize_email(email):
def normalize_project(project):
"""Replace spaces and hyphens with underscores in project teams
and then lower-case them, for more convenient filenames"""
return project.translate(string.maketrans(' -', '__')).lower()
return project.translate(maketrans(' -', '__')).lower()
def date_merged(change, after=None, before=None):
@ -178,14 +182,8 @@ def query_gerrit(query):
return decoded
def main():
"""The giant pile of spaghetti which does everything else"""
# Record the start time for use later
start = datetime.datetime.utcnow()
# TODO(fungi): this could be trivially extracted to a separate
# function
def usage(argv):
"""Parse command line argument"""
parser = argparse.ArgumentParser(
description="When run using OpenStack's Gerrit server, this builds "
"YAML representations of aggregate change owner details and change "
@ -203,7 +201,16 @@ def main():
parser.add_argument("-o", "--outdir", help="Create an output directory")
parser.add_argument("-r", "--ref", help="Specify a Governance refname")
parser.add_argument("-s", "--sieve", help="Add Gerrit query parameters")
options = parser.parse_args()
return parser.parse_args(argv[1:])
def main(argv=sys.argv):
"""The giant pile of spaghetti which does everything else"""
# Record the start time for use later
start = datetime.datetime.utcnow()
options = usage(argv)
# If we're supplied a configuration file, use it
if options.config:
@ -638,4 +645,5 @@ def main():
fd.writelines(electorate)
fd.close()
main()
if __name__ == "__main__":
main()