def find(self): ''' Find installed Slackware packages ''' self.binary = "".join(self.binary) matching = size = 0 print("\nPackages with matching name [ {0}{1}{2} ]\n".format( CYAN, self.binary, ENDC)) for match in find_package(self.binary, pkg_path): if self.binary in match: matching += 1 print("[ {0}installed{1} ] - {2}".format( GREEN, ENDC, match)) with open(pkg_path + match, "r") as f: data = f.read() f.close() for line in data.splitlines(): if line.startswith("UNCOMPRESSED PACKAGE SIZE:"): if "M" in line[26:]: size += float(line[26:-1]) * 1024 else: size += float(line[26:-1]) break if matching == 0: message = "Can't find" pkg_not_found("", self.binary, message, "\n") else: print("\n{0}Total found {1} matching packages.{2}".format( GREY, matching, ENDC)) unit = "Kb" if size > 1024: unit = "Mb" size = (size / 1024) print("{0}Size of installed packages {1} {2}.{3}\n".format( GREY, round(size, 2), unit, ENDC))
def find(self): ''' Find installed Slackware packages ''' self.binary = "".join(self.binary) matching = size = 0 print("\nPackages with matching name [ {0}{1}{2} ]\n".format( CYAN, self.binary, ENDC)) for match in find_package(self.binary, pkg_path): if self.binary in match: matching += 1 print("[ {0}installed{1} ] - {2}".format(GREEN, ENDC, match)) with open(pkg_path + match, "r") as f: data = f.read() f.close() for line in data.splitlines(): if line.startswith("UNCOMPRESSED PACKAGE SIZE:"): if "M" in line[26:]: size += float(line[26:-1]) * 1024 else: size += float(line[26:-1]) break if matching == 0: message = "Can't find" pkg_not_found("", self.binary, message, "\n") else: print("\n{0}Total found {1} matching packages.{2}".format( GREY, matching, ENDC)) unit = "Kb" if size > 1024: unit = "Mb" size = (size / 1024) print("{0}Size of installed packages {1} {2}.{3}\n".format( GREY, round(size, 2), unit, ENDC))
def view(self): ''' View SlackBuild package, read or install them from slackbuilds.org ''' if self.sbo_url: prgnam = ("{0}-{1}".format(self.name, self.sbo_version)) view_sbo( self.name, self.sbo_url, self.sbo_desc, self.sbo_dwn.split("/")[-1], ", ".join([src.split("/")[-1] for src in self.source_dwn]), self.sbo_req) FAULT = error_uns(self.source_dwn) while True: choice = read_choice() if choice in ["D", "d"]: download("", self.sbo_dwn, self.source_dwn) break elif choice in ["R", "r"]: README = Read(self.sbo_url).readme("README") fill = fill_pager(README) pydoc.pager(README + fill) elif choice in ["F", "f"]: info = Read(self.sbo_url).info(self.name, ".info") fill = fill_pager(info) pydoc.pager(info + fill) elif choice in ["S", "s"]: SlackBuild = Read(self.sbo_url).slackbuild( self.name, ".SlackBuild") fill = fill_pager(SlackBuild) pydoc.pager(SlackBuild + fill) elif choice in ["B", "b"]: build(self.sbo_dwn, self.source_dwn, FAULT) break elif choice in ["I", "i"]: if not find_package(prgnam + sp, pkg_path): build(self.sbo_dwn, self.source_dwn, FAULT) install(self.name, prgnam, self.sbo_url) break else: template(78) pkg_found(self.name, self.sbo_version) template(78) break else: break else: pkg_not_found("\n", self.name, "Can't view", "\n")
def view_removed(binary): ''' View packages before removed ''' removed = [] print("\nPackages with name matching [ {0}{1}{2} ]\n".format( CYAN, ", ".join(binary), ENDC)) for pkg in binary: pkgs = find_package(pkg + sp, pkg_path) if pkgs: print("[ {0}delete{1} ] --> {2}".format(RED, ENDC, "\n ".join(pkgs))) removed.append(pkg) else: pkg_not_found("", pkg, "Can't remove", "") return removed
def view_removed(binary): ''' View packages before removed ''' removed = [] print("\nPackages with name matching [ {0}{1}{2} ]\n".format( CYAN, ", ".join(binary), ENDC)) for pkg in binary: pkgs = find_package(pkg + sp, pkg_path) if pkgs: print("[ {0}delete{1} ] --> {2}".format( RED, ENDC, "\n ".join(pkgs))) removed.append(pkg) else: pkg_not_found("", pkg, "Can't remove", "") return removed
def view(self): ''' View SlackBuild package, read or install them from slackbuilds.org ''' if self.sbo_url: prgnam = ("{0}-{1}".format(self.name, self.sbo_version)) view_sbo(self.name, self.sbo_url, self.sbo_desc, self.sbo_dwn.split("/")[-1], ", ".join([src.split("/")[-1] for src in self.source_dwn]), self.sbo_req) FAULT = error_uns(self.source_dwn) while True: choice = read_choice() if choice in ["D", "d"]: download("", self.sbo_dwn, self.source_dwn) break elif choice in ["R", "r"]: README = Read(self.sbo_url).readme("README") fill = fill_pager(README) pydoc.pager(README + fill) elif choice in ["F", "f"]: info = Read(self.sbo_url).info(self.name, ".info") fill = fill_pager(info) pydoc.pager(info + fill) elif choice in ["S", "s"]: SlackBuild = Read(self.sbo_url).slackbuild(self.name, ".SlackBuild") fill = fill_pager(SlackBuild) pydoc.pager(SlackBuild + fill) elif choice in ["B", "b"]: build(self.sbo_dwn, self.source_dwn, FAULT) break elif choice in ["I", "i"]: if not find_package(prgnam + sp, pkg_path): build(self.sbo_dwn, self.source_dwn, FAULT) install(self.name, prgnam, self.sbo_url) break else: template(78) pkg_found(self.name, self.sbo_version) template(78) break else: break else: pkg_not_found("\n", self.name, "Can't view", "\n")
def start(self): ''' Install packages from official Slackware distribution ''' try: data = slack_data(self.PACKAGES_TXT, 700) (dwn_links, install_all, comp_sum, uncomp_sum) = store(data[0], data[1], data[2], data[3], self.slack_pkg, self.version) sys.stdout.write("{0}Done{1}\n\n".format(GREY, ENDC)) if install_all: template(78) print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( "| Package", " " * 17, "Version", " " * 12, "Arch", " " * 4, "Build", " " * 2, "Repos", " " * 10, "Size")) template(78) print("Installing:") sums = views(install_all, comp_sum) unit, size = units(comp_sum, uncomp_sum) msg = msgs(install_all, sums[2]) print("\nInstalling summary") print("=" * 79) print("{0}Total {1} {2}.".format(GREY, len(install_all), msg[0])) print("{0} {1} will be installed, {2} will be upgraded and " "{3} will be resettled.".format(sums[2], msg[1], 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], ENDC)) read = raw_input("\nWould you like to install [Y/n]? ") if read == "Y" or read == "y": slack_dwn(self.tmp_path, dwn_links) install(self.tmp_path, install_all) delete(self.tmp_path, install_all) else: pkg_not_found("", self.slack_pkg, "No matching", "\n") except KeyboardInterrupt: print # new line at exit sys.exit()
def display(self): ''' Print the Slackware packages contents ''' for pkg in self.binary: find = find_package(pkg + sp, pkg_path) if find: with open(pkg_path + "".join(find), "r") as package: for line in package: print(line).strip() print # new line per file else: message = "Can't dislpay" if len(self.binary) > 1: bol = eol = "" else: bol = eol = "\n" pkg_not_found(bol, pkg, message, eol)
def display(self): ''' Print the Slackware packages contents ''' for pkg in self.binary: find = find_package(pkg + sp, pkg_path) if find: with open(pkg_path + "".join(find), "r") as package: for line in package: print(line).strip() print # new line per file else: message = "Can't dislpay" if len(self.binary) > 1: bol = eol = "" else: bol = eol = "\n" pkg_not_found(bol, pkg, message, eol)
def start(self): ''' Install packages from official Slackware distribution ''' try: data = slack_data(self.PACKAGES_TXT, 700) (dwn_links, install_all, comp_sum, uncomp_sum) = store(data[0], data[1], data[2], data[3], self.slack_pkg, self.version) sys.stdout.write("{0}Done{1}\n\n".format(GREY, ENDC)) if install_all: template(78) print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( "| Package", " " * 17, "Version", " " * 12, "Arch", " " * 4, "Build", " " * 2, "Repos", " " * 10, "Size")) template(78) print("Installing:") sums = views(install_all, comp_sum) unit, size = units(comp_sum, uncomp_sum) msg = msgs(install_all, sums[2]) print("\nInstalling summary") print("=" * 79) print("{0}Total {1} {2}.".format(GREY, len(install_all), msg[0])) print("{0} {1} will be installed, {2} will be upgraded and " "{3} will be resettled.".format(sums[2], msg[1], 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], ENDC)) read = raw_input("\nWould you like to install [Y/n]? ") if read == "Y" or read == "y": slack_dwn(self.tmp_path, dwn_links) install(self.tmp_path, install_all) delete(self.tmp_path, install_all) else: pkg_not_found("", self.slack_pkg, "No matching", "\n") except KeyboardInterrupt: print # new line at exit sys.exit()
def build(self): ''' Build package from source and create log file in path /var/log/slpkg/sbo/build_logs/. Also check md5sum calculates. ''' try: tar = tarfile.open(self.script) tar.extractall() tar.close() sbo_md5_list = SBoGrep(self.prgnam).checksum() for src, sbo_md5 in zip(self.sources, sbo_md5_list): # fix build sources with spaces src = src.replace("%20", " ") check_md5(sbo_md5, src) shutil.copy2(src, self.prgnam) os.chdir(self.path + self.prgnam) # change permissions subprocess.call("chmod +x {0}.SlackBuild".format(self.prgnam), shell=True) # start log write log_head(self.build_logs, self.log_file, self.start_log_time) subprocess.Popen("./{0}.SlackBuild 2>&1 | tee -a {1}{2}".format( self.prgnam, self.build_logs, self.log_file), shell=True, stdout=sys.stdout).communicate() sum_time = build_time(self.start_time) # write end in log file log_end(self.build_logs, self.log_file, sum_time) os.chdir(self.path) print("Total build time for package {0} : {1}\n".format( self.prgnam, sum_time)) except (OSError, IOError): pkg_not_found("\n", self.prgnam, "Wrong file", "\n") except KeyboardInterrupt: print # new line at exit sys.exit()
def build(self): ''' Build package from source and create log file in path /var/log/slpkg/sbo/build_logs/. Also check md5sum calculates. ''' try: tar = tarfile.open(self.script) tar.extractall() tar.close() sbo_md5_list = SBoGrep(self.prgnam).checksum() for src, sbo_md5 in zip(self.sources, sbo_md5_list): # fix build sources with spaces src = src.replace("%20", " ") check_md5(sbo_md5, src) shutil.copy2(src, self.prgnam) os.chdir(self.path + self.prgnam) # change permissions subprocess.call("chmod +x {0}.SlackBuild".format(self.prgnam), shell=True) # start log write log_head(self.build_logs, self.log_file, self.start_log_time) subprocess.Popen("./{0}.SlackBuild 2>&1 | tee -a {1}{2}".format( self.prgnam, self.build_logs, self.log_file), shell=True, stdout=sys.stdout).communicate() sum_time = build_time(self.start_time) # write end in log file log_end(self.build_logs, self.log_file, sum_time) os.chdir(self.path) print("Total build time for package {0} : {1}\n".format(self.prgnam, sum_time)) except (OSError, IOError): pkg_not_found("\n", self.prgnam, "Wrong file", "\n") except KeyboardInterrupt: print # new line at exit sys.exit()
def not_found(message, binary, pkg): if len(binary) > 1: bol = eol = "" else: bol = eol = "\n" pkg_not_found(bol, pkg, message, eol)
def start(self): ''' Download, build and install or upgrade packages with all dependencies if version is greater than that established. ''' try: if self.dependencies_list or sbo_search_pkg(self.name) is not None: requires = one_for_all(self.name, self.dependencies_list) dependencies = remove_dbs(requires) # sbo versions = idata[0] # package arch = idata[1] # package sum = idata[2] # sources = idata[3] idata = installing_data(dependencies, self.UNST) sys.stdout.write("{0}Done{1}\n".format(GREY, ENDC)) # count upgraded = cnt[0] # count installed = cnt[1] (PKG_COLOR, count) = pkg_colors_tag(self.name, idata[0], 0, 0) print("\nThe following packages will be automatically " "installed or upgraded") print("with new version:\n") top_view() print("Installing:") ARCH_COLOR = arch_colors_tag(self.UNST, idata[1]) view_packages(PKG_COLOR, self.name, idata[0][-1], ARCH_COLOR, idata[1][-1]) print("Installing for dependencies:") for dep, ver, dep_arch in zip(dependencies[:-1], idata[0][:-1], idata[1][:-1]): (DEP_COLOR, count) = pkg_colors_tag(dep, ver, count[0], count[1]) ARCH_COLOR = arch_colors_tag(self.UNST, dep) view_packages(DEP_COLOR, dep, ver, ARCH_COLOR, dep_arch) # insstall message = msg[0] # upgraded message = msg[1] # total message = msg[2] msg = msgs(dependencies, count[1], count[0]) print("\nInstalling summary") print("=" * 79) print("{0}Total {1} {2}.".format(GREY, len(dependencies), msg[2])) print("{0} {1} will be installed, {2} allready installed and " "{3} {4}".format(count[1], msg[0], idata[2], count[0], msg[1])) print("will be upgraded.{0}\n".format(ENDC)) read = arch_support(idata[3], self.UNST, idata[2], dependencies) if read == "Y" or read == "y": # installs = b_ins[0] # upgraded = b_ins[1] # versions = b_ins[2] b_ins = build_install(dependencies, idata[0], idata[1]) reference(count[1], msg[0], count[0], msg[1], b_ins[0], b_ins[2], b_ins[1]) write_deps(self.name, dependencies) else: count_installed = count_uninstalled = 0 # sbo matching = mdata[0] # sbo version = mdata1] # package arch = mdata[2] mdata = matching_data(self.name, self.UNST) sys.stdout.write("{0}Done{1}\n".format(GREY, ENDC)) if mdata[0]: print("\nPackages with name matching [ {0}{1}{2} ]" "\n".format(CYAN, self.name, ENDC)) top_view() print("Matching:") for match, ver, march in zip(mdata[0], mdata[1], mdata[2]): if find_package(match + sp + ver, pkg_path): view_packages(GREEN, match, ver, "", march) count_installed += 1 else: view_packages(RED, match, ver, "", march) count_uninstalled += 1 # insstall message = msg[0] # uninstall message = msg[1] # total message = msg[2] msg = msgs(mdata[0], count_installed, count_uninstalled) print("\nInstalling summary") print("=" * 79) print("{0}Total found {1} matching {2}.".format( GREY, len(mdata[0]), msg[2])) print("{0} installed {1} and {2} uninstalled {3}.{4}" "\n".format(count_installed, msg[0], count_uninstalled, msg[1], ENDC)) else: pkg_not_found("\n", self.name, "No matching", "\n") except KeyboardInterrupt: print # new line at exit sys.exit()
def start(self): ''' Download, build and install or upgrade packages with all dependencies if version is greater than that established. ''' try: if self.dependencies_list or sbo_search_pkg(self.name) is not None: requires = one_for_all(self.name, self.dependencies_list) dependencies = remove_dbs(requires) # sbo versions = idata[0] # package arch = idata[1] # package sum = idata[2] # sources = idata[3] idata = installing_data(dependencies, self.UNST) sys.stdout.write("{0}Done{1}\n".format(GREY, ENDC)) # count upgraded = cnt[0] # count installed = cnt[1] (PKG_COLOR, count) = pkg_colors_tag(self.name, idata[0], 0, 0) print("\nThe following packages will be automatically " "installed or upgraded") print("with new version:\n") top_view() print("Installing:") ARCH_COLOR = arch_colors_tag(self.UNST, idata[1]) view_packages(PKG_COLOR, self.name, idata[0][-1], ARCH_COLOR, idata[1][-1]) print("Installing for dependencies:") for dep, ver, dep_arch in zip(dependencies[:-1], idata[0][:-1], idata[1][:-1]): (DEP_COLOR, count) = pkg_colors_tag(dep, ver, count[0], count[1]) ARCH_COLOR = arch_colors_tag(self.UNST, dep) view_packages(DEP_COLOR, dep, ver, ARCH_COLOR, dep_arch) # insstall message = msg[0] # upgraded message = msg[1] # total message = msg[2] msg = msgs(dependencies, count[1], count[0]) print("\nInstalling summary") print("=" * 79) print("{0}Total {1} {2}.".format(GREY, len(dependencies), msg[2])) print("{0} {1} will be installed, {2} allready installed and " "{3} {4}".format(count[1], msg[0], idata[2], count[0], msg[1])) print("will be upgraded.{0}\n".format(ENDC)) read = arch_support(idata[3], self.UNST, idata[2], dependencies) if read == "Y" or read == "y": # installs = b_ins[0] # upgraded = b_ins[1] # versions = b_ins[2] b_ins = build_install(dependencies, idata[0], idata[1]) reference(count[1], msg[0], count[0], msg[1], b_ins[0], b_ins[2], b_ins[1]) write_deps(self.name, dependencies) else: count_installed = count_uninstalled = 0 # sbo matching = mdata[0] # sbo version = mdata1] # package arch = mdata[2] mdata = matching_data(self.name, self.UNST) sys.stdout.write("{0}Done{1}\n".format(GREY, ENDC)) if mdata[0]: print("\nPackages with name matching [ {0}{1}{2} ]" "\n".format(CYAN, self.name, ENDC)) top_view() print("Matching:") for match, ver, march in zip(mdata[0], mdata[1], mdata[2]): if find_package(match + sp + ver, pkg_path): view_packages(GREEN, match, ver, "", march) count_installed += 1 else: view_packages(RED, match, ver, "", march) count_uninstalled += 1 # insstall message = msg[0] # uninstall message = msg[1] # total message = msg[2] msg = msgs(mdata[0], count_installed, count_uninstalled) print("\nInstalling summary") print("=" * 79) print("{0}Total found {1} matching {2}.".format( GREY, len(mdata[0]), msg[2])) print("{0} installed {1} and {2} uninstalled {3}.{4}" "\n".format(count_installed, msg[0], count_uninstalled, msg[1], ENDC)) else: pkg_not_found("\n", self.name, "No matching", "\n") except KeyboardInterrupt: print # new line at exit sys.exit()
def not_found(message, binary, pkg): if len(binary) > 1: bol = eol = "" else: bol = eol = "\n" pkg_not_found(bol, pkg, message, eol)