update messages to class

This commit is contained in:
Dimitris Zlatanidis 2015-01-31 00:04:51 +02:00
parent 9c83f6fe70
commit 7b8e2a3ddb
15 changed files with 214 additions and 282 deletions

View file

@ -21,14 +21,11 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from slpkg.messages import Msg
from slpkg.toolbar import status from slpkg.toolbar import status
from slpkg.blacklist import BlackList from slpkg.blacklist import BlackList
from slpkg.splitting import split_package from slpkg.splitting import split_package
from slpkg.__metadata__ import MetaData as _m from slpkg.__metadata__ import MetaData as _m
from slpkg.messages import (
msg_done,
msg_checking
)
from slpkg.pkg.find import find_package from slpkg.pkg.find import find_package
@ -42,7 +39,7 @@ def pkg_upgrade(repo):
''' '''
Checking packages fro upgrade Checking packages fro upgrade
''' '''
msg_checking() Msg().checking()
PACKAGES_TXT = RepoInit(repo).fetch()[0] PACKAGES_TXT = RepoInit(repo).fetch()[0]
pkgs_for_upgrade = [] pkgs_for_upgrade = []
ver_for_upgrade = [] ver_for_upgrade = []
@ -63,7 +60,7 @@ def pkg_upgrade(repo):
inst_pkg[0] not in BlackList().packages()): inst_pkg[0] not in BlackList().packages()):
pkgs_for_upgrade.append(repo_pkg[0]) pkgs_for_upgrade.append(repo_pkg[0])
ver_for_upgrade.append('-' + inst_pkg[1]) ver_for_upgrade.append('-' + inst_pkg[1])
msg_done() Msg().done()
return pkgs_for_upgrade, ver_for_upgrade return pkgs_for_upgrade, ver_for_upgrade

View file

