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')) |