Skip to content
Browse files

cli - api util methods changed to raise exceptions

instead of returning None when a record was not found.
This allows us to remove the ubiquitous checks for None value from action bodies.
  • Loading branch information...
1 parent 50c20c6 commit a9ee6fcdf6f628cfa673556d0b5f0f1ca68f0541 @tstrachota tstrachota committed May 2, 2012
View
60 cli/src/katello/client/api/utils.py
@@ -30,12 +30,21 @@
from katello.client.api.filter import FilterAPI
from katello.client.api.system import SystemAPI
+
+class ApiDataError(Exception):
+ """
+ Exception to indicate an error in search for data via api.
+ The only argument is [0] the error message.
+ """
+ pass
+
+
def get_organization(orgName):
organization_api = OrganizationAPI()
org = organization_api.organization(orgName)
if org == None:
- print >> sys.stderr, _("Could not find organization [ %s ]") % orgName
+ raise ApiDataError(_("Could not find organization [ %s ]") % orgName)
return org
@@ -50,7 +59,7 @@ def get_environment(orgName, envName=None):
env = environment_api.environment_by_name(orgName, envName)
if env == None:
- print >> sys.stderr, _("Could not find environment [ %s ] within organization [ %s ]") % (envName, orgName)
+ raise ApiDataError(_("Could not find environment [ %s ] within organization [ %s ]") % (envName, orgName))
return env
@@ -63,83 +72,71 @@ def get_product(orgName, prodName):
prod = product_api.product_by_name(orgName, prodName)
if prod == None:
- print >> sys.stderr, _("Could not find product [ %s ] within organization [ %s ]") % (prodName, orgName)
+ raise ApiDataError(_("Could not find product [ %s ] within organization [ %s ]") % (prodName, orgName))
return prod
def get_repo(orgName, prodName, repoName, envName=None, includeDisabled=False):
repo_api = RepoAPI()
env = get_environment(orgName, envName)
- if env == None:
- return None
-
prod = get_product(orgName, prodName)
- if prod == None:
- return None
repos = repo_api.repos_by_env_product(env["id"], prod["id"], repoName, includeDisabled)
if len(repos) > 0:
#repo by id call provides more information
return repo_api.repo(repos[0]["id"])
- print >> sys.stderr, _("Could not find repository [ %s ] within organization [ %s ], product [ %s ] and environment [ %s ]") % (repoName, orgName, prodName, env["name"])
- return None
+ raise ApiDataError(_("Could not find repository [ %s ] within organization [ %s ], product [ %s ] and environment [ %s ]") % (repoName, orgName, prodName, env["name"]))
def get_provider(orgName, provName):
provider_api = ProviderAPI()
prov = provider_api.provider_by_name(orgName, provName)
if prov == None:
- print >> sys.stderr, _("Could not find provider [ %s ] within organization [ %s ]") % (provName, orgName)
+ raise ApiDataError(_("Could not find provider [ %s ] within organization [ %s ]") % (provName, orgName))
return prov
def get_template(orgName, envName, tplName):
template_api = TemplateAPI()
env = get_environment(orgName, envName)
- if env == None:
- return None
-
tpl = template_api.template_by_name(env["id"], tplName)
if tpl == None:
- print >> sys.stderr, _("Could not find template [ %s ] within environment [ %s ]") % (tplName, env["name"])
+ raise ApiDataError(_("Could not find template [ %s ] within environment [ %s ]") % (tplName, env["name"]))
return tpl
def get_changeset(orgName, envName, csName):
changeset_api = ChangesetAPI()
env = get_environment(orgName, envName)
- if env == None:
- return None
-
cset = changeset_api.changeset_by_name(orgName, env["id"], csName)
if cset == None:
- print >> sys.stderr, _("Could not find changeset [ %s ] within environment [ %s ]") % (csName, env["name"])
+ raise ApiDataError(_("Could not find changeset [ %s ] within environment [ %s ]") % (csName, env["name"]))
return cset
def get_user(userName):
user_api = UserAPI()
user = user_api.user_by_name(userName)
if user == None:
- print >> sys.stderr, _("Could not fing user [ %s ]") % (userName)
+ raise ApiDataError(_("Could not fing user [ %s ]") % (userName))
return user
def get_role(name):
user_role_api = UserRoleAPI()
role = user_role_api.role_by_name(name)
if role == None:
- print >> sys.stderr, _("Cannot find user role [ %s ]") % (name)
+ raise ApiDataError(_("Cannot find user role [ %s ]") % (name))
return role
def get_sync_plan(org_name, name):
plan_api = SyncPlanAPI()
plan = plan_api.sync_plan_by_name(org_name, name)
if plan == None:
- print >> sys.stderr, _("Cannot find sync plan [ %s ]") % (name)
+ raise ApiDataError(_("Cannot find sync plan [ %s ]") % (name))
return plan
def get_permission(role_name, permission_name):
@@ -151,38 +148,31 @@ def get_permission(role_name, permission_name):
perm = permission_api.permission_by_name(role['id'], permission_name)
if perm == None:
- print >> sys.stderr, _("Cannot find permission [ %s ] for user role [ %s ]") % (role_name, permission_name)
+ raise ApiDataError(_("Cannot find permission [ %s ] for user role [ %s ]") % (role_name, permission_name))
return perm
def get_filter(org_name, name):
filter_api = FilterAPI()
filter = filter_api.info(org_name, name)
if filter == None:
- print >> sys.stderr, _("Cannot find filter [ %s ]") % (name)
+ raise ApiDataError(_("Cannot find filter [ %s ]") % (name))
return filter
def get_system(org_name, sys_name, env_name=None):
system_api = SystemAPI()
if env_name is None:
systems = system_api.systems_by_org(org_name, {'name': sys_name})
if systems is None:
- print >> sys.stderr, _("Could not find System [ %s ] in Org [ %s ]") % (sys_name, org_name)
- return None
+ raise ApiDataError(_("Could not find System [ %s ] in Org [ %s ]") % (sys_name, org_name))
elif len(systems) != 1:
- print >> sys.stderr, _("Found ambiguous Systems [ %s ] in Environment [ %s ] in Org [ %s ]") % (name, env_name, org)
- return None
-
+ raise ApiDataError( _("Found ambiguous Systems [ %s ] in Environment [ %s ] in Org [ %s ]") % (sys_name, env_name, org_name))
else:
environment = get_environment(org_name, env_name)
- if environemnt is None:
- return None
systems = system_api.systems_by_env(org_name, environment["id"], {'name': sys_name})
if systems is None:
- print >> sys.stderr, _("Could not find System [ %s ] in Environment [ %s ] in Org [ %s ]") % (sys_name, env_name, org_name)
- return None
+ raise ApiDataError(_("Could not find System [ %s ] in Environment [ %s ] in Org [ %s ]") % (sys_name, env_name, org_name))
elif len(systems) != 1:
- print >> sys.stderr, _("Found ambiguous Systems [ %s ] in Org [ %s ], you have to specify the environment") % (name, org)
- return None
+ raise ApiDataError(_("Found ambiguous Systems [ %s ] in Org [ %s ], you have to specify the environment") % (sys_name, org_name))
return system_api.system(systems[0]['uuid'])
View
BIN cli/src/katello/client/core/.sync_plan.py.kate-swp
Binary file not shown.
View
10 cli/src/katello/client/core/activation_key.py
@@ -83,14 +83,10 @@ def run(self):
def get_keys_for_organization(self, orgName):
organization = get_organization(orgName)
- if not organization: return os.EX_DATAERR
-
return self.api.activation_keys_by_organization(organization['cp_key'])
def get_keys_for_environment(self, orgName, envName):
environment = get_environment(orgName, envName)
- if not environment: return os.EX_DATAERR
-
return self.api.activation_keys_by_environment(environment['id'])
class Info(ActivationKeyAction):
@@ -112,7 +108,6 @@ def run(self):
keyName = self.get_option('name')
organization = get_organization(orgName)
- if not organization: return os.EX_DATAERR
keys = self.api.activation_keys_by_organization(organization['cp_key'], keyName)
if len(keys) == 0:
@@ -162,7 +157,6 @@ def run(self):
templateName = self.get_option('template')
environment = get_environment(orgName, envName)
- if not environment: return os.EX_DATAERR
try:
templateId = self.get_template_id(environment['id'], templateName)
@@ -218,11 +212,9 @@ def run(self):
remove_poolids = self.get_option('remove_poolid') or []
organization = get_organization(orgName)
- if not organization: return os.EX_DATAERR
if envName != None:
environment = get_environment(orgName, envName)
- if not environment: return os.EX_DATAERR
else:
environment = None
@@ -269,10 +261,10 @@ def run(self):
keyName = self.get_option('name')
organization = get_organization(orgName)
- if not organization: return os.EX_DATAERR
keys = self.api.activation_keys_by_organization(organization['cp_key'], keyName)
if len(keys) == 0:
+ #TODO: not found?
return os.EX_DATAERR
self.api.delete(keys[0]['id'])
View
5 cli/src/katello/client/core/base.py
@@ -21,6 +21,7 @@
from socket import error as SocketError
from katello.client.config import Config
+from katello.client.api.utils import ApiDataError
from katello.client.core.utils import system_exit, parse_tokens, SystemExitRequest
from katello.client.utils.printer import Printer, GrepStrategy, VerboseStrategy
from katello.client.utils.encoding import u_str, u_obj
@@ -428,6 +429,10 @@ def main(self, args):
except OptionParserExitError, opee:
return opee.args[0]
+ except ApiDataError, ade:
+ print >> sys.stderr, ade.args[0]
+ return os.EX_DATAERR
+
except SystemExitRequest, ser:
msg = "\n".join(ser.args[1]).strip()
if ser.args[0] == os.EX_OK:
View
11 cli/src/katello/client/core/changeset.py
@@ -56,9 +56,6 @@ def run(self):
verbose = self.get_option('verbose')
env = get_environment(orgName, envName)
- if env == None:
- return os.EX_DATAERR
-
changesets = self.api.changesets(orgName, env['id'])
self.printer.add_column('id')
@@ -104,8 +101,6 @@ def run(self):
displayDeps = self.has_option('deps')
cset = get_changeset(orgName, envName, csName)
- if cset == None:
- return os.EX_DATAERR
cset['environment_name'] = envName
@@ -380,8 +375,6 @@ def run(self):
csDescription = self.get_option('description')
cset = get_changeset(orgName, envName, csName)
- if cset == None:
- return os.EX_DATAERR
self.update(cset["id"], csNewName, csDescription)
addPatch = self.PatchBuilder.build_patch('add', self.AddPatchItemBuilder(orgName, envName), items)
@@ -426,8 +419,6 @@ def run(self):
envName = self.get_option('env')
cset = get_changeset(orgName, envName, csName)
- if cset == None:
- return os.EX_DATAERR
msg = self.api.delete(cset["id"])
print msg
@@ -457,8 +448,6 @@ def run(self):
envName = self.get_option('env')
cset = get_changeset(orgName, envName, csName)
- if cset == None:
- return os.EX_DATAERR
task = self.api.promote(cset["id"])
task = AsyncTask(task)
View
3 cli/src/katello/client/core/distribution.py
@@ -71,11 +71,8 @@ def run(self):
if not repoId:
repo = get_repo(orgName, prodName, repoName, envName)
- if repo == None:
- return os.EX_DATAERR
repoId = repo["id"]
-
self.printer.set_header(_("Distribution List For Repo %s") % repoId)
distributions = self.api.distributions_by_repo(repoId)
View
51 cli/src/katello/client/core/environment.py
@@ -89,18 +89,17 @@ def run(self):
envName = self.get_option('name')
env = get_environment(orgName, envName)
- if env != None:
- self.printer.add_column('id')
- self.printer.add_column('name')
- self.printer.add_column('description', multiline=True)
- self.printer.add_column('organization', _('Org'))
- self.printer.add_column('prior', _('Prior Environment'))
-
- self.printer.set_header(_("Environment Info"))
- self.printer.print_item(env)
- return os.EX_OK
- else:
- return os.EX_DATAERR
+
+ self.printer.add_column('id')
+ self.printer.add_column('name')
+ self.printer.add_column('description', multiline=True)
+ self.printer.add_column('organization', _('Org'))
+ self.printer.add_column('prior', _('Prior Environment'))
+
+ self.printer.set_header(_("Environment Info"))
+ self.printer.print_item(env)
+ return os.EX_OK
+
class Create(EnvironmentAction):
@@ -171,16 +170,15 @@ def run(self):
priorName = self.get_option('prior')
env = get_environment(orgName, envName)
- if env != None:
- if priorName != None:
- priorId = self.get_prior_id(orgName, priorName)
- else:
- priorId = None
- env = self.api.update(orgName, env["id"], envName, description, priorId)
- print _("Successfully updated environment [ %s ]") % env['name']
- return os.EX_OK
+
+ if priorName != None:
+ priorId = self.get_prior_id(orgName, priorName)
else:
- return os.EX_DATAERR
+ priorId = None
+ env = self.api.update(orgName, env["id"], envName, description, priorId)
+ print _("Successfully updated environment [ %s ]") % env['name']
+ return os.EX_OK
+
class Delete(EnvironmentAction):
@@ -203,12 +201,11 @@ def run(self):
envName = self.get_option('name')
env = get_environment(orgName, envName)
- if env != None:
- self.api.delete(orgName, env["id"])
- print _("Successfully deleted environment [ %s ]") % envName
- return os.EX_OK
- else:
- return os.EX_DATAERR
+
+ self.api.delete(orgName, env["id"])
+ print _("Successfully deleted environment [ %s ]") % envName
+ return os.EX_OK
+
# environment command ------------------------------------------------------------
View
16 cli/src/katello/client/core/errata.py
@@ -80,21 +80,13 @@ def run(self):
if not repo_id:
if repo_name:
repo = get_repo(org_name, prod_name, repo_name, env_name)
- if repo == None:
- return os.EX_DATAERR
repo_id = repo["id"]
else:
env = get_environment(org_name, env_name)
- if env == None:
- return os.EX_DATAERR
- else:
- env_id = env["id"]
+ env_id = env["id"]
if prod_name:
product = get_product(org_name, prod_name)
- if product == None:
- return os.EX_DATAERR
- else:
- prod_id = product["id"]
+ prod_id = product["id"]
errata = self.api.errata_filter(repo_id=repo_id, environment_id=env_id, type=self.get_option('type'), severity=self.get_option('severity'),prod_id=prod_id)
@@ -123,8 +115,6 @@ def run(self):
sys_name = self.get_option('name')
systems = systemApi.systems_by_org(org_name, {'name': sys_name})
- if len(systems) == 0:
- return os.EX_DATAERR
errata = systemApi.errata(systems[0]["uuid"])
@@ -172,8 +162,6 @@ def run(self):
if not repoId:
repo = get_repo(orgName, prodName, repoName, envName)
- if repo == None:
- return os.EX_DATAERR
repoId = repo["id"]
pack = self.api.errata(errId, repoId)
View
2 cli/src/katello/client/core/package.py
@@ -72,8 +72,6 @@ def run(self):
if not repoId:
repo = get_repo(orgName, prodName, repoName, envName)
- if repo == None:
- return os.EX_DATAERR
repoId = repo["id"]
pack = self.api.package(packId, repoId)
View
8 cli/src/katello/client/core/permission.py
@@ -107,8 +107,6 @@ def run(self):
tag_ids = self.tags_to_ids(tags, org_name, scope)
role = get_role(role_name)
- if role == None:
- return os.EX_DATAERR
permission = self.api.create(role['id'], name, desc, scope, verbs, tag_ids, org_name)
if is_valid_record(permission):
@@ -136,11 +134,7 @@ def run(self):
name = self.get_option('name')
role = get_role(role_name)
- if role == None:
- return os.EX_DATAERR
perm = get_permission(role_name, name)
- if perm == None:
- return os.EX_DATAERR
self.api.delete(role['id'], perm['id'])
print _("Successfully deleted permission [ %s ] for role [ %s ]") % (name, role_name)
@@ -167,8 +161,6 @@ def run(self):
role_name = self.get_option('user_role')
role = get_role(role_name)
- if role == None:
- return os.EX_DATAERR
permissions = self.api.permissions(role['id'])
View
36 cli/src/katello/client/core/product.py
@@ -88,12 +88,7 @@ def run(self):
planName = self.get_option('plan')
prod = get_product(orgName, prodName)
- if (prod == None):
- return os.EX_DATAERR
-
plan = get_sync_plan(orgName, planName)
- if (plan == None):
- return os.EX_DATAERR
msg = self.api.set_sync_plan(orgName, prod['id'], plan['id'])
print msg
@@ -111,8 +106,6 @@ def run(self):
prodName = self.get_option('name')
prod = get_product(orgName, prodName)
- if (prod == None):
- return os.EX_DATAERR
msg = self.api.remove_sync_plan(orgName, prod['id'])
print msg
@@ -150,16 +143,12 @@ def run(self):
if prov_name:
prov = get_provider(org_name, prov_name)
- if prov == None:
- return os.EX_DATAERR
self.printer.set_header(_("Product List For Provider %s") % (prov_name))
prods = self.api.products_by_provider(prov["id"])
else:
env = get_environment(org_name, env_name)
- if env == None:
- return os.EX_DATAERR
self.printer.set_header(_("Product List For Organization %s, Environment '%s'") % (org_name, env["name"]))
prods = self.api.products_by_env(env['id'])
@@ -179,8 +168,6 @@ def run(self):
prodName = self.get_option('name')
prod = get_product(orgName, prodName)
- if (prod == None):
- return os.EX_DATAERR
task = AsyncTask(self.api.sync(orgName, prod["id"]))
run_async_task_with_status(task, ProgressBar())
@@ -209,8 +196,6 @@ def run(self):
prodName = self.get_option('name')
prod = get_product(orgName, prodName)
- if (prod == None):
- return os.EX_DATAERR
msg = self.api.cancel_sync(orgName, prod["id"])
print msg
@@ -228,8 +213,6 @@ def run(self):
prodName = self.get_option('name')
prod = get_product(orgName, prodName)
- if (prod == None):
- return os.EX_DATAERR
task = AsyncTask(self.api.last_sync_status(orgName, prod['id']))
@@ -272,12 +255,7 @@ def run(self):
envName = self.get_option('env')
env = get_environment(orgName, envName)
- if (env == None):
- return os.EX_DATAERR
-
prod = get_product(orgName, prodName)
- if (prod == None):
- return os.EX_DATAERR
returnCode = os.EX_OK
@@ -354,8 +332,6 @@ def run(self):
def create_product_with_repos(self, provName, orgName, name, description, url, assumeyes, nodiscovery, gpgkey):
prov = get_provider(orgName, provName)
- if prov == None:
- return os.EX_DATAERR
prod = self.api.create(prov["id"], name, description, gpgkey)
print _("Successfully created product [ %s ]") % name
@@ -400,8 +376,6 @@ def run(self):
gpgkey_recursive = self.get_option('recursive')
prod = get_product(orgName, prodName)
- if (prod == None):
- return os.EX_DATAERR
prod = self.api.update(orgName, prod["id"], description, gpgkey, nogpgkey, gpgkey_recursive)
print _("Successfully updated product [ %s ]") % prodName
@@ -417,8 +391,6 @@ def run(self):
orgName = self.get_option('org')
prodName = self.get_option('name')
product = get_product(orgName, prodName)
- if product == None:
- return os.EX_DATAERR
msg = self.api.delete(orgName, product["id"])
print msg
@@ -434,8 +406,6 @@ def run(self):
orgName = self.get_option('org')
prodName = self.get_option('name')
prod = get_product(orgName, prodName)
- if (prod == None):
- return os.EX_DATAERR
filters = self.api.filters(orgName, prod['id'])
self.printer.add_column('name')
@@ -478,11 +448,7 @@ def run(self):
filter_name = self.get_option('filter')
prod = get_product(org_name, prod_name)
- if (prod == None):
- return os.EX_DATAERR
-
- if get_filter(org_name, filter_name) == None:
- return os.EX_DATAERR
+ get_filter(org_name, filter_name)
filters = self.api.filters(org_name, prod['id'])
filters = [f['name'] for f in filters]
View
43 cli/src/katello/client/core/provider.py
@@ -94,19 +94,18 @@ def run(self):
orgName = self.get_option('org')
prov = get_provider(orgName, provName)
- if prov != None:
- self.printer.add_column('id')
- self.printer.add_column('name')
- self.printer.add_column('provider_type', 'Type')
- self.printer.add_column('repository_url', 'Url')
- self.printer.add_column('organization_id', 'Org Id')
- self.printer.add_column('description', multiline=True)
-
- self.printer.set_header(_("Provider Information"))
- self.printer.print_item(prov)
- return os.EX_OK
- else:
- return os.EX_DATAERR
+
+ self.printer.add_column('id')
+ self.printer.add_column('name')
+ self.printer.add_column('provider_type', 'Type')
+ self.printer.add_column('repository_url', 'Url')
+ self.printer.add_column('organization_id', 'Org Id')
+ self.printer.add_column('description', multiline=True)
+
+ self.printer.set_header(_("Provider Information"))
+ self.printer.print_item(prov)
+ return os.EX_OK
+
# ==============================================================================
@@ -203,12 +202,10 @@ def run(self):
orgName = self.get_option('org')
prov = get_provider(orgName, provName)
- if prov != None:
- msg = self.api.delete(prov["id"])
- print msg
- return os.EX_OK
- else:
- return os.EX_DATAERR
+
+ msg = self.api.delete(prov["id"])
+ print msg
+ return os.EX_OK
# ==============================================================================
@@ -223,8 +220,6 @@ def run(self):
def sync_provider(self, providerName, orgName):
prov = get_provider(orgName, providerName)
- if prov == None:
- return os.EX_DATAERR
task = AsyncTask(self.api.sync(prov["id"]))
run_async_task_with_status(task, ProgressBar())
@@ -250,8 +245,6 @@ def run(self):
orgName = self.get_option('org')
prov = get_provider(orgName, provName)
- if prov == None:
- return os.EX_DATAERR
msg = self.api.cancel_sync(prov["id"])
print msg
@@ -269,8 +262,6 @@ def run(self):
orgName = self.get_option('org')
prov = get_provider(orgName, provName)
- if prov == None:
- return os.EX_DATAERR
task = AsyncTask(self.api.last_sync_status(prov['id']))
@@ -349,8 +340,6 @@ def run(self):
orgName = self.get_option('org')
prov = get_provider(orgName, provName)
- if prov == None:
- return os.EX_DATAERR
self.api.refresh_products(prov["id"])
print _("Provider successfully refreshed [ %s ]") % prov['name']
View
38 cli/src/katello/client/core/repo.py
@@ -145,14 +145,9 @@ def run(self):
gpgkey = self.get_option('gpgkey')
nogpgkey = self.get_option('nogpgkey')
-
prod = get_product(orgName, prodName)
- if prod != None:
- self.api.create(orgName, prod["id"], name, url, gpgkey, nogpgkey)
- print _("Successfully created repository [ %s ]") % name
- else:
- print _("No product [ %s ] found") % prodName
- return os.EX_DATAERR
+ self.api.create(orgName, prod["id"], name, url, gpgkey, nogpgkey)
+ print _("Successfully created repository [ %s ]") % name
return os.EX_OK
@@ -442,24 +437,22 @@ def run(self):
if prodName and envName:
env = get_environment(orgName, envName)
prod = get_product(orgName, prodName)
- if env != None and prod != None:
- self.printer.set_header(_("Repo List For Org %s Environment %s Product %s") % (orgName, env["name"], prodName))
- repos = self.api.repos_by_env_product(env["id"], prod["id"], None, listDisabled)
- self.printer.print_items(repos)
+
+ self.printer.set_header(_("Repo List For Org %s Environment %s Product %s") % (orgName, env["name"], prodName))
+ repos = self.api.repos_by_env_product(env["id"], prod["id"], None, listDisabled)
+ self.printer.print_items(repos)
+
elif prodName:
prod = get_product(orgName, prodName)
- if prod != None:
- self.printer.set_header(_("Repo List for Product %s in Org %s ") % (prodName, orgName))
- repos = self.api.repos_by_product(orgName, prod["id"], listDisabled)
- self.printer.print_items(repos)
- else:
- return os.EX_DATAERR
+ self.printer.set_header(_("Repo List for Product %s in Org %s ") % (prodName, orgName))
+ repos = self.api.repos_by_product(orgName, prod["id"], listDisabled)
+ self.printer.print_items(repos)
+
else:
env = get_environment(orgName, envName)
- if env != None:
- self.printer.set_header(_("Repo List For Org %s Environment %s") % (orgName, env["name"]))
- repos = self.api.repos_by_org_env(orgName, env["id"], listDisabled)
- self.printer.print_items(repos)
+ self.printer.set_header(_("Repo List For Org %s Environment %s") % (orgName, env["name"]))
+ repos = self.api.repos_by_org_env(orgName, env["id"], listDisabled)
+ self.printer.print_items(repos)
return os.EX_OK
@@ -530,8 +523,7 @@ def run(self):
repo = self.get_repo()
- if get_filter(org_name, filter_name) == None:
- return os.EX_DATAERR
+ get_filter(org_name, filter_name)
filters = self.api.filters(repo['id'])
filters = [f['name'] for f in filters]
View
6 cli/src/katello/client/core/sync_plan.py
@@ -94,8 +94,6 @@ def run(self):
plan_name = self.get_option('name')
plan = get_sync_plan(org_name, plan_name)
- if plan == None:
- return os.EX_DATAERR
self.printer.add_column('id')
self.printer.add_column('name')
@@ -179,8 +177,6 @@ def run(self):
time = self.get_option('time')
plan = get_sync_plan(org_name, name)
- if plan == None:
- return os.EX_DATAERR
if date != None and time != None:
sync_date = self.parse_datetime(date, time)
@@ -209,8 +205,6 @@ def run(self):
plan_name = self.get_option('name')
plan = get_sync_plan(org_name, plan_name)
- if plan == None:
- return os.EX_DATAERR
self.api.delete(org_name, plan["id"])
print _("Successfully deleted sync plan [ %s ]") % plan_name
View
30 cli/src/katello/client/core/system.py
@@ -72,8 +72,6 @@ def run(self):
pool_id = self.get_option('pool_id')
systems = self.get_systems(org_name, env_name, pool_id)
- if systems is None:
- return os.EX_DATAERR
if env_name is None:
self.printer.set_header(_("Systems List For Org [ %s ]") % org_name)
@@ -115,8 +113,6 @@ def run(self):
# get system details
system = get_system(org_name, sys_name, env_name)
- if not system:
- return os.EX_DATAERR
for akey in system['activation_key']:
system["activation_keys"] = "[ "+ ", ".join([akey["name"] for pool in akey["pools"]]) +" ]"
@@ -196,8 +192,6 @@ def run(self):
self.printer.set_header(_("Package Information for System [ %s ] in Environment [ %s ] in Org [ %s ]") % (sys_name, env_name, org_name))
system = get_system(org_name, sys_name, env_name)
- if not system:
- return os.EX_DATAERR
system_id = system['uuid']
if install:
@@ -269,11 +263,8 @@ def run(self):
self.printer.set_header(_("Remote tasks"))
environment = get_environment(org_name, env_name)
- if environment is None:
- return os.EX_DATAERR
tasks = self.api.tasks(org_name, environment["id"], sys_name)
-
for t in tasks:
t['result'] = "\n" + t['result_description']
@@ -349,8 +340,6 @@ def run(self):
if sys_name:
system = get_system(org_name, sys_name)
- if not system:
- return os.EX_DATAERR
releases = self.api.releases_for_system(system["uuid"])["releases"]
else:
environment = get_environment(org_name, env_name)
@@ -391,8 +380,6 @@ def run(self):
self.printer.set_header(_("System Facts For System [ %s ] in Environment [ %s] in Org [ %s ]") % (sys_name, env_name, org_name))
system = get_system(org_name, sys_name, env_name)
- if not system:
- return os.EX_DATAERR
system_id = system['uuid']
facts_hash = system['facts']
@@ -445,8 +432,6 @@ def run(self):
facts = dict(self.get_option('fact') or {})
environment = get_environment(org, environment_name)
- if environment is None:
- return os.EX_DATAERR
system = self.api.register(name, org, environment['id'], activation_keys, 'system', release, sla, facts=facts)
if is_valid_record(system):
@@ -477,8 +462,6 @@ def run(self):
env_name = self.get_option('environment')
try:
system = get_system(org, name, env_name)
- if not system:
- return os.EX_DATAERR
except ServerRequestError, e:
if e[0] == 404:
@@ -516,8 +499,6 @@ def run(self):
qty = self.get_option('quantity') or 1
system = get_system(org, name)
- if not system:
- return os.EX_DATAERR
self.api.subscribe(system['uuid'], pool, qty)
print _("Successfully subscribed System [ %s ]") % name
@@ -544,8 +525,6 @@ def run(self):
available = self.get_option('available')
system = get_system(org, name)
- if not system:
- return os.EX_DATAERR
self.printer.set_strategy(VerboseStrategy())
if not available:
@@ -631,9 +610,7 @@ def run(self):
serial = self.get_option('serial')
all_entitlements = self.get_option('all')
- system = get_system(org_name, sys_name, env_name)
- if not system:
- return os.EX_DATAERR
+ system = get_system(org, name)
if all_entitlements: #unsubscribe from all
self.api.unsubscribe_all(system['uuid'])
@@ -683,8 +660,6 @@ def run(self):
new_sla = self.get_option('sla')
system = get_system(org_name, sys_name, env_name)
- if not system:
- return os.EX_DATAERR
system_uuid = system['uuid']
updates = {}
@@ -727,11 +702,8 @@ def run(self):
report = self.api.report_by_org(orgId, convert_to_mime_type(format, 'text'))
else:
environment = get_environment(orgId, envName)
- if environment is None:
- return os.EX_DATAERR
report = self.api.report_by_env(environment['id'], convert_to_mime_type(format, 'text'))
-
if format == 'pdf':
save_report(report[0], attachment_file_name(report[1], 'katello_systems_report.pdf'))
else:
View
63 cli/src/katello/client/core/template.py
@@ -63,9 +63,6 @@ def run(self):
orgName = self.get_option('org')
environment = get_environment(orgName, envName)
-
- if not environment:
- return os.EX_DATAERR
templates = self.api.templates(environment["id"])
if not templates:
@@ -105,8 +102,6 @@ def run(self):
envName = self.get_option('env')
template = get_template(orgName, envName, tplName)
- if template == None:
- return os.EX_DATAERR
template["products"] = [p["name"] for p in template["products"]]
template["repositories"] = [r["name"] for r in template["repositories"]]
@@ -175,8 +170,6 @@ def run(self):
tplPath = self.get_option('file')
env = get_library(orgName)
- if env == None:
- return os.EX_DATAERR
try:
f = self.open_file(tplPath)
@@ -225,8 +218,6 @@ def run(self):
tplPath = self.get_option('file')
template = get_template(orgName, envName, tplName)
- if not template:
- return os.EX_DATAERR
try:
f = self.open_file(tplPath)
@@ -274,23 +265,22 @@ def run(self):
parentName = self.get_option('parent')
env = get_library(orgName)
- if env != None:
- if parentName != None:
- parentId = self.get_parent_id(orgName, env['name'], parentName)
- else:
- parentId = None
- template = self.api.create(env["id"], name, desc, parentId)
- if is_valid_record(template):
- print _("Successfully created template [ %s ]") % template['name']
- return os.EX_OK
- else:
- print >> sys.stderr, _("Could not create template [ %s ]") % name
- return os.EX_DATAERR
+ if parentName != None:
+ parentId = self.get_parent_id(orgName, env['name'], parentName)
+ else:
+ parentId = None
+
+ template = self.api.create(env["id"], name, desc, parentId)
+ if is_valid_record(template):
+ print _("Successfully created template [ %s ]") % template['name']
+ return os.EX_OK
else:
+ print >> sys.stderr, _("Could not create template [ %s ]") % name
return os.EX_DATAERR
+
# ==============================================================================
class Update(TemplateAction):
@@ -419,22 +409,18 @@ def run(self):
content = self.getContent()
env = get_library(orgName)
- if env == None:
- return os.EX_DATAERR
-
template = get_template(orgName, env["name"], tplName)
- if template != None:
- if parentName != None:
- parentId = self.get_parent_id(orgName, env["name"], parentName)
- else:
- parentId = None
- run_spinner_in_bg(self.updateTemplate, [template["id"], newName, desc, parentId], _("Updating the template, please wait... "))
- run_spinner_in_bg(self.updateContent, [template["id"], content], _("Updating the template, please wait... "))
- print _("Successfully updated template [ %s ]") % template['name']
- return os.EX_OK
+ if parentName != None:
+ parentId = self.get_parent_id(orgName, env["name"], parentName)
else:
- return os.EX_DATAERR
+ parentId = None
+
+ run_spinner_in_bg(self.updateTemplate, [template["id"], newName, desc, parentId], _("Updating the template, please wait... "))
+ run_spinner_in_bg(self.updateContent, [template["id"], content], _("Updating the template, please wait... "))
+ print _("Successfully updated template [ %s ]") % template['name']
+ return os.EX_OK
+
def productNamesToIds(self, orgName, productNames):
@@ -520,12 +506,9 @@ def run(self):
envName = self.get_option('env')
template = get_template(orgName, envName, tplName)
- if template != None:
- msg = self.api.delete(template["id"])
- print msg
- return os.EX_OK
- else:
- return os.EX_DATAERR
+ msg = self.api.delete(template["id"])
+ print msg
+ return os.EX_OK
# provider command =============================================================
View
14 cli/src/katello/client/core/user.py
@@ -90,8 +90,6 @@ def run(self):
if default_environment is not None:
environment = get_environment(default_organization, default_environment)
- if environment is None:
- return os.EX_DATAERR
else:
environment = None
@@ -118,8 +116,6 @@ def run(self):
username = self.get_option('username')
user = get_user(username)
- if user == None:
- return os.EX_DATAERR
self.printer.add_column('id')
self.printer.add_column('username')
@@ -148,8 +144,6 @@ def run(self):
username = self.get_option('username')
user = get_user(username)
- if user == None:
- return os.EX_DATAERR
self.api.delete(user['id'])
print _("Successfully deleted user [ %s ]") % username
@@ -198,14 +192,10 @@ def run(self):
environment = None
elif default_environment is not None:
environment = get_environment(default_organization, default_environment)
- if environment is None:
- return os.EX_DATAERR
else:
environment = False
user = get_user(username)
- if user == None:
- return os.EX_DATAERR
user = self.api.update(user['id'], password, email, disabled, environment)
print _("Successfully updated user [ %s ]") % username
@@ -227,8 +217,6 @@ def run(self):
username = self.get_option('username')
user = get_user(username)
- if user == None:
- return os.EX_DATAERR
roles = self.api.roles(user['id'])
@@ -283,8 +271,6 @@ def run(self):
roleName = self.get_option('role')
user = get_user(userName)
- if user == None:
- return os.EX_DATAERR
role = self.role_api.role_by_name(roleName)
if role == None:
View
2 cli/src/katello/client/core/user_role.py
@@ -101,7 +101,7 @@ def getPermissions(self, roleId):
def getLdapGroups(self, roleId):
ldap_groups = self.api.ldap_groups(roleId)
return [lg['ldap_group'] for lg in ldap_groups]
-
+
def formatPermission(self, p, details=True):
if details:

0 comments on commit a9ee6fc

Please sign in to comment.
Something went wrong with that request. Please try again.