@ -25,6 +25,7 @@ import os
import sys import sys
from slpkg.sizes import units from slpkg.sizes import units
from slpkg.messages import Msg
from slpkg.remove import delete from slpkg.remove import delete
from slpkg.log_deps import write_deps from slpkg.log_deps import write_deps
from slpkg.checksum import check_md5 from slpkg.checksum import check_md5
@ -32,16 +33,6 @@ from slpkg.blacklist import BlackList
from slpkg.downloader import Download from slpkg.downloader import Download
from slpkg.grep_md5 import pkg_checksum from slpkg.grep_md5 import pkg_checksum
from slpkg.splitting import split_package 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 ( from slpkg.utils import (
remove_dbs, remove_dbs,
dimensional_list dimensional_list
@ -73,7 +64,7 @@ class BinaryInstall(object):
self.dependencies = [] self.dependencies = []
self.deps_dict = {} self.deps_dict = {}
self.answer = '' self.answer = ''
msg_reading() Msg().reading()
self.PACKAGES_TXT, self.mirror = RepoInit(self.repo).fetch() self.PACKAGES_TXT, self.mirror = RepoInit(self.repo).fetch()
num_lines = sum(1 for line in self.PACKAGES_TXT) num_lines = sum(1 for line in self.PACKAGES_TXT)
self.step = (num_lines / (100 * len(self.packages))) 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] self.packages, self.pkg_ver = self.packages[0], self.packages[1]
mas_sum = dep_sum = sums = [0, 0, 0] mas_sum = dep_sum = sums = [0, 0, 0]
self.pkg_exist() self.pkg_exist()
msg_done() Msg().done()
self.dependencies = self.resolving_deps() self.dependencies = self.resolving_deps()
(self.dep_dwn, self.dep_install, self.dep_comp_sum, (self.dep_dwn, self.dep_install, self.dep_comp_sum,
self.dep_uncomp_sum) = self.store(self.dependencies) self.dep_uncomp_sum) = self.store(self.dependencies)
self.packages = self.clear_masters() self.packages = self.clear_masters()
(self.dwn, self.install, self.comp_sum, (self.dwn, self.install, self.comp_sum,
self.uncomp_sum) = self.store(self.packages) self.uncomp_sum) = self.store(self.packages)
msg_done() Msg().done()
if self.install: if self.install:
print("") # new line at start print("") # new line at start
self.top_view() self.top_view()
msg_upg_inst(self.if_upgrade) Msg().upg_inst(self.if_upgrade)
mas_sum = self.views(self.install, self.comp_sum) mas_sum = self.views(self.install, self.comp_sum)
if self.dependencies: if self.dependencies:
print("Installing for dependencies:") print("Installing for dependencies:")
@ -113,26 +104,26 @@ class BinaryInstall(object):
print("\nInstalling summary") print("\nInstalling summary")
print("=" * 79) print("=" * 79)
print("{0}Total {1} {2}.".format(_m.color['GREY'], sum(sums), 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 " print("{0} {1} will be installed, {2} will be upgraded and "
"{3} will be reinstalled.".format(sums[2], "{3} will be reinstalled.".format(sums[2],
msg_pkg(sums[2]), Msg().pkg(sums[2]),
sums[1], sums[0])) sums[1], sums[0]))
print("Need to get {0} {1} of archives.".format(size[0], print("Need to get {0} {1} of archives.".format(size[0],
unit[0])) unit[0]))
print("After this process, {0} {1} of additional disk " print("After this process, {0} {1} of additional disk "
"space will be used.{2}".format(size[1], unit[1], "space will be used.{2}".format(size[1], unit[1],
_m.color['ENDC'])) _m.color['ENDC']))
self.answer = self.continue_install() print('')
if self.answer in ['y', 'Y']: if Msg().answer() in ['y', 'Y']:
self.install.reverse() self.install.reverse()
Download(self.tmp_path, (self.dep_dwn + self.dwn)).start() Download(self.tmp_path, (self.dep_dwn + self.dwn)).start()
ins, upg = self.install_packages() ins, upg = self.install_packages()
reference(ins, upg) Msg().reference(ins, upg)
write_deps(self.deps_dict) write_deps(self.deps_dict)
delete(self.tmp_path, self.install) delete(self.tmp_path, self.install)
else: else:
msg_not_found(self.if_upgrade) Msg().not_found(self.if_upgrade)
except KeyboardInterrupt: except KeyboardInterrupt:
print("") # new line at exit print("") # new line at exit
sys.exit(0) sys.exit(0)
@ -206,22 +197,12 @@ class BinaryInstall(object):
else: else:
check_md5(pkg_checksum(install, self.repo), self.tmp_path + install) 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): def resolving_deps(self):
''' '''
Return package dependencies Return package dependencies
''' '''
requires = [] requires = []
msg_resolving() Msg().resolving()
for dep in self.packages: for dep in self.packages:
dependencies = [] dependencies = []
dependencies = dimensional_list(Dependencies(self.PACKAGES_TXT, dependencies = dimensional_list(Dependencies(self.PACKAGES_TXT,
@ -266,7 +247,7 @@ class BinaryInstall(object):
return [pkg_sum, upg_sum, uni_sum] return [pkg_sum, upg_sum, uni_sum]
def top_view(self): def top_view(self):
template(78) Msg().template(78)
print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format(
"| Package", " " * 17, "| Package", " " * 17,
"Version", " " * 12, "Version", " " * 12,
@ -274,7 +255,7 @@ class BinaryInstall(object):
"Build", " " * 2, "Build", " " * 2,
"Repos", " " * 10, "Repos", " " * 10,
"Size")) "Size"))
template(78) Msg().template(78)
def store(self, packages): def store(self, packages):
''' '''

View file

@ -24,7 +24,7 @@
import sys import sys
from md5sum import md5 from md5sum import md5
from messages import template from messages import Msg
from __metadata__ import MetaData as _m from __metadata__ import MetaData as _m
@ -34,24 +34,20 @@ def check_md5(pkg_md5, src_file):
''' '''
md5s = md5(src_file) md5s = md5(src_file)
if pkg_md5 != md5s: if pkg_md5 != md5s:
template(78) Msg().template(78)
print("| MD5SUM check for {0} [ {1}FAILED{2} ]".format( print("| MD5SUM check for {0} [ {1}FAILED{2} ]".format(
src_file.split("/")[-1], _m.color['RED'], _m.color['ENDC'])) src_file.split("/")[-1], _m.color['RED'], _m.color['ENDC']))
template(78) Msg().template(78)
print("| Expected: {0}".format(md5s)) print("| Expected: {0}".format(md5s))
print("| Found: {0}".format(pkg_md5)) print("| Found: {0}".format(pkg_md5))
template(78) Msg().template(78)
if _m.default_answer == "y": if Msg().answer() in ['y', 'Y']:
answer = _m.default_answer
else:
answer = raw_input("Would you like to continue [Y/n]? ")
if answer in ['y', 'Y']:
print("") # new line after answer print("") # new line after answer
else: else:
sys.exit(0) sys.exit(0)
else: else:
template(78) Msg().template(78)
print("| MD5SUM check for {0} [ {1}PASSED{2} ]".format( print("| MD5SUM check for {0} [ {1}PASSED{2} ]".format(
src_file.split("/")[-1], _m.color['GREEN'], _m.color['ENDC'])) src_file.split("/")[-1], _m.color['GREEN'], _m.color['ENDC']))
template(78) Msg().template(78)
print("") # new line after pass checksum print("") # new line after pass checksum

View file

@ -22,8 +22,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from messages import Msg
from utils import read_file from utils import read_file
from messages import pkg_not_found
from __metadata__ import MetaData as _m from __metadata__ import MetaData as _m
@ -69,6 +69,6 @@ class PkgDesc(object):
count += 1 count += 1
print(self.COLOR + line[31:] + _m.color['ENDC']) print(self.COLOR + line[31:] + _m.color['ENDC'])
if count == 0: if count == 0:
pkg_not_found("", self.name, "No matching", "\n") Msg().pkg_not_found("", self.name, "No matching", "\n")
else: else:
print("") # new line at end print("") # new line at end

View file

@ -21,9 +21,11 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys import sys
import subprocess import subprocess
from messages import Msg
from __metadata__ import MetaData as _m from __metadata__ import MetaData as _m
@ -36,17 +38,23 @@ class Download(object):
def start(self): def start(self):
''' '''
Download files usign wget. Download files usign wget.
Check if file already download and skip or continue
download if before stoped.
''' '''
for dwn in self.url: 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'], print("\n[ {0}Download{1} ] -->{1} {2}\n".format(_m.color['GREEN'],
_m.color['ENDC'], _m.color['ENDC'],
file_name)) self.file_name))
try: try:
subprocess.call("wget {0} --directory-prefix={1} {2}".format( subprocess.call("wget {0} --directory-prefix={1} {2}".format(
_m.wget_option, self.path, dwn), shell=True) _m.wget_option, self.path, dwn), shell=True)
self.check()
except KeyboardInterrupt: except KeyboardInterrupt:
print # new line at cancel print # new line at cancel
sys.exit(0) 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)

