From dcc431b608c78918ceb507132f9a0297289e3437 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 5 Aug 2015 06:20:04 +0300 Subject: [PATCH] Replace sys.exit() module with SystemExit() --- slpkg/auto_pkg.py | 2 +- slpkg/binary/check.py | 3 +-- slpkg/binary/dependency.py | 2 +- slpkg/binary/install.py | 3 +-- slpkg/binary/search.py | 4 +--- slpkg/checks.py | 8 +++----- slpkg/checksum.py | 4 +--- slpkg/config.py | 3 +-- slpkg/downloader.py | 7 +++---- slpkg/file_size.py | 3 +-- slpkg/health.py | 5 ++--- slpkg/init.py | 8 ++++---- slpkg/main.py | 4 ++-- slpkg/messages.py | 4 ++-- slpkg/pkg/build.py | 2 +- slpkg/pkg/manager.py | 11 +++++------ slpkg/pkg_find.py | 4 +--- slpkg/repoinfo.py | 3 +-- slpkg/repolist.py | 4 +--- slpkg/repositories.py | 9 ++++----- slpkg/sbo/check.py | 3 +-- slpkg/sbo/dependency.py | 2 +- slpkg/sbo/search.py | 4 +--- slpkg/sbo/slackbuild.py | 5 ++--- slpkg/slack/patches.py | 3 +-- slpkg/slpkg_update.py | 5 ++--- slpkg/toolbar.py | 2 +- slpkg/url_read.py | 3 +-- slpkg/utils.py | 5 ++--- 29 files changed, 49 insertions(+), 76 deletions(-) diff --git a/slpkg/auto_pkg.py b/slpkg/auto_pkg.py index 34ead6e6..2e638b4d 100644 --- a/slpkg/auto_pkg.py +++ b/slpkg/auto_pkg.py @@ -64,7 +64,7 @@ class Auto(object): sys.stdout.flush() except KeyboardInterrupt: print("") - sys.exit(0) + raise SystemExit() self.execute() def execute(self): diff --git a/slpkg/binary/check.py b/slpkg/binary/check.py index 053acb0b..bee7705c 100644 --- a/slpkg/binary/check.py +++ b/slpkg/binary/check.py @@ -22,7 +22,6 @@ # along with this program. If not, see . -import sys from distutils.version import LooseVersion from slpkg.messages import Msg @@ -65,7 +64,7 @@ def pkg_upgrade(repo, skip): return pkgs_for_upgrade except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() def installed(): diff --git a/slpkg/binary/dependency.py b/slpkg/binary/dependency.py index 019fb79e..c45aadbb 100644 --- a/slpkg/binary/dependency.py +++ b/slpkg/binary/dependency.py @@ -60,6 +60,6 @@ class Dependencies(object): return self.dep_results except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() else: return [] diff --git a/slpkg/binary/install.py b/slpkg/binary/install.py index 0d6bb36e..4fdbb723 100644 --- a/slpkg/binary/install.py +++ b/slpkg/binary/install.py @@ -23,7 +23,6 @@ import os -import sys from slpkg.utils import Utils from slpkg.sizes import units @@ -133,7 +132,7 @@ class BinaryInstall(object): Msg().not_found(self.if_upgrade) except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() def update_deps(self): """Update dependencies dictionary with all package diff --git a/slpkg/binary/search.py b/slpkg/binary/search.py index c1d285c3..4019e1ce 100644 --- a/slpkg/binary/search.py +++ b/slpkg/binary/search.py @@ -22,8 +22,6 @@ # along with this program. If not, see . -import sys - from slpkg.utils import Utils from slpkg.toolbar import status from slpkg.blacklist import BlackList @@ -49,4 +47,4 @@ def search_pkg(name, repo): return pkg_name except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() diff --git a/slpkg/checks.py b/slpkg/checks.py index 71ffbc9f..d5944eec 100644 --- a/slpkg/checks.py +++ b/slpkg/checks.py @@ -22,8 +22,6 @@ # along with this program. If not, see . -import sys - from messages import Msg from arguments import usage from init import Initialization @@ -76,12 +74,12 @@ class Updates(object): self.check = self.all_repos[self.repo]() except OSError: usage(self.repo) - sys.exit(0) + raise SystemExit() elif self.repo in self.meta.repositories: self.check = self._init.custom(self.repo) else: usage(self.repo) - sys.exit(0) + raise SystemExit() self.status_bar() self.status() self.print_status(self.repo) @@ -97,7 +95,7 @@ class Updates(object): self.check = self.all_repos[repo]() except OSError: usage(self.repo) - sys.exit(0) + raise SystemExit() elif repo in self.meta.repositories: self.check = self._init.custom(repo) self.status() diff --git a/slpkg/checksum.py b/slpkg/checksum.py index bd43e694..d74053cc 100644 --- a/slpkg/checksum.py +++ b/slpkg/checksum.py @@ -22,8 +22,6 @@ # along with this program. If not, see . -import sys - from md5sum import md5 from messages import Msg from __metadata__ import MetaData as _meta_ @@ -47,7 +45,7 @@ def check_md5(pkg_md5, src_file): Msg().template(78) print("") if not Msg().answer() in ["y", "Y"]: - sys.exit(0) + raise SystemExit() else: Msg().template(78) print("| MD5SUM check for {0} [ {1}PASSED{2} ]".format( diff --git a/slpkg/config.py b/slpkg/config.py index 0de65079..d3a2bec5 100644 --- a/slpkg/config.py +++ b/slpkg/config.py @@ -22,7 +22,6 @@ # along with this program. If not, see . -import sys import subprocess from utils import Utils @@ -73,7 +72,7 @@ class Config(object): self.meta.color["ENDC"])) except KeyboardInterrupt: print("") - sys.exit(0) + raise SystemExit() print("") # new line at end def edit(self, editor): diff --git a/slpkg/downloader.py b/slpkg/downloader.py index 2050700b..15f7b20e 100644 --- a/slpkg/downloader.py +++ b/slpkg/downloader.py @@ -23,7 +23,6 @@ import os -import sys import subprocess from messages import Msg @@ -68,7 +67,7 @@ class Download(object): dwn_count += 1 except KeyboardInterrupt: print # new line at cancel - sys.exit(0) + raise SystemExit() def _directory_prefix(self): """Downloader options for specific directory @@ -90,7 +89,7 @@ class Download(object): Msg().template(78) print("") if not Msg().answer() in ["y", "Y"]: - sys.exit(0) + raise SystemExit() def _check_certificate(self): """Check for certificates options for wget @@ -106,4 +105,4 @@ class Download(object): print("") self.downder_options += certificate if not Msg().answer() in ["y", "Y"]: - sys.exit(0) + raise SystemExit() diff --git a/slpkg/file_size.py b/slpkg/file_size.py index 31beba22..c750f23c 100644 --- a/slpkg/file_size.py +++ b/slpkg/file_size.py @@ -23,7 +23,6 @@ import os -import sys import urllib2 @@ -44,7 +43,7 @@ class FileSize(object): return " " except KeyboardInterrupt: print("") # new line at cancel - sys.exit(0) + raise SystemExit() def local(self): """ diff --git a/slpkg/health.py b/slpkg/health.py index 5eb25782..2f438fa5 100644 --- a/slpkg/health.py +++ b/slpkg/health.py @@ -23,7 +23,6 @@ import os -import sys from messages import Msg from __metadata__ import MetaData as _meta_ @@ -63,7 +62,7 @@ class PackageHealth(object): print(line) except (KeyboardInterrupt, IOError): print("") - sys.exit(0) + raise SystemExit() def test(self): """Get started test each package and read file list @@ -81,7 +80,7 @@ class PackageHealth(object): self.check(line, pkg) except KeyboardInterrupt: print("") - sys.exit(0) + raise SystemExit() self.results() def results(self): diff --git a/slpkg/init.py b/slpkg/init.py index 61fd54b9..e5b0dcf9 100644 --- a/slpkg/init.py +++ b/slpkg/init.py @@ -659,7 +659,7 @@ class Initialization(object): shutil.rmtree(files) except KeyboardInterrupt: print("") - sys.exit(0) + raise SystemExit() Update().repository(only) @@ -700,9 +700,9 @@ class Update(object): sys.stdout.write(self.error) except KeyboardInterrupt: print("") - sys.exit(0) + raise SystemExit() print("") # new line at end - sys.exit(0) + raise SystemExit() def check_exists_repositories(): @@ -721,4 +721,4 @@ def check_exists_repositories(): print("\n Please update packages lists. Run 'slpkg update'.\n" + " This command should be used to synchronize packages\n" + " lists from the repositories are enabled.\n") - sys.exit(0) + raise SystemExit() diff --git a/slpkg/main.py b/slpkg/main.py index c97af02c..06b18570 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -555,7 +555,7 @@ class ArgParse(object): if not_found: for ntf in not_found: Msg().pkg_not_found("", ntf, "Not installed", "") - sys.exit(0) + raise SystemExit() def main(): @@ -568,7 +568,7 @@ def main(): if len(args) == 0: usage("") - sys.exit(0) + raise SystemExit() argparse.auto_detect(args) diff --git a/slpkg/messages.py b/slpkg/messages.py index 98ce4523..61e9d1d5 100644 --- a/slpkg/messages.py +++ b/slpkg/messages.py @@ -54,7 +54,7 @@ class Msg(object): """ if user != "root": print("\nslpkg: error: must have root privileges\n") - sys.exit(0) + raise SystemExit() def build_FAILED(self, sbo_url, prgnam): """Print error message if build failed @@ -136,7 +136,7 @@ class Msg(object): answer = raw_input("Would you like to continue [y/N]? ") except (KeyboardInterrupt, EOFError): print("") - sys.exit(0) + raise SystemExit() return answer def reference(self, install, upgrade): diff --git a/slpkg/pkg/build.py b/slpkg/pkg/build.py index 931133cf..357910ba 100644 --- a/slpkg/pkg/build.py +++ b/slpkg/pkg/build.py @@ -104,7 +104,7 @@ class BuildPackage(object): Msg().pkg_not_found("\n", self.prgnam, "Wrong file", "\n") except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() def _makeflags(self): """Set variable MAKEFLAGS with the numbers of diff --git a/slpkg/pkg/manager.py b/slpkg/pkg/manager.py index 058ee5ea..40fadf78 100644 --- a/slpkg/pkg/manager.py +++ b/slpkg/pkg/manager.py @@ -23,7 +23,6 @@ import os -import sys import subprocess from slpkg.utils import Utils @@ -99,7 +98,7 @@ class PackageManager(object): str(len(self.removed)), msg)) except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() if remove_pkg in ["y", "Y"]: self._check_if_used(self.binary) for rmv in self.removed: @@ -131,7 +130,7 @@ class PackageManager(object): print("") except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() return remove_dep def _view_removed(self): @@ -176,7 +175,7 @@ class PackageManager(object): os.remove(self.dep_path + package) # remove log except KeyboardInterrupt: print("") - sys.exit(0) + raise SystemExit() def _rmv_deps(self, dependencies, package): """Remove dependencies @@ -210,7 +209,7 @@ class PackageManager(object): self.skip = raw_input(" > ").split() except KeyboardInterrupt: print("") - sys.exit(0) + raise SystemExit() for s in self.skip: if s in self.removed: self.removed.remove(s) @@ -348,7 +347,7 @@ class PackageManager(object): print("") # new line at end except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() def list_greps(self, repo, packages): """Grep packages diff --git a/slpkg/pkg_find.py b/slpkg/pkg_find.py index 1b68f866..9dabacd4 100644 --- a/slpkg/pkg_find.py +++ b/slpkg/pkg_find.py @@ -22,8 +22,6 @@ # along with this program. If not, see . -import sys - from messages import Msg from sbo.greps import SBoGrep from pkg.manager import PackageManager @@ -63,7 +61,7 @@ def find_from_repos(pkg): _meta_.color["GREY"], count_pkg, count_repo, _meta_.color["ENDC"])) except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() def sbo_version(repo, find): diff --git a/slpkg/repoinfo.py b/slpkg/repoinfo.py index 539bb090..01a465fa 100644 --- a/slpkg/repoinfo.py +++ b/slpkg/repoinfo.py @@ -23,7 +23,6 @@ import os -import sys from sizes import units from utils import Utils @@ -101,7 +100,7 @@ class RepoInfo(object): for key, value in sorted(self.form.iteritems()): print self.meta.color["GREY"] + key + self.meta.color["ENDC"], value print("") - sys.exit(0) + raise SystemExit() def repository_data(self, repo): """ diff --git a/slpkg/repolist.py b/slpkg/repolist.py index f5b7f1ed..953ef14f 100644 --- a/slpkg/repolist.py +++ b/slpkg/repolist.py @@ -22,8 +22,6 @@ # along with this program. If not, see . -import sys - from messages import Msg from repositories import Repo from __metadata__ import MetaData as _meta_ @@ -92,4 +90,4 @@ class RepoList(object): print("For enable or disable default repositories edit " "'/etc/slpkg/slpkg.conf' file.\n{0}".format( self.meta.color["ENDC"])) - sys.exit(0) + raise SystemExit() diff --git a/slpkg/repositories.py b/slpkg/repositories.py index f37bcbce..bd76d832 100644 --- a/slpkg/repositories.py +++ b/slpkg/repositories.py @@ -23,7 +23,6 @@ import os -import sys from utils import Utils from __metadata__ import MetaData as _meta_ @@ -52,17 +51,17 @@ class Repo(object): print("\nRepository name '{0}' exist, select different name.\n" "View all repositories with command 'repo-list'.\n".format( repo)) - sys.exit(0) + raise SystemExit() elif len(repo) > 6: print("\nMaximum repository name length must be six (6) " "characters\n") - sys.exit(0) + raise SystemExit() with open(self.repo_file, "a") as repos: new_line = " {0}{1}{2}\n".format(repo, " " * (10 - len(repo)), url) repos.write(new_line) repos.close() print("\nRepository '{0}' successfully added\n".format(repo)) - sys.exit(0) + raise SystemExit() def remove(self, repo): """ @@ -81,7 +80,7 @@ class Repo(object): repos.close() if not rem_repo: print("\nRepository '{0}' doesn't exist\n".format(repo)) - sys.exit(0) + raise SystemExit() def custom_repository(self): """ diff --git a/slpkg/sbo/check.py b/slpkg/sbo/check.py index dc17ad97..67086807 100644 --- a/slpkg/sbo/check.py +++ b/slpkg/sbo/check.py @@ -23,7 +23,6 @@ import os -import sys from distutils.version import LooseVersion from slpkg.messages import Msg @@ -57,7 +56,7 @@ def sbo_upgrade(skip): return upgrade_names except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() def sbo_list(): diff --git a/slpkg/sbo/dependency.py b/slpkg/sbo/dependency.py index aff9bdb9..e5d15bed 100644 --- a/slpkg/sbo/dependency.py +++ b/slpkg/sbo/dependency.py @@ -65,6 +65,6 @@ class Requires(object): return self.dep_results except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() else: return [] diff --git a/slpkg/sbo/search.py b/slpkg/sbo/search.py index 957003a0..156e75cc 100644 --- a/slpkg/sbo/search.py +++ b/slpkg/sbo/search.py @@ -22,8 +22,6 @@ # along with this program. If not, see . -import sys - from slpkg.utils import Utils from slpkg.repositories import Repo from slpkg.__metadata__ import MetaData as _meta_ @@ -48,4 +46,4 @@ def sbo_search_pkg(name): return "" except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() diff --git a/slpkg/sbo/slackbuild.py b/slpkg/sbo/slackbuild.py index 3e831a65..d84ffc74 100644 --- a/slpkg/sbo/slackbuild.py +++ b/slpkg/sbo/slackbuild.py @@ -23,7 +23,6 @@ import os -import sys from slpkg.utils import Utils from slpkg.messages import Msg @@ -131,7 +130,7 @@ class SBoInstall(object): Msg().not_found(if_upgrade) except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() def update_deps(self): """Update dependencies dictionary with all package @@ -315,7 +314,7 @@ class SBoInstall(object): binary = (self.meta.output + max(binary_list)).split() except ValueError: Msg().build_FAILED(sbo_url, prgnam) - sys.exit(0) + raise SystemExit() find = GetFromInstalled(pkg).name() if find == pkg: print("[ {0}Upgrading{1} ] --> {2}".format( diff --git a/slpkg/slack/patches.py b/slpkg/slack/patches.py index ef4c8402..4551ab83 100644 --- a/slpkg/slack/patches.py +++ b/slpkg/slack/patches.py @@ -23,7 +23,6 @@ import os -import sys import shutil import subprocess @@ -128,7 +127,7 @@ class Patches(object): "date\n".format(slack_arch, self.version, slack_ver())) except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() def store(self): """ diff --git a/slpkg/slpkg_update.py b/slpkg/slpkg_update.py index 6ad64641..15bd638f 100644 --- a/slpkg/slpkg_update.py +++ b/slpkg/slpkg_update.py @@ -24,7 +24,6 @@ import os import re -import sys import tarfile import subprocess @@ -62,7 +61,7 @@ def it_self_update(): if answer in ["y", "Y"]: print("") # new line after answer else: - sys.exit(0) + raise SystemExit() dwn_link = ["https://{0}.com/{1}/{2}/archive/" "v{3}.tar.gz".format(repository, _meta_.__author__, _meta_.__all__, @@ -85,4 +84,4 @@ def it_self_update(): else: print("\n{0}: There is no new version, already used the last !" "\n".format(_meta_.__all__)) - sys.exit(0) + raise SystemExit() diff --git a/slpkg/toolbar.py b/slpkg/toolbar.py index 63ba8fb0..1c6df554 100644 --- a/slpkg/toolbar.py +++ b/slpkg/toolbar.py @@ -41,4 +41,4 @@ def status(sec): time.sleep(float(sec)) except KeyboardInterrupt: print("") - sys.exit(0) + raise SystemExit() diff --git a/slpkg/url_read.py b/slpkg/url_read.py index c34bf5a9..37949b8f 100644 --- a/slpkg/url_read.py +++ b/slpkg/url_read.py @@ -22,7 +22,6 @@ # along with this program. If not, see . -import sys import urllib2 from __metadata__ import MetaData as _meta_ @@ -48,4 +47,4 @@ class URL(object): return " " except KeyboardInterrupt: print("") # new line at exit - sys.exit(0) + raise SystemExit() diff --git a/slpkg/utils.py b/slpkg/utils.py index 73de3505..2d2e3cd4 100644 --- a/slpkg/utils.py +++ b/slpkg/utils.py @@ -23,7 +23,6 @@ import os -import sys from splitting import split_package @@ -70,7 +69,7 @@ class Utils(object): return packages except KeyboardInterrupt: print("") - sys.exit(0) + raise SystemExit() def check_downloaded(self, path, maybe_downloaded): """ @@ -95,4 +94,4 @@ class Utils(object): return line except KeyboardInterrupt: print("") - sys.exit(0) + raise SystemExit()