mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-18 10:26:29 +01:00
update code
This commit is contained in:
parent
4dfbdbff85
commit
c63ebfa2ff
1 changed files with 82 additions and 67 deletions
|
@ -44,53 +44,62 @@ def install(slack_pkg, version):
|
||||||
Install packages from official Slackware distribution
|
Install packages from official Slackware distribution
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
done = "{0}Done{1}\n".format(GREY, ENDC)
|
var = {
|
||||||
reading_lists = "{0}Reading package lists ...{1}".format(GREY, ENDC)
|
'done': "{0}Done{1}\n".format(GREY, ENDC),
|
||||||
(comp_sum, uncomp_sum, names, dwn_list, comp_size, uncomp_size,
|
'reading_lists': "{0}Reading package lists ...{1}".format(GREY,
|
||||||
install_all, package_name, package_location) = ([] for i in range(9))
|
ENDC),
|
||||||
arch = COLOR = ""
|
'comp_sum': [],
|
||||||
pkg_sum = uni_sum = upg_sum = 0
|
'uncomp_sum': [],
|
||||||
# create directories if not exists
|
'comp_size': [],
|
||||||
tmp_path = slpkg_tmp + "packages/"
|
'uncomp_size': [],
|
||||||
if not os.path.exists(slpkg_tmp):
|
'install_all': [],
|
||||||
os.mkdir(slpkg_tmp)
|
'package_name': [],
|
||||||
if not os.path.exists(tmp_path):
|
'package_location': [],
|
||||||
os.mkdir(tmp_path)
|
'names': [],
|
||||||
|
'dwn_list': [],
|
||||||
|
'pkg_sum': 0,
|
||||||
|
'uni_sum': 0,
|
||||||
|
'upg_sum': 0,
|
||||||
|
'index': 0,
|
||||||
|
'toolbar_width': 800,
|
||||||
|
'tmp_path': slpkg_tmp + "packages/",
|
||||||
|
}
|
||||||
|
init(var['tmp_path'])
|
||||||
print("\nPackages with name matching [ {0}{1}{2} ]\n".format(
|
print("\nPackages with name matching [ {0}{1}{2} ]\n".format(
|
||||||
CYAN, slack_pkg, ENDC))
|
CYAN, slack_pkg, ENDC))
|
||||||
sys.stdout.write(reading_lists)
|
sys.stdout.write(var['reading_lists'])
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
blacklist = BlackList().packages()
|
|
||||||
PACKAGES = url_read(mirrors("PACKAGES.TXT", "", version))
|
PACKAGES = url_read(mirrors("PACKAGES.TXT", "", version))
|
||||||
EXTRA = url_read(mirrors("PACKAGES.TXT", "extra/", version))
|
EXTRA = url_read(mirrors("PACKAGES.TXT", "extra/", version))
|
||||||
PASTURE = url_read(mirrors("PACKAGES.TXT", "pasture/", version))
|
PASTURE = url_read(mirrors("PACKAGES.TXT", "pasture/", version))
|
||||||
PACKAGES_TXT = PACKAGES + EXTRA + PASTURE
|
PACKAGES_TXT = PACKAGES + EXTRA + PASTURE
|
||||||
index, toolbar_width = 0, 800
|
|
||||||
for line in PACKAGES_TXT.splitlines():
|
for line in PACKAGES_TXT.splitlines():
|
||||||
index += 1
|
var['index'] += 1
|
||||||
if index == toolbar_width:
|
if var['index'] == var['toolbar_width']:
|
||||||
sys.stdout.write("{0}.{1}".format(GREY, ENDC))
|
sys.stdout.write("{0}.{1}".format(GREY, ENDC))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
toolbar_width += 800
|
var['toolbar_width'] += 800
|
||||||
time.sleep(0.00888)
|
time.sleep(0.00888)
|
||||||
if line.startswith("PACKAGE NAME"):
|
if line.startswith("PACKAGE NAME"):
|
||||||
package_name.append(line[15:].strip())
|
var['package_name'].append(line[15:].strip())
|
||||||
if line.startswith("PACKAGE LOCATION"):
|
if line.startswith("PACKAGE LOCATION"):
|
||||||
package_location.append(line[21:].strip())
|
var['package_location'].append(line[21:].strip())
|
||||||
if line.startswith("PACKAGE SIZE (compressed): "):
|
if line.startswith("PACKAGE SIZE (compressed): "):
|
||||||
comp_size.append(line[28:-2].strip())
|
var['comp_size'].append(line[28:-2].strip())
|
||||||
if line.startswith("PACKAGE SIZE (uncompressed): "):
|
if line.startswith("PACKAGE SIZE (uncompressed): "):
|
||||||
uncomp_size.append(line[30:-2].strip())
|
var['uncomp_size'].append(line[30:-2].strip())
|
||||||
for loc, name, comp, uncomp in zip(package_location, package_name,
|
for loc, name, comp, uncomp in zip(var['package_location'],
|
||||||
comp_size, uncomp_size):
|
var['package_name'],
|
||||||
if slack_pkg in name and slack_pkg not in blacklist:
|
var['comp_size'],
|
||||||
dwn_list.append("{0}{1}/{2}".format(mirrors("", "", version),
|
var['uncomp_size']):
|
||||||
loc, name))
|
if slack_pkg in name and slack_pkg not in BlackList().packages():
|
||||||
install_all.append(name)
|
var['dwn_list'].append("{0}{1}/{2}".format(
|
||||||
comp_sum.append(comp)
|
mirrors("", "", version), loc, name))
|
||||||
uncomp_sum.append(uncomp)
|
var['install_all'].append(name)
|
||||||
sys.stdout.write(done)
|
var['comp_sum'].append(comp)
|
||||||
if install_all:
|
var['uncomp_sum'].append(uncomp)
|
||||||
|
sys.stdout.write(var['done'] + "\n")
|
||||||
|
if var['install_all']:
|
||||||
template(78)
|
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,
|
||||||
|
@ -101,32 +110,27 @@ def install(slack_pkg, version):
|
||||||
"Size"))
|
"Size"))
|
||||||
template(78)
|
template(78)
|
||||||
print("Installing:")
|
print("Installing:")
|
||||||
for pkg, comp in zip(install_all, comp_sum):
|
for pkg, comp in zip(var['install_all'], var['comp_sum']):
|
||||||
pkg_split = split_package(pkg[:-4])
|
pkg_split = split_package(pkg[:-4])
|
||||||
name = pkg_split[0]
|
var['names'].append(pkg_split[0])
|
||||||
ver = pkg_split[1]
|
|
||||||
arch = pkg_split[2]
|
|
||||||
build = pkg_split[3]
|
|
||||||
names.append(name)
|
|
||||||
if os.path.isfile(pkg_path + pkg[:-4]):
|
if os.path.isfile(pkg_path + pkg[:-4]):
|
||||||
pkg_sum += 1
|
var['pkg_sum'] += 1
|
||||||
COLOR = GREEN
|
COLOR = GREEN
|
||||||
elif find_package(name + "-", pkg_path):
|
elif find_package(name + "-", pkg_path):
|
||||||
COLOR = YELLOW
|
COLOR = YELLOW
|
||||||
upg_sum += 1
|
var['upg_sum'] += 1
|
||||||
else:
|
else:
|
||||||
COLOR = RED
|
COLOR = RED
|
||||||
uni_sum += 1
|
var['uni_sum'] += 1
|
||||||
print(" {0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11:>12}{12}".format(
|
print(" {0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11:>12}{12}".format(
|
||||||
COLOR, name, ENDC,
|
COLOR, pkg_split[0], ENDC,
|
||||||
" " * (25-len(name)), ver,
|
" " * (25-len(pkg_split[0])), pkg_split[1],
|
||||||
" " * (19-len(ver)), arch,
|
" " * (19-len(pkg_split[1])), pkg_split[2],
|
||||||
" " * (8-len(arch)), build,
|
" " * (8-len(pkg_split[2])), pkg_split[3],
|
||||||
" " * (7-len(build)), "Slack",
|
" " * (7-len(pkg_split[3])), "Slack",
|
||||||
comp, " K"))
|
comp, " K"))
|
||||||
comp_unit = uncomp_unit = "Mb"
|
compressed = round((sum(map(float, var['comp_sum'])) / 1024), 2)
|
||||||
compressed = round((sum(map(float, comp_sum)) / 1024), 2)
|
uncompressed = round((sum(map(float, var['uncomp_sum'])) / 1024), 2)
|
||||||
uncompressed = round((sum(map(float, uncomp_sum)) / 1024), 2)
|
|
||||||
if compressed > 1024:
|
if compressed > 1024:
|
||||||
compressed = round((compressed / 1024), 2)
|
compressed = round((compressed / 1024), 2)
|
||||||
comp_unit = "Gb"
|
comp_unit = "Gb"
|
||||||
|
@ -134,34 +138,35 @@ def install(slack_pkg, version):
|
||||||
uncompressed = round((uncompressed / 1024), 2)
|
uncompressed = round((uncompressed / 1024), 2)
|
||||||
uncomp_unit = "Gb"
|
uncomp_unit = "Gb"
|
||||||
if compressed < 1:
|
if compressed < 1:
|
||||||
compressed = sum(map(int, comp_sum))
|
compressed = sum(map(int, var['comp_sum']))
|
||||||
comp_unit = "Kb"
|
comp_unit = "Kb"
|
||||||
if uncompressed < 1:
|
if uncompressed < 1:
|
||||||
uncompressed = sum(map(int, uncomp_sum))
|
uncompressed = sum(map(int, var['uncomp_sum']))
|
||||||
uncomp_unit = "Kb"
|
uncomp_unit = "Kb"
|
||||||
msg_pkg = "package"
|
msg_pkg = "package"
|
||||||
msg_2_pkg = msg_pkg
|
msg_2_pkg = msg_pkg
|
||||||
if len(install_all) > 1:
|
if len(var['install_all']) > 1:
|
||||||
msg_pkg = msg_pkg + "s"
|
msg_pkg = msg_pkg + "s"
|
||||||
if uni_sum > 1:
|
if var['uni_sum'] > 1:
|
||||||
msg_2_pkg = msg_2_pkg + "s"
|
msg_2_pkg = msg_2_pkg + "s"
|
||||||
print("\nInstalling summary")
|
print("\nInstalling summary")
|
||||||
print("=" * 79)
|
print("=" * 79)
|
||||||
print("{0}Total {1} {2}.".format(GREY, len(install_all), msg_pkg))
|
print("{0}Total {1} {2}.".format(GREY, len(var['install_all']),
|
||||||
|
msg_pkg))
|
||||||
print("{0} {1} will be installed, {2} will be upgraded and {3} "
|
print("{0} {1} will be installed, {2} will be upgraded and {3} "
|
||||||
"will be resettled.".format(uni_sum, msg_2_pkg,
|
"will be resettled.".format(var['uni_sum'], msg_2_pkg,
|
||||||
upg_sum, pkg_sum))
|
var['upg_sum'], var['pkg_sum']))
|
||||||
print("Need to get {0} {1} of archives.".format(compressed,
|
print("Need to get {0} {1} of archives.".format(compressed,
|
||||||
comp_unit))
|
comp_unit))
|
||||||
print("After this process, {0} {1} of additional disk space will "
|
print("After this process, {0} {1} of additional disk space will "
|
||||||
"be used.{2}".format(uncompressed, uncomp_unit, ENDC))
|
"be used.{2}".format(uncompressed, uncomp_unit, ENDC))
|
||||||
read = raw_input("\nWould you like to install [Y/n]? ")
|
read = raw_input("\nWould you like to install [Y/n]? ")
|
||||||
if read == "Y" or read == "y":
|
if read == "Y" or read == "y":
|
||||||
for dwn in dwn_list:
|
for dwn in var['dwn_list']:
|
||||||
Download(tmp_path, dwn).start()
|
Download(var['tmp_path'], dwn).start()
|
||||||
Download(tmp_path, dwn + ".asc").start()
|
Download(var['tmp_path'], dwn + ".asc").start()
|
||||||
for install, name in zip(install_all, names):
|
for install, name in zip(var['install_all'], var['names']):
|
||||||
package = ((tmp_path + install).split())
|
package = ((var['tmp_path'] + install).split())
|
||||||
if os.path.isfile(pkg_path + install[:-4]):
|
if os.path.isfile(pkg_path + install[:-4]):
|
||||||
print("[ {0}reinstalling{1} ] --> {2}".format(
|
print("[ {0}reinstalling{1} ] --> {2}".format(
|
||||||
GREEN, ENDC, install))
|
GREEN, ENDC, install))
|
||||||
|
@ -176,20 +181,30 @@ def install(slack_pkg, version):
|
||||||
PackageManager(package).upgrade()
|
PackageManager(package).upgrade()
|
||||||
read = raw_input("Removal downloaded packages [Y/n]? ")
|
read = raw_input("Removal downloaded packages [Y/n]? ")
|
||||||
if read == "Y" or read == "y":
|
if read == "Y" or read == "y":
|
||||||
for remove in install_all:
|
for remove in var['install_all']:
|
||||||
os.remove(tmp_path + remove)
|
os.remove(var['tmp_path'] + remove)
|
||||||
os.remove(tmp_path + remove + ".asc")
|
os.remove(var['tmp_path'] + remove + ".asc")
|
||||||
if not os.listdir(tmp_path):
|
if not os.listdir(var['tmp_path']):
|
||||||
print("Packages removed")
|
print("Packages removed")
|
||||||
else:
|
else:
|
||||||
print("\nThere are packages in directory {0}\n".format(
|
print("\nThere are packages in directory {0}\n".format(
|
||||||
tmp_path))
|
var['tmp_path']))
|
||||||
else:
|
else:
|
||||||
print("\nThere are packages in directory {0}\n".format(
|
print("\nThere are packages in directory {0}\n".format(
|
||||||
tmp_path))
|
var['tmp_path']))
|
||||||
else:
|
else:
|
||||||
message = "No matching"
|
message = "No matching"
|
||||||
pkg_not_found("\n", slack_pkg, message, "\n")
|
pkg_not_found("\n", slack_pkg, message, "\n")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print # new line at exit
|
print # new line at exit
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
def init(tmp_path):
|
||||||
|
'''
|
||||||
|
create directories if not exists
|
||||||
|
'''
|
||||||
|
if not os.path.exists(slpkg_tmp):
|
||||||
|
os.mkdir(slpkg_tmp)
|
||||||
|
if not os.path.exists(tmp_path):
|
||||||
|
os.mkdir(tmp_path)
|
||||||
|
|
Loading…
Reference in a new issue