ATC listing script is importable
* tools/atc/email_stats.py: Move procedural code out of the global scope to make this file safely importable, and clean up a couple of unused variables flake8 noticed in the newly importable main codeblock. Change-Id: I1a29c84e067eea875ba57a16196723f65f60ff01
This commit is contained in:
parent
1c608c8143
commit
876ba7a23b
75
tools/atc/email_stats.py
Executable file → Normal file
75
tools/atc/email_stats.py
Executable file → Normal file
@ -28,7 +28,6 @@ import re
|
|||||||
|
|
||||||
MAILTO_RE = re.compile('mailto:(.*)')
|
MAILTO_RE = re.compile('mailto:(.*)')
|
||||||
USERNAME_RE = re.compile('username:(.*)')
|
USERNAME_RE = re.compile('username:(.*)')
|
||||||
accounts = {}
|
|
||||||
|
|
||||||
|
|
||||||
class Account(object):
|
class Account(object):
|
||||||
@ -39,17 +38,21 @@ class Account(object):
|
|||||||
self.username = None
|
self.username = None
|
||||||
|
|
||||||
|
|
||||||
def get_account(num):
|
def get_account(accounts, num):
|
||||||
a = accounts.get(num)
|
a = accounts.get(num)
|
||||||
if not a:
|
if not a:
|
||||||
a = Account(num)
|
a = Account(num)
|
||||||
accounts[num] = a
|
accounts[num] = a
|
||||||
return a
|
return a
|
||||||
|
|
||||||
for row in csv.reader(open('emails.csv')):
|
|
||||||
|
def main():
|
||||||
|
accounts = {}
|
||||||
|
|
||||||
|
for row in csv.reader(open('emails.csv')):
|
||||||
num, email, pw, external = row
|
num, email, pw, external = row
|
||||||
num = int(num)
|
num = int(num)
|
||||||
a = get_account(num)
|
a = get_account(accounts, num)
|
||||||
if email and email != '\\N' and email not in a.emails:
|
if email and email != '\\N' and email not in a.emails:
|
||||||
a.emails.append(email)
|
a.emails.append(email)
|
||||||
m = MAILTO_RE.match(external)
|
m = MAILTO_RE.match(external)
|
||||||
@ -64,46 +67,45 @@ for row in csv.reader(open('emails.csv')):
|
|||||||
raise Exception("Already a username")
|
raise Exception("Already a username")
|
||||||
a.username = m.group(1)
|
a.username = m.group(1)
|
||||||
|
|
||||||
for row in csv.reader(open('accounts.csv')):
|
for row in csv.reader(open('accounts.csv')):
|
||||||
num = int(row[-1])
|
num = int(row[-1])
|
||||||
name = row[1]
|
name = row[1]
|
||||||
a = get_account(num)
|
a = get_account(accounts, num)
|
||||||
a.full_name = name
|
a.full_name = name
|
||||||
|
|
||||||
username_accounts = {}
|
username_accounts = {}
|
||||||
for a in accounts.values():
|
for a in accounts.values():
|
||||||
username_accounts[a.username] = a
|
username_accounts[a.username] = a
|
||||||
|
|
||||||
atcs = []
|
atcs = []
|
||||||
|
|
||||||
optparser = optparse.OptionParser()
|
optparser = optparse.OptionParser()
|
||||||
optparser.add_option(
|
optparser.add_option(
|
||||||
'-p', '--project', default='nova', help='Project to generate stats for')
|
'-p', '--project', default='nova',
|
||||||
optparser.add_option(
|
help='Project to generate stats for')
|
||||||
|
optparser.add_option(
|
||||||
'-o', '--output', default='out.csv', help='Output file')
|
'-o', '--output', default='out.csv', help='Output file')
|
||||||
options, args = optparser.parse_args()
|
options, args = optparser.parse_args()
|
||||||
|
|
||||||
QUERY = "project:%s status:merged" % options.project
|
QUERY = "project:%s status:merged" % options.project
|
||||||
|
|
||||||
client = paramiko.SSHClient()
|
client = paramiko.SSHClient()
|
||||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
client.load_system_host_keys()
|
client.load_system_host_keys()
|
||||||
client.connect(
|
client.connect(
|
||||||
'review.openstack.org', port=29418,
|
'review.openstack.org', port=29418,
|
||||||
key_filename='/home/corvus/.ssh/id_rsa', username='CHANGME')
|
key_filename='/home/corvus/.ssh/id_rsa', username='CHANGME')
|
||||||
stdin, stdout, stderr = client.exec_command(
|
stdin, stdout, stderr = client.exec_command(
|
||||||
'gerrit query %s --all-approvals --format JSON' % QUERY)
|
'gerrit query %s --all-approvals --format JSON' % QUERY)
|
||||||
changes = []
|
|
||||||
|
|
||||||
done = False
|
done = False
|
||||||
last_sortkey = ''
|
last_sortkey = ''
|
||||||
tz = datetime.tzinfo
|
start_date = datetime.datetime(2012, 9, 27, 0, 0, 0)
|
||||||
start_date = datetime.datetime(2012, 9, 27, 0, 0, 0)
|
end_date = datetime.datetime(2013, 7, 30, 0, 0, 0)
|
||||||
end_date = datetime.datetime(2013, 7, 30, 0, 0, 0)
|
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
earliest = datetime.datetime.now()
|
earliest = datetime.datetime.now()
|
||||||
while not done:
|
while not done:
|
||||||
for l in stdout:
|
for l in stdout:
|
||||||
data = json.loads(l)
|
data = json.loads(l)
|
||||||
if 'rowCount' in data:
|
if 'rowCount' in data:
|
||||||
@ -137,10 +139,13 @@ while not done:
|
|||||||
'gerrit query %s resume_sortkey:%s --all-approvals'
|
'gerrit query %s resume_sortkey:%s --all-approvals'
|
||||||
' --format JSON' % (QUERY, last_sortkey))
|
' --format JSON' % (QUERY, last_sortkey))
|
||||||
|
|
||||||
print 'project: %s' % options.project
|
print 'project: %s' % options.project
|
||||||
print 'examined %s changes' % count
|
print 'examined %s changes' % count
|
||||||
print 'earliest timestamp: %s' % earliest
|
print 'earliest timestamp: %s' % earliest
|
||||||
writer = csv.writer(open(options.output, 'w'))
|
writer = csv.writer(open(options.output, 'w'))
|
||||||
for a in atcs:
|
for a in atcs:
|
||||||
writer.writerow([a.username, a.full_name] + a.emails)
|
writer.writerow([a.username, a.full_name] + a.emails)
|
||||||
print
|
print
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user