Commit 83dfe64a authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

astakos: Use `with' to open file in management command

parent a0f09a72
......@@ -49,6 +49,7 @@ AddResourceArgs = namedtuple('AddQuotaArgs', ('resource',
'capacity',
))
class Command(BaseCommand):
help = """Import user quota limits from file or set quota
for a single user from the command line
......@@ -171,12 +172,8 @@ for a single user from the command line
qh_sync_user(user.id)
def import_from_file(self, location):
try:
f = open(location, 'r')
except IOError, e:
raise CommandError(e)
users = set()
with open(location) as f:
for line in f.readlines():
try:
t = line.rstrip('\n').split(' ')
......@@ -190,7 +187,8 @@ for a single user from the command line
user = AstakosUser.objects.get(uuid=user)
users.add(user.id)
except AstakosUser.DoesNotExist:
self.stdout.write('Not found user having uuid: %s\n' % user)
self.stdout.write('Not found user having uuid: %s\n'
% user)
continue
else:
try:
......@@ -198,9 +196,6 @@ for a single user from the command line
except Exception, e:
self.stdout.write('Failed to policy: %s\n' % e)
continue
finally:
f.close()
qh_sync_users(users)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment