mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-11-17 07:48:18 +01:00
update code
This commit is contained in:
parent
2bd674a8e2
commit
1768c0a388
3 changed files with 122 additions and 123 deletions
|
@ -39,7 +39,7 @@ from sbo.tracking import track_dep
|
|||
from sbo.slackbuild import sbo_install
|
||||
|
||||
from slack.patches import patches
|
||||
from slack.install import install
|
||||
from slack.install import slack_install
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -136,11 +136,14 @@ def main():
|
|||
sbo_install(args[2])
|
||||
elif args[1] == repository[1]:
|
||||
version = "stable"
|
||||
install(args[2], version)
|
||||
slack_install(args[2], version)
|
||||
else:
|
||||
for opt in usage:
|
||||
print(opt)
|
||||
elif len(args) == 4 and args[0] == "-s":
|
||||
if args[1] == repository[1] and args[3] == "--current":
|
||||
version = "current"
|
||||
install(args[2], version)
|
||||
slack_install(args[2], version)
|
||||
else:
|
||||
for opt in usage:
|
||||
print(opt)
|
||||
|
|
|
@ -43,22 +43,18 @@ def build_package(script, sources, path):
|
|||
file in path /var/log/slpkg/sbo/build_logs/.
|
||||
Also check md5sum calculates.
|
||||
'''
|
||||
var = {
|
||||
'prgnam': script[:-7],
|
||||
'log_file': "build_{0}_log".format(script[:-7]),
|
||||
'sbo_logs': log_path + "sbo/",
|
||||
'build_logs': log_path + "sbo/build_logs/",
|
||||
'log_date': time.strftime("%d/%m/%Y"),
|
||||
'start_log_time': time.strftime("%H:%M:%S"),
|
||||
'start_time': time.time(),
|
||||
'log_line': ("#" * 79 + "\n\n")
|
||||
}
|
||||
init(var['sbo_logs'], var['build_logs'], var['log_file'])
|
||||
prgnam = script[:-7]
|
||||
log_file = "build_{0}_log".format(prgnam)
|
||||
sbo_logs = log_path + "sbo/"
|
||||
build_logs = sbo_logs + "build_logs/"
|
||||
start_log_time = time.strftime("%H:%M:%S")
|
||||
start_time = time.time()
|
||||
_init(sbo_logs, build_logs, log_file)
|
||||
try:
|
||||
tar = tarfile.open(script)
|
||||
tar.extractall()
|
||||
tar.close()
|
||||
sbo_md5_list = SBoGrep(var['prgnam']).checksum()
|
||||
sbo_md5_list = SBoGrep(prgnam).checksum()
|
||||
for src, sbo_md5 in zip(sources, sbo_md5_list):
|
||||
# fix build sources with spaces
|
||||
src = src.replace("%20", " ")
|
||||
|
@ -82,44 +78,43 @@ def build_package(script, sources, path):
|
|||
src, GREEN, ENDC))
|
||||
template(78)
|
||||
print # new line after pass checksum
|
||||
shutil.copy2(src, var['prgnam'])
|
||||
os.chdir(path + var['prgnam'])
|
||||
subprocess.call("chmod +x {0}.SlackBuild".format(var['prgnam']),
|
||||
shutil.copy2(src, prgnam)
|
||||
os.chdir(path + prgnam)
|
||||
subprocess.call("chmod +x {0}.SlackBuild".format(prgnam),
|
||||
shell=True)
|
||||
# write headers to log file
|
||||
with open(var['build_logs'] + var['log_file'], "w") as log:
|
||||
log.write(var['log_line'])
|
||||
log.write("File : " + var['log_file'] + "\n")
|
||||
log.write("Path : " + var['build_logs'] + "\n")
|
||||
log.write("Date : " + var['log_date'] + "\n")
|
||||
log.write("Time : " + var['start_log_time'] + "\n\n")
|
||||
log.write(var['log_line'])
|
||||
with open(build_logs + log_file, "w") as log:
|
||||
log.write("#" * 79 + "\n\n")
|
||||
log.write("File : " + log_file + "\n")
|
||||
log.write("Path : " + build_logs + "\n")
|
||||
log.write("Date : " + time.strftime("%d/%m/%Y") + "\n")
|
||||
log.write("Time : " + start_log_time + "\n\n")
|
||||
log.write("#" * 79 + "\n\n")
|
||||
log.close()
|
||||
subprocess.Popen("./{0}.SlackBuild 2>&1 | tee -a {1}{2}".format(
|
||||
var['prgnam'], var['build_logs'], var['log_file']),
|
||||
prgnam, build_logs, log_file),
|
||||
shell=True, stdout=sys.stdout).communicate()
|
||||
sum_time = build_time(var['start_time'])
|
||||
sum_time = _build_time(start_time)
|
||||
# append END tag to a log file
|
||||
with open(var['build_logs'] + var['log_file'], "a") as log:
|
||||
with open(build_logs + log_file, "a") as log:
|
||||
log.seek(2)
|
||||
log.write(var['log_line'])
|
||||
log.write("#" * 79 + "\n\n")
|
||||
log.write("Time : " + time.strftime("%H:%M:%S") + "\n")
|
||||
log.write("Total build time : {0}\n".format(sum_time))
|
||||
log.write(" " * 38 + "E N D\n\n")
|
||||
log.write(var['log_line'])
|
||||
log.write("#" * 79 + "\n\n")
|
||||
log.close()
|
||||
os.chdir(path)
|
||||
print("Total build time for package {0} : {1}\n".format(var['prgnam'],
|
||||
print("Total build time for package {0} : {1}\n".format(prgnam,
|
||||
sum_time))
|
||||
except (OSError, IOError):
|
||||
message = "Wrong file"
|
||||
pkg_not_found("\n", var['prgnam'], message, "\n")
|
||||
pkg_not_found("\n", prgnam, "Wrong file", "\n")
|
||||
except KeyboardInterrupt:
|
||||
print # new line at exit
|
||||
sys.exit()
|
||||
|
||||
|
||||
def init(sbo_logs, build_logs, log_file):
|
||||
def _init(sbo_logs, build_logs, log_file):
|
||||
'''
|
||||
Create working directories if not exists
|
||||
'''
|
||||
|
@ -133,7 +128,7 @@ def init(sbo_logs, build_logs, log_file):
|
|||
os.remove(build_logs + log_file)
|
||||
|
||||
|
||||
def build_time(start_time):
|
||||
def _build_time(start_time):
|
||||
'''
|
||||
Calculate build time per package
|
||||
'''
|
||||
|
|
|
@ -39,64 +39,52 @@ from pkg.manager import PackageManager
|
|||
from mirrors import mirrors
|
||||
|
||||
|
||||
def install(slack_pkg, version):
|
||||
def slack_install(slack_pkg, version):
|
||||
'''
|
||||
Install packages from official Slackware distribution
|
||||
'''
|
||||
try:
|
||||
var = {
|
||||
'done': "{0}Done{1}\n".format(GREY, ENDC),
|
||||
'reading_lists': "{0}Reading package lists ...{1}".format(GREY,
|
||||
ENDC),
|
||||
'comp_sum': [],
|
||||
'uncomp_sum': [],
|
||||
'comp_size': [],
|
||||
'uncomp_size': [],
|
||||
'install_all': [],
|
||||
'package_name': [],
|
||||
'package_location': [],
|
||||
'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'])
|
||||
done = "{0}Done{1}\n".format(GREY, ENDC)
|
||||
reading_lists = "{0}Reading package lists ...{1}".format(GREY, ENDC)
|
||||
(comp_sum, uncomp_sum, comp_size, uncomp_size, install_all,
|
||||
package_name, package_location, names,
|
||||
dwn_list) = ([] for i in range(9))
|
||||
pkg_sum = uni_sum = upg_sum = index = 0
|
||||
toolbar_width = 800
|
||||
tmp_path = slpkg_tmp + "packages/"
|
||||
_init(tmp_path)
|
||||
print("\nPackages with name matching [ {0}{1}{2} ]\n".format(
|
||||
CYAN, slack_pkg, ENDC))
|
||||
sys.stdout.write(var['reading_lists'])
|
||||
sys.stdout.write(reading_lists)
|
||||
sys.stdout.flush()
|
||||
PACKAGES_TXT = data(version)
|
||||
PACKAGES_TXT = _data(version)
|
||||
for line in PACKAGES_TXT.splitlines():
|
||||
var['index'] += 1
|
||||
if var['index'] == var['toolbar_width']:
|
||||
index += 1
|
||||
if index == toolbar_width:
|
||||
sys.stdout.write("{0}.{1}".format(GREY, ENDC))
|
||||
sys.stdout.flush()
|
||||
var['toolbar_width'] += 800
|
||||
toolbar_width += 800
|
||||
time.sleep(0.00888)
|
||||
if line.startswith("PACKAGE NAME"):
|
||||
var['package_name'].append(line[15:].strip())
|
||||
package_name.append(line[15:].strip())
|
||||
if line.startswith("PACKAGE LOCATION"):
|
||||
var['package_location'].append(line[21:].strip())
|
||||
package_location.append(line[21:].strip())
|
||||
if line.startswith("PACKAGE SIZE (compressed): "):
|
||||
var['comp_size'].append(line[28:-2].strip())
|
||||
comp_size.append(line[28:-2].strip())
|
||||
if line.startswith("PACKAGE SIZE (uncompressed): "):
|
||||
var['uncomp_size'].append(line[30:-2].strip())
|
||||
for loc, name, comp, uncomp in zip(var['package_location'],
|
||||
var['package_name'],
|
||||
var['comp_size'],
|
||||
var['uncomp_size']):
|
||||
uncomp_size.append(line[30:-2].strip())
|
||||
for loc, name, comp, uncomp in zip(package_location,
|
||||
package_name,
|
||||
comp_size,
|
||||
uncomp_size):
|
||||
if slack_pkg in name and slack_pkg not in BlackList().packages():
|
||||
var['dwn_list'].append("{0}{1}/{2}".format(
|
||||
dwn_list.append("{0}{1}/{2}".format(
|
||||
mirrors("", "", version), loc, name))
|
||||
var['install_all'].append(name)
|
||||
var['comp_sum'].append(comp)
|
||||
var['uncomp_sum'].append(uncomp)
|
||||
sys.stdout.write(var['done'] + "\n")
|
||||
if var['install_all']:
|
||||
install_all.append(name)
|
||||
comp_sum.append(comp)
|
||||
uncomp_sum.append(uncomp)
|
||||
sys.stdout.write(done + "\n")
|
||||
if install_all:
|
||||
template(78)
|
||||
print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format(
|
||||
"| Package", " " * 17,
|
||||
|
@ -107,18 +95,18 @@ def install(slack_pkg, version):
|
|||
"Size"))
|
||||
template(78)
|
||||
print("Installing:")
|
||||
for pkg, comp in zip(var['install_all'], var['comp_sum']):
|
||||
for pkg, comp in zip(install_all, comp_sum):
|
||||
pkg_split = split_package(pkg[:-4])
|
||||
var['names'].append(pkg_split[0])
|
||||
names.append(pkg_split[0])
|
||||
if os.path.isfile(pkg_path + pkg[:-4]):
|
||||
var['pkg_sum'] += 1
|
||||
pkg_sum += 1
|
||||
COLOR = GREEN
|
||||
elif find_package(name + "-", pkg_path):
|
||||
elif find_package(pkg_split[0] + "-", pkg_path):
|
||||
COLOR = YELLOW
|
||||
var['upg_sum'] += 1
|
||||
upg_sum += 1
|
||||
else:
|
||||
COLOR = RED
|
||||
var['uni_sum'] += 1
|
||||
uni_sum += 1
|
||||
print(" {0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11:>12}{12}".format(
|
||||
COLOR, pkg_split[0], ENDC,
|
||||
" " * (25-len(pkg_split[0])), pkg_split[1],
|
||||
|
@ -126,8 +114,9 @@ def install(slack_pkg, version):
|
|||
" " * (8-len(pkg_split[2])), pkg_split[3],
|
||||
" " * (7-len(pkg_split[3])), "Slack",
|
||||
comp, " K"))
|
||||
compressed = round((sum(map(float, var['comp_sum'])) / 1024), 2)
|
||||
uncompressed = round((sum(map(float, var['uncomp_sum'])) / 1024), 2)
|
||||
compressed = round((sum(map(float, comp_sum)) / 1024), 2)
|
||||
uncompressed = round((sum(map(float, uncomp_sum)) / 1024), 2)
|
||||
comp_unit = uncomp_unit = "Mb"
|
||||
if compressed > 1024:
|
||||
compressed = round((compressed / 1024), 2)
|
||||
comp_unit = "Gb"
|
||||
|
@ -135,60 +124,33 @@ def install(slack_pkg, version):
|
|||
uncompressed = round((uncompressed / 1024), 2)
|
||||
uncomp_unit = "Gb"
|
||||
if compressed < 1:
|
||||
compressed = sum(map(int, var['comp_sum']))
|
||||
compressed = sum(map(int, comp_sum))
|
||||
comp_unit = "Kb"
|
||||
if uncompressed < 1:
|
||||
uncompressed = sum(map(int, var['uncomp_sum']))
|
||||
uncompressed = sum(map(int, uncomp_sum))
|
||||
uncomp_unit = "Kb"
|
||||
msg_pkg = "package"
|
||||
msg_2_pkg = msg_pkg
|
||||
if len(var['install_all']) > 1:
|
||||
if len(install_all) > 1:
|
||||
msg_pkg = msg_pkg + "s"
|
||||
if var['uni_sum'] > 1:
|
||||
if uni_sum > 1:
|
||||
msg_2_pkg = msg_2_pkg + "s"
|
||||
print("\nInstalling summary")
|
||||
print("=" * 79)
|
||||
print("{0}Total {1} {2}.".format(GREY, len(var['install_all']),
|
||||
print("{0}Total {1} {2}.".format(GREY, len(install_all),
|
||||
msg_pkg))
|
||||
print("{0} {1} will be installed, {2} will be upgraded and {3} "
|
||||
"will be resettled.".format(var['uni_sum'], msg_2_pkg,
|
||||
var['upg_sum'], var['pkg_sum']))
|
||||
"will be resettled.".format(uni_sum, msg_2_pkg,
|
||||
upg_sum, pkg_sum))
|
||||
print("Need to get {0} {1} of archives.".format(compressed,
|
||||
comp_unit))
|
||||
print("After this process, {0} {1} of additional disk space will "
|
||||
"be used.{2}".format(uncompressed, uncomp_unit, ENDC))
|
||||
read = raw_input("\nWould you like to install [Y/n]? ")
|
||||
if read == "Y" or read == "y":
|
||||
for dwn in var['dwn_list']:
|
||||
Download(var['tmp_path'], dwn).start()
|
||||
Download(var['tmp_path'], dwn + ".asc").start()
|
||||
for install, name in zip(var['install_all'], var['names']):
|
||||
package = ((var['tmp_path'] + install).split())
|
||||
if os.path.isfile(pkg_path + install[:-4]):
|
||||
print("[ {0}reinstalling{1} ] --> {2}".format(
|
||||
GREEN, ENDC, install))
|
||||
PackageManager(package).reinstall()
|
||||
elif find_package(name + "-", pkg_path):
|
||||
print("[ {0}upgrading{1} ] --> {2}".format(
|
||||
YELLOW, ENDC, install))
|
||||
PackageManager(package).upgrade()
|
||||
else:
|
||||
print("[ {0}installing{1} ] --> {2}".format(
|
||||
GREEN, ENDC, install))
|
||||
PackageManager(package).upgrade()
|
||||
read = raw_input("Removal downloaded packages [Y/n]? ")
|
||||
if read == "Y" or read == "y":
|
||||
for remove in var['install_all']:
|
||||
os.remove(var['tmp_path'] + remove)
|
||||
os.remove(var['tmp_path'] + remove + ".asc")
|
||||
if not os.listdir(var['tmp_path']):
|
||||
print("Packages removed")
|
||||
else:
|
||||
print("\nThere are packages in directory {0}\n".format(
|
||||
var['tmp_path']))
|
||||
else:
|
||||
print("\nThere are packages in directory {0}\n".format(
|
||||
var['tmp_path']))
|
||||
_download(tmp_path, dwn_list)
|
||||
_install(tmp_path, install_all, names)
|
||||
_remove(tmp_path, install_all)
|
||||
else:
|
||||
message = "No matching"
|
||||
pkg_not_found("\n", slack_pkg, message, "\n")
|
||||
|
@ -197,7 +159,7 @@ def install(slack_pkg, version):
|
|||
sys.exit()
|
||||
|
||||
|
||||
def init(tmp_path):
|
||||
def _init(tmp_path):
|
||||
'''
|
||||
Create directories if not exists
|
||||
'''
|
||||
|
@ -207,7 +169,7 @@ def init(tmp_path):
|
|||
os.mkdir(tmp_path)
|
||||
|
||||
|
||||
def data(version):
|
||||
def _data(version):
|
||||
'''
|
||||
Collects and return data
|
||||
'''
|
||||
|
@ -215,3 +177,42 @@ def data(version):
|
|||
EXTRA = url_read(mirrors("PACKAGES.TXT", "extra/", version))
|
||||
PASTURE = url_read(mirrors("PACKAGES.TXT", "pasture/", version))
|
||||
return (PACKAGES + EXTRA + PASTURE)
|
||||
|
||||
|
||||
def _download(tmp_path, dwn_list):
|
||||
for dwn in dwn_list:
|
||||
Download(tmp_path, dwn).start()
|
||||
Download(tmp_path, dwn + ".asc").start()
|
||||
|
||||
|
||||
def _install(tmp_path, install_all, names):
|
||||
for install, name in zip(install_all, names):
|
||||
package = ((tmp_path + install).split())
|
||||
if os.path.isfile(pkg_path + install[:-4]):
|
||||
print("[ {0}reinstalling{1} ] --> {2}".format(
|
||||
GREEN, ENDC, install))
|
||||
PackageManager(package).reinstall()
|
||||
elif find_package(name + "-", pkg_path):
|
||||
print("[ {0}upgrading{1} ] --> {2}".format(
|
||||
YELLOW, ENDC, install))
|
||||
PackageManager(package).upgrade()
|
||||
else:
|
||||
print("[ {0}installing{1} ] --> {2}".format(
|
||||
GREEN, ENDC, install))
|
||||
PackageManager(package).upgrade()
|
||||
|
||||
|
||||
def _remove(tmp_path, install_all):
|
||||
read = raw_input("Removal downloaded packages [Y/n]? ")
|
||||
if read == "Y" or read == "y":
|
||||
for remove in install_all:
|
||||
os.remove(tmp_path + remove)
|
||||
os.remove(tmp_path + remove + ".asc")
|
||||
if not os.listdir(tmp_path):
|
||||
print("Packages removed")
|
||||
else:
|
||||
print("\nThere are packages in directory {0}\n".format(
|
||||
tmp_path))
|
||||
else:
|
||||
print("\nThere are packages in directory {0}\n".format(
|
||||
tmp_path))
|
||||
|
|
Loading…
Reference in a new issue