From 54a07389ef80462cbf6094cdf0b8ec6974e31b5f Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 9 Sep 2015 08:09:13 +0300 Subject: [PATCH] Fix complexity --- slpkg/sbo/network.py | 143 ++++++++++++++++++++++++++++--------------- 1 file changed, 94 insertions(+), 49 deletions(-) diff --git a/slpkg/sbo/network.py b/slpkg/sbo/network.py index efd69c65..ea7ee812 100644 --- a/slpkg/sbo/network.py +++ b/slpkg/sbo/network.py @@ -84,48 +84,103 @@ class SBoNetwork(object): self.view_sbo() while True: self.read_choice() - if self.choice in ["D", "d"]: - Download(path="", url=self.dwn_srcs, repo="sbo").start() - break - elif self.choice in ["R", "r"]: - README = ReadSBo(self.sbo_url).readme("README") - fill = self.fill_pager(README) - self.pager(README + fill) - elif self.choice in ["F", "f"]: - info = ReadSBo(self.sbo_url).info(self.name, ".info") - fill = self.fill_pager(info) - self.pager(info + fill) - elif self.choice in ["S", "s"]: - SlackBuild = ReadSBo(self.sbo_url).slackbuild(self.name, - ".SlackBuild") - fill = self.fill_pager(SlackBuild) - self.pager(SlackBuild + fill) - elif self.choice in ["O", "o"]: - doinst_sh = ReadSBo(self.sbo_url).doinst("doinst.sh") - if doinst_sh != " ": - fill = self.fill_pager(doinst_sh) - self.pager(doinst_sh + fill) - elif self.choice in ["B", "b"]: - self.build() - delete(self.build_folder) - break - elif self.choice in ["I", "i"]: - if not find_package(self.prgnam + self.meta.sp, - self.meta.pkg_path): - self.build() - self.install() - delete(self.build_folder) - break - else: - self.msg.template(78) - self.msg.pkg_found() - self.msg.template(78) - break - else: - break + choice = { + "r": self.choice_README, + "R": self.choice_README, + "s": self.choice_SlackBuild, + "S": self.choice_SlackBuild, + "f": self.choice_info, + "F": self.choice_info, + "o": self.choice_doinst, + "O": self.choice_doinst, + "d": self.choice_download, + "D": self.choice_download, + "b": self.choice_build, + "B": self.choice_build, + "i": self.choice_install, + "I": self.choice_install, + "q": self.choice_quit, + "Q": self.choice_quit, + } + try: + choice[self.choice]() + except KeyError: + raise SystemExit() else: self.msg.pkg_not_found("\n", self.name, "Can't view", "\n") + def read_choice(self): + """Return choice + """ + try: + self.choice = raw_input("{0} Choose an option > {1}".format( + self.grey, self.endc)) + except (KeyboardInterrupt, EOFError): + print("") + raise SystemExit() + + def choice_README(self): + """View README file + """ + README = ReadSBo(self.sbo_url).readme("README") + fill = self.fill_pager(README) + self.pager(README + fill) + + def choice_SlackBuild(self): + """View .SlackBuild file + """ + SlackBuild = ReadSBo(self.sbo_url).slackbuild(self.name, ".SlackBuild") + fill = self.fill_pager(SlackBuild) + self.pager(SlackBuild + fill) + + def choice_info(self): + """View .info file + """ + info = ReadSBo(self.sbo_url).info(self.name, ".info") + fill = self.fill_pager(info) + self.pager(info + fill) + + def choice_doinst(self): + """View doinst.sh file + """ + doinst_sh = ReadSBo(self.sbo_url).doinst("doinst.sh") + if doinst_sh != " ": + fill = self.fill_pager(doinst_sh) + self.pager(doinst_sh + fill) + + def choice_download(self): + """Download script.tar.gz and sources + """ + Download(path="", url=self.dwn_srcs, repo="sbo").start() + raise SystemExit() + + def choice_build(self): + """Build package + """ + self.build() + delete(self.build_folder) + raise SystemExit() + + def choice_install(self): + """Download, build and install package + """ + if not find_package(self.prgnam + self.meta.sp, + self.meta.pkg_path): + self.build() + self.install() + delete(self.build_folder) + raise SystemExit() + else: + self.msg.template(78) + self.msg.pkg_found(self.prgnam) + self.msg.template(78) + raise SystemExit() + + def choice_quit(self): + """Quit from choices + """ + raise SystemExit() + def view_sbo(self): """View slackbuild.org """ @@ -193,16 +248,6 @@ class SBoNetwork(object): else: return "" - def read_choice(self): - """Return choice - """ - try: - self.choice = raw_input("{0} Choose an option > {1}".format( - self.grey, self.endc)) - except (KeyboardInterrupt, EOFError): - print("") - raise SystemExit() - def error_uns(self): """Check if package supported by arch before proceed to install