View file

@ -24,10 +24,10 @@
import sys import sys
import getpass import getpass
from messages import Msg
from desc import PkgDesc from desc import PkgDesc
from config import Config from config import Config
from queue import QueuePkgs from queue import QueuePkgs
from messages import s_user
from repoinfo import RepoInfo from repoinfo import RepoInfo
from repolist import RepoList from repolist import RepoList
from repositories import Repo from repositories import Repo
@ -37,8 +37,8 @@ from version import prog_version
from arguments import options, usage from arguments import options, usage
from slpkg_update import it_self_update from slpkg_update import it_self_update
from init import ( from init import (
Initialization,
Update, Update,
Initialization,
check_exists_repositories check_exists_repositories
) )
from __metadata__ import MetaData as _m from __metadata__ import MetaData as _m
@ -79,7 +79,7 @@ class Case(object):
def main(): def main():
s_user(getpass.getuser()) Msg().s_user(getpass.getuser())
args = sys.argv args = sys.argv
args.pop(0) args.pop(0)
blacklist = BlackList() blacklist = BlackList()

View file

@ -28,28 +28,27 @@ from __metadata__ import MetaData as _m
from slpkg.pkg.find import find_package from slpkg.pkg.find import find_package
def pkg_not_found(bol, pkg, message, eol): class Msg(object):
def pkg_not_found(self, bol, pkg, message, eol):
''' '''
Print message when package not found Print message when package not found
''' '''
print("{0}No such package {1}: {2}{3}".format(bol, pkg, message, eol)) print("{0}No such package {1}: {2}{3}".format(bol, pkg, message, eol))
def pkg_found(self, pkg, version):
def pkg_found(pkg, version):
''' '''
Print message when package found Print message when package found
''' '''
print("| Package {0}-{1} is already installed".format(pkg, version)) print("| Package {0}-{1} is already installed".format(pkg, version))
def pkg_installed(self, pkg):
def pkg_installed(pkg):
''' '''
Print message when package installed Print message when package installed
''' '''
print("| Package {0} installed".format(pkg)) print("| Package {0} installed".format(pkg))
def s_user(self, user):
def s_user(user):
''' '''
Check for root user Check for root user
''' '''
@ -57,52 +56,48 @@ def s_user(user):
print("\nslpkg: error: must have root privileges\n") print("\nslpkg: error: must have root privileges\n")
sys.exit(0) sys.exit(0)
def build_FAILED(self, sbo_url, prgnam):
def build_FAILED(sbo_url, prgnam):
''' '''
Print error message if build failed Print error message if build failed
''' '''
template(78) self.template(78)
print("| Build package {0} [ {1}FAILED{2} ]".format(prgnam, _m.color['RED'], 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'])) _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")) print("| {0}{1}".format(sbo_url, "README"))
template(78) self.template(78)
print # new line at end print # new line at end
def template(self, max_len):
def template(max_len):
''' '''
Print template Print template
''' '''
print("+" + "=" * max_len) print("+" + "=" * max_len)
def checking(self):
def msg_checking():
sys.stdout.write("{0}Checking ...{1}".format(_m.color['GREY'], sys.stdout.write("{0}Checking ...{1}".format(_m.color['GREY'],
_m.color['ENDC'])) _m.color['ENDC']))
sys.stdout.flush() sys.stdout.flush()
def reading(self):
def msg_reading(): sys.stdout.write("{0}Reading package lists ...{1}".format(
sys.stdout.write("{0}Reading package lists ...{1}".format(_m.color['GREY'], _m.color['GREY'], _m.color['ENDC']))
_m.color['ENDC']))
sys.stdout.flush() sys.stdout.flush()
def resolving(self):
def msg_resolving():
sys.stdout.write("{0}Resolving dependencies ...{1}".format( sys.stdout.write("{0}Resolving dependencies ...{1}".format(
_m.color['GREY'], _m.color['ENDC'])) _m.color['GREY'], _m.color['ENDC']))
sys.stdout.flush() sys.stdout.flush()
def done(self):
sys.stdout.write("{0}Done{1}\n".format(_m.color['GREY'],
_m.color['ENDC']))
def msg_done(): def pkg(self, count):
sys.stdout.write("{0}Done{1}\n".format(_m.color['GREY'], _m.color['ENDC']))
def msg_pkg(count):
''' '''
Print singular plural Print singular plural
''' '''
@ -111,31 +106,35 @@ def msg_pkg(count):
message = message + "s" message = message + "s"
return message return message
def not_found(self, if_upgrade):
def msg_not_found(if_upgrade):
if if_upgrade: if if_upgrade:
print('\nNot found packages for upgrade\n') print('\nNot found packages for upgrade\n')
else: else:
print('\nNot found packages for installation\n') print('\nNot found packages for installation\n')
def upg_inst(self, if_upgrade):
def msg_upg_inst(if_upgrade):
if not if_upgrade: if not if_upgrade:
print("Installing:") print("Installing:")
else: else:
print("Upgrading:") 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(install, upgrade): def reference(self, install, upgrade):
''' '''
Reference list with packages installed Reference list with packages installed
and upgraded and upgraded
''' '''
template(78) self.template(78)
print("| Total {0} {1} installed and {2} {3} upgraded".format( print("| Total {0} {1} installed and {2} {3} upgraded".format(
len(install), msg_pkg(len(install)), len(install), self.pkg(len(install)),
len(upgrade), msg_pkg(len(upgrade)))) len(upgrade), self.pkg(len(upgrade))))
template(78) self.template(78)
for installed in (install + upgrade): for installed in (install + upgrade):
name = '-'.join(installed.split('-')[:-1]) name = '-'.join(installed.split('-')[:-1])
if find_package(installed, _m.pkg_path): if find_package(installed, _m.pkg_path):
@ -145,4 +144,4 @@ def reference(install, upgrade):
print("| Package {0} installed successfully".format(name)) print("| Package {0} installed successfully".format(name))
else: else:
print("| Package {0} NOT installed".format(name)) print("| Package {0} NOT installed".format(name))
template(78) self.emplate(78)

View file

@ -29,8 +29,8 @@ import shutil
import tarfile import tarfile
import subprocess import subprocess
from slpkg.messages import Msg
from slpkg.checksum import check_md5 from slpkg.checksum import check_md5
from slpkg.messages import pkg_not_found
from slpkg.__metadata__ import MetaData as _m from slpkg.__metadata__ import MetaData as _m
from slpkg.sbo.greps import SBoGrep from slpkg.sbo.greps import SBoGrep
@ -94,7 +94,7 @@ class BuildPackage(object):
shell=True)) shell=True))
os.chdir(self.path) os.chdir(self.path)
except (OSError, IOError): except (OSError, IOError):
pkg_not_found("\n", self.prgnam, "Wrong file", "\n") Msg().pkg_not_found("\n", self.prgnam, "Wrong file", "\n")
except KeyboardInterrupt: except KeyboardInterrupt:
print("") # new line at exit print("") # new line at exit
sys.exit(0) sys.exit(0)

