Commit 8c4cbb98 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

Fix stdout/stderr write in astakos/quota commands

Write actual command output and user prompts to stdout; error and progress
messages to stderr.
parent 6d0d27d4
......@@ -111,6 +111,6 @@ class Command(BaseCommand):
profile.save()
if update:
print "Profile updated"
self.stderr.write("Profile updated\n")
else:
print "Profile stored"
self.stderr.write("Profile stored\n")
......@@ -44,10 +44,10 @@ class Command(NoArgsCommand):
help = "Cleanup sessions and session catalog"
def handle_noargs(self, **options):
self.stdout.write('Cleanup sessions ...\n')
self.stderr.write('Cleanup sessions ...\n')
call_command('cleanup')
self.stdout.write('Cleanup session catalog ...\n')
self.stderr.write('Cleanup session catalog ...\n')
engine = import_module(settings.SESSION_ENGINE)
store = engine.SessionStore()
tbd = (entry for entry in SessionCatalog.objects.all()
......
......@@ -49,8 +49,8 @@ class Command(NoArgsCommand):
fixed = fix_superusers()
count = len(fixed)
if count != 0:
self.stdout.write("Fixed %s superuser(s).\n" % count)
self.stderr.write("Fixed %s superuser(s).\n" % count)
else:
self.stdout.write("No superuser needed a fix.\n")
self.stderr.write("No superuser needed a fix.\n")
except BaseException, e:
raise CommandError(e)
......@@ -47,4 +47,4 @@ class Command(BaseCommand):
raise CommandError("Invalid number of arguments")
Group.objects.get_or_create(name=args[0].strip())
print "Group created"
self.stderr.write("Group created\n")
......@@ -124,23 +124,23 @@ class Command(BaseCommand):
s = '1 expired project:\n'
else:
s = '%d expired projects:\n' % (length,)
self.stdout.write(s)
self.stderr.write(s)
if length > 0:
labels = ('Project', 'Name', 'Status', 'Expiration date')
columns = (10, 30, 14, 30)
line = ' '.join(l.rjust(w) for l, w in zip(labels, columns))
self.stdout.write(line + '\n')
self.stderr.write(line + '\n')
sep = '-' * len(line)
self.stdout.write(sep + '\n')
self.stderr.write(sep + '\n')
for project in projects:
line = ' '.join(f.rjust(w) for f, w in zip(project, columns))
self.stdout.write(line + '\n')
self.stderr.write(line + '\n')
if execute:
self.stdout.write('%d projects have been terminated.\n' % (
self.stderr.write('%d projects have been terminated.\n' % (
length,))
def expire(self, execute=False):
......
......@@ -79,20 +79,20 @@ class Command(SynnefoCommand):
def print_sync(self, diff_quotas):
size = len(diff_quotas)
if size == 0:
self.stdout.write("No sync needed.\n")
self.stderr.write("No sync needed.\n")
else:
self.stdout.write("Synced %s users:\n" % size)
self.stderr.write("Synced %s users:\n" % size)
uuids = diff_quotas.keys()
users = AstakosUser.objects.filter(uuid__in=uuids)
for user in users:
self.stdout.write("%s (%s)\n" % (user.uuid, user.username))
self.stderr.write("%s (%s)\n" % (user.uuid, user.username))
def print_verify(self, qh_limits, diff_quotas):
for holder, local in diff_quotas.iteritems():
registered = qh_limits.pop(holder, None)
user = get_user_by_uuid(holder)
if registered is None:
self.stdout.write(
self.stderr.write(
"No quota for %s (%s) in quotaholder.\n" %
(holder, user.username))
else:
......@@ -105,4 +105,4 @@ class Command(SynnefoCommand):
diffs = len(diff_quotas)
if diffs:
self.stdout.write("Quota differ for %d users.\n" % (diffs))
self.stderr.write("Quota differ for %d users.\n" % (diffs))
......@@ -69,7 +69,7 @@ class Command(BaseCommand):
@transaction.commit_on_success
def handle(self, *args, **options):
write = self.stdout.write
write = self.stderr.write
force = options['force']
userid = options['userid']
......@@ -130,7 +130,7 @@ class Command(BaseCommand):
headers = ("User", "Resource", "Astakos", "Quotaholder")
if unsynced:
pprint_table(self.stderr, unsynced, headers)
pprint_table(self.stdout, unsynced, headers)
if options["fix"]:
provisions = map(create_provision, unsynced)
try:
......
......@@ -111,7 +111,7 @@ class Command(BaseCommand):
resource = self.get_resource(resource_name)
resource.api_visible = allow
if not allow and resource.ui_visible:
self.stdout.write("Also resetting 'ui_visible' for consistency.\n")
self.stderr.write("Also resetting 'ui_visible' for consistency.\n")
resource.ui_visible = False
resource.save()
......@@ -127,7 +127,7 @@ class Command(BaseCommand):
resource.ui_visible = allow
if allow and not resource.api_visible:
self.stdout.write("Also setting 'api_visible' for consistency.\n")
self.stderr.write("Also setting 'api_visible' for consistency.\n")
resource.api_visible = True
resource.save()
......@@ -196,7 +196,7 @@ class Command(BaseCommand):
updates.append((resource, value))
break
if updates:
self.stdout.write("Updating...\n")
self.stderr.write("Updating...\n")
update_resources(updates)
def parse_limit(self, limit):
......
......@@ -73,7 +73,7 @@ class Command(BaseCommand):
self.add_services(data)
def add_services(self, data):
write = self.stdout.write
write = self.stderr.write
output = []
for name, service_dict in data.iteritems():
try:
......@@ -91,7 +91,7 @@ class Command(BaseCommand):
try:
existed = add_service(component, name, service_type, endpoints,
out=self.stdout)
out=self.stderr)
except RegisterException as e:
raise CommandError(e.message)
......
......@@ -59,4 +59,4 @@ class Command(BaseCommand):
activation_backend.send_user_verification_email(user)
self.stdout.write("Activation sent to '%s'\n" % (user.email,))
self.stderr.write("Activation sent to '%s'\n" % (user.email,))
......@@ -257,7 +257,7 @@ class Command(BaseCommand):
group = Group.objects.get(name=groupname)
user.groups.add(group)
except Group.DoesNotExist, e:
self.stdout.write(
self.stderr.write(
"Group named %s does not exist\n" % groupname)
groupname = options.get('delete-group')
......@@ -266,7 +266,7 @@ class Command(BaseCommand):
group = Group.objects.get(name=groupname)
user.groups.remove(group)
except Group.DoesNotExist, e:
self.stdout.write(
self.stderr.write(
"Group named %s does not exist\n" % groupname)
pname = options.get('add-permission')
......@@ -274,13 +274,13 @@ class Command(BaseCommand):
try:
r, created = add_user_permission(user, pname)
if created:
self.stdout.write(
self.stderr.write(
'Permission: %s created successfully\n' % pname)
if r > 0:
self.stdout.write(
self.stderr.write(
'Permission: %s added successfully\n' % pname)
elif r == 0:
self.stdout.write(
self.stderr.write(
'User has already permission: %s\n' % pname)
except Exception, e:
raise CommandError(e)
......@@ -290,12 +290,12 @@ class Command(BaseCommand):
try:
r = remove_user_permission(user, pname)
if r < 0:
self.stdout.write(
self.stderr.write(
'Invalid permission codename: %s\n' % pname)
elif r == 0:
self.stdout.write('User has not permission: %s\n' % pname)
self.stderr.write('User has not permission: %s\n' % pname)
elif r > 0:
self.stdout.write(
self.stderr.write(
'Permission: %s removed successfully\n' % pname)
except Exception, e:
raise CommandError(e)
......@@ -374,7 +374,7 @@ class Command(BaseCommand):
self.stdout.write("Confirm? [y/N] ")
response = raw_input()
if string.lower(response) not in ['y', 'yes']:
self.stdout.write("Aborted.\n")
self.stderr.write("Aborted.\n")
exit()
def handle_limits_user(self, user, res, capacity, style):
......
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'synnefo.settings'
import sys
from optparse import OptionParser
from synnefo.lib.services import fill_endpoints, filter_public
from django.utils import simplejson as json
......@@ -303,7 +304,7 @@ def main():
try:
services = definitions[component]
except KeyError:
print "Unrecognized component %s" % component
print >> sys.stderr, "Unrecognized component %s" % component
exit(1)
base_url = args[1]
print_definitions(services, base_url)
......
......@@ -77,10 +77,10 @@ class Command(SynnefoCommand):
)
def confirm(self):
self.stderr.write("Confirm? [y/N] ")
self.stdout.write("Confirm? [y/N] ")
response = raw_input()
if string.lower(response) not in ['y', 'yes']:
self.stdout.write("Aborted.\n")
self.stderr.write("Aborted.\n")
exit()
def get_handlers(self, resources):
......@@ -180,11 +180,11 @@ class Command(SynnefoCommand):
return
headers = ("#", "User", "Source", "Resource", "Limit", "Usage")
pprint_table(self.stderr, overlimit, headers,
pprint_table(self.stdout, overlimit, headers,
options["output_format"], title="Violations")
if any(actions.values()):
write("\n")
self.stdout.write("\n")
if fix:
if dangerous and not force:
write("You are enforcing resources that may permanently "
......@@ -197,5 +197,5 @@ class Command(SynnefoCommand):
headers = ("Type", "ID", "State", "Backend", "Action", "Violation")
if fix:
headers += ("Result",)
pprint_table(self.stderr, log, headers,
pprint_table(self.stdout, log, headers,
options["output_format"], title=title)
......@@ -65,7 +65,7 @@ class Command(BaseCommand):
)
def handle(self, *args, **options):
write = self.stdout.write
write = self.stderr.write
userid = options['userid']
# Get holdings from Cyclades DB
......@@ -117,7 +117,7 @@ class Command(BaseCommand):
headers = ("User", "Resource", "Database", "Quotaholder")
if unsynced:
pprint_table(self.stderr, unsynced, headers)
pprint_table(self.stdout, unsynced, headers)
if options["fix"]:
qh = quotas.Quotaholder.get()
request = {}
......
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