fix check downloaded pkgs

This commit is contained in:
Dimitris Zlatanidis 2015-01-31 08:31:50 +02:00
parent 70ce59db9c
commit f89ac7af83
7 changed files with 87 additions and 66 deletions

View file

@ -115,6 +115,10 @@ class BinaryInstall(object):
if Msg().answer() in ['y', 'Y']:
self.install.reverse()
Download(self.tmp_path, (self.dep_dwn + self.dwn)).start()
self.dep_install = Utils().check_downloaded(
self.tmp_path, self.dep_install)
self.install = Utils().check_downloaded(
self.tmp_path, self.install)
ins, upg = self.install_packages()
Msg().reference(ins, upg)
write_deps(self.deps_dict)

View file

@ -32,6 +32,7 @@ def check_md5(pkg_md5, src_file):
'''
MD5 Checksum
'''
print('')
md5s = md5(src_file)
if pkg_md5 != md5s:
Msg().template(78)
@ -41,13 +42,12 @@ def check_md5(pkg_md5, src_file):
print("| Expected: {0}".format(md5s))
print("| Found: {0}".format(pkg_md5))
Msg().template(78)
if Msg().answer() in ['y', 'Y']:
print("") # new line after answer
else:
print('')
if not Msg().answer() in ['y', 'Y']:
sys.exit(0)
else:
Msg().template(78)
print("| MD5SUM check for {0} [ {1}PASSED{2} ]".format(
src_file.split("/")[-1], _m.color['GREEN'], _m.color['ENDC']))
Msg().template(78)
print("") # new line after pass checksum
print('') # new line after pass checksum

View file

@ -58,3 +58,6 @@ class Download(object):
print("| Download '{0}' file {1}[ FAILED ]{2}".format(
self.file_name, _m.color['RED'], _m.color['ENDC']))
Msg().template(78)
print('')
if not Msg().answer() in ['y', 'Y']:
sys.exit(0)

View file

@ -144,4 +144,4 @@ class Msg(object):
print("| Package {0} installed successfully".format(name))
else:
print("| Package {0} NOT installed".format(name))
self.emplate(78)
self.template(78)

View file

@ -124,7 +124,7 @@ class SBoInstall(object):
count_ins, count_upg,
Msg().pkg(count_upg)))
print("will be upgraded.{0}\n".format(_m.color['ENDC']))
if self.master_packages and Msg().answer() in['y', 'Y']:
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)

View file