View file

@ -25,11 +25,8 @@ import os
import sys import sys
import subprocess import subprocess
from slpkg.messages import Msg
from slpkg.utils import read_file from slpkg.utils import read_file
from slpkg.messages import (
pkg_not_found,
template
)
from slpkg.__metadata__ import MetaData as _m from slpkg.__metadata__ import MetaData as _m
from slpkg.pkg.find import find_package from slpkg.pkg.find import find_package
@ -85,7 +82,7 @@ class PackageManager(object):
bol = eol = "" bol = eol = ""
else: else:
bol = eol = "\n" bol = eol = "\n"
pkg_not_found(bol, pkg, message, eol) Msg().pkg_not_found(bol, pkg, message, eol)
def remove(self): def remove(self):
''' '''
@ -155,7 +152,7 @@ class PackageManager(object):
"\n ".join(pkgs))) "\n ".join(pkgs)))
removed.append(pkg) removed.append(pkg)
else: else:
pkg_not_found("", pkg, "Can't remove", "") Msg().pkg_not_found("", pkg, "Can't remove", "")
return removed return removed
@staticmethod @staticmethod
@ -165,12 +162,12 @@ class PackageManager(object):
''' '''
dependencies = read_file(path + package) dependencies = read_file(path + package)
print("") # new line at start print("") # new line at start
template(78) Msg().template(78)
print("| Found dependencies for package {0}:".format(package)) print("| Found dependencies for package {0}:".format(package))
template(78) Msg().template(78)
for dep in dependencies.splitlines(): for dep in dependencies.splitlines():
print("| {0}{1}{2}".format(_m.color['RED'], dep, _m.color['ENDC'])) print("| {0}{1}{2}".format(_m.color['RED'], dep, _m.color['ENDC']))
template(78) Msg().template(78)
return dependencies return dependencies
@staticmethod @staticmethod
@ -203,15 +200,15 @@ class PackageManager(object):
''' '''
Prints all removed packages Prints all removed packages
''' '''
template(78) Msg().template(78)
print("| Total {0} packages removed".format(len(removes))) print("| Total {0} packages removed".format(len(removes)))
template(78) Msg().template(78)
for pkg in removes: for pkg in removes:
if not find_package(pkg + _m.sp, _m.pkg_path): if not find_package(pkg + _m.sp, _m.pkg_path):
print("| Package {0} removed".format(pkg)) print("| Package {0} removed".format(pkg))
else: else:
print("| Package {0} not found".format(pkg)) print("| Package {0} not found".format(pkg))
template(78) Msg().template(78)
print("") # new line at end print("") # new line at end
def find(self): def find(self):
@ -237,7 +234,7 @@ class PackageManager(object):
break break
if matching == 0: if matching == 0:
message = "Can't find" message = "Can't find"
pkg_not_found("", self.binary, message, "\n") Msg().pkg_not_found("", self.binary, message, "\n")
else: else:
print("\n{0}Total found {1} matching packages.{2}".format( print("\n{0}Total found {1} matching packages.{2}".format(
_m.color['GREY'], matching, _m.color['ENDC'])) _m.color['GREY'], matching, _m.color['ENDC']))
@ -265,7 +262,7 @@ class PackageManager(object):
bol = eol = "" bol = eol = ""
else: else:
bol = eol = "\n" bol = eol = "\n"
pkg_not_found(bol, pkg, message, eol) Msg().pkg_not_found(bol, pkg, message, eol)
def list(self, repo, INDEX): def list(self, repo, INDEX):
''' '''

