Skip to content

Commit

Permalink
Merge branch 'master' into rails309
Browse files Browse the repository at this point in the history
  • Loading branch information
swarmingbee committed Sep 21, 2011
2 parents 052ed44 + 88804cf commit abf9ba7
Show file tree
Hide file tree
Showing 206 changed files with 6,100 additions and 1,825 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ src/locale/pom.xml
.settings
cli/po/build
cli/po/POTFILES.in

cli/cover
5 changes: 4 additions & 1 deletion cli/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SRC_DIR = src/katello
SRC_DIR = src/katello

po/POTFILES.in:
# generate the POTFILES.in file expected by intltool. it wants one
Expand All @@ -23,3 +23,6 @@ uniq-po:
for f in $(shell find po/ -name "*.po") ; do \
msguniq $$f -o $$f ; \
done

cover:
nosetests --with-coverage --cover-package=katello --cover-html --cover-inclusive .
2 changes: 2 additions & 0 deletions cli/bin/katello
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def setup_admin(admin):
org_cmd.add_action('list', organization.List())
org_cmd.add_action('update', organization.Update())
org_cmd.add_action('delete', organization.Delete())
org_cmd.add_action('generate_debug_cert', organization.GenerateDebugCert())
org_cmd.add_action('delete_debug_cert', organization.DeleteDebugCert())
admin.add_command('org', org_cmd)

user_cmd = user.User()
Expand Down
13 changes: 13 additions & 0 deletions cli/katello-cli.spec
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# vim: sw=4:ts=4:et
#
# Copyright 2011 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

%define base_name katello

Name: %{base_name}-cli
Expand Down
9 changes: 9 additions & 0 deletions cli/src/katello/client/api/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ def organization(self, name):
path = "/api/organizations/%s" % str(name)
org = self.server.GET(path)[1]
return org

def generate_debug_cert(self, name):
path = "/api/organizations/%s/generate_debug_cert" % str(name)
return self.server.POST(path, {})[1]

def delete_debug_cert(self, name):
path = "/api/organizations/%s/delete_debug_cert" % str(name)
return self.server.POST(path, {})[1]

4 changes: 2 additions & 2 deletions cli/src/katello/client/api/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
class TemplateAPI(KatelloAPI):

def templates(self, envId):
path = "/api/templates/"
tpls = self.server.GET(path, {"environment_id": envId})[1]
path = "/api//environments/%s/templates/" % str(envId)
tpls = self.server.GET(path)[1]
return tpls


Expand Down
29 changes: 25 additions & 4 deletions cli/src/katello/client/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
from katello.client.logutil import getLogger
from katello.client.server import ServerRequestError

from copy import copy
from optparse import Option, OptionValueError

Config()
_log = getLogger(__name__)

Expand Down Expand Up @@ -103,7 +106,7 @@ def get_action(self, name):

def process_options(self, args):

self.parser = OptionParser()
self.parser = OptionParser(option_class=KatelloOption)
self.parser.disable_interspersed_args()
self.parser.set_usage(self.usage)
if not args:
Expand Down Expand Up @@ -158,7 +161,7 @@ def __init__(self):
self.optErrors = []
self.printer = None

self.parser = OptionParser()
self.parser = OptionParser(option_class=KatelloOption)
self.parser.add_option('-g', dest='grep',
action="store_true",
help=_("grep friendly output"))
Expand Down Expand Up @@ -323,9 +326,12 @@ def require_credentials(self):
return True

def error(self, errorMsg):
print errorMsg
_log.error("error: %s" % str(errorMsg))
print >> sys.stderr, _('error: operation failed: ') + str(errorMsg)
if str(errorMsg) == '':
msg = _('error: operation failed')
else:
msg = str(errorMsg)
print >> sys.stderr, msg

