diff --git a/slpkg/binary/check.py b/slpkg/binary/check.py index b3ee3309..1dc99860 100644 --- a/slpkg/binary/check.py +++ b/slpkg/binary/check.py @@ -21,14 +21,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from slpkg.messages import Msg from slpkg.toolbar import status from slpkg.blacklist import BlackList from slpkg.splitting import split_package from slpkg.__metadata__ import MetaData as _m -from slpkg.messages import ( - msg_done, - msg_checking -) from slpkg.pkg.find import find_package @@ -42,7 +39,7 @@ def pkg_upgrade(repo): ''' Checking packages fro upgrade ''' - msg_checking() + Msg().checking() PACKAGES_TXT = RepoInit(repo).fetch()[0] pkgs_for_upgrade = [] ver_for_upgrade = [] @@ -63,7 +60,7 @@ def pkg_upgrade(repo): inst_pkg[0] not in BlackList().packages()): pkgs_for_upgrade.append(repo_pkg[0]) ver_for_upgrade.append('-' + inst_pkg[1]) - msg_done() + Msg().done() return pkgs_for_upgrade, ver_for_upgrade diff --git a/slpkg/binary/install.py b/slpkg/binary/install.py index 48694faa..2f7c8787 100644 --- a/slpkg/binary/install.py +++ b/slpkg/binary/install.py @@ -25,6 +25,7 @@ import os import sys from slpkg.sizes import units +from slpkg.messages import Msg from slpkg.remove import delete from slpkg.log_deps import write_deps from slpkg.checksum import check_md5 @@ -32,16 +33,6 @@ from slpkg.blacklist import BlackList from slpkg.downloader import Download from slpkg.grep_md5 import pkg_checksum from slpkg.splitting import split_package -from slpkg.messages import ( - msg_pkg, - template, - msg_done, - reference, - msg_reading, - msg_upg_inst, - msg_resolving, - msg_not_found, -) from slpkg.utils import ( remove_dbs, dimensional_list @@ -73,7 +64,7 @@ class BinaryInstall(object): self.dependencies = [] self.deps_dict = {} self.answer = '' - msg_reading() + Msg().reading() self.PACKAGES_TXT, self.mirror = RepoInit(self.repo).fetch() num_lines = sum(1 for line in self.PACKAGES_TXT) self.step = (num_lines / (100 * len(self.packages))) @@ -89,18 +80,18 @@ class BinaryInstall(object): self.packages, self.pkg_ver = self.packages[0], self.packages[1] mas_sum = dep_sum = sums = [0, 0, 0] self.pkg_exist() - msg_done() + Msg().done() self.dependencies = self.resolving_deps() (self.dep_dwn, self.dep_install, self.dep_comp_sum, self.dep_uncomp_sum) = self.store(self.dependencies) self.packages = self.clear_masters() (self.dwn, self.install, self.comp_sum, self.uncomp_sum) = self.store(self.packages) - msg_done() + Msg().done() if self.install: print("") # new line at start self.top_view() - msg_upg_inst(self.if_upgrade) + Msg().upg_inst(self.if_upgrade) mas_sum = self.views(self.install, self.comp_sum) if self.dependencies: print("Installing for dependencies:") @@ -113,26 +104,26 @@ class BinaryInstall(object): print("\nInstalling summary") print("=" * 79) print("{0}Total {1} {2}.".format(_m.color['GREY'], sum(sums), - msg_pkg(sum(sums)))) + Msg().pkg(sum(sums)))) print("{0} {1} will be installed, {2} will be upgraded and " "{3} will be reinstalled.".format(sums[2], - msg_pkg(sums[2]), + Msg().pkg(sums[2]), sums[1], sums[0])) print("Need to get {0} {1} of archives.".format(size[0], unit[0])) print("After this process, {0} {1} of additional disk " "space will be used.{2}".format(size[1], unit[1], _m.color['ENDC'])) - self.answer = self.continue_install() - if self.answer in ['y', 'Y']: + print('') + if Msg().answer() in ['y', 'Y']: self.install.reverse() Download(self.tmp_path, (self.dep_dwn + self.dwn)).start() ins, upg = self.install_packages() - reference(ins, upg) + Msg().reference(ins, upg) write_deps(self.deps_dict) delete(self.tmp_path, self.install) else: - msg_not_found(self.if_upgrade) + Msg().not_found(self.if_upgrade) except KeyboardInterrupt: print("") # new line at exit sys.exit(0) @@ -206,22 +197,12 @@ class BinaryInstall(object): else: check_md5(pkg_checksum(install, self.repo), self.tmp_path + install) - def continue_install(self): - ''' - Default answer - ''' - if _m.default_answer == "y": - self.answer = _m.default_answer - else: - self.answer = raw_input("\nWould you like to continue [Y/n]? ") - return self.answer - def resolving_deps(self): ''' Return package dependencies ''' requires = [] - msg_resolving() + Msg().resolving() for dep in self.packages: dependencies = [] dependencies = dimensional_list(Dependencies(self.PACKAGES_TXT, @@ -266,7 +247,7 @@ class BinaryInstall(object): return [pkg_sum, upg_sum, uni_sum] def top_view(self): - template(78) + Msg().template(78) print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( "| Package", " " * 17, "Version", " " * 12, @@ -274,7 +255,7 @@ class BinaryInstall(object): "Build", " " * 2, "Repos", " " * 10, "Size")) - template(78) + Msg().template(78) def store(self, packages): ''' diff --git a/slpkg/checksum.py b/slpkg/checksum.py index b2cc3c04..922d3026 100644 --- a/slpkg/checksum.py +++ b/slpkg/checksum.py @@ -24,7 +24,7 @@ import sys from md5sum import md5 -from messages import template +from messages import Msg from __metadata__ import MetaData as _m @@ -34,24 +34,20 @@ def check_md5(pkg_md5, src_file): ''' md5s = md5(src_file) if pkg_md5 != md5s: - template(78) + Msg().template(78) print("| MD5SUM check for {0} [ {1}FAILED{2} ]".format( src_file.split("/")[-1], _m.color['RED'], _m.color['ENDC'])) - template(78) + Msg().template(78) print("| Expected: {0}".format(md5s)) print("| Found: {0}".format(pkg_md5)) - template(78) - if _m.default_answer == "y": - answer = _m.default_answer - else: - answer = raw_input("Would you like to continue [Y/n]? ") - if answer in ['y', 'Y']: + Msg().template(78) + if Msg().answer() in ['y', 'Y']: print("") # new line after answer else: sys.exit(0) else: - template(78) + Msg().template(78) print("| MD5SUM check for {0} [ {1}PASSED{2} ]".format( src_file.split("/")[-1], _m.color['GREEN'], _m.color['ENDC'])) - template(78) + Msg().template(78) print("") # new line after pass checksum diff --git a/slpkg/desc.py b/slpkg/desc.py index 1ac521d6..12007ef6 100644 --- a/slpkg/desc.py +++ b/slpkg/desc.py @@ -22,8 +22,8 @@ # along with this program. If not, see . +from messages import Msg from utils import read_file -from messages import pkg_not_found from __metadata__ import MetaData as _m @@ -69,6 +69,6 @@ class PkgDesc(object): count += 1 print(self.COLOR + line[31:] + _m.color['ENDC']) if count == 0: - pkg_not_found("", self.name, "No matching", "\n") + Msg().pkg_not_found("", self.name, "No matching", "\n") else: print("") # new line at end diff --git a/slpkg/downloader.py b/slpkg/downloader.py index f6750326..6e31b251 100644 --- a/slpkg/downloader.py +++ b/slpkg/downloader.py @@ -21,9 +21,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os import sys import subprocess +from messages import Msg from __metadata__ import MetaData as _m @@ -36,17 +38,23 @@ class Download(object): def start(self): ''' Download files usign wget. - Check if file already download and skip or continue - download if before stoped. ''' for dwn in self.url: - file_name = dwn.split("/")[-1] + self.file_name = dwn.split("/")[-1] print("\n[ {0}Download{1} ] -->{1} {2}\n".format(_m.color['GREEN'], _m.color['ENDC'], - file_name)) + self.file_name)) try: subprocess.call("wget {0} --directory-prefix={1} {2}".format( _m.wget_option, self.path, dwn), shell=True) + self.check() except KeyboardInterrupt: print # new line at cancel sys.exit(0) + + def check(self): + if not os.path.isfile(self.path + self.file_name): + Msg().template(78) + print("| Download '{0}' file {1}[ FAILED ]{2}".format( + self.file_name, _m.color['RED'], _m.color['ENDC'])) + Msg().template(78) diff --git a/slpkg/main.py b/slpkg/main.py index 533825f6..29712923 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -24,10 +24,10 @@ import sys import getpass +from messages import Msg from desc import PkgDesc from config import Config from queue import QueuePkgs -from messages import s_user from repoinfo import RepoInfo from repolist import RepoList from repositories import Repo @@ -37,8 +37,8 @@ from version import prog_version from arguments import options, usage from slpkg_update import it_self_update from init import ( - Initialization, Update, + Initialization, check_exists_repositories ) from __metadata__ import MetaData as _m @@ -79,7 +79,7 @@ class Case(object): def main(): - s_user(getpass.getuser()) + Msg().s_user(getpass.getuser()) args = sys.argv args.pop(0) blacklist = BlackList() diff --git a/slpkg/messages.py b/slpkg/messages.py index fbc47872..71a47f9b 100644 --- a/slpkg/messages.py +++ b/slpkg/messages.py @@ -28,121 +28,120 @@ from __metadata__ import MetaData as _m from slpkg.pkg.find import find_package -def pkg_not_found(bol, pkg, message, eol): - ''' - Print message when package not found - ''' - print("{0}No such package {1}: {2}{3}".format(bol, pkg, message, eol)) +class Msg(object): + def pkg_not_found(self, bol, pkg, message, eol): + ''' + Print message when package not found + ''' + print("{0}No such package {1}: {2}{3}".format(bol, pkg, message, eol)) -def pkg_found(pkg, version): - ''' - Print message when package found - ''' - print("| Package {0}-{1} is already installed".format(pkg, version)) + def pkg_found(self, pkg, version): + ''' + Print message when package found + ''' + print("| Package {0}-{1} is already installed".format(pkg, version)) + def pkg_installed(self, pkg): + ''' + Print message when package installed + ''' + print("| Package {0} installed".format(pkg)) -def pkg_installed(pkg): - ''' - Print message when package installed - ''' - print("| Package {0} installed".format(pkg)) + def s_user(self, user): + ''' + Check for root user + ''' + if user != "root": + print("\nslpkg: error: must have root privileges\n") + sys.exit(0) + def build_FAILED(self, sbo_url, prgnam): + ''' + Print error message if build failed + ''' + self.template(78) + print("| Build package {0} [ {1}FAILED{2} ]".format(prgnam, + _m.color['RED'], + _m.color['ENDC'])) + self.template(78) + print("| See log file in '{0}/var/log/slpkg/sbo/build_logs{1}' " + "directory or read README file:".format(_m.color['CYAN'], + _m.color['ENDC'])) + print("| {0}{1}".format(sbo_url, "README")) + self.template(78) + print # new line at end -def s_user(user): - ''' - Check for root user - ''' - if user != "root": - print("\nslpkg: error: must have root privileges\n") - sys.exit(0) + def template(self, max_len): + ''' + Print template + ''' + print("+" + "=" * max_len) + def checking(self): + sys.stdout.write("{0}Checking ...{1}".format(_m.color['GREY'], + _m.color['ENDC'])) + sys.stdout.flush() -def build_FAILED(sbo_url, prgnam): - ''' - Print error message if build failed - ''' - template(78) - print("| Build package {0} [ {1}FAILED{2} ]".format(prgnam, _m.color['RED'], - _m.color['ENDC'])) - template(78) - print("| See log file in '{0}/var/log/slpkg/sbo/build_logs{1}' directory " - "or read README file:".format(_m.color['CYAN'], _m.color['ENDC'])) - print("| {0}{1}".format(sbo_url, "README")) - template(78) - print # new line at end + def reading(self): + sys.stdout.write("{0}Reading package lists ...{1}".format( + _m.color['GREY'], _m.color['ENDC'])) + sys.stdout.flush() + def resolving(self): + sys.stdout.write("{0}Resolving dependencies ...{1}".format( + _m.color['GREY'], _m.color['ENDC'])) + sys.stdout.flush() -def template(max_len): - ''' - Print template - ''' - print("+" + "=" * max_len) + def done(self): + sys.stdout.write("{0}Done{1}\n".format(_m.color['GREY'], + _m.color['ENDC'])) + def pkg(self, count): + ''' + Print singular plural + ''' + message = "package" + if count > 1: + message = message + "s" + return message -def msg_checking(): - sys.stdout.write("{0}Checking ...{1}".format(_m.color['GREY'], - _m.color['ENDC'])) - sys.stdout.flush() - - -def msg_reading(): - sys.stdout.write("{0}Reading package lists ...{1}".format(_m.color['GREY'], - _m.color['ENDC'])) - sys.stdout.flush() - - -def msg_resolving(): - sys.stdout.write("{0}Resolving dependencies ...{1}".format( - _m.color['GREY'], _m.color['ENDC'])) - sys.stdout.flush() - - -def msg_done(): - sys.stdout.write("{0}Done{1}\n".format(_m.color['GREY'], _m.color['ENDC'])) - - -def msg_pkg(count): - ''' - Print singular plural - ''' - message = "package" - if count > 1: - message = message + "s" - return message - - -def msg_not_found(if_upgrade): - if if_upgrade: - print('\nNot found packages for upgrade\n') - else: - print('\nNot found packages for installation\n') - - -def msg_upg_inst(if_upgrade): - if not if_upgrade: - print("Installing:") - else: - print("Upgrading:") - - -def reference(install, upgrade): - ''' - Reference list with packages installed - and upgraded - ''' - template(78) - print("| Total {0} {1} installed and {2} {3} upgraded".format( - len(install), msg_pkg(len(install)), - len(upgrade), msg_pkg(len(upgrade)))) - template(78) - for installed in (install + upgrade): - name = '-'.join(installed.split('-')[:-1]) - if find_package(installed, _m.pkg_path): - if installed in upgrade: - print("| Package {0} upgraded successfully".format(name)) - else: - print("| Package {0} installed successfully".format(name)) + def not_found(self, if_upgrade): + if if_upgrade: + print('\nNot found packages for upgrade\n') else: - print("| Package {0} NOT installed".format(name)) - template(78) + print('\nNot found packages for installation\n') + + def upg_inst(self, if_upgrade): + if not if_upgrade: + print("Installing:") + else: + print("Upgrading:") + + def answer(self): + if _m.default_answer == "y": + answer = _m.default_answer + else: + answer = raw_input("Would you like to continue [Y/n]? ") + return answer + + def reference(self, install, upgrade): + ''' + Reference list with packages installed + and upgraded + ''' + self.template(78) + print("| Total {0} {1} installed and {2} {3} upgraded".format( + len(install), self.pkg(len(install)), + len(upgrade), self.pkg(len(upgrade)))) + self.template(78) + for installed in (install + upgrade): + name = '-'.join(installed.split('-')[:-1]) + if find_package(installed, _m.pkg_path): + if installed in upgrade: + print("| Package {0} upgraded successfully".format(name)) + else: + print("| Package {0} installed successfully".format(name)) + else: + print("| Package {0} NOT installed".format(name)) + self.emplate(78) diff --git a/slpkg/pkg/build.py b/slpkg/pkg/build.py index 74f6a47b..9f1c07c3 100644 --- a/slpkg/pkg/build.py +++ b/slpkg/pkg/build.py @@ -29,8 +29,8 @@ import shutil import tarfile import subprocess +from slpkg.messages import Msg from slpkg.checksum import check_md5 -from slpkg.messages import pkg_not_found from slpkg.__metadata__ import MetaData as _m from slpkg.sbo.greps import SBoGrep @@ -94,7 +94,7 @@ class BuildPackage(object): shell=True)) os.chdir(self.path) except (OSError, IOError): - pkg_not_found("\n", self.prgnam, "Wrong file", "\n") + Msg().pkg_not_found("\n", self.prgnam, "Wrong file", "\n") except KeyboardInterrupt: print("") # new line at exit sys.exit(0) diff --git a/slpkg/pkg/manager.py b/slpkg/pkg/manager.py index d60763ee..a9334423 100644 --- a/slpkg/pkg/manager.py +++ b/slpkg/pkg/manager.py @@ -25,11 +25,8 @@ import os import sys import subprocess +from slpkg.messages import Msg from slpkg.utils import read_file -from slpkg.messages import ( - pkg_not_found, - template -) from slpkg.__metadata__ import MetaData as _m from slpkg.pkg.find import find_package @@ -85,7 +82,7 @@ class PackageManager(object): bol = eol = "" else: bol = eol = "\n" - pkg_not_found(bol, pkg, message, eol) + Msg().pkg_not_found(bol, pkg, message, eol) def remove(self): ''' @@ -155,7 +152,7 @@ class PackageManager(object): "\n ".join(pkgs))) removed.append(pkg) else: - pkg_not_found("", pkg, "Can't remove", "") + Msg().pkg_not_found("", pkg, "Can't remove", "") return removed @staticmethod @@ -165,12 +162,12 @@ class PackageManager(object): ''' dependencies = read_file(path + package) print("") # new line at start - template(78) + Msg().template(78) print("| Found dependencies for package {0}:".format(package)) - template(78) + Msg().template(78) for dep in dependencies.splitlines(): print("| {0}{1}{2}".format(_m.color['RED'], dep, _m.color['ENDC'])) - template(78) + Msg().template(78) return dependencies @staticmethod @@ -203,15 +200,15 @@ class PackageManager(object): ''' Prints all removed packages ''' - template(78) + Msg().template(78) print("| Total {0} packages removed".format(len(removes))) - template(78) + Msg().template(78) for pkg in removes: if not find_package(pkg + _m.sp, _m.pkg_path): print("| Package {0} removed".format(pkg)) else: print("| Package {0} not found".format(pkg)) - template(78) + Msg().template(78) print("") # new line at end def find(self): @@ -237,7 +234,7 @@ class PackageManager(object): break if matching == 0: message = "Can't find" - pkg_not_found("", self.binary, message, "\n") + Msg().pkg_not_found("", self.binary, message, "\n") else: print("\n{0}Total found {1} matching packages.{2}".format( _m.color['GREY'], matching, _m.color['ENDC'])) @@ -265,7 +262,7 @@ class PackageManager(object): bol = eol = "" else: bol = eol = "\n" - pkg_not_found(bol, pkg, message, eol) + Msg().pkg_not_found(bol, pkg, message, eol) def list(self, repo, INDEX): ''' diff --git a/slpkg/repolist.py b/slpkg/repolist.py index a36a985e..def57ec0 100644 --- a/slpkg/repolist.py +++ b/slpkg/repolist.py @@ -24,8 +24,8 @@ import sys +from messages import Msg from repositories import Repo -from messages import template from __metadata__ import MetaData as _m @@ -55,13 +55,13 @@ class RepoList(object): View or enabled or disabled repositories ''' print('') - template(78) + Msg().template(78) print('{0}{1}{2}{3}{4}{5}{6}'.format( '| Repo id', ' ' * 2, 'Repo URL', ' ' * 44, 'Default', ' ' * 3, 'Status')) - template(78) + Msg().template(78) for repo_id, repo_URL in sorted(self.all_repos.iteritems()): status, COLOR = 'disabled', _m.color['RED'] default = 'yes' diff --git a/slpkg/sbo/check.py b/slpkg/sbo/check.py index b2868fb2..fe1928e2 100644 --- a/slpkg/sbo/check.py +++ b/slpkg/sbo/check.py @@ -25,13 +25,10 @@ import os import sys +from slpkg.messages import Msg from slpkg.toolbar import status from slpkg.splitting import split_package from slpkg.__metadata__ import MetaData as _m -from slpkg.messages import ( - msg_done, - msg_checking -) from greps import SBoGrep from search import sbo_search_pkg @@ -42,7 +39,7 @@ def sbo_upgrade(): Return packages for upgrade ''' try: - msg_checking() + Msg().checking() upgrade_names, pkg_ver = [], [] index, toolbar_width = 0, 3 for pkg in sbo_list(): @@ -56,7 +53,7 @@ def sbo_upgrade(): if sbo_package > package: upgrade_names.append(name) pkg_ver.append(ver) - msg_done() + Msg().done() return upgrade_names, pkg_ver except KeyboardInterrupt: print("") # new line at exit diff --git a/slpkg/sbo/slackbuild.py b/slpkg/sbo/slackbuild.py index fbbc9b75..e14f93d1 100644 --- a/slpkg/sbo/slackbuild.py +++ b/slpkg/sbo/slackbuild.py @@ -33,18 +33,7 @@ from slpkg.utils import ( dimensional_list, remove_dbs ) -from slpkg.messages import ( - msg_pkg, - template, - msg_done, - pkg_found, - reference, - msg_reading, - msg_upg_inst, - build_FAILED, - msg_not_found, - msg_resolving -) +from slpkg.messages import Msg from slpkg.__metadata__ import MetaData as _m from slpkg.pkg.find import find_package @@ -71,7 +60,7 @@ class SBoInstall(object): self.deps_dict = {} self.toolbar_width, self.index = 2, 0 self.answer = '' - msg_reading() + Msg().reading() def start(self, if_upgrade): try: @@ -98,17 +87,17 @@ class SBoInstall(object): self.package_found = self.matching(self.package_not_found) self.master_packages, mas_src = self.sbo_version_source( self.package_found) - msg_done() - msg_resolving() + Msg().done() + Msg().resolving() self.dependencies, dep_src = self.sbo_version_source( self.one_for_all(self.deps)) - msg_done() + Msg().done() self.master_packages = self.clear_masters() if self.package_found: print("\nThe following packages will be automatically " "installed or upgraded \nwith new version:\n") self.top_view() - msg_upg_inst(self.if_upgrade) + Msg().upg_inst(self.if_upgrade) # view master packages for sbo, ver, ar in zip(self.master_packages, self.pkg_ver, mas_src): @@ -132,21 +121,19 @@ class SBoInstall(object): print("\nInstalling summary") print("=" * 79) print("{0}Total {1} {2}.".format( - _m.color['GREY'], count_total, msg_pkg(count_total))) + _m.color['GREY'], count_total, Msg().pkg(count_total))) print("{0} {1} will be installed, {2} allready installed and " - "{3} {4}".format(count_uni, msg_pkg(count_uni), + "{3} {4}".format(count_uni, Msg().pkg(count_uni), count_ins, count_upg, - msg_pkg(count_upg))) + Msg().pkg(count_upg))) print("will be upgraded.{0}\n".format(_m.color['ENDC'])) - if self.master_packages: - self.answer = self.continue_install() - if self.answer in['y', 'Y']: - b_ins = self.build_install() - reference(b_ins[0], b_ins[1]) - write_deps(self.deps_dict) - delete(_m.build_path) + if self.master_packages and Msg().answer() in['y', 'Y']: + b_ins = self.build_install() + Msg().reference(b_ins[0], b_ins[1]) + write_deps(self.deps_dict) + delete(_m.build_path) else: - msg_not_found(if_upgrade) + Msg().not_found(if_upgrade) except KeyboardInterrupt: print("") # new line at exit sys.exit(0) @@ -207,7 +194,7 @@ class SBoInstall(object): ''' View top template ''' - template(78) + Msg().template(78) print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( "| Package", " " * 17, "Version", " " * 12, @@ -215,7 +202,7 @@ class SBoInstall(object): "Build", " " * 2, "Repos", " " * 10, "Size")) - template(78) + Msg().template(78) def view_version(self): ''' @@ -269,16 +256,6 @@ class SBoInstall(object): arch = item return arch - def continue_install(self): - ''' - Default answer - ''' - if _m.default_answer == "y": - self.answer = _m.default_answer - else: - self.answer = raw_input("Would you like to continue [Y/n]? ") - return self.answer - def filenames(self, sources): ''' Return filenames from sources @@ -317,15 +294,15 @@ class SBoInstall(object): sbo_file = "".join(find_package(prgnam, _m.pkg_path)) src_link = SBoGrep(pkg).source().split() if sbo_file: - template(78) - pkg_found(pkg, split_package(sbo_file)[1]) - template(78) + Msg().template(78) + Msg().pkg_found(pkg, split_package(sbo_file)[1]) + Msg().template(78) elif self.unst[0] in src_link or self.unst[1] in src_link: - template(78) + Msg().template(78) print("| Package {0} {1}{2}{3}".format(sbo, _m.color['RED'], ''.join(src_link), _m.color['ENDC'])) - template(78) + Msg().template(78) else: sbo_url = sbo_search_pkg(pkg) sbo_link = SBoLink(sbo_url).tar_gz() @@ -338,7 +315,7 @@ class SBoInstall(object): try: binary = (_m.output + max(binary_list)).split() except ValueError: - build_FAILED(sbo_url, prgnam) + Msg().build_FAILED(sbo_url, prgnam) sys.exit(0) if find_package(pkg + '-', _m.pkg_path): print("{0}[ Upgrading ] --> {1}{2}".format( diff --git a/slpkg/sbo/views.py b/slpkg/sbo/views.py index 1a460914..d44d2785 100644 --- a/slpkg/sbo/views.py +++ b/slpkg/sbo/views.py @@ -25,16 +25,9 @@ import os import sys import pydoc +from slpkg.messages import Msg from slpkg.downloader import Download from slpkg.__metadata__ import MetaData as _m -from slpkg.messages import ( - msg_done, - template, - pkg_found, - msg_reading, - build_FAILED, - pkg_not_found -) from slpkg.pkg.find import find_package from slpkg.pkg.build import BuildPackage @@ -51,7 +44,7 @@ class SBoNetwork(object): def __init__(self, name): self.name = name - msg_reading() + Msg().reading() grep = SBoGrep(self.name) self.sbo_url = sbo_search_pkg(self.name) if self.sbo_url: @@ -62,7 +55,7 @@ class SBoNetwork(object): self.sbo_version = grep.version() self.dwn_srcs = self.sbo_dwn.split() + self.source_dwn self.space = ("\n" * 50) - msg_done() + Msg().done() def view(self): ''' @@ -106,14 +99,14 @@ class SBoNetwork(object): delete(_m.build_path) break else: - template(78) - pkg_found(self.name, self.sbo_version) - template(78) + Msg().template(78) + Msg().pkg_found(self.name, self.sbo_version) + Msg().template(78) break else: break else: - pkg_not_found("\n", self.name, "Can't view", "\n") + Msg().pkg_not_found("\n", self.name, "Can't view", "\n") @staticmethod def view_sbo(*args): @@ -122,12 +115,12 @@ class SBoNetwork(object): ''' color = _m.color print("") # new line at start - template(78) + Msg().template(78) print("| {0}Package {1}{2}{3} --> {4}".format(color['GREEN'], color['CYAN'], args[0], color['GREEN'], color['ENDC'] + args[1])) - template(78) + Msg().template(78) print("| {0}Description : {1}{2}".format(color['GREEN'], color['ENDC'], args[2])) print("| {0}SlackBuild : {1}{2}".format(color['GREEN'], color['ENDC'], @@ -137,7 +130,7 @@ class SBoNetwork(object): print("| {0}Requirements : {1}{2}".format(color['YELLOW'], color['ENDC'], ", ".join(args[5]))) - template(78) + Msg().template(78) print(" {0}R{1}EADME View the README file".format( color['RED'], color['ENDC'])) print(" {0}S{1}lackBuild View the SlackBuild file".format( @@ -219,7 +212,7 @@ class SBoNetwork(object): try: binary = (_m.output + max(binary_list)).split() except ValueError: - build_FAILED(self.sbo_url, prgnam) + Msg().build_FAILED(self.sbo_url, prgnam) sys.exit(0) print("[ {0}Installing{1} ] --> {2}".format(_m.color['GREEN'], _m.color['ENDC'], diff --git a/slpkg/slack/patches.py b/slpkg/slack/patches.py index 8515a243..6b53047e 100644 --- a/slpkg/slack/patches.py +++ b/slpkg/slack/patches.py @@ -26,6 +26,7 @@ import sys import subprocess from slpkg.sizes import units +from slpkg.messages import Msg from slpkg.url_read import URL from slpkg.remove import delete from slpkg.checksum import check_md5 @@ -33,13 +34,6 @@ from slpkg.blacklist import BlackList from slpkg.downloader import Download from slpkg.grep_md5 import pkg_checksum from slpkg.splitting import split_package -from slpkg.messages import ( - msg_pkg, - template, - msg_done, - reference, - msg_reading -) from slpkg.__metadata__ import MetaData as _m from slpkg.pkg.find import find_package @@ -56,7 +50,7 @@ class Patches(object): def __init__(self, version): self.version = version self.patch_path = _m.slpkg_tmp_patches - msg_reading() + Msg().reading() if self.version == "stable": self.PACKAGES_TXT = URL(mirrors("PACKAGES.TXT", "patches/")).reading() @@ -72,10 +66,10 @@ class Patches(object): try: (pkg_for_upgrade, dwn_links, upgrade_all, comp_sum, uncomp_sum) = self.store() - msg_done() + Msg().done() if upgrade_all: print("\nThese packages need upgrading:\n") - template(78) + Msg().template(78) print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( "| Package", " " * 17, "Version", " " * 12, @@ -83,28 +77,25 @@ class Patches(object): "Build", " " * 2, "Repos", " " * 10, "Size")) - template(78) + Msg().template(78) print("Upgrading:") views(pkg_for_upgrade, upgrade_all, comp_sum) unit, size = units(comp_sum, uncomp_sum) print("\nInstalling summary") print("=" * 79) print("{0}Total {1} {2} will be upgraded.".format( - _m.color['GREY'], len(upgrade_all), msg_pkg(upgrade_all))) + _m.color['GREY'], len(upgrade_all), Msg().pkg(upgrade_all))) print("Need to get {0} {1} of archives.".format(size[0], unit[0])) print("After this process, {0} {1} of additional disk space " "will be used.{2}".format(size[1], unit[1], _m.color['ENDC'])) - if _m.default_answer == "y": - answer = _m.default_answer - else: - answer = raw_input("\nWould you like to continue [Y/n]? ") - if answer in ['y', 'Y']: + print('') + if Msg().answer() in ['y', 'Y']: Download(self.patch_path, dwn_links).start() upg = upgrade(self.patch_path, upgrade_all) kernel(upgrade_all) - reference([], upg) + Msg().reference([], upg) delete(self.patch_path, upgrade_all) else: slack_arch = "" @@ -180,10 +171,10 @@ def kernel(upgrade_all): answer = _m.default_answer else: print("") - template(78) + Msg().template(78) print("| {0}*** HIGHLY recommended reinstall 'LILO' " "***{1}".format(_m.color['RED'], _m.color['ENDC'])) - template(78) + Msg().template(78) answer = raw_input("\nThe kernel has been upgraded, " "reinstall `LILO` [Y/n]? ") if answer in ['y', 'Y']: diff --git a/slpkg/tracking.py b/slpkg/tracking.py index cc465caa..b20f1260 100644 --- a/slpkg/tracking.py +++ b/slpkg/tracking.py @@ -27,11 +27,7 @@ from utils import ( remove_dbs, dimensional_list ) -from messages import ( - template, - msg_done, - msg_resolving -) +from messages import Msg from __metadata__ import MetaData as _m from pkg.find import find_package @@ -50,7 +46,7 @@ def track_dep(name, repo): if allready installed and color red if not installed. ''' - msg_resolving() + Msg().resolving() if repo == "sbo": dependencies_list = Requires().sbo(name) find_pkg = sbo_search_pkg(name) @@ -59,7 +55,7 @@ def track_dep(name, repo): repo)) dependencies_list = Dependencies(PACKAGES_TXT, repo).binary(name) find_pkg = search_pkg(name, repo) - msg_done() + Msg().done() if find_pkg: requires, dependencies = [], [] requires = dimensional_list(dependencies_list) @@ -69,11 +65,11 @@ def track_dep(name, repo): dependencies = ["No dependencies"] pkg_len = len(name) + 24 print("") # new line at start - template(pkg_len) + Msg().template(pkg_len) print("| Package {0}{1}{2} dependencies :".format(_m.color['CYAN'], name, _m.color['ENDC'])) - template(pkg_len) + Msg().template(pkg_len) print("\\") print(" +---{0}[ Tree of dependencies ]{1}".format(_m.color['YELLOW'], _m.color['ENDC']))