View file

@ -24,8 +24,8 @@
import sys import sys
from messages import Msg
from repositories import Repo from repositories import Repo
from messages import template
from __metadata__ import MetaData as _m from __metadata__ import MetaData as _m
@ -55,13 +55,13 @@ class RepoList(object):
View or enabled or disabled repositories View or enabled or disabled repositories
''' '''
print('') print('')
template(78) Msg().template(78)
print('{0}{1}{2}{3}{4}{5}{6}'.format( print('{0}{1}{2}{3}{4}{5}{6}'.format(
'| Repo id', ' ' * 2, '| Repo id', ' ' * 2,
'Repo URL', ' ' * 44, 'Repo URL', ' ' * 44,
'Default', ' ' * 3, 'Default', ' ' * 3,
'Status')) 'Status'))
template(78) Msg().template(78)
for repo_id, repo_URL in sorted(self.all_repos.iteritems()): for repo_id, repo_URL in sorted(self.all_repos.iteritems()):
status, COLOR = 'disabled', _m.color['RED'] status, COLOR = 'disabled', _m.color['RED']
default = 'yes' default = 'yes'

View file

@ -25,13 +25,10 @@
import os import os
import sys import sys
from slpkg.messages import Msg
from slpkg.toolbar import status from slpkg.toolbar import status
from slpkg.splitting import split_package from slpkg.splitting import split_package
from slpkg.__metadata__ import MetaData as _m from slpkg.__metadata__ import MetaData as _m
from slpkg.messages import (
msg_done,
msg_checking
)
from greps import SBoGrep from greps import SBoGrep
from search import sbo_search_pkg from search import sbo_search_pkg
@ -42,7 +39,7 @@ def sbo_upgrade():
Return packages for upgrade Return packages for upgrade
''' '''
try: try:
msg_checking() Msg().checking()
upgrade_names, pkg_ver = [], [] upgrade_names, pkg_ver = [], []
index, toolbar_width = 0, 3 index, toolbar_width = 0, 3
for pkg in sbo_list(): for pkg in sbo_list():
@ -56,7 +53,7 @@ def sbo_upgrade():
if sbo_package > package: if sbo_package > package:
upgrade_names.append(name) upgrade_names.append(name)
pkg_ver.append(ver) pkg_ver.append(ver)
msg_done() Msg().done()
return upgrade_names, pkg_ver return upgrade_names, pkg_ver
except KeyboardInterrupt: except KeyboardInterrupt:
print("") # new line at exit print("") # new line at exit

View file

