Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/management/bin/generateHgAuth.py

Issue 11275006: Added script to generate notification.json for the emergencynotification mechanism (Closed)
Patch Set: Fixed closing and iterating through tar files Created July 29, 2013, 2:08 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « .sitescripts.example ('k') | sitescripts/management/bin/generateNotifications.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/management/bin/generateHgAuth.py
===================================================================
--- a/sitescripts/management/bin/generateHgAuth.py
+++ b/sitescripts/management/bin/generateHgAuth.py
@@ -21,18 +21,17 @@ from sitescripts.utils import get_config
def generateData(authRepo):
command = ['hg', '-R', authRepo, 'archive', '-r', 'default', '-t', 'tar', '-p', '.', '-']
data = subprocess.check_output(command)
users = {}
repos = []
tarFile = tarfile.open(mode='r:', fileobj=StringIO(data))
- fileInfo = tarFile.next()
- while fileInfo:
+ for fileInfo in tarFile:
name = fileInfo.name
if name.startswith('./'):
name = name[2:]
if fileInfo.type == tarfile.REGTYPE and name.startswith('users/'):
name = os.path.basename(name).lower()
options = []
match = re.search(r'^(.*)\[(.*)\]$', name)
@@ -57,17 +56,16 @@ def generateData(authRepo):
else:
print >>sys.stderr, 'Unknown user option: %s' % option
user['key'] = re.sub(r'\s', '', tarFile.extractfile(fileInfo).read())
users[name] = user
elif fileInfo.type == tarfile.REGTYPE and name.startswith('repos/'):
repos.append(fileInfo)
elif fileInfo.type == tarfile.REGTYPE and not name.startswith('.'):
print >>sys.stderr, 'Unrecognized file in the repository: %s' % name
- fileInfo = tarFile.next()
for fileInfo in repos:
name = os.path.basename(fileInfo.name).lower()
repoUsers = tarFile.extractfile(fileInfo).readlines()
for user in repoUsers:
user = user.strip()
if user == '' or user.startswith('#'):
continue
@@ -80,21 +78,22 @@ def generateData(authRepo):
if user['disabled']:
continue
yield 'no-pty,environment="HGUSER=%s",environment="HGREPOS=%s" %s %s\n' % (
user['name'] if not user['trusted'] else '',
' '.join(user['repos']),
'ssh-rsa' if user['keytype'] == 'rsa' else 'ssh-dss',
user['key']
)
+ tarFile.close()
def hook(ui, repo, **kwargs):
setupStderr()
- result = generateData(get_config().get('hg', 'auth_repository'))
+ result = generateData(repo)
file = open(get_config().get('hg', 'auth_file'), 'wb')
for s in result:
file.write(s)
file.close()
if __name__ == '__main__':
- hook()
+ hook(None, get_config().get('hg', 'auth_repository'))
« no previous file with comments | « .sitescripts.example ('k') | sitescripts/management/bin/generateNotifications.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld