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
19
tools/atc/email_stats.py
Executable file → Normal file
19
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
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
accounts = {}
|
||||||
|
|
||||||
for row in csv.reader(open('emails.csv')):
|
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)
|
||||||
@ -67,7 +70,7 @@ for row in csv.reader(open('emails.csv')):
|
|||||||
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 = {}
|
||||||
@ -78,7 +81,8 @@ 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',
|
||||||
|
help='Project to generate stats for')
|
||||||
optparser.add_option(
|
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()
|
||||||
@ -93,11 +97,9 @@ client.connect(
|
|||||||
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)
|
||||||
|
|
||||||
@ -144,3 +146,6 @@ 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