diff --git a/client/text_cache.py b/client/text_cache.py index 47952ee13..eeb4b14c6 100644 --- a/client/text_cache.py +++ b/client/text_cache.py @@ -21,8 +21,9 @@ def cache(options): rc = 0 from entropy.client.interfaces import Client - entropy_client = Client(noclientdb = True) + entropy_client = None try: + entropy_client = Client(noclientdb = True) if cmd == "clean": entropy_client.output( blue(_("Cleaning Entropy cache, please wait ...")), @@ -39,7 +40,8 @@ def cache(options): else: rc = -10 finally: - entropy_client.shutdown() + if entropy_client is not None: + entropy_client.shutdown() return rc diff --git a/client/text_configuration.py b/client/text_configuration.py index 3bd9fb512..58f2240af 100644 --- a/client/text_configuration.py +++ b/client/text_configuration.py @@ -43,8 +43,9 @@ def configurator(options): return 1 from entropy.client.interfaces import Client - etp_client = Client() + etp_client = None try: + etp_client = Client() cmd = options.pop(0) if cmd == "info": rc = confinfo(etp_client) @@ -53,7 +54,8 @@ def configurator(options): else: rc = -10 finally: - etp_client.shutdown() + if etp_client is not None: + etp_client.shutdown() return rc diff --git a/client/text_repositories.py b/client/text_repositories.py index 191816700..b6949811f 100644 --- a/client/text_repositories.py +++ b/client/text_repositories.py @@ -32,6 +32,7 @@ def repositories(options): # Options available for all the packages submodules myopts = options[1:] + cmd = options[0] e_req_force_update = False rc = 0 repo_names = [] @@ -46,9 +47,10 @@ def repositories(options): repo_names.append(opt) from entropy.client.interfaces import Client - entropy_client = Client(noclientdb = True) + entropy_client = None try: - if options[0] == "update": + entropy_client = Client(noclientdb = True) + if cmd == "update": # check if I am root er_txt = darkred(_("You must be either root or in this group:")) + \ " " + etpConst['sysgroup'] @@ -61,11 +63,11 @@ def repositories(options): rc = _do_sync(entropy_client, repo_identifiers = repo_names, force = e_req_force_update) - elif options[0] == "status": + elif cmd == "status": for repo in SystemSettings['repositories']['order']: _show_repository_info(entropy_client, repo) - elif options[0] == "repo": + elif cmd == "repo": er_txt = darkred(_("You must be root")) if not entropy.tools.is_root(): @@ -92,7 +94,7 @@ def repositories(options): else: rc = -10 - elif options[0] == "notice": + elif cmd == "notice": myopts = options[1:] myopts = [x for x in myopts if x in \ SystemSettings['repositories']['available']] @@ -105,7 +107,8 @@ def repositories(options): else: rc = -10 finally: - entropy_client.shutdown() + if entropy_client is not None: + entropy_client.shutdown() return rc diff --git a/client/text_rescue.py b/client/text_rescue.py index 522e293cd..dc20723c4 100644 --- a/client/text_rescue.py +++ b/client/text_rescue.py @@ -74,23 +74,25 @@ def database(options): print_error(red(mytxt+".")) return 1 - etp_client = Client(noclientdb = True) + cmd = options[0] + etp_client = None try: + etp_client = Client(noclientdb = True) - if options[0] == "generate": + if cmd == "generate": return _database_generate(etp_client) - elif options[0] == "check": + elif cmd == "check": return _database_check(etp_client) - elif options[0] == "resurrect": + elif cmd == "resurrect": return _database_resurrect(etp_client) - elif options[0] == "revdeps": + elif cmd == "revdeps": return _database_revdeps(etp_client) - elif options[0] in ("counters", "spmuids",): - if options[0] == "counters": + elif cmd in ("counters", "spmuids",): + if cmd == "counters": print_warning("") print_warning("'%s' %s: '%s'" % ( purple("equo database counters"), @@ -99,8 +101,8 @@ def database(options): print_warning("") return _database_counters(etp_client) - elif options[0] in ("gentoosync", "spmsync",): - if options[0] == "gentoosync": + elif cmd in ("gentoosync", "spmsync",): + if cmd == "gentoosync": print_warning("") print_warning("'%s' %s: '%s'" % ( purple("equo database gentoosync"), @@ -109,24 +111,25 @@ def database(options): print_warning("") return _database_spmsync(etp_client) - elif options[0] == "backup": + elif cmd == "backup": status, err_msg = etp_client.backup_repository( etpConst['etpdatabaseclientfilepath']) if status: return 0 return 1 - elif options[0] == "restore": + elif cmd == "restore": return _database_restore(etp_client) - elif options[0] == "vacuum": + elif cmd == "vacuum": return _database_vacuum(etp_client) - elif options[0] == "info": + elif cmd == "info": return _getinfo(etp_client) finally: - etp_client.shutdown() + if etp_client is not None: + etp_client.shutdown() return -10 diff --git a/client/text_security.py b/client/text_security.py index 53277086a..9e15c97e2 100644 --- a/client/text_security.py +++ b/client/text_security.py @@ -36,11 +36,13 @@ def security(options): elif opt == "--force": force = True + cmd = options[0] from entropy.client.interfaces import Client - entropy_client = Client() + entropy_client = None try: + entropy_client = Client() - if options[0] == "update": + if cmd == "update": security_intf = entropy_client.Security() er_txt = darkred(_("You must be either root or in this group:")) + \ " " + etpConst['sysgroup'] @@ -49,22 +51,23 @@ def security(options): return 1 rc = security_intf.sync(force = force) - elif options[0] == "list": + elif cmd == "list": security_intf = entropy_client.Security() rc = list_advisories(security_intf, only_affected = only_affected, only_unaffected = only_unaffected) - elif options[0] == "install": + elif cmd == "install": security_intf = entropy_client.Security() rc = install_packages(entropy_client, security_intf, fetch = fetch) - elif options[0] == "info": + elif cmd == "info": security_intf = entropy_client.Security() rc = show_advisories_info(security_intf, options[1:]) else: rc = -10 finally: - entropy_client.shutdown() + if entropy_client is not None: + entropy_client.shutdown() return rc diff --git a/client/text_smart.py b/client/text_smart.py index f31538d29..23b833763 100644 --- a/client/text_smart.py +++ b/client/text_smart.py @@ -57,8 +57,9 @@ def smart(options): rc = 0 from entropy.client.interfaces import Client - entropy_client = Client() + entropy_client = None try: + entropy_client = Client() if options[0] == "application": rc = smart_apps_handler(entropy_client, options[1:]) @@ -76,7 +77,8 @@ def smart(options): else: rc = -10 finally: - entropy_client.shutdown() + if entropy_client is not None: + entropy_client.shutdown() return rc diff --git a/client/text_ugc.py b/client/text_ugc.py index 50d9e2425..87a702a10 100644 --- a/client/text_ugc.py +++ b/client/text_ugc.py @@ -38,9 +38,10 @@ def ugc(options): rc = -10 from entropy.client.interfaces import Client - entropy_client = Client() - entropy_client.UGC.show_progress = True + entropy_client = None try: + entropy_client = Client() + entropy_client.UGC.show_progress = True if cmd == "login": if options: rc = _ugc_login(entropy_client, options[0], @@ -55,7 +56,8 @@ def ugc(options): if options: rc = _ugc_votes(entropy_client, options) finally: - entropy_client.shutdown() + if entropy_client is not None: + entropy_client.shutdown() return rc