text_prompt
stringlengths
157
13.1k
code_prompt
stringlengths
7
19.8k
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def it_self_update(): """Check from GitHub slpkg repository if new version is available download and update itself """
__new_version__ = "" repository = "gitlab" branch = "master" ver_link = ("https://raw.{0}usercontent.com/{1}/{2}/" "{3}/{4}/__metadata__.py".format(repository, _meta_.__author__, _meta_.__all__, branch, _meta_.__all__)) version_data = URL(ver_link).reading() for line in version_data.splitlines(): line = line.strip() if line.startswith("__version_info__"): __new_version__ = ".".join(re.findall(r"\d+", line)) if __new_version__ > _meta_.__version__: if _meta_.default_answer in ["y", "Y"]: answer = _meta_.default_answer else: print("\nNew version '{0}-{1}' is available !\n".format( _meta_.__all__, __new_version__)) try: answer = raw_input("Would you like to upgrade [y/N]? ") except EOFError: print("") raise SystemExit() if answer in ["y", "Y"]: print("") # new line after answer else: raise SystemExit() dwn_link = ["https://{0}.com/{1}/{2}/archive/" "v{3}/{4}-{5}.tar.gz".format(repository, _meta_.__author__, _meta_.__all__, __new_version__, _meta_.__all__, __new_version__)] if not os.path.exists(_meta_.build_path): os.makedirs(_meta_.build_path) Download(_meta_.build_path, dwn_link, repo="").start() os.chdir(_meta_.build_path) slpkg_tar_file = "slpkg" + "-" + __new_version__ + ".tar.gz" tar = tarfile.open(slpkg_tar_file) tar.extractall() tar.close() file_name = "{0}-{1}".format(_meta_.__all__, __new_version__) os.chdir(file_name) check_md5(pkg_checksum(slpkg_tar_file, _meta_.__all__), _meta_.build_path + slpkg_tar_file) subprocess.call("chmod +x {0}".format("install.sh"), shell=True) subprocess.call("sh install.sh", shell=True) else: print("\n{0}: There is no new version, already used the last !" "\n".format(_meta_.__all__)) raise SystemExit()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def if_all_installed(self): """Check if all packages is already installed """
count_inst = 0 for inst in (self.dep_install + self.install): if (os.path.isfile(self.meta.pkg_path + inst[:-4]) and "--download-only" not in self.flag): count_inst += 1 if (count_inst == len(self.dep_install + self.install) and "--reinstall" not in self.flag): raise SystemExit()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def clear_masters(self): """Clear master packages if already exist in dependencies or if added to install two or more times """
packages = [] for mas in Utils().remove_dbs(self.packages): if mas not in self.dependencies: packages.append(mas) self.packages = packages
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def install_packages(self): """Install or upgrade packages """
installs, upgraded = [], [] for inst in (self.dep_install + self.install): package = (self.tmp_path + inst).split() pkg_ver = "{0}-{1}".format(split_package(inst)[0], split_package(inst)[1]) self.checksums(inst) if GetFromInstalled(split_package(inst)[0]).name(): print("[ {0}upgrading{1} ] --> {2}".format( self.meta.color["YELLOW"], self.meta.color["ENDC"], inst)) upgraded.append(pkg_ver) if "--reinstall" in self.flag: PackageManager(package).upgrade("--reinstall") else: PackageManager(package).upgrade("--install-new") else: print("[ {0}installing{1} ] --> {2}".format( self.meta.color["GREEN"], self.meta.color["ENDC"], inst)) installs.append(pkg_ver) PackageManager(package).upgrade("--install-new") return [installs, upgraded]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def not_downgrade(self, package): """Don't downgrade packages if repository version is lower than installed"""
name = split_package(package)[0] rep_ver = split_package(package)[1] ins_ver = GetFromInstalled(name).version()[1:] if not ins_ver: ins_ver = "0" if LooseVersion(rep_ver) < LooseVersion(ins_ver): self.msg.template(78) print("| Package {0} don't downgrade, " "setting by user".format(name)) self.msg.template(78) return True
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def checksums(self, install): """Checksums before install """
check_md5(pkg_checksum(install, self.repo), self.tmp_path + install)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def resolving_deps(self): """Return package dependencies """
requires = [] if (self.meta.rsl_deps in ["on", "ON"] and self.flag != "--resolve-off"): self.msg.resolving() for dep in self.packages: status(0.05) dependencies = [] dependencies = Utils().dimensional_list(Dependencies( self.repo, self.blacklist).binary(dep, self.flag)) requires += self._fix_deps_repos(dependencies) self.deps_dict[dep] = Utils().remove_dbs(requires) return Utils().remove_dbs(requires)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _fix_deps_repos(self, dependencies): """Fix store deps include in repository """
requires = [] for dep in dependencies: if dep in self.repo_pkg_names: requires.append(dep) return requires
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def top_view(self): """Print packages status bar """
self.msg.template(78) print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( "| Package", " " * 17, "New Version", " " * 8, "Arch", " " * 4, "Build", " " * 2, "Repos", " " * 10, "Size")) self.msg.template(78)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def store(self, packages): """Store and return packages for install """
dwn, install, comp_sum, uncomp_sum = ([] for i in range(4)) # name = data[0] # location = data[1] # size = data[2] # unsize = data[3] for pkg in packages: for pk, loc, comp, uncomp in zip(self.data[0], self.data[1], self.data[2], self.data[3]): if (pk and pkg == split_package(pk)[0] and pk not in install and split_package(pk)[0] not in self.blacklist): dwn.append("{0}{1}/{2}".format(self.mirror, loc, pk)) install.append(pk) comp_sum.append(comp) uncomp_sum.append(uncomp) if not install: for pkg in packages: for pk, loc, comp, uncomp in zip(self.data[0], self.data[1], self.data[2], self.data[3]): name = split_package(pk)[0] if (pk and pkg in name and name not in self.blacklist): self.matching = True dwn.append("{0}{1}/{2}".format(self.mirror, loc, pk)) install.append(pk) comp_sum.append(comp) uncomp_sum.append(uncomp) dwn.reverse() install.reverse() comp_sum.reverse() uncomp_sum.reverse() if self.repo == "slack": dwn, install, comp_sum, uncomp_sum = self.patches(dwn, install, comp_sum, uncomp_sum) return [dwn, install, comp_sum, uncomp_sum]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pkg_checksum(binary, repo): """Return checksum from CHECKSUMS.md5 file by repository """
md5 = "None" if repo == "slack_patches" and _meta_.slack_rel == "stable": CHECKSUMS_md5 = URL(mirrors("CHECKSUMS.md5", "patches/")).reading() elif repo == "slack_patches" and _meta_.slack_rel == "current": CHECKSUMS_md5 = URL(mirrors("CHECKSUMS.md5", "")).reading() elif repo == "slpkg": CHECKSUMS_md5 = URL(_meta_.CHECKSUMS_link).reading() else: lib = "{0}{1}_repo/CHECKSUMS.md5".format(_meta_.lib_path, repo) f = open(lib, "r") CHECKSUMS_md5 = f.read() f.close() for line in CHECKSUMS_md5.splitlines(): if line.endswith("/{0}".format(binary)): md5 = line.split()[0] return md5
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def library(repo): """Load packages from slpkg library and from local """
pkg_list, packages = [], "" if repo == "sbo": if (os.path.isfile( _meta_.lib_path + "{0}_repo/SLACKBUILDS.TXT".format(repo))): packages = Utils().read_file(_meta_.lib_path + "{0}_repo/" "SLACKBUILDS.TXT".format(repo)) else: if (os.path.isfile( _meta_.lib_path + "{0}_repo/PACKAGES.TXT".format(repo))): packages = Utils().read_file(_meta_.lib_path + "{0}_repo/" "PACKAGES.TXT".format(repo)) for line in packages.splitlines(): if repo == "sbo": if line.startswith("SLACKBUILD NAME: "): pkg_list.append(line[17:].strip()) elif "local" not in repo: if line.startswith("PACKAGE NAME: "): pkg_list.append(line[15:].strip()) if repo == "local": pkg_list = find_package("", _meta_.pkg_path) return pkg_list
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def info(self, name, sbo_file): """Read info file """
return URL(self.sbo_url + name + sbo_file).reading()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def slackbuild(self, name, sbo_file): """Read SlackBuild file """
return URL(self.sbo_url + name + sbo_file).reading()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def run(self): """Build package and fix ordelist per checksum """
self.files_exist() self.info_file() sources = self.sources if len(sources) > 1 and self.sbo_sources != sources: sources = self.sbo_sources # If the list does not have the same order use from .info # order. BuildPackage(self.script, sources, self.path, auto=True).build() raise SystemExit()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def info_file(self): """Grab sources from .info file and store filename """
sources = SBoGrep(self.prgnam).source().split() for source in sources: self.sbo_sources.append(source.split("/")[-1])
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def files_exist(self): """Check if SlackBuild archive.tar.gz and sources exist """
if not os.path.isfile(self.path + self.script): print("\nslpkg: Error: SlackBuild archive.tar.gz not found\n") raise SystemExit() for src in self.sources: if not os.path.isfile(self.path + src): print("\nslpkg: Error: Source file '{0}' not found\n".format( src)) raise SystemExit()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def help_version(self): """Help and version info """
if (len(self.args) == 1 and self.args[0] in ["-h", "--help"] and self.args[1:] == []): options() elif (len(self.args) == 1 and self.args[0] in ["-v", "--version"] and self.args[1:] == []): prog_version() else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def command_update(self): """Update package lists repositories """
if len(self.args) == 1 and self.args[0] == "update": Update().repository(only="") elif (len(self.args) == 2 and self.args[0] == "update" and self.args[1].startswith("--only=")): repos = self.args[1].split("=")[-1].split(",") for rp in repos: if rp not in self.meta.repositories: repos.remove(rp) Update().repository(repos) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def command_repo_add(self): """Add custom repositories """
if len(self.args) == 3 and self.args[0] == "repo-add": Repo().add(self.args[1], self.args[2]) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def command_repo_remove(self): """Remove custom repositories """
if len(self.args) == 2 and self.args[0] == "repo-remove": Repo().remove(self.args[1]) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def command_upgrade(self): """Recreate repositories package lists """
if len(self.args) == 1 and self.args[0] == "upgrade": Initialization(False).upgrade(only="") elif (len(self.args) == 2 and self.args[0] == "upgrade" and self.args[1].startswith("--only=")): repos = self.args[1].split("=")[-1].split(",") for rp in repos: if rp not in self.meta.repositories: repos.remove(rp) Initialization(False).upgrade(repos) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def command_health(self): """Check package health """
if len(self.args) == 1 and self.args[0] == "health": PackageHealth(mode="").test() elif (len(self.args) == 2 and self.args[0] == "health" and self.args[1] == "--silent"): PackageHealth(mode=self.args[1]).test() else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def command_deps_status(self): """Print dependencies status """
image = "" for arg in self.args: if arg.startswith("--graph="): image = arg.split("=")[1] if len(self.args) == 1 and self.args[0] == "deps-status": DependenciesStatus(image).show() elif len(self.args) == 2 and self.args[0] == "deps-status" and image: DependenciesStatus(image).show() elif (len(self.args) == 2 and self.args[0] == "deps-status" and "--tree" in self.args): DependenciesStatus(image).tree() elif (len(self.args) == 3 and self.args[0] == "deps-status" and "--tree" in self.args and image): DependenciesStatus(image).tree() else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def command_new_config(self): """Manage .new configuration files """
if len(self.args) == 1 and self.args[0] == "new-config": NewConfig().run() else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def auto_build(self): """Auto built tool """
options = [ "-a", "--autobuild" ] if len(self.args) >= 3 and self.args[0] in options: AutoBuild(self.args[1], self.args[2:], self.meta.path).run() else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pkg_list(self): """List of packages by repository """
options = [ "-l", "--list" ] flag = ["--index", "--installed", "--name"] name = INDEX = installed = False for arg in self.args[2:]: if flag[0] == arg: INDEX = True if flag[1] in arg: installed = True if flag[2] == arg: name = True if arg not in flag: usage("") raise SystemExit() if (len(self.args) > 1 and len(self.args) <= 5 and self.args[0] in options): if self.args[1] in self.meta.repositories: PackageManager(binary=None).package_list(self.args[1], name, INDEX, installed) else: usage(self.args[1]) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pkg_upgrade(self): """Check and upgrade packages by repository """
options = [ "-c", "--check" ] flags = [ "--upgrade", "--skip=", "--resolve-off", "--checklist", "--rebuild" ] flag, skip = self.__pkg_upgrade_flags(flags) if (len(self.args) == 3 and self.args[0] in options and self.args[2] == flags[0] and self.args[1] in self.meta.repositories): if self.args[1] not in ["slack", "sbo"]: BinaryInstall(pkg_upgrade(self.args[1], skip, flag), self.args[1], flag).start(is_upgrade=True) elif self.args[1] == "slack": if self.meta.only_installed in ["on", "ON"]: BinaryInstall(pkg_upgrade("slack", skip, flag), "slack", flag).start(is_upgrade=True) else: Patches(skip, flag).start() elif self.args[1] == "sbo": SBoInstall(sbo_upgrade(skip, flag), flag).start(is_upgrade=True) else: usage(self.args[1]) elif len(self.args) == 2 and self.args[0] in options: if self.args[1] == "ALL": Updates(repo="").ALL() else: Updates(self.args[1]).run() elif (len(self.args) >= 2 and self.args[0] in options and self.args[1] not in self.meta.repositories): usage(self.args[1]) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def __pkg_upgrade_flags(self, flags): """Manage flags for package upgrade option """
flag, skip = [], "" if flags[0] in self.args: for arg in self.args[3:]: if arg.startswith(flags[1]): skip = Regex(arg.split("=")[1]).get() self.args.remove(arg) if arg in flags: flag.append(arg) if arg in self.args: self.args.remove(arg) return flag, skip
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pkg_install(self): """Install packages by repository """
flag = [] options = [ "-s", "--sync" ] additional_options = [ "--resolve-off", "--download-only", "--directory-prefix=", "--case-ins", "--rebuild", "--reinstall", "--patches" ] for arg in self.args: if arg.startswith(additional_options[2]): flag.append(arg) arg = "" if arg in additional_options: flag.append(arg) # clean from flags for ar in flag: if ar in self.args: self.args.remove(ar) if len(self.args) >= 3 and self.args[0] in options: if (self.args[1] in self.meta.repositories and self.args[1] not in ["sbo"]): BinaryInstall(self.args[2:], self.args[1], flag).start( is_upgrade=False) elif (self.args[1] == "sbo" and self.args[1] in self.meta.repositories): SBoInstall(self.args[2:], flag).start(is_upgrade=False) else: usage(self.args[1]) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pkg_tracking(self): """Tracking package dependencies """
flag = [] options = [ "-t", "--tracking" ] additional_options = [ "--check-deps", "--graph=", "--case-ins" ] for arg in self.args[2:]: if arg.startswith(additional_options[1]): flag.append(arg) self.args.remove(arg) if arg in additional_options: flag.append(arg) # clean additional options from args for f in flag: if f in self.args: self.args.remove(f) # print usage message if wrong additional option for arg in self.args: if arg.startswith("--"): if arg not in additional_options: usage("") raise SystemExit() if (len(self.args) >= 3 and len(self.args) <= 3 and self.args[0] in options and self.args[1] in self.meta.repositories): TrackingDeps(self.args[2], self.args[1], flag).run() elif (len(self.args) >= 2 and self.args[1] not in self.meta.repositories): usage(self.args[1]) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sbo_network(self): """View slackbuilds packages """
flag = [] options = [ "-n", "--network" ] additional_options = [ "--checklist", "--case-ins" ] for add in additional_options: if add in self.args: flag.append(add) self.args.remove(add) if (len(self.args) == 2 and self.args[0] in options and "sbo" in self.meta.repositories): SBoNetwork(self.args[1], flag).view() else: usage("sbo")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pkg_blacklist(self): """Manage blacklist packages """
blacklist = BlackList() options = [ "-b", "--blacklist" ] flag = [ "--add", "--remove" ] command = ["list"] if (len(self.args) == 2 and self.args[0] in options and self.args[1] == command[0]): blacklist.listed() elif (len(self.args) > 2 and self.args[0] in options and flag[0] in self.args): self.args.remove(flag[0]) blacklist.add(self.args[1:]) elif (len(self.args) == 3 and self.args[0] in options and "ALL" in self.args and flag[1] in self.args): self.args.remove(flag[1]) blacklist.remove(blacklist.get_black()) elif (len(self.args) > 2 and self.args[0] in options and flag[1] in self.args): self.args.remove(flag[1]) blacklist.remove(self.args[1:]) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pkg_queue(self): """Manage packages in queue """
queue = QueuePkgs() options = [ "-q", "--queue" ] flag = [ "--add", "--remove" ] command = [ "list", "build", "install", "build-install" ] if (len(self.args) > 2 and self.args[0] in options and flag[0] in self.args): self.args.remove(flag[0]) queue.add(self.args[1:]) elif (len(self.args) == 3 and self.args[0] in options and "ALL" in self.args and flag[1] in self.args): self.args.remove(flag[1]) queue.remove(queue.packages()) elif (len(self.args) > 2 and self.args[0] in options and flag[1] in self.args): self.args.remove(flag[1]) queue.remove(self.args[1:]) elif (len(self.args) == 2 and self.args[0] in options and self.args[1] == command[0]): queue.listed() elif (len(self.args) == 2 and self.args[0] in options and self.args[1] == command[1]): queue.build() elif (len(self.args) == 2 and self.args[0] in options and self.args[1] == command[2]): queue.install() elif (len(self.args) == 2 and self.args[0] in options and self.args[1] == command[3]): queue.build() queue.install() else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def bin_install(self): """Install Slackware binary packages """
packages = self.args[1:] options = [ "-i", "--installpkg" ] flag = "" flags = [ "--warn", "--md5sum", "--root", "--infobox", "--menu", "--terse", "--ask", "--priority", "--tagfile" ] if len(self.args) > 1 and self.args[0] in options: if self.args[1] in flags: flag = self.args[1] packages = self.args[2:] PackageManager(packages).install(flag) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def bin_upgrade(self): """Install-upgrade Slackware binary packages """
packages = self.args[1:] options = [ "-u", "--upgradepkg" ] flag = "" flags = [ "--dry-run", "--install-new", "--reinstall", "--verbose" ] if len(self.args) > 1 and self.args[0] in options: if self.args[1] in flags: flag = self.args[1] packages = self.args[2:] PackageManager(packages).upgrade(flag) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def bin_remove(self): """Remove Slackware packages """
packages = self.args[1:] options = [ "-r", "--removepkg" ] additional_options = [ "--deps", "--check-deps", "--tag", "--checklist" ] flag, extra = "", [] flags = [ "-warn", "-preserve", "-copy", "-keep" ] # merge --check-deps and --deps options if (additional_options[1] in self.args and additional_options[0] not in self.args): self.args.append(additional_options[0]) if len(self.args) > 1 and self.args[0] in options: for additional in additional_options: if additional in self.args: extra.append(additional) self.args.remove(additional) packages = self.args[1:] for fl in flags: if fl in self.args: flag = self.args[1] packages = self.args[2:] PackageManager(packages).remove(flag, extra) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def bin_find(self): """Find installed packages """
flag = [] options = [ "-f", "--find" ] additional_options = ["--case-ins"] for arg in self.args: if arg in additional_options: flag.append(arg) self.args.remove(arg) packages = self.args[1:] if len(self.args) > 1 and self.args[0] in options: PackageManager(packages).find(flag) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pkg_desc(self): """Print slack-desc by repository """
options = [ "-p", "--desc" ] flag = ["--color="] colors = [ "red", "green", "yellow", "cyan", "grey" ] tag = "" for arg in self.args: if arg.startswith(flag[0]): tag = arg[len(flag[0]):] self.args.remove(arg) break if tag and tag not in colors: print("\nslpkg: Error: Available colors {0}\n".format( colors)) raise SystemExit() if (len(self.args) == 3 and self.args[0] in options and self.args[1] in self.meta.repositories and tag in colors): PkgDesc(self.args[2], self.args[1], tag).view() elif (len(self.args) == 3 and self.args[0] in options and self.args[1] in self.meta.repositories): PkgDesc(self.args[2], self.args[1], paint="").view() elif (len(self.args) > 1 and self.args[0] in options and self.args[1] not in self.meta.repositories): usage(self.args[1]) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pkg_find(self): """Find packages from all enabled repositories """
flag = [] options = [ "-F", "--FIND" ] additional_options = ["--case-ins"] for arg in self.args: if arg in additional_options: flag.append(arg) self.args.remove(arg) packages = self.args[1:] if len(self.args) > 1 and self.args[0] in options: FindFromRepos().find(packages, flag) else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pkg_contents(self): """Print packages contents """
packages = self.args[1:] options = [ "-d", "--display" ] if len(self.args) > 1 and self.args[0] in options: PackageManager(packages).display() else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def congiguration(self): """Manage slpkg configuration file """
options = [ "-g", "--config" ] command = [ "print", "edit", "reset" ] conf = Config() if (len(self.args) == 2 and self.args[0] in options and self.args[1] == command[1]): conf.edit() elif (len(self.args) == 2 and self.args[0] in options and self.args[1] == (command[0])): conf.view() elif (len(self.args) == 2 and self.args[0] in options and self.args[1] == (command[2])): conf.reset() else: usage("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def auto_detect(self, args): """Check for already Slackware binary packages exist """
suffixes = [ ".tgz", ".txz", ".tbz", ".tlz" ] if (not args[0].startswith("-") and args[0] not in self.commands and args[0].endswith(tuple(suffixes))): packages, not_found = [], [] for pkg in args: if pkg.endswith(tuple(suffixes)): if os.path.isfile(pkg): packages.append(pkg) else: not_found.append(pkg) if packages: Auto(packages).select() if not_found: for ntf in not_found: self.msg.pkg_not_found("", ntf, "Not installed", "") raise SystemExit()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def search_pkg(name, repo): """Search if package exists in PACKAGES.TXT file and return the name. """
PACKAGES_TXT = Utils().read_file(_meta_.lib_path + "{0}_repo/" "PACKAGES.TXT".format(repo)) names = Utils().package_name(PACKAGES_TXT) blacklist = BlackList().packages(pkgs=names, repo=repo) for line in PACKAGES_TXT.splitlines(): status(0) if line.startswith("PACKAGE NAME: ") and len(line) > 16: pkg_name = split_package(line[15:])[0].strip() if name == pkg_name and name not in blacklist: return pkg_name
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def data(self): """Check all installed packages and create dictionary database """
for pkg in self.installed: if os.path.isfile(self.meta.pkg_path + pkg): name = split_package(pkg)[0] for log in self.logs: deps = Utils().read_file(self.dep_path + log) for dep in deps.splitlines(): if name == dep: if name not in self.dmap.keys(): self.dmap[name] = [log] if not self.count_pkg: self.count_pkg = 1 else: self.dmap[name] += [log] self.count_packages()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def count_packages(self): """Count dependencies and packages """
packages = [] for pkg in self.dmap.values(): packages += pkg self.count_dep += 1 self.count_pkg = len(set(packages))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show(self): """Show dependencies status """
self.data() print("") self.msg.template(78) print("| {0}{1}{2}".format("Dependencies", " " * 20, "Packages")) self.msg.template(78) for key, value in self.dmap.iteritems(): print(" {0}{1}{2}{3}{4}".format( self.green, key, self.endc, " " * (32-len(key)), ", ".join(value))) self.summary() if self.image: Graph(self.image).dependencies(self.dmap)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def tree(self): """Like tree view mode """
self.msg.template(78) print("| Dependencies\n" "| -- Packages") self.msg.template(78) self.data() for pkg, dep in self.dmap.iteritems(): print("+ {0}{1}{2}".format(self.green, pkg, self.endc)) print("|") for d in dep: print("+-- {0}".format(d)) print("|") sys.stdout.write("\x1b[1A{0}\n".format(" ")) sys.stdout.flush() self.summary() if self.image: Graph(self.image).dependencies(self.dmap)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def summary(self): """Summary by packages and dependencies """
print("\nStatus summary") print("=" * 79) print("{0}found {1} dependencies in {2} packages.{3}\n".format( self.grey, self.count_dep, self.count_pkg, self.endc))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def find(self, pkg, flag): """Start to find packages and print """
print("\nPackages with name matching [ {0}{1}{2} ]\n".format( self.cyan, ", ".join(pkg), self.endc)) Msg().template(78) print("| {0} {1}{2}{3}".format("Repository", "Package", " " * 54, "Size")) Msg().template(78) for repo in _meta_.repositories: PACKAGES_TXT = PackageManager(pkg).list_lib(repo) packages, sizes = PackageManager(pkg).list_greps(repo, PACKAGES_TXT) for find, size in zip(packages, sizes): for p in pkg: if "--case-ins" in flag: self.p_cache = p.lower() self.find_cache = find.lower() else: self.p_cache = p self.find_cache = find if self.p_cache in self.find_cache: if self.cache != repo: self.count_repo += 1 self.cache = repo self.count_pkg += 1 ver = self.sbo_version(repo, find) print(" {0}{1}{2}{3}{4} {5}{6:>11}".format( self.cyan, repo, self.endc, " " * (12 - len(repo)), find + ver, " " * (53 - len(find + ver)), size)) print("\nFound summary") print("=" * 79) print("{0}Total found {1} packages in {2} repositories." "{3}\n".format(self.grey, self.count_pkg, self.count_repo, self.endc))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sbo_version(self, repo, find): """ Add version to SBo packages """
ver = "" if repo == "sbo": ver = "-" + SBoGrep(find).version() return ver
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add(self, repo, url): """Write custom repository name and url in a file """
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()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def remove(self, repo): """Remove custom repository """
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()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def default_repository(self): """Return dictionary with default repo name and url """
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
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def slack(self): """Official slackware repository """
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
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def view(self): """View SlackBuild package, read or install them from slackbuilds.org """
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)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def choice_README(self): """View README file """
README = ReadSBo(self.sbo_url).readme("README") fill = self.fill_pager(README) self.pager(README + fill)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def choice_SlackBuild(self): """View .SlackBuild file """
SlackBuild = ReadSBo(self.sbo_url).slackbuild(self.name, ".SlackBuild") fill = self.fill_pager(SlackBuild) self.pager(SlackBuild + fill)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def choice_info(self): """View .info file """
info = ReadSBo(self.sbo_url).info(self.name, ".info") fill = self.fill_pager(info) self.pager(info + fill)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def choice_doinst(self): """View doinst.sh file """
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)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def choice_download(self): """Download script.tar.gz and sources """
Download(path="", url=self.dwn_srcs, repo="sbo").start() raise SystemExit()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def choice_install(self): """Download, build and install package """
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()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def with_checklist(self): """Using dialog and checklist option """
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")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def fill_pager(self, page): """Fix pager spaces """
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 ""
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def error_uns(self): """Check if package supported by arch before proceed to install """
self.FAULT = "" UNST = ["UNSUPPORTED", "UNTESTED"] if "".join(self.source_dwn) in UNST: self.FAULT = "".join(self.source_dwn)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def build(self): """Only build and create Slackware package """
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)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def listed(self): """Print packages from queue """
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("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add(self, pkgs): """Add packages in queue if not exist """
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("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def remove(self, pkgs): """Remove packages from queue """
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("")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def build(self): """Build packages from queue """
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)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def install(self): """Install packages from queue """
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)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pkg_upgrade(repo, skip, flag): """Checking packages for upgrade """
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
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def split_package(package): """ Split package in name, version arch and build tag. """
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]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def remove_repositories(repositories, default_repositories): """ Remove no default repositories """
repos = [] for repo in repositories: if repo in default_repositories: repos.append(repo) return repos
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_repositories(repositories, conf_path): """ Upadate with user custom repositories """
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
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def names(self): """Grab all packages name """
pkg_names = [] for line in self.SLACKBUILDS_TXT.splitlines(): if line.startswith(self.line_name): pkg_names.append(line[17:].strip()) return pkg_names
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def source(self): """Grab sources downloads links """
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)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _select_source_arch(self, source, source64): """Return sources by arch """
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
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def requires(self): """Grab package requirements """
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()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def version(self): """Grab package version """
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()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def checksum(self): """Grab checksum string """
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)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _select_md5sum_arch(self, md5sum, md5sum64): """Return checksums by arch """
if md5sum and md5sum64: if self.meta.arch == "x86_64": return md5sum64 else: return md5sum if md5sum: return md5sum else: return md5sum64
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def description(self): """Grab package verion """
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()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def check_exists_repositories(repo): """Checking if repositories exists by PACKAGES.TXT file """
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 ""
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def check_for_local_repos(repo): """Check if repository is local """
repos_dict = Repo().default_repository() if repo in repos_dict: repo_url = repos_dict[repo] if repo_url.startswith("file:///"): return True
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def slack(self): """Creating slack local libraries """
log = self.log_path + "slack/" lib = self.lib_path + "slack_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) dirs = ["core/", "extra/", "pasture/", "patches/"] for d in dirs: if not os.path.exists(lib + d): os.mkdir(lib + d) PACKAGES_TXT = mirrors(lib_file, "") FILELIST_TXT = "" CHECKSUMS_MD5 = mirrors(md5_file, "") self.EXTRA = mirrors(lib_file, dirs[1]) self.EXT_CHECKSUMS = mirrors(md5_file, dirs[1]) self.PASTURE = mirrors(lib_file, dirs[2]) self.PAS_CHECKSUMS = mirrors(md5_file, dirs[2]) self.PATCHES = mirrors(lib_file, dirs[3]) self.PAT_CHECKSUMS = mirrors(md5_file, dirs[3]) ChangeLog_txt = mirrors(log_file, "") if self.check: return self.checks_logs(log, ChangeLog_txt) self.down(lib + dirs[0], PACKAGES_TXT, repo_name) self.down(lib + dirs[0], CHECKSUMS_MD5, repo_name) self.down(lib + dirs[1], self.EXTRA, repo_name) self.down(lib + dirs[1], self.EXT_CHECKSUMS, repo_name) if slack_ver() != "14.0": # no pasture/ folder for 14.0 version self.down(lib + dirs[2], self.PASTURE, repo_name) self.down(lib + dirs[2], self.PAS_CHECKSUMS, repo_name) self.down(lib + dirs[3], self.PATCHES, repo_name) self.down(lib + dirs[3], self.PAT_CHECKSUMS, repo_name) self.down(log, ChangeLog_txt, repo_name) self.remote(log, ChangeLog_txt, lib, PACKAGES_TXT, CHECKSUMS_MD5, FILELIST_TXT, repo_name) self.merge(lib, "PACKAGES.TXT", ["core/PACKAGES.TXT", "extra/PACKAGES.TXT", "pasture/PACKAGES.TXT", "patches/PACKAGES.TXT"]) self.merge(lib, "CHECKSUMS.md5", ["core/CHECKSUMS.md5", "extra/CHECKSUMS.md5", "pasture/CHECKSUMS.md5", "patches/CHECKSUMS_md5"])
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def conrad(self): """Creating slackers local library """
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)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def remote(self, *args): """Remove and recreate files """
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)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def file_remove(self, path, filename): """Check if filename exists and remove """
if os.path.isfile(path + filename): os.remove(path + filename)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def checks_logs(self, log_path, url): """Checks ChangeLog.txt for changes """
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
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def upgrade(self, only): """Remove all package lists with changelog and checksums files and create lists again"""
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)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def repository(self, only): """Update repositories lists """
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()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def checklist(self): """Run dialog checklist """
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()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def buildlist(self, enabled): """Run dialog buildlist """
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()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def unicode_to_string(self): """Convert unicode in string """
for tag in self.tags: self.ununicode.append(str(tag))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sbo_upgrade(skip, flag): """Return packages for upgrade """
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
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sbo_list(): """Return all SBo packages """
sbo_packages = [] for pkg in os.listdir(_meta_.pkg_path): if pkg.endswith("_SBo"): sbo_packages.append(pkg) return sbo_packages
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def delete_package(path, packages): """Remove downloaded packages """
if _meta_.del_all in ["on", "ON"]: for pkg in packages: os.remove(path + pkg)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def delete(build_folder): """Delete build directory and all its contents. """
if _meta_.del_build in ["on", "ON"] and os.path.exists(build_folder): shutil.rmtree(build_folder)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def start(self): """ Install new patches from official Slackware mirrors """
self.store() self.msg.done() if self.upgrade_all: if "--checklist" in self.flag: self.dialog_checklist() print("\nThese packages need upgrading:\n") self.msg.template(78) print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( "| Package", " " * 17, "New Version", " " * 8, "Arch", " " * 4, "Build", " " * 2, "Repos", " " * 10, "Size")) self.msg.template(78) print("Upgrading:") self.views() unit, size = units(self.comp_sum, self.uncomp_sum) print("\nInstalling summary") print("=" * 79) print("{0}Total {1} {2} will be upgraded and {3} will be " "installed.".format(self.meta.color["GREY"], self.count_upg, self.msg.pkg(self.upgrade_all), self.count_added)) 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], self.meta.color["ENDC"])) print("") if self.msg.answer() in ["y", "Y"]: Download(self.patch_path, self.dwn_links, repo="slack").start() self.upgrade_all = self.utils.check_downloaded( self.patch_path, self.upgrade_all) self.upgrade() self.kernel() if self.meta.slackpkg_log in ["on", "ON"]: self.slackpkg_update() self.msg.reference(self.installed, self.upgraded) delete_package(self.patch_path, self.upgrade_all) self.update_lists() else: slack_arch = "" if self.meta.arch == "x86_64": slack_arch = "64" print("\nSlackware{0} '{1}' v{2} distribution is up to " "date\n".format(slack_arch, self.version, slack_ver()))