def main(self, args):
"""
Expand All @@ -352,6 +358,8 @@ def main(self, args):
msg = ", ".join(re.args[1]["errors"])
except:
msg = re.args[1]
if re.args[0] == 401:
msg = _("Invalid credentials or unable to authenticate")

self.error(msg)
return re.args[0]
Expand Down Expand Up @@ -379,3 +387,16 @@ def main(self, args):
return os.EX_NOUSER

print ''

# optparse type extenstions --------------------------------------------------

def check_bool(option, opt, value):
if value.lower() in ["true","false"]:
return value.lower()
else:
raise OptionValueError(_("option %s: invalid boolean value: %r") % (opt, value))

class KatelloOption(Option):
TYPES = Option.TYPES + ("bool",)
TYPE_CHECKER = copy(Option.TYPE_CHECKER)
TYPE_CHECKER["bool"] = check_bool
8 changes: 4 additions & 4 deletions cli/src/katello/client/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def run(self):
try:
Config.save()
verb = "overwrote" if has_option else "remembered"
print ("Successfully " + verb + " option [ {} ] ").format(option)
print ("Successfully " + verb + " option [ {0} ] ").format(option)
except (Exception):
print "Unsuccessfully remembered option [ {} ]".format(option)
print "Unsuccessfully remembered option [ {0} ]".format(option)
raise # re-raise to get into main method -> log

return os.EX_OK
Expand All @@ -83,9 +83,9 @@ def run(self):
Config.parser.remove_option('options', option)
try:
Config.save()
print "Successfully forgot option [ {} ]".format(option)
print "Successfully forgot option [ {0} ]".format(option)
except (Exception):
print "Unsuccessfully forgot option [ {} ]".format(option)
print "Unsuccessfully forgot option [ {0} ]".format(option)
raise # re-raise to get into main method -> log

return os.EX_OK
Expand Down
39 changes: 39 additions & 0 deletions cli/src/katello/client/core/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,45 @@ def run(self):
print _("Successfully updated org [ %s ]") % name
return os.EX_OK

# ------------------------------------------------------------------------------

class GenerateDebugCert(OrganizationAction):

description = _('generate ueber certificate')

def setup_parser(self):
self.parser.add_option('--name', dest='name',
help=_("organization name eg: foo.example.com (required)"))

def check_options(self):
self.require_option('name')

def run(self):
name = self.get_option('name')

self.api.generate_debug_cert(name)
print _("Successfully generated debug cert for org [ %s ]") % name
return os.EX_OK

# ------------------------------------------------------------------------------

class DeleteDebugCert(OrganizationAction):

description = _('remove ueber certificate')

def setup_parser(self):
self.parser.add_option('--name', dest='name',
help=_("organization name eg: foo.example.com (required)"))

def check_options(self):
self.require_option('name')

def run(self):
name = self.get_option('name')

self.api.delete_debug_cert(name)
print _("Successfully deleted debug cert for org [ %s ]") % name
return os.EX_OK

# organization command ------------------------------------------------------------

Expand Down
40 changes: 26 additions & 14 deletions cli/src/katello/client/core/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#

import os
import itertools
from gettext import gettext as _

from katello.client.api.template import TemplateAPI
Expand Down Expand Up @@ -119,6 +120,8 @@ def run(self):
template["products"] = "\n".join([p["name"] for p in template["products"]])
template["packages"] = "\n".join([p["package_name"] for p in template["packages"]])
template["parameters"] = "\n".join([ key+":\t"+value for key, value in template["parameters"].iteritems() ])
template["package_groups"] = "\n".join(["{"+_("repo")+":\t"+pg["repo_id"]+", "+_("id")+":\t"+pg["package_group_id"]+"}" for pg in template["package_groups"] ])
template["package_group_categories"] = "\n".join(["{"+_("repo")+":\t"+pg["repo_id"]+", "+_("id")+":\t"+pg["pg_category_id"]+"}" for pg in template["pg_categories"] ])

self.printer.addColumn('id')
self.printer.addColumn('name')
Expand All @@ -130,6 +133,8 @@ def run(self):
self.printer.addColumn('products', multiline=True, show_in_grep=False)
self.printer.addColumn('packages', multiline=True, show_in_grep=False)
self.printer.addColumn('parameters', multiline=True, show_in_grep=False)
self.printer.addColumn('package_groups', multiline=True, show_in_grep=False)
self.printer.addColumn('package_group_categories', multiline=True, show_in_grep=False)

self.printer.setHeader(_("Template Info"))
self.printer.printItem(template)
Expand Down Expand Up @@ -274,14 +279,18 @@ def run(self):
class UpdateContent(TemplateAction):

actions = {
'add_product': ['product'],
'remove_product': ['product'],
'add_package': ['package'],
'remove_package': ['package'],
'add_erratum': ['erratum'],
'remove_erratum': ['erratum'],
'add_parameter': ['parameter', 'value'],
'remove_parameter': ['parameter']
'add_product': [{'product': None}],
'remove_product': [{'product': None}],
'add_package': [{'package': None}],
'remove_package': [{'package': None}],
'add_erratum': [{'erratum': None}],
'remove_erratum': [{'erratum': None}],
'add_parameter': [{'parameter': None}, {'value': None}],
'remove_parameter': [{'parameter': None}],
'add_package_group': [{'package_group': _("Package group id")},{'repo': _("Repo id")}],
'remove_package_group': [{'package_group': _("Package group id")},{'repo': _("Repo id")}],
'add_package_group_category': [{'package_group_category': _("Package group category id")},{'repo': _("Repo id")}],
'remove_package_group_category': [{'package_group_category': _("Package group category id")},{'repo': _("Repo id")}],
}

description = _('updates content of a template')
Expand All @@ -297,12 +306,14 @@ def setup_parser(self):
actionParams = set()
for action, params in self.actions.iteritems():
self.parser.add_option('--'+action, dest=action, action="store_true")
#save action parameters
actionParams.update(params)

#add action parameters
for param in actionParams:
for param_and_help in itertools.chain(*self.actions.values()):
param, help = param_and_help.keys()[0], param_and_help.values()[0]
if param in actionParams:
continue
self.parser.add_option('--'+param, dest=param)
actionParams.add(param)


def check_options(self):
Expand All @@ -313,8 +324,8 @@ def check_options(self):
for action, params in self.actions.iteritems():
if self.has_option(action):
self.selectedAction = action
for param in params:
self.require_option(param)
for param_and_help in params:
self.require_option(param_and_help.keys()[0])
return

self.add_option_error(_("No action was set!"))
Expand All @@ -332,7 +343,8 @@ def run(self):

if template != None:
updateParams = {}
for paramName in self.actions[self.selectedAction]:
for param_and_help in self.actions[self.selectedAction]:
paramName = param_and_help.keys()[0]
updateParams[paramName] = self.get_option(paramName)

msg = self.api.update_content(template["id"], self.selectedAction, updateParams)
Expand Down
2 changes: 1 addition & 1 deletion cli/src/katello/client/core/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def setup_parser(self):
help=_("user name (required)"))
self.parser.add_option('--password', dest='password',
help=_("initial password (required)"))
self.parser.add_option("--disabled", dest="disabled",
self.parser.add_option("--disabled", dest="disabled", type="bool",
help=_("disabled account (default is 'false')"))

def check_options(self):
Expand Down
2 changes: 1 addition & 1 deletion cli/src/katello/client/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _printItem(self, item, indent=""):
value = item[col['attr_name']]
if not col['multiline']:
output = format_date(value) if col['time_format'] else value
print ("{:<" + str(colWidth + 1) + "} {}").format(col['name'] + ":", output)
print ("{0:<" + str(colWidth + 1) + "} {1}").format(col['name'] + ":", output)
# +1 to account for the : after the column name
else:
print indent+col['name']+":"
Expand Down
3 changes: 2 additions & 1 deletion cli/src/katello/client/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ def __init__(self, host, port=443, protocol='https', path_prefix='/katello/api')
default_locale = locale.getdefaultlocale()[0].lower().replace('_', '-')
default_headers = {'Accept': 'application/json',
'Accept-Language': default_locale,
'content-type': 'application/json'}
'content-type': 'application/json',
'User-Agent': 'katello-cli/0.1'}
self.headers.update(default_headers)

self._log = getLogger('katello')
Expand Down
Loading

0 comments on commit abf9ba7

Please sign in to comment.