@ -33,18 +33,7 @@ from slpkg.utils import (
dimensional_list, dimensional_list,
remove_dbs remove_dbs
) )
from slpkg.messages import ( from slpkg.messages import Msg
msg_pkg,
template,
msg_done,
pkg_found,
reference,
msg_reading,
msg_upg_inst,
build_FAILED,
msg_not_found,
msg_resolving
)
from slpkg.__metadata__ import MetaData as _m from slpkg.__metadata__ import MetaData as _m
from slpkg.pkg.find import find_package from slpkg.pkg.find import find_package
@ -71,7 +60,7 @@ class SBoInstall(object):
self.deps_dict = {} self.deps_dict = {}
self.toolbar_width, self.index = 2, 0 self.toolbar_width, self.index = 2, 0
self.answer = '' self.answer = ''
msg_reading() Msg().reading()
def start(self, if_upgrade): def start(self, if_upgrade):
try: try:
@ -98,17 +87,17 @@ class SBoInstall(object):
self.package_found = self.matching(self.package_not_found) self.package_found = self.matching(self.package_not_found)
self.master_packages, mas_src = self.sbo_version_source( self.master_packages, mas_src = self.sbo_version_source(
self.package_found) self.package_found)
msg_done() Msg().done()
msg_resolving() Msg().resolving()
self.dependencies, dep_src = self.sbo_version_source( self.dependencies, dep_src = self.sbo_version_source(
self.one_for_all(self.deps)) self.one_for_all(self.deps))
msg_done() Msg().done()
self.master_packages = self.clear_masters() self.master_packages = self.clear_masters()
if self.package_found: if self.package_found:
print("\nThe following packages will be automatically " print("\nThe following packages will be automatically "
"installed or upgraded \nwith new version:\n") "installed or upgraded \nwith new version:\n")
self.top_view() self.top_view()
msg_upg_inst(self.if_upgrade) Msg().upg_inst(self.if_upgrade)
# view master packages # view master packages
for sbo, ver, ar in zip(self.master_packages, self.pkg_ver, for sbo, ver, ar in zip(self.master_packages, self.pkg_ver,
mas_src): mas_src):
@ -132,21 +121,19 @@ class SBoInstall(object):
print("\nInstalling summary") print("\nInstalling summary")
print("=" * 79) print("=" * 79)
print("{0}Total {1} {2}.".format( 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 " 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, count_ins, count_upg,
msg_pkg(count_upg))) Msg().pkg(count_upg)))
print("will be upgraded.{0}\n".format(_m.color['ENDC'])) print("will be upgraded.{0}\n".format(_m.color['ENDC']))
if self.master_packages: if self.master_packages and Msg().answer() in['y', 'Y']:
self.answer = self.continue_install()
if self.answer in['y', 'Y']:
b_ins = self.build_install() b_ins = self.build_install()
reference(b_ins[0], b_ins[1]) Msg().reference(b_ins[0], b_ins[1])
write_deps(self.deps_dict) write_deps(self.deps_dict)
delete(_m.build_path) delete(_m.build_path)
else: else:
msg_not_found(if_upgrade) Msg().not_found(if_upgrade)
except KeyboardInterrupt: except KeyboardInterrupt:
print("") # new line at exit print("") # new line at exit
sys.exit(0) sys.exit(0)
@ -207,7 +194,7 @@ class SBoInstall(object):
''' '''
View top template View top template
''' '''
template(78) Msg().template(78)
print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format(
"| Package", " " * 17, "| Package", " " * 17,
"Version", " " * 12, "Version", " " * 12,
@ -215,7 +202,7 @@ class SBoInstall(object):
"Build", " " * 2, "Build", " " * 2,
"Repos", " " * 10, "Repos", " " * 10,
"Size")) "Size"))
template(78) Msg().template(78)
def view_version(self): def view_version(self):
''' '''
@ -269,16 +256,6 @@ class SBoInstall(object):
arch = item arch = item
return arch 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): def filenames(self, sources):
''' '''
Return filenames from sources Return filenames from sources
@ -317,15 +294,15 @@ class SBoInstall(object):
sbo_file = "".join(find_package(prgnam, _m.pkg_path)) sbo_file = "".join(find_package(prgnam, _m.pkg_path))
src_link = SBoGrep(pkg).source().split() src_link = SBoGrep(pkg).source().split()
if sbo_file: if sbo_file:
template(78) Msg().template(78)
pkg_found(pkg, split_package(sbo_file)[1]) Msg().pkg_found(pkg, split_package(sbo_file)[1])
template(78) Msg().template(78)
elif self.unst[0] in src_link or self.unst[1] in src_link: 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'], print("| Package {0} {1}{2}{3}".format(sbo, _m.color['RED'],
''.join(src_link), ''.join(src_link),
_m.color['ENDC'])) _m.color['ENDC']))
template(78) Msg().template(78)
else: else:
sbo_url = sbo_search_pkg(pkg) sbo_url = sbo_search_pkg(pkg)
sbo_link = SBoLink(sbo_url).tar_gz() sbo_link = SBoLink(sbo_url).tar_gz()
@ -338,7 +315,7 @@ class SBoInstall(object):
try: try:
binary = (_m.output + max(binary_list)).split() binary = (_m.output + max(binary_list)).split()
except ValueError: except ValueError:
build_FAILED(sbo_url, prgnam) Msg().build_FAILED(sbo_url, prgnam)
sys.exit(0) sys.exit(0)
if find_package(pkg + '-', _m.pkg_path): if find_package(pkg + '-', _m.pkg_path):
print("{0}[ Upgrading ] --> {1}{2}".format( print("{0}[ Upgrading ] --> {1}{2}".format(

View file

@ -25,16 +25,9 @@ import os
import sys import sys
import pydoc import pydoc
from slpkg.messages import Msg
from slpkg.downloader import Download from slpkg.downloader import Download
from slpkg.__metadata__ import MetaData as _m 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.find import find_package
from slpkg.pkg.build import BuildPackage from slpkg.pkg.build import BuildPackage
@ -51,7 +44,7 @@ class SBoNetwork(object):
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
msg_reading() Msg().reading()
grep = SBoGrep(self.name) grep = SBoGrep(self.name)
self.sbo_url = sbo_search_pkg(self.name) self.sbo_url = sbo_search_pkg(self.name)
if self.sbo_url: if self.sbo_url:
@ -62,7 +55,7 @@ class SBoNetwork(object):
self.sbo_version = grep.version() self.sbo_version = grep.version()
self.dwn_srcs = self.sbo_dwn.split() + self.source_dwn self.dwn_srcs = self.sbo_dwn.split() + self.source_dwn
self.space = ("\n" * 50) self.space = ("\n" * 50)
msg_done() Msg().done()
def view(self): def view(self):
''' '''
@ -106,14 +99,14 @@ class SBoNetwork(object):
delete(_m.build_path) delete(_m.build_path)
break break
else: else:
template(78) Msg().template(78)
pkg_found(self.name, self.sbo_version) Msg().pkg_found(self.name, self.sbo_version)
template(78) Msg().template(78)
break break
else: else:
break break
else: else:
pkg_not_found("\n", self.name, "Can't view", "\n") Msg().pkg_not_found("\n", self.name, "Can't view", "\n")
@staticmethod @staticmethod
def view_sbo(*args): def view_sbo(*args):
@ -122,12 +115,12 @@ class SBoNetwork(object):
''' '''
color = _m.color color = _m.color
print("") # new line at start print("") # new line at start
template(78) Msg().template(78)
print("| {0}Package {1}{2}{3} --> {4}".format(color['GREEN'], print("| {0}Package {1}{2}{3} --> {4}".format(color['GREEN'],
color['CYAN'], args[0], color['CYAN'], args[0],
color['GREEN'], color['GREEN'],
color['ENDC'] + args[1])) color['ENDC'] + args[1]))
template(78) Msg().template(78)
print("| {0}Description : {1}{2}".format(color['GREEN'], print("| {0}Description : {1}{2}".format(color['GREEN'],
color['ENDC'], args[2])) color['ENDC'], args[2]))
print("| {0}SlackBuild : {1}{2}".format(color['GREEN'], color['ENDC'], 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'], print("| {0}Requirements : {1}{2}".format(color['YELLOW'],
color['ENDC'], color['ENDC'],
", ".join(args[5]))) ", ".join(args[5])))
template(78) Msg().template(78)
print(" {0}R{1}EADME View the README file".format( print(" {0}R{1}EADME View the README file".format(
color['RED'], color['ENDC'])) color['RED'], color['ENDC']))
print(" {0}S{1}lackBuild View the SlackBuild file".format( print(" {0}S{1}lackBuild View the SlackBuild file".format(
@ -219,7 +212,7 @@ class SBoNetwork(object):
try: try:
binary = (_m.output + max(binary_list)).split() binary = (_m.output + max(binary_list)).split()
except ValueError: except ValueError:
build_FAILED(self.sbo_url, prgnam) Msg().build_FAILED(self.sbo_url, prgnam)
sys.exit(0) sys.exit(0)
print("[ {0}Installing{1} ] --> {2}".format(_m.color['GREEN'], print("[ {0}Installing{1} ] --> {2}".format(_m.color['GREEN'],
_m.color['ENDC'], _m.color['ENDC'],

View file

@ -26,6 +26,7 @@ import sys
import subprocess import subprocess
from slpkg.sizes import units from slpkg.sizes import units
from slpkg.messages import Msg
from slpkg.url_read import URL from slpkg.url_read import URL
from slpkg.remove import delete from slpkg.remove import delete
from slpkg.checksum import check_md5 from slpkg.checksum import check_md5
@ -33,13 +34,6 @@ from slpkg.blacklist import BlackList
from slpkg.downloader import Download from slpkg.downloader import Download
from slpkg.grep_md5 import pkg_checksum from slpkg.grep_md5 import pkg_checksum
from slpkg.splitting import split_package 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.__metadata__ import MetaData as _m
from slpkg.pkg.find import find_package from slpkg.pkg.find import find_package
@ -56,7 +50,7 @@ class Patches(object):
def __init__(self, version): def __init__(self, version):
self.version = version self.version = version
self.patch_path = _m.slpkg_tmp_patches self.patch_path = _m.slpkg_tmp_patches
msg_reading() Msg().reading()
if self.version == "stable": if self.version == "stable":
self.PACKAGES_TXT = URL(mirrors("PACKAGES.TXT", self.PACKAGES_TXT = URL(mirrors("PACKAGES.TXT",
"patches/")).reading() "patches/")).reading()
@ -72,10 +66,10 @@ class Patches(object):
try: try:
(pkg_for_upgrade, dwn_links, upgrade_all, comp_sum, (pkg_for_upgrade, dwn_links, upgrade_all, comp_sum,
uncomp_sum) = self.store() uncomp_sum) = self.store()
msg_done() Msg().done()
if upgrade_all: if upgrade_all:
print("\nThese packages need upgrading:\n") print("\nThese packages need upgrading:\n")
template(78) Msg().template(78)
print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format(
"| Package", " " * 17, "| Package", " " * 17,
"Version", " " * 12, "Version", " " * 12,
@ -83,28 +77,25 @@ class Patches(object):
"Build", " " * 2, "Build", " " * 2,
"Repos", " " * 10, "Repos", " " * 10,
"Size")) "Size"))
template(78) Msg().template(78)
print("Upgrading:") print("Upgrading:")
views(pkg_for_upgrade, upgrade_all, comp_sum) views(pkg_for_upgrade, upgrade_all, comp_sum)
unit, size = units(comp_sum, uncomp_sum) unit, size = units(comp_sum, uncomp_sum)
print("\nInstalling summary") print("\nInstalling summary")
print("=" * 79) print("=" * 79)
print("{0}Total {1} {2} will be upgraded.".format( 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], print("Need to get {0} {1} of archives.".format(size[0],
unit[0])) unit[0]))
print("After this process, {0} {1} of additional disk space " print("After this process, {0} {1} of additional disk space "
"will be used.{2}".format(size[1], unit[1], "will be used.{2}".format(size[1], unit[1],
_m.color['ENDC'])) _m.color['ENDC']))
if _m.default_answer == "y": print('')
answer = _m.default_answer if Msg().answer() in ['y', 'Y']:
else:
answer = raw_input("\nWould you like to continue [Y/n]? ")
if answer in ['y', 'Y']:
Download(self.patch_path, dwn_links).start() Download(self.patch_path, dwn_links).start()
upg = upgrade(self.patch_path, upgrade_all) upg = upgrade(self.patch_path, upgrade_all)
kernel(upgrade_all) kernel(upgrade_all)
reference([], upg) Msg().reference([], upg)
delete(self.patch_path, upgrade_all) delete(self.patch_path, upgrade_all)
else: else:
slack_arch = "" slack_arch = ""
@ -180,10 +171,10 @@ def kernel(upgrade_all):
answer = _m.default_answer answer = _m.default_answer
else: else:
print("") print("")
template(78) Msg().template(78)
print("| {0}*** HIGHLY recommended reinstall 'LILO' " print("| {0}*** HIGHLY recommended reinstall 'LILO' "
"***{1}".format(_m.color['RED'], _m.color['ENDC'])) "***{1}".format(_m.color['RED'], _m.color['ENDC']))
template(78) Msg().template(78)
answer = raw_input("\nThe kernel has been upgraded, " answer = raw_input("\nThe kernel has been upgraded, "
"reinstall `LILO` [Y/n]? ") "reinstall `LILO` [Y/n]? ")
if answer in ['y', 'Y']: if answer in ['y', 'Y']:

View file

@ -27,11 +27,7 @@ from utils import (
remove_dbs, remove_dbs,
dimensional_list dimensional_list
) )
from messages import ( from messages import Msg
template,
msg_done,
msg_resolving
)
from __metadata__ import MetaData as _m from __metadata__ import MetaData as _m
from pkg.find import find_package from pkg.find import find_package
@ -50,7 +46,7 @@ def track_dep(name, repo):
if allready installed and color red if allready installed and color red
if not installed. if not installed.
''' '''
msg_resolving() Msg().resolving()
if repo == "sbo": if repo == "sbo":
dependencies_list = Requires().sbo(name) dependencies_list = Requires().sbo(name)
find_pkg = sbo_search_pkg(name) find_pkg = sbo_search_pkg(name)
@ -59,7 +55,7 @@ def track_dep(name, repo):
repo)) repo))
dependencies_list = Dependencies(PACKAGES_TXT, repo).binary(name) dependencies_list = Dependencies(PACKAGES_TXT, repo).binary(name)
find_pkg = search_pkg(name, repo) find_pkg = search_pkg(name, repo)
msg_done() Msg().done()
if find_pkg: if find_pkg:
requires, dependencies = [], [] requires, dependencies = [], []
requires = dimensional_list(dependencies_list) requires = dimensional_list(dependencies_list)
@ -69,11 +65,11 @@ def track_dep(name, repo):
dependencies = ["No dependencies"] dependencies = ["No dependencies"]
pkg_len = len(name) + 24 pkg_len = len(name) + 24
print("") # new line at start print("") # new line at start
template(pkg_len) Msg().template(pkg_len)
print("| Package {0}{1}{2} dependencies :".format(_m.color['CYAN'], print("| Package {0}{1}{2} dependencies :".format(_m.color['CYAN'],
name, name,
_m.color['ENDC'])) _m.color['ENDC']))
template(pkg_len) Msg().template(pkg_len)
print("\\") print("\\")
print(" +---{0}[ Tree of dependencies ]{1}".format(_m.color['YELLOW'], print(" +---{0}[ Tree of dependencies ]{1}".format(_m.color['YELLOW'],
_m.color['ENDC'])) _m.color['ENDC']))