Skip to content

Commit

Permalink
Merge pull request Katello#200 from tstrachota/cli_fixes
Browse files Browse the repository at this point in the history
Cli fixes
  • Loading branch information
Tom McKay committed Jun 13, 2012
2 parents 23d9f47 + b8c6165 commit 036eab5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 51 deletions.
12 changes: 7 additions & 5 deletions cli/src/katello/client/cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ def setup_parser(self, parser):
@note: this method may be overridden to define new options
"""
parser.add_option("-v", "--version", action="store_true", default=False,
dest="version", help=_('prints version information'))
dest="version", help=_('prints version information'))

credentials = OptionGroup(parser, _('Katello User Account Credentials'))
credentials.add_option('-u', '--username', dest='username',
default=None, help=_('account username'))
default=None, help=_('account username'))
credentials.add_option('-p', '--password', dest='password',
default=None, help=_('account password'))
default=None, help=_('account password'))
credentials.add_option('--cert-file', dest='certfile',
default=None, help=SUPPRESS_HELP)
default=None, help=SUPPRESS_HELP)
credentials.add_option('--key-file', dest='keyfile',
default=None, help=SUPPRESS_HELP)
default=None, help=SUPPRESS_HELP)
parser.add_option_group(credentials)

server = OptionGroup(parser, _('Katello Server Information'))
Expand Down Expand Up @@ -138,6 +138,8 @@ def error(self, exception, errorMsg = None):
def run(self):
self.setup_server()
self.setup_credentials()
if self.get_option('version'):
self.args = ["version"]

def main(self, args, command_name=None, parent_usage=None):
try:
Expand Down
51 changes: 6 additions & 45 deletions cli/src/katello/client/core/system_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from katello.client.core.base import BaseAction, Command
from katello.client.api.system_group import SystemGroupAPI
from katello.client.api.utils import get_system_group
from katello.client.core.utils import is_valid_record
from katello.client.core.utils import test_record


Config()
Expand Down Expand Up @@ -56,16 +56,12 @@ def run(self):
org_name = self.get_option('org')

system_groups = self.api.system_groups(org_name)

self.printer.set_header(_("System Groups List For Org [ %s ]") % org_name)

if system_groups is None:
return os.EX_DATAERR

self.printer.set_header(_("System Groups List For Org [ %s ]") % org_name)
self.printer.add_column('id')
self.printer.add_column('name')

self.printer._grep = True
self.printer.print_items(system_groups)
return os.EX_OK

Expand Down Expand Up @@ -95,12 +91,10 @@ def run(self):

system_group = self.api.create(org_name, name, description, max_systems)

if is_valid_record(system_group):
print _("Successfully created system group [ %s ]") % system_group['name']
return os.EX_OK
else:
print >> sys.stderr, _("Could not create system group [ %s ]") % name
return os.EX_DATAERR
test_record(system_group,
_("Successfully created system group [ %s ]") % system_group['name'],
_("Could not create system group [ %s ]") % name
)


class Info(SystemGroupAction):
Expand All @@ -125,9 +119,6 @@ def run(self):
# get system details
system_group = get_system_group(org_name, system_group_name)

if not system_group:
return os.EX_DATAERR

self.printer.add_column('id')
self.printer.add_column('name')
self.printer.add_column('description', multiline=True)
Expand Down Expand Up @@ -159,10 +150,6 @@ def run(self):

system_group = get_system_group(org_name, system_group_name)

if not system_group:
return os.EX_DATAERR


# get list of jobs
history = self.api.system_group_history(org_name, system_group['id'])

Expand Down Expand Up @@ -200,7 +187,6 @@ def run(self):
org_name = self.get_option('org')
system_group_name = self.get_option('name')
job_id = self.get_option('job_id')
# info is always grep friendly

self.printer.set_header(_("System Group Job tasks For [ %s ]") % (system_group_name))

Expand Down Expand Up @@ -251,8 +237,6 @@ def run(self):

system_group = get_system_group(org_name, name)

if system_group is None:
return os.EX_DATAERR

system_group = self.api.update(org_name, system_group["id"], new_name, new_description, max_systems)

Expand Down Expand Up @@ -281,11 +265,8 @@ def run(self):
name = self.get_option('name')

system_group = get_system_group(org_name, name)
if not system_group:
return os.EX_DATAERR

message = self.api.delete(org_name, system_group["id"])

if message != None:
print message
return os.EX_OK
Expand All @@ -309,23 +290,17 @@ def check_options(self, validator):
def run(self):
org_name = self.get_option('org')
system_group_name = self.get_option('name')
# info is always grep friendly

# get system details
system_group = get_system_group(org_name, system_group_name)
if not system_group:
return os.EX_DATAERR

systems = self.api.system_group_systems(org_name, system_group["id"])

if systems is None:
return os.EX_DATAERR

self.printer.set_header(_("Systems within System Group [ %s ] For Org [ %s ]") % (system_group["name"], org_name))

self.printer.add_column('id')
self.printer.add_column('name')

self.printer.print_items(systems)

return os.EX_OK
Expand All @@ -347,13 +322,9 @@ def check_options(self, validator):
def run(self):
org_name = self.get_option('org')
system_group_name = self.get_option('name')
# info is always grep friendly

# get system details
system_group = get_system_group(org_name, system_group_name)
if not system_group:
return os.EX_DATAERR

system_group = self.api.lock(org_name, system_group["id"])

if system_group != None:
Expand All @@ -379,13 +350,9 @@ def check_options(self, validator):
def run(self):
org_name = self.get_option('org')
system_group_name = self.get_option('name')
# info is always grep friendly

# get system details
system_group = get_system_group(org_name, system_group_name)
if not system_group:
return os.EX_DATAERR

system_group = self.api.unlock(org_name, system_group["id"])

if system_group != None:
Expand Down Expand Up @@ -417,9 +384,6 @@ def run(self):

system_group = get_system_group(org_name, name)

if system_group is None:
return os.EX_DATAERR

systems = self.api.add_systems(org_name, system_group["id"], system_ids)

if systems != None:
Expand Down Expand Up @@ -451,9 +415,6 @@ def run(self):

system_group = get_system_group(org_name, name)

if system_group is None:
return os.EX_DATAERR

systems = self.api.remove_systems(org_name, system_group["id"], system_ids)

if systems != None:
Expand Down
4 changes: 3 additions & 1 deletion cli/src/katello/client/core/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# in this software or its documentation.
#

import os
from gettext import gettext as _

from katello.client.api.version import VersionAPI
Expand Down Expand Up @@ -45,7 +46,8 @@ def check_options(self, validator):
return 0

def run(self):
return self.api.version_formatted()
print self.api.version_formatted()
return os.EX_OK


# ping command ------------------------------------------------------------
Expand Down

0 comments on commit 036eab5

Please sign in to comment.