code
stringlengths
52
7.75k
docs
stringlengths
1
5.85k
def add(self, repo, url): repo_name = [] if not url.endswith("/"): url = url + "/" for line in self.custom_repositories_list.splitlines(): line = line.lstrip() if line and not line.startswith("#"): repo_name.append(line.split()[0]) if (repo in self.meta.repositories or repo in repo_name or repo in self.meta.default_repositories): print("\nRepository name '{0}' exist, select different name.\n" "View all repositories with command 'slpkg " "repo-list'.\n".format(repo)) raise SystemExit() elif len(repo) > 6: print("\nslpkg: Error: Maximum repository name length must be " "six (6) characters\n") raise SystemExit() with open(self.custom_repo_file, "a") as repos: new_line = " {0}{1}{2}\n".format(repo, " " * (10 - len(repo)), url) repos.write(new_line) repos.close() print("\nRepository '{0}' successfully added\n".format(repo)) raise SystemExit()
Write custom repository name and url in a file
def remove(self, repo): rem_repo = False with open(self.custom_repo_file, "w") as repos: for line in self.custom_repositories_list.splitlines(): repo_name = line.split()[0] if repo_name != repo: repos.write(line + "\n") else: print("\nRepository '{0}' successfully " "removed\n".format(repo)) rem_repo = True repos.close() if not rem_repo: print("\nRepository '{0}' doesn't exist\n".format(repo)) raise SystemExit()
Remove custom repository
def custom_repository(self): custom_dict_repo = {} for line in self.custom_repositories_list.splitlines(): line = line.lstrip() if not line.startswith("#"): custom_dict_repo[line.split()[0]] = line.split()[1] return custom_dict_repo
Return dictionary with repo name and url (used external)
def default_repository(self): default_dict_repo = {} for line in self.default_repositories_list.splitlines(): line = line.lstrip() if not line.startswith("#"): if line.split()[0] in self.DEFAULT_REPOS_NAMES: default_dict_repo[line.split()[0]] = line.split()[1] else: print("\nslpkg: Error: Repository name '{0}' is not " "default.\n Please check file: " "/etc/slpkg/default-repositories\n".format( line.split()[0])) raise SystemExit() return default_dict_repo
Return dictionary with default repo name and url
def slack(self): default = "http://mirrors.slackware.com/slackware/" if self.meta.arch.startswith("arm"): default = "http://ftp.arm.slackware.com/slackwarearm/" if os.path.isfile("/etc/slpkg/slackware-mirrors"): mirrors = Utils().read_file( self.meta.conf_path + "slackware-mirrors") for line in mirrors.splitlines(): line = line.rstrip() if not line.startswith("#") and line: default = line.split()[-1] if not default.endswith("/"): default += "/" return default
Official slackware repository
def check_md5(pkg_md5, src_file): if _meta_.checkmd5 in ["on", "ON"]: print("") md5s = md5(src_file) if pkg_md5 != md5s: Msg().template(78) print("| MD5SUM check for {0} [ {1}FAILED{2} ]".format( src_file.split("/")[-1], _meta_.color["RED"], _meta_.color["ENDC"])) Msg().template(78) print("| Expected: {0}".format(pkg_md5)) print("| Found: {0}".format(md5s)) Msg().template(78) print("") if not Msg().answer() in ["y", "Y"]: raise SystemExit() else: Msg().template(78) print("| MD5SUM check for {0} [ {1}PASSED{2} ]".format( src_file.split("/")[-1], _meta_.color["GREEN"], _meta_.color["ENDC"])) Msg().template(78) print("")
MD5 Checksum
def view(self): if self.sbo_url and self.name not in self.blacklist: self.prgnam = ("{0}-{1}".format(self.name, self.sbo_version)) self.view_sbo() while True: self.read_choice() choice = { "r": self.choice_README, "R": self.choice_README, "s": self.choice_SlackBuild, "S": self.choice_SlackBuild, "f": self.choice_info, "F": self.choice_info, "o": self.choice_doinst, "O": self.choice_doinst, "d": self.choice_download, "D": self.choice_download, "download": self.choice_download, "b": self.choice_build, "B": self.choice_build, "build": self.choice_build, "i": self.choice_install, "I": self.choice_install, "install": self.choice_install, "c": self.choice_clear_screen, "C": self.choice_clear_screen, "clear": self.choice_clear_screen, "q": self.choice_quit, "quit": self.choice_quit, "Q": self.choice_quit } try: choice[self.choice]() except KeyError: pass else: self.msg.pkg_not_found("\n", self.name, "Can't view", "\n") raise SystemExit(1)
View SlackBuild package, read or install them from slackbuilds.org
def case_insensitive(self): if "--case-ins" in self.flag: data_dict = Utils().case_sensitive(self.data) for key, value in data_dict.iteritems(): if key == self.name.lower(): self.name = value
Matching packages distinguish between uppercase and lowercase
def read_choice(self): commands = { "r": "README", "R": "README", "s": "{0}.SlackBuild".format(self.name), "S": "{0}.SlackBuild".format(self.name), "f": "{0}.info".format(self.name), "F": "{0}.info".format(self.name), "o": "doinst.sh", "O": "doinst.sh", "d": "download", "D": "download", "download": "download", "b": "build", "B": "build", "build": "build", "i": "install", "I": "install", "install": "install", "c": "clear", "C": "clear", "clear": "clear", "q": "quit", "quit": "quit", "Q": "quit" } try: message = " Choose an option > " self.choice = raw_input("{0}{1}{2}".format(self.grey, message, self.endc)) except EOFError: print("") raise SystemExit() try: sys.stdout.write("{0}\x1b[1A{1}{2}{3}\n".format( " " * len(message), self.cyan, commands[self.choice], self.endc)) sys.stdout.flush() except KeyError: pass
Return choice
def choice_README(self): README = ReadSBo(self.sbo_url).readme("README") fill = self.fill_pager(README) self.pager(README + fill)
View README file
def choice_SlackBuild(self): SlackBuild = ReadSBo(self.sbo_url).slackbuild(self.name, ".SlackBuild") fill = self.fill_pager(SlackBuild) self.pager(SlackBuild + fill)
View .SlackBuild file
def choice_info(self): info = ReadSBo(self.sbo_url).info(self.name, ".info") fill = self.fill_pager(info) self.pager(info + fill)
View .info file
def choice_doinst(self): if "doinst.sh" in self.sbo_files.split(): doinst_sh = ReadSBo(self.sbo_url).doinst("doinst.sh") fill = self.fill_pager(doinst_sh) self.pager(doinst_sh + fill)
View doinst.sh file
def choice_download(self): Download(path="", url=self.dwn_srcs, repo="sbo").start() raise SystemExit()
Download script.tar.gz and sources
def choice_install(self): pkg_security([self.name]) if not find_package(self.prgnam, self.meta.pkg_path): self.build() self.install() delete(self.build_folder) raise SystemExit() else: self.msg.template(78) self.msg.pkg_found(self.prgnam) self.msg.template(78) raise SystemExit()
Download, build and install package
def with_checklist(self): data = [] if self.name == "ALL": data = self.data else: for name in self.data: if self.name in name: data.append(name) if data: text = "Press 'spacebar' to choose SlackBuild for view" title = " SlackBuilds.org " backtitle = "{0} {1}".format(_meta_.__all__, _meta_.__version__) status = False pkg = DialogUtil(data, text, title, backtitle, status).checklist() if pkg and len(pkg) > 1: print("\nslpkg: Error: Choose only one package") raise SystemExit() if pkg is None: raise SystemExit() self.name = "".join(pkg) os.system("clear")
Using dialog and checklist option
def fill_pager(self, page): tty_size = os.popen("stty size", "r").read().split() rows = int(tty_size[0]) - 1 lines = sum(1 for line in page.splitlines()) diff = rows - lines fill = "\n" * diff if diff > 0: return fill else: return ""
Fix pager spaces
def error_uns(self): self.FAULT = "" UNST = ["UNSUPPORTED", "UNTESTED"] if "".join(self.source_dwn) in UNST: self.FAULT = "".join(self.source_dwn)
Check if package supported by arch before proceed to install
def build(self): pkg_security([self.name]) self.error_uns() if self.FAULT: print("") self.msg.template(78) print("| Package {0} {1} {2} {3}".format(self.prgnam, self.red, self.FAULT, self.endc)) self.msg.template(78) else: sources = [] if not os.path.exists(self.meta.build_path): os.makedirs(self.meta.build_path) if not os.path.exists(self._SOURCES): os.makedirs(self._SOURCES) os.chdir(self.meta.build_path) Download(self.meta.build_path, self.sbo_dwn.split(), repo="sbo").start() Download(self._SOURCES, self.source_dwn, repo="sbo").start() script = self.sbo_dwn.split("/")[-1] for src in self.source_dwn: sources.append(src.split("/")[-1]) BuildPackage(script, sources, self.meta.build_path, auto=False).build() slack_package(self.prgnam)
Only build and create Slackware package
def install(self): binary = slack_package(self.prgnam) print("[ {0}Installing{1} ] --> {2}".format(self.green, self.endc, self.name)) PackageManager(binary).upgrade(flag="--install-new")
Install SBo package found in /tmp directory.
def packages(self): queue_list = [] for read in self.queued.splitlines(): read = read.lstrip() if not read.startswith("#"): queue_list.append(read.replace("\n", "")) return queue_list
Return queue list from /var/lib/queue/queue_list file.
def listed(self): print("\nPackages in the queue:\n") for pkg in self.packages(): if pkg: print("{0}{1}{2}".format(self.meta.color["GREEN"], pkg, self.meta.color["ENDC"])) self.quit = True if self.quit: print("")
Print packages from queue
def add(self, pkgs): queue_list = self.packages() pkgs = list(OrderedDict.fromkeys(pkgs)) print("\nAdd packages in the queue:\n") with open(self.queue_list, "a") as queue: for pkg in pkgs: find = sbo_search_pkg(pkg) if pkg not in queue_list and find is not None: print("{0}{1}{2}".format(self.meta.color["GREEN"], pkg, self.meta.color["ENDC"])) queue.write(pkg + "\n") self.quit = True else: print("{0}{1}{2}".format(self.meta.color["RED"], pkg, self.meta.color["ENDC"])) self.quit = True queue.close() if self.quit: print("")
Add packages in queue if not exist
def remove(self, pkgs): print("\nRemove packages from the queue:\n") with open(self.queue_list, "w") as queue: for line in self.queued.splitlines(): if line not in pkgs: queue.write(line + "\n") else: print("{0}{1}{2}".format(self.meta.color["RED"], line, self.meta.color["ENDC"])) self.quit = True queue.close() if self.quit: print("")
Remove packages from queue
def build(self): packages = self.packages() if packages: for pkg in packages: if not os.path.exists(self.meta.build_path): os.mkdir(self.meta.build_path) if not os.path.exists(self._SOURCES): os.mkdir(self._SOURCES) sbo_url = sbo_search_pkg(pkg) sbo_dwn = SBoLink(sbo_url).tar_gz() source_dwn = SBoGrep(pkg).source().split() sources = [] os.chdir(self.meta.build_path) script = sbo_dwn.split("/")[-1] Download(self.meta.build_path, sbo_dwn.split(), repo="sbo").start() for src in source_dwn: Download(self._SOURCES, src.split(), repo="sbo").start() sources.append(src.split("/")[-1]) BuildPackage(script, sources, self.meta.build_path, auto=False).build() else: print("\nPackages not found in the queue for building\n") raise SystemExit(1)
Build packages from queue
def install(self): packages = self.packages() if packages: print("") # new line at start for pkg in packages: ver = SBoGrep(pkg).version() prgnam = "{0}-{1}".format(pkg, ver) if find_package(prgnam, self.meta.output): binary = slack_package(prgnam) PackageManager(binary).upgrade(flag="--install-new") else: print("\nPackage {0} not found in the {1} for " "installation\n".format(prgnam, self.meta.output)) else: print("\nPackages not found in the queue for installation\n") raise SystemExit(1)
Install packages from queue
def pkg_upgrade(repo, skip, flag): Msg().checking() PACKAGES_TXT = RepoInit(repo).fetch()[0] pkgs_for_upgrade = [] # name = data[0] # location = data[1] # size = data[2] # unsize = data[3] data = repo_data(PACKAGES_TXT, repo, flag="") for pkg in installed(): status(0.0005) inst_pkg = split_package(pkg) for name in data[0]: if name: # this tips because some pkg_name is empty repo_pkg = split_package(name[:-4]) if (repo_pkg[0] == inst_pkg[0] and LooseVersion(repo_pkg[1]) > LooseVersion(inst_pkg[1]) and repo_pkg[3] >= inst_pkg[3] and inst_pkg[0] not in skip and repo_pkg[1] != "blacklist"): pkgs_for_upgrade.append(repo_pkg[0]) Msg().done() if "--checklist" in flag: pkgs_for_upgrade = choose_upg(pkgs_for_upgrade) return pkgs_for_upgrade
Checking packages for upgrade
def split_package(package): name = ver = arch = build = [] split = package.split("-") if len(split) > 2: build = split[-1] build_a, build_b = "", "" build_a = build[:1] if build[1:2].isdigit(): build_b = build[1:2] build = build_a + build_b arch = split[-2] ver = split[-3] name = "-".join(split[:-3]) return [name, ver, arch, build]
Split package in name, version arch and build tag.
def remove_repositories(repositories, default_repositories): repos = [] for repo in repositories: if repo in default_repositories: repos.append(repo) return repos
Remove no default repositories
def update_repositories(repositories, conf_path): repo_file = "{0}custom-repositories".format(conf_path) if os.path.isfile(repo_file): f = open(repo_file, "r") repositories_list = f.read() f.close() for line in repositories_list.splitlines(): line = line.lstrip() if line and not line.startswith("#"): repositories.append(line.split()[0]) return repositories
Upadate with user custom repositories
def grab_sub_repo(repositories, repos): for i, repo in enumerate(repositories): if repos in repo: sub = repositories[i].replace(repos, "") repositories[i] = repos return sub return ""
Grab SUB_REPOSITORY
def names(self): pkg_names = [] for line in self.SLACKBUILDS_TXT.splitlines(): if line.startswith(self.line_name): pkg_names.append(line[17:].strip()) return pkg_names
Grab all packages name
def source(self): source, source64, = "", "" for line in self.SLACKBUILDS_TXT.splitlines(): if line.startswith(self.line_name): sbo_name = line[17:].strip() if line.startswith(self.line_down): if sbo_name == self.name and line[21:].strip(): source = line[21:] if line.startswith(self.line_down_64): if sbo_name == self.name and line[28:].strip(): source64 = line[28:] return self._select_source_arch(source, source64)
Grab sources downloads links
def _select_source_arch(self, source, source64): src = "" if self.meta.arch == "x86_64": if source64: src = source64 else: src = source if self.meta.skip_unst in self.answer and source64 in self.unst: src = source else: if source: src = source if self.meta.skip_unst in self.answer and source in self.unst: src = source64 return src
Return sources by arch
def requires(self): for line in self.SLACKBUILDS_TXT.splitlines(): if line.startswith(self.line_name): sbo_name = line[17:].strip() if line.startswith(self.line_req): if sbo_name == self.name: return line[21:].strip().split()
Grab package requirements
def version(self): for line in self.SLACKBUILDS_TXT.splitlines(): if line.startswith(self.line_name): sbo_name = line[17:].strip() if line.startswith(self.line_ver): if sbo_name == self.name: return line[20:].strip()
Grab package version
def checksum(self): md5sum, md5sum64, = [], [] for line in self.SLACKBUILDS_TXT.splitlines(): if line.startswith(self.line_name): sbo_name = line[17:].strip() if line.startswith(self.line_md5_64): if sbo_name == self.name and line[26:].strip(): md5sum64 = line[26:].strip().split() if line.startswith(self.line_md5): if sbo_name == self.name and line[19:].strip(): md5sum = line[19:].strip().split() return self._select_md5sum_arch(md5sum, md5sum64)
Grab checksum string
def _select_md5sum_arch(self, md5sum, md5sum64): if md5sum and md5sum64: if self.meta.arch == "x86_64": return md5sum64 else: return md5sum if md5sum: return md5sum else: return md5sum64
Return checksums by arch
def description(self): for line in self.SLACKBUILDS_TXT.splitlines(): if line.startswith(self.line_name): sbo_name = line[17:].strip() if line.startswith(self.line_des): if sbo_name == self.name: return line[31:].strip()
Grab package verion
def files(self): for line in self.SLACKBUILDS_TXT.splitlines(): if line.startswith(self.line_name): sbo_name = line[17:].strip() if line.startswith(self.line_files): if sbo_name == self.name: return line[18:].strip()
Grab files
def check_exists_repositories(repo): pkg_list = "PACKAGES.TXT" if repo == "sbo": pkg_list = "SLACKBUILDS.TXT" if check_for_local_repos(repo) is True: pkg_list = "PACKAGES.TXT" return "" if not os.path.isfile("{0}{1}{2}".format( _meta_.lib_path, repo, "_repo/{0}".format(pkg_list))): return repo return ""
Checking if repositories exists by PACKAGES.TXT file
def check_for_local_repos(repo): repos_dict = Repo().default_repository() if repo in repos_dict: repo_url = repos_dict[repo] if repo_url.startswith("file:///"): return True
Check if repository is local
def conrad(self): repo = self.def_repos_dict["conrad"] log = self.log_path + "conrad/" lib = self.lib_path + "conrad_repo/" repo_name = log[:-1].split("/")[-1] lib_file = "PACKAGES.TXT" # lst_file = "" md5_file = "CHECKSUMS.md5" log_file = "ChangeLog.txt" if not os.path.exists(log): os.mkdir(log) if not os.path.exists(lib): os.mkdir(lib) PACKAGES_TXT = "{0}{1}".format(repo, lib_file) FILELIST_TXT = "" CHECKSUMS_MD5 = "{0}{1}".format(repo, md5_file) ChangeLog_txt = "{0}{1}".format(repo, log_file) if self.check: return self.checks_logs(log, ChangeLog_txt) self.down(lib, PACKAGES_TXT, repo_name) self.down(lib, CHECKSUMS_MD5, repo_name) self.down(log, ChangeLog_txt, repo_name) self.remote(log, ChangeLog_txt, lib, PACKAGES_TXT, CHECKSUMS_MD5, FILELIST_TXT, repo_name)
Creating slackers local library
def down(self, path, link, repo): filename = link.split("/")[-1] if not os.path.isfile(path + filename): Download(path, link.split(), repo).start()
Download files
def remote(self, *args): log_path = args[0] ChangeLog_txt = args[1] lib_path = args[2] PACKAGES_TXT = args[3] CHECKSUMS_MD5 = args[4] FILELIST_TXT = args[5] repo = args[6] if self.checks_logs(log_path, ChangeLog_txt): # remove old files self.file_remove(log_path, ChangeLog_txt.split("/")[-1]) self.file_remove(lib_path, PACKAGES_TXT.split("/")[-1]) self.file_remove(lib_path, CHECKSUMS_MD5.split("/")[-1]) self.file_remove(lib_path, FILELIST_TXT.split("/")[-1]) if repo == "slack": dirs = ["core/", "extra/", "pasture/"] for d in dirs: self.file_remove(lib_path + d, "PACKAGES.TXT") self.file_remove(lib_path + d, "CHECKSUMS.md5") self.down(lib_path + "core/", PACKAGES_TXT, repo) self.down(lib_path + "core/", CHECKSUMS_MD5, repo) self.down(lib_path + "extra/", self.EXTRA, repo) self.down(lib_path + "extra/", self.EXT_CHECKSUMS, repo) if slack_ver() != "14.0": # no pasture/ folder for 14.0 version self.down(lib_path + "pasture/", self.PASTURE, repo) self.down(lib_path + "pasture/", self.PAS_CHECKSUMS, repo) # download new files if repo != "slack": self.down(lib_path, PACKAGES_TXT, repo) self.down(lib_path, CHECKSUMS_MD5, repo) self.down(lib_path, FILELIST_TXT, repo) self.down(log_path, ChangeLog_txt, repo)
Remove and recreate files
def merge(self, path, outfile, infiles): with open(path + outfile, 'w') as out_f: for i in infiles: if os.path.isfile("{0}{1}".format(path, i)): with open(path + i, "r") as in_f: for line in in_f: out_f.write(line)
Merge files
def file_remove(self, path, filename): if os.path.isfile(path + filename): os.remove(path + filename)
Check if filename exists and remove
def checks_logs(self, log_path, url): local = "" filename = url.split("/")[-1] server = FileSize(url).server() if os.path.isfile(log_path + filename): local = FileSize(log_path + filename).local() if server != local: return True return False
Checks ChangeLog.txt for changes
def upgrade(self, only): repositories = self.meta.repositories if only: repositories = only for repo in repositories: changelogs = "{0}{1}{2}".format(self.log_path, repo, "/ChangeLog.txt") if os.path.isfile(changelogs): os.remove(changelogs) if os.path.isdir(self.lib_path + "{0}_repo/".format(repo)): for f in (os.listdir(self.lib_path + "{0}_repo/".format( repo))): files = "{0}{1}_repo/{2}".format(self.lib_path, repo, f) if os.path.isfile(files): os.remove(files) elif os.path.isdir(files): shutil.rmtree(files) Update().repository(only)
Remove all package lists with changelog and checksums files and create lists again
def repository(self, only): print("\nCheck and update repositories:\n") default = self.meta.default_repositories enabled = self.meta.repositories if only: enabled = only for repo in enabled: if check_for_local_repos(repo) is True: continue sys.stdout.write("{0}Check repository [{1}{2}{3}] ... " "{4}".format( self.meta.color["GREY"], self.meta.color["CYAN"], repo, self.meta.color["GREY"], self.meta.color["ENDC"])) sys.stdout.flush() if repo in default: exec("{0}.{1}()".format(self._init, repo)) sys.stdout.write(self.done) elif repo in enabled: Initialization(False).custom(repo) sys.stdout.write(self.done) else: sys.stdout.write(self.error) print("") # new line at end raise SystemExit()
Update repositories lists
def checklist(self): choice = [] for item in self.data: choice.append((item, "", self.status)) code, self.tags = self.d.checklist( text=self.text, height=20, width=65, list_height=13, choices=choice, title=self.title, backtitle=self.backtitle) if code == "ok": self.unicode_to_string() return self.ununicode if code in ["cancel", "esc"]: self.exit()
Run dialog checklist
def buildlist(self, enabled): choice = [] for item in self.data: choice.append((item, False)) for item in enabled: choice.append((item, True)) items = [(tag, tag, sta) for (tag, sta) in choice] code, self.tags = self.d.buildlist( text=self.text, items=items, visit_items=True, item_help=False, title=self.title) if code == "ok": self.unicode_to_string() return self.ununicode if code in ["cancel", "esc"]: self.exit()
Run dialog buildlist
def unicode_to_string(self): for tag in self.tags: self.ununicode.append(str(tag))
Convert unicode in string
def sbo_upgrade(skip, flag): Msg().checking() upgrade_names = [] data = SBoGrep(name="").names() blacklist = BlackList().packages(pkgs=data, repo="sbo") for pkg in sbo_list(): status(0.02) name = split_package(pkg)[0] ver = split_package(pkg)[1] if (name in data and name not in skip and name not in blacklist): sbo_package = ("{0}-{1}".format(name, SBoGrep(name).version())) package = ("{0}-{1}".format(name, ver)) if LooseVersion(sbo_package) > LooseVersion(package): upgrade_names.append(name) Msg().done() if "--checklist" in flag: upgrade_names = choose_upg(upgrade_names) return upgrade_names
Return packages for upgrade
def sbo_list(): sbo_packages = [] for pkg in os.listdir(_meta_.pkg_path): if pkg.endswith("_SBo"): sbo_packages.append(pkg) return sbo_packages
Return all SBo packages
def delete_package(path, packages): if _meta_.del_all in ["on", "ON"]: for pkg in packages: os.remove(path + pkg)
Remove downloaded packages
def repository_data(self, repo): sum_pkgs, size, unsize, last_upd = 0, [], [], "" for line in (Utils().read_file( self.meta.lib_path + repo + "_repo/PACKAGES.TXT").splitlines()): if line.startswith("PACKAGES.TXT;"): last_upd = line[14:].strip() if line.startswith("PACKAGE NAME:"): sum_pkgs += 1 if line.startswith("PACKAGE SIZE (compressed): "): size.append(line[28:-2].strip()) if line.startswith("PACKAGE SIZE (uncompressed): "): unsize.append(line[30:-2].strip()) if repo in ["salix", "slackl"]: log = Utils().read_file( self.meta.log_path + "{0}/ChangeLog.txt".format(repo)) last_upd = log.split("\n", 1)[0] return [sum_pkgs, size, unsize, last_upd]
Grap data packages
def delete(build_folder): if _meta_.del_build in ["on", "ON"] and os.path.exists(build_folder): shutil.rmtree(build_folder)
Delete build directory and all its contents.
def store(self): data = repo_data(self.PACKAGES_TXT, "slack", self.flag) black = BlackList().packages(pkgs=data[0], repo="slack") for name, loc, comp, uncomp in zip(data[0], data[1], data[2], data[3]): status(0.0003) repo_pkg_name = split_package(name)[0] if (not os.path.isfile(self.meta.pkg_path + name[:-4]) and repo_pkg_name not in black and repo_pkg_name not in self.skip): self.dwn_links.append("{0}{1}/{2}".format(mirrors("", ""), loc, name)) self.comp_sum.append(comp) self.uncomp_sum.append(uncomp) self.upgrade_all.append(name) self.count_upg += 1 if not find_package(repo_pkg_name + self.meta.sp, self.meta.pkg_path): self.count_added += 1 self.count_upg -= 1 return self.count_upg
Store and return packages for upgrading
def dialog_checklist(self): data = [] for upg in self.upgrade_all: data.append(upg[:-4]) text = "Press 'spacebar' to unchoose packages from upgrade" title = " Upgrade " backtitle = "{0} {1}".format(self.meta.__all__, self.meta.__version__) status = True pkgs = DialogUtil(data, text, title, backtitle, status).checklist() index = 0 for pkg, comp, uncomp in zip(self.upgrade_all, self.comp_sum, self.uncomp_sum): if pkg[:-4] not in pkgs: self.dwn_links.pop(index) self.upgrade_all.pop(index) self.comp_sum.pop(index) self.uncomp_sum.pop(index) self.count_upg -= 1 del comp, uncomp index -= 1 index += 1 if not self.upgrade_all: raise SystemExit()
Create checklist to choose packages for upgrade
def views(self): for upg, size in sorted(zip(self.upgrade_all, self.comp_sum)): pkg_repo = split_package(upg[:-4]) color = self.meta.color["RED"] pkg_inst = GetFromInstalled(pkg_repo[0]).name() if pkg_repo[0] == pkg_inst: color = self.meta.color["YELLOW"] ver = GetFromInstalled(pkg_repo[0]).version() print(" {0}{1}{2}{3} {4}{5} {6}{7}{8}{9}{10}{11:>12}{12}".format( color, pkg_repo[0] + ver, self.meta.color["ENDC"], " " * (23-len(pkg_repo[0] + ver)), pkg_repo[1], " " * (18-len(pkg_repo[1])), pkg_repo[2], " " * (8-len(pkg_repo[2])), pkg_repo[3], " " * (7-len(pkg_repo[3])), "Slack", size, " K")).rstrip()
Views packages
def upgrade(self): 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]) if find_package(split_package(pkg)[0] + self.meta.sp, self.meta.pkg_path): print("[ {0}upgrading{1} ] --> {2}".format( self.meta.color["YELLOW"], self.meta.color["ENDC"], pkg[:-4])) PackageManager((self.patch_path + pkg).split()).upgrade( "--install-new") self.upgraded.append(pkg_ver) else: print("[ {0}installing{1} ] --> {2}".format( self.meta.color["GREEN"], self.meta.color["ENDC"], pkg[:-4])) PackageManager((self.patch_path + pkg).split()).upgrade( "--install-new") self.installed.append(pkg_ver)
Upgrade packages
def kernel(self): for core in self.upgrade_all: if "kernel" in core: if self.meta.default_answer in ["y", "Y"]: answer = self.meta.default_answer else: print("") self.msg.template(78) print("| {0}*** HIGHLY recommended reinstall 'LILO' " "***{1}".format(self.meta.color["RED"], self.meta.color["ENDC"])) self.msg.template(78) try: answer = raw_input("\nThe kernel has been upgraded, " "reinstall `LILO` [y/N]? ") except EOFError: print("") raise SystemExit() if answer in ["y", "Y"]: subprocess.call("lilo", shell=True) break
Check if kernel upgraded if true then reinstall "lilo"
def slackpkg_update(self): NEW_ChangeLog_txt = URL(mirrors("ChangeLog.txt", "")).reading() if os.path.isfile(self.meta.slackpkg_lib_path + "ChangeLog.txt.old"): os.remove(self.meta.slackpkg_lib_path + "ChangeLog.txt.old") if os.path.isfile(self.meta.slackpkg_lib_path + "ChangeLog.txt"): shutil.copy2(self.meta.slackpkg_lib_path + "ChangeLog.txt", self.meta.slackpkg_lib_path + "ChangeLog.txt.old") os.remove(self.meta.slackpkg_lib_path + "ChangeLog.txt") with open(self.meta.slackpkg_lib_path + "ChangeLog.txt", "w") as log: log.write(NEW_ChangeLog_txt) log.close()
This replace slackpkg ChangeLog.txt file with new from Slackware official mirrors after update distribution.
def update_lists(self): print("{0}Update the package lists ?{1}".format( self.meta.color["GREEN"], self.meta.color["ENDC"])) print("=" * 79) if self.msg.answer() in ["y", "Y"]: Update().repository(["slack"])
Update packages list and ChangeLog.txt file after upgrade distribution
def choose_upg(packages): selected_packages, data = [], [] if packages: for pkg in packages: name = GetFromInstalled(pkg).name() ver = GetFromInstalled(pkg).version() binary = "{0}{1}".format(name, ver) installed = find_package(binary + _meta_.sp, _meta_.pkg_path)[0] data.append(installed) text = "Press 'spacebar' to unchoose packages from upgrade" title = " Upgrade " backtitle = "{0} {1}".format(_meta_.__all__, _meta_.__version__) status = True pkgs = DialogUtil(data, text, title, backtitle, status).checklist() pkgs = [] if pkgs is None else pkgs for pkg in pkgs: name = split_package(pkg)[0] if name in packages: selected_packages.append(name) if not selected_packages: raise SystemExit() print("") return selected_packages
Create checklist to choose packages for upgrade
def log_head(path, log_file, log_time): with open(path + log_file, "w") as log: log.write("#" * 79 + "\n\n") log.write("File : " + log_file + "\n") log.write("Path : " + path + "\n") log.write("Date : " + time.strftime("%d/%m/%Y") + "\n") log.write("Time : " + log_time + "\n\n") log.write("#" * 79 + "\n\n") log.close()
write headers to log file
def log_end(path, log_file, sum_time): with open(path + log_file, "a") as log: log.seek(2) 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("#" * 79 + "\n\n") log.close()
append END tag to a log file
def build_time(start_time): diff_time = round(time.time() - start_time, 2) if diff_time <= 59.99: sum_time = str(diff_time) + " Sec" elif diff_time > 59.99 and diff_time <= 3599.99: sum_time = round(diff_time / 60, 2) sum_time_list = re.findall(r"\d+", str(sum_time)) sum_time = ("{0} Min {1} Sec".format(sum_time_list[0], sum_time_list[1])) elif diff_time > 3599.99: sum_time = round(diff_time / 3600, 2) sum_time_list = re.findall(r"\d+", str(sum_time)) sum_time = ("{0} Hours {1} Min".format(sum_time_list[0], sum_time_list[1])) return sum_time
Calculate build time per package
def _create_md5_dict(self): self.sbo_md5 = {} md5_lists = SBoGrep(self.prgnam).checksum() for src, md5 in zip(self.sources, md5_lists): self.sbo_md5[src] = md5
Create md5 dictionary per source
def _makeflags(self): if self.meta.makeflags in ["on", "ON"]: cpus = multiprocessing.cpu_count() os.environ["MAKEFLAGS"] = "-j{0}".format(cpus)
Set variable MAKEFLAGS with the numbers of processors
def _pass_variable(self): pass_var = [] for var in os.environ.keys(): expVAR = var.split("_") if expVAR[0] == self.prgnam.upper() and expVAR[1] != "PATH": pass_var.append("{0}={1}".format(expVAR[1], os.environ[var])) return pass_var
Return enviroment variables
def _delete_sbo_tar_gz(self): if not self.auto and os.path.isfile(self.meta.build_path + self.script): os.remove(self.meta.build_path + self.script)
Delete slackbuild tar.gz file after untar
def _delete_dir(self): if not self.auto and os.path.isdir(self.meta.build_path + self.prgnam): shutil.rmtree(self.meta.build_path + self.prgnam)
Delete old folder if exists before start build
def get_black(self): blacklist = [] for read in self.black_conf.splitlines(): read = read.lstrip() if not read.startswith("#"): blacklist.append(read.replace("\n", "")) return blacklist
Return blacklist packages from /etc/slpkg/blacklist configuration file.
def listed(self): print("\nPackages in the blacklist:\n") for black in self.get_black(): if black: print("{0}{1}{2}".format(self.meta.color["GREEN"], black, self.meta.color["ENDC"])) self.quit = True if self.quit: print("")
Print blacklist packages
def add(self, pkgs): blacklist = self.get_black() pkgs = set(pkgs) print("\nAdd packages in the blacklist:\n") with open(self.blackfile, "a") as black_conf: for pkg in pkgs: if pkg not in blacklist: print("{0}{1}{2}".format(self.meta.color["GREEN"], pkg, self.meta.color["ENDC"])) black_conf.write(pkg + "\n") self.quit = True black_conf.close() if self.quit: print("")
Add blacklist packages if not exist
def remove(self, pkgs): print("\nRemove packages from the blacklist:\n") with open(self.blackfile, "w") as remove: for line in self.black_conf.splitlines(): if line not in pkgs: remove.write(line + "\n") else: print("{0}{1}{2}".format(self.meta.color["RED"], line, self.meta.color["ENDC"])) self.quit = True remove.close() if self.quit: print("")
Remove packages from blacklist
def packages(self, pkgs, repo): self.black = [] for bl in self.get_black(): pr = bl.split(":") for pkg in pkgs: self.__priority(pr, repo, pkg) self.__blackpkg(bl, repo, pkg) return self.black
Return packages in blacklist or by repository
def __priority(self, pr, repo, pkg): if (pr[0] == repo and pr[1].startswith("*") and pr[1].endswith("*")): if pr[1][1:-1] in pkg: self.black.append(self.__add(repo, pkg)) elif pr[0] == repo and pr[1].endswith("*"): if pkg.startswith(pr[1][:-1]): self.black.append(self.__add(repo, pkg)) elif pr[0] == repo and pr[1].startswith("*"): if pkg.endswith(pr[1][1:]): self.black.append(self.__add(repo, pkg)) elif pr[0] == repo and "*" not in pr[1]: self.black.append(self.__add(repo, pkg))
Add packages in blacklist by priority
def __blackpkg(self, bl, repo, pkg): if bl.startswith("*") and bl.endswith("*"): if bl[1:-1] in pkg: self.black.append(self.__add(repo, pkg)) elif bl.endswith("*"): if pkg.startswith(bl[:-1]): self.black.append(self.__add(repo, pkg)) elif bl.startswith("*"): if pkg.endswith(bl[1:]): self.black.append(self.__add(repo, pkg)) if bl not in self.black and "*" not in bl: self.black.append(bl)
Add packages in blacklist
def view(self): print("") # new line at start description, count = "", 0 if self.repo == "sbo": description = SBoGrep(self.name).description() else: PACKAGES_TXT = Utils().read_file(self.lib) for line in PACKAGES_TXT.splitlines(): if line.startswith(self.name + ":"): description += line[len(self.name) + 2:] + "\n" count += 1 if count == 11: break if description: print("{0}{1}{2}".format(self.COLOR, description, self.meta.color["ENDC"])) else: self.msg.pkg_not_found("", self.name, "No matching", "\n") raise SystemExit(1) if description and self.repo == "sbo": print("")
Print package description by repository
def start(self): dwn_count = 1 self._directory_prefix() for dwn in self.url: # get file name from url and fix passing char '+' self.file_name = dwn.split("/")[-1].replace("%2B", "+") if dwn.startswith("file:///"): source_dir = dwn[7:-7].replace(slack_ver(), "") self._make_tarfile(self.file_name, source_dir) self._check_certificate() print("\n[{0}/{1}][ {2}Download{3} ] --> {4}\n".format( dwn_count, len(self.url), self.meta.color["GREEN"], self.meta.color["ENDC"], self.file_name)) if self.downder in ["wget"]: subprocess.call("{0} {1} {2}{3} {4}".format( self.downder, self.downder_options, self.dir_prefix, self.path, dwn), shell=True) if self.downder in ["aria2c"]: subprocess.call("{0} {1} {2}{3} {4}".format( self.downder, self.downder_options, self.dir_prefix, self.path[:-1], dwn), shell=True) elif self.downder in ["curl", "http"]: subprocess.call("{0} {1} {2}{3} {4}".format( self.downder, self.downder_options, self.path, self.file_name, dwn), shell=True) self._check_if_downloaded() dwn_count += 1
Download files using wget or other downloader. Optional curl, aria2c and httpie
def _make_tarfile(self, output_filename, source_dir): with tarfile.open(output_filename, "w:gz") as tar: tar.add(source_dir, arcname=os.path.basename(source_dir))
Create .tar.gz file
def _directory_prefix(self): if self.downder == "wget": self.dir_prefix = "--directory-prefix=" elif self.downder == "aria2c": self.dir_prefix = "--dir="
Downloader options for specific directory
def _check_if_downloaded(self): if not os.path.isfile(self.path + self.file_name): print("") self.msg.template(78) print("| Download '{0}' file [ {1}FAILED{2} ]".format( self.file_name, self.meta.color["RED"], self.meta.color["ENDC"])) self.msg.template(78) print("") if not self.msg.answer() in ["y", "Y"]: raise SystemExit()
Check if file downloaded
def _check_certificate(self): if (self.file_name.startswith("jdk-") and self.repo == "sbo" and self.downder == "wget"): certificate = (' --no-check-certificate --header="Cookie: ' 'oraclelicense=accept-securebackup-cookie"') self.msg.template(78) print("| '{0}' need to go ahead downloading".format( certificate[:23].strip())) self.msg.template(78) print("") self.downder_options += certificate if not self.msg.answer() in ["y", "Y"]: raise SystemExit()
Check for certificates options for wget
def slack_package(prgnam): binaries, cache, binary = [], "0", "" for pkg in find_package(prgnam, _meta_.output): if pkg.startswith(prgnam) and pkg[:-4].endswith("_SBo"): binaries.append(pkg) for bins in binaries: if LooseVersion(bins) > LooseVersion(cache): binary = bins cache = binary if not binary: Msg().build_FAILED(prgnam) raise SystemExit(1) return ["".join(_meta_.output + binary)]
Return maximum binary Slackware package from output directory
def server(self): try: tar = urllib2.urlopen(self.registry) meta = tar.info() return int(meta.getheaders("Content-Length")[0]) except (urllib2.URLError, IndexError): return " "
Returns the size of remote files
def units(comp_sum, uncomp_sum): 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" if uncompressed > 1024: uncompressed = round((uncompressed / 1024), 2) uncomp_unit = "Gb" if compressed < 1: compressed = sum(map(int, comp_sum)) comp_unit = "Kb" if uncompressed < 1: uncompressed = sum(map(int, uncomp_sum)) uncomp_unit = "Kb" return [comp_unit, uncomp_unit], [compressed, uncompressed]
Calculate package size
def status(sec): if _meta_.prg_bar in ["on", "ON"]: syms = ["|", "/", "-", "\\"] for sym in syms: sys.stdout.write("\b{0}{1}{2}".format(_meta_.color["GREY"], sym, _meta_.color["ENDC"])) sys.stdout.flush() time.sleep(float(sec))
Toolbar progressive status
def update_deps(self): onelist, dependencies = [], [] onelist = Utils().dimensional_list(self.deps) dependencies = Utils().remove_dbs(onelist) for dep in dependencies: deps = Requires(self.flag).sbo(dep) self.deps_dict[dep] = self.one_for_all(deps)
Update dependencies dictionary with all package
def continue_to_install(self): if (self.count_uni > 0 or self.count_upg > 0 or "--download-only" in self.flag or "--rebuild" in self.flag): if self.master_packages and self.msg.answer() in ["y", "Y"]: installs, upgraded = self.build_install() if "--download-only" in self.flag: raise SystemExit() self.msg.reference(installs, upgraded) write_deps(self.deps_dict) delete(self.build_folder)
Continue to install ?
def clear_masters(self): self.master_packages = Utils().remove_dbs(self.master_packages) for mas in self.master_packages: if mas in self.dependencies: self.master_packages.remove(mas)
Clear master slackbuilds if already exist in dependencies or if added to install two or more times
def matching(self): for sbo in self.package_not_found: for pkg in self.data: if sbo in pkg and pkg not in self.blacklist: self.package_found.append(pkg)
Return found matching SBo packages
def sbo_version_source(self, slackbuilds): sbo_versions, sources = [], [] for sbo in slackbuilds: status(0.02) sbo_ver = "{0}-{1}".format(sbo, SBoGrep(sbo).version()) sbo_versions.append(sbo_ver) sources.append(SBoGrep(sbo).source()) return [sbo_versions, sources]
Create sbo name with version
def one_for_all(self, deps): requires, dependencies = [], [] deps.reverse() # Inverting the list brings the # dependencies in order to be installed. requires = Utils().dimensional_list(deps) dependencies = Utils().remove_dbs(requires) return dependencies
Because there are dependencies that depend on other dependencies are created lists into other lists. Thus creating this loop create one-dimensional list and remove double packages from dependencies.
def view_packages(self, *args): ver = GetFromInstalled(args[1]).version() print(" {0}{1}{2}{3} {4}{5} {6}{7}{8}{9}{10}{11:>11}{12}".format( args[0], args[1] + ver, self.meta.color["ENDC"], " " * (23-len(args[1] + ver)), args[2], " " * (18-len(args[2])), args[3], " " * (15-len(args[3])), "", "", "SBo", "", "")).rstrip()
:View slackbuild packages with version and arch args[0] package color args[1] package args[2] version args[3] arch
def tag(self, sbo): # split sbo name with version and get name sbo_name = "-".join(sbo.split("-")[:-1]) find = GetFromInstalled(sbo_name).name() if find_package(sbo, self.meta.pkg_path): paint = self.meta.color["GREEN"] self.count_ins += 1 if "--rebuild" in self.flag: self.count_upg += 1 elif sbo_name == find: paint = self.meta.color["YELLOW"] self.count_upg += 1 else: paint = self.meta.color["RED"] self.count_uni += 1 return paint
Tag with color green if package already installed, color yellow for packages to upgrade and color red if not installed.
def select_arch(self, src): arch = self.arch for item in self.unst: if item in src: arch = item return arch
Looks if sources unsupported or untested from arch else select arch.