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