@ -25,6 +25,7 @@ import os
import sys
import subprocess
from slpkg.utils import Utils
from slpkg.sizes import units
from slpkg.messages import Msg
from slpkg.url_read import URL
@ -64,10 +65,10 @@ class Patches(object):
Install new patches from official Slackware mirrors
'''
try:
(pkg_for_upgrade, dwn_links, upgrade_all, comp_sum,
uncomp_sum) = self.store()
(self.pkg_for_upgrade, self.dwn_links, self.upgrade_all,
self.comp_sum, self.uncomp_sum) = self.store()
Msg().done()
if upgrade_all:
if self.upgrade_all:
print("\nThese packages need upgrading:\n")
Msg().template(78)
print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format(
@ -79,12 +80,13 @@ class Patches(object):
"Size"))
Msg().template(78)
print("Upgrading:")
views(pkg_for_upgrade, upgrade_all, comp_sum)
unit, size = units(comp_sum, uncomp_sum)
self.views()
unit, size = units(self.comp_sum, self.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(self.upgrade_all),
Msg().pkg(self.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 "
@ -92,11 +94,13 @@ class Patches(object):
_m.color['ENDC']))
print('')
if Msg().answer() in ['y', 'Y']:
Download(self.patch_path, dwn_links).start()
upg = upgrade(self.patch_path, upgrade_all)
kernel(upgrade_all)
Download(self.patch_path, self.dwn_links).start()
self.upgrade_all = Utils().check_downloaded(
self.patch_path, self.upgrade_all)
upg = self.upgrade()
self.kernel()
Msg().reference([], upg)
delete(self.patch_path, upgrade_all)
delete(self.patch_path, self.upgrade_all)
else:
slack_arch = ""
if os.uname()[4] == "x86_64":
@ -128,55 +132,55 @@ class Patches(object):
split_package(''.join(inst_pkg[0]))[1]))
return [pkg_for_upgrade, dwn, upgrade, comp_sum, uncomp_sum]
def views(self):
'''
Views packages
'''
for upg, upgrade, size in sorted(zip(self.pkg_for_upgrade,
self.upgrade_all,
self.comp_sum)):
pkg_split = split_package(upgrade[:-4])
print(" {0}{1}{2}{3} {4}{5} {6}{7}{8}{9}{10}{11:>12}{12}".format(
_m.color['YELLOW'], upg, _m.color['ENDC'],
" " * (24-len(upg)), pkg_split[1],
" " * (18-len(pkg_split[1])), pkg_split[2],
" " * (8-len(pkg_split[2])), pkg_split[3],
" " * (7-len(pkg_split[3])), "Slack",
size, " K"))
def views(pkg_for_upgrade, upgrade_all, comp_sum):
'''
Views packages
'''
for upg, upgrade, size in sorted(zip(pkg_for_upgrade, upgrade_all,
comp_sum)):
pkg_split = split_package(upgrade[:-4])
print(" {0}{1}{2}{3} {4}{5} {6}{7}{8}{9}{10}{11:>12}{12}".format(
_m.color['YELLOW'], upg, _m.color['ENDC'],
" " * (24-len(upg)), pkg_split[1],
" " * (18-len(pkg_split[1])), pkg_split[2],
" " * (8-len(pkg_split[2])), pkg_split[3],
" " * (7-len(pkg_split[3])), "Slack",
size, " K"))
def upgrade(self):
'''
Upgrade packages
'''
upgraded = []
for pkg in self.upgrade_all:
check_md5(pkg_checksum(pkg, "slack_patches"), self.patch_path + pkg)
pkg_ver = '{0}-{1}'.format(split_package(pkg)[0],
split_package(pkg)[1])
print("[ {0}upgrading{1} ] --> {2}".format(_m.color['YELLOW'],
_m.color['ENDC'],
pkg[:-4]))
PackageManager((self.patch_path + pkg).split()).upgrade()
upgraded.append(pkg_ver)
return upgraded
def upgrade(patch_path, upgrade_all):
'''
Upgrade packages
'''
upgraded = []
for pkg in upgrade_all:
check_md5(pkg_checksum(pkg, "slack_patches"), patch_path + pkg)
pkg_ver = '{0}-{1}'.format(split_package(pkg)[0], split_package(pkg)[1])
print("[ {0}upgrading{1} ] --> {2}".format(_m.color['YELLOW'],
_m.color['ENDC'], pkg[:-4]))
PackageManager((patch_path + pkg).split()).upgrade()
upgraded.append(pkg_ver)
return upgraded
def kernel(upgrade_all):
'''
Check if kernel upgraded if true
then reinstall 'lilo'
'''
for core in upgrade_all:
if "kernel" in core:
if _m.default_answer == "y":
answer = _m.default_answer
else:
print("")
Msg().template(78)
print("| {0}*** HIGHLY recommended reinstall 'LILO' "
"***{1}".format(_m.color['RED'], _m.color['ENDC']))
Msg().template(78)
answer = raw_input("\nThe kernel has been upgraded, "
"reinstall `LILO` [Y/n]? ")
if answer in ['y', 'Y']:
subprocess.call("lilo", shell=True)
break
def kernel(self):
'''
Check if kernel upgraded if true
then reinstall 'lilo'
'''
for core in self.upgrade_all:
if "kernel" in core:
if _m.default_answer == "y":
answer = _m.default_answer
else:
print("")
Msg().template(78)
print("| {0}*** HIGHLY recommended reinstall 'LILO' "
"***{1}".format(_m.color['RED'], _m.color['ENDC']))
Msg().template(78)
answer = raw_input("\nThe kernel has been upgraded, "
"reinstall `LILO` [Y/n]? ")
if answer in ['y', 'Y']:
subprocess.call("lilo", shell=True)
break

View file

@ -22,6 +22,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
from splitting import split_package
@ -61,3 +63,11 @@ class Utils(object):
else:
packages.append(split_package(line[14:].strip())[0])
return packages
def check_downloaded(self, path, maybe_downloaded):
""" Return downloaded packages """
downloaded = []
for pkg in maybe_downloaded:
if os.path.isfile(path + pkg):
downloaded.append(pkg)
return downloaded