Exemplo n.º 1
0
 def find(self):
     """Find installed Slackware packages
     """
     matching = size = 0
     print("\nPackages with matching name [ {0}{1}{2} ]\n".format(
         self.meta.color["CYAN"], ", ".join(self.binary),
         self.meta.color["ENDC"]))
     for pkg in self.binary:
         for match in find_package("", self.meta.pkg_path):
             if pkg in match:
                 matching += 1
                 print("[ {0}installed{1} ] - {2}".format(
                     self.meta.color["GREEN"], self.meta.color["ENDC"],
                     match))
                 data = Utils().read_file(self.meta.pkg_path + match)
                 for line in data.splitlines():
                     if line.startswith("UNCOMPRESSED PACKAGE SIZE:"):
                         if "M" in line[26:]:
                             size += float(line[26:-1]) * 1024
                         else:
                             size += float(line[26:-1])
                         break
     if matching == 0:
         message = "Can't find"
         Msg().pkg_not_found("", ", ".join(self.binary), message, "\n")
     else:
         print("\n{0}Total found {1} matching packages.{2}".format(
             self.meta.color["GREY"], matching, self.meta.color["ENDC"]))
         unit = "Kb"
         if size > 1024:
             unit = "Mb"
             size = (size / 1024)
         print("{0}Size of installed packages {1} {2}.{3}\n".format(
             self.meta.color["GREY"], round(size, 2), unit,
             self.meta.color["ENDC"]))
Exemplo n.º 2
0
 def view(self):
     """View slpkg config file
     """
     print("")   # new line at start
     conf_args = [
         "RELEASE",
         "BUILD_PATH",
         "PACKAGES",
         "PATCHES",
         "CHECKMD5",
         "DEL_ALL",
         "DEL_BUILD",
         "SBO_BUILD_LOG",
         "MAKEFLAGS",
         "DEFAULT_ANSWER",
         "REMOVE_DEPS_ANSWER",
         "SKIP_UNST",
         "RSL_DEPS",
         "DEL_DEPS",
         "USE_COLORS",
         "DOWNDER",
         "DOWNDER_OPTIONS",
         "SLACKPKG_LOG",
         "ONLY_INSTALLED",
         "PRG_BAR",
         "EDITOR"
     ]
     read_conf = Utils().read_file(self.config_file)
     for line in read_conf.splitlines():
         if not line.startswith("#") and line.split("=")[0] in conf_args:
             print("{0}".format(line))
         else:
             print("{0}{1}{2}".format(self.meta.color["CYAN"], line,
                                      self.meta.color["ENDC"]))
     print("")   # new line at end
Exemplo n.º 3
0
 def get_deps(self):
     """Grap package requirements from repositories
     """
     if self.repo == "rlw":
         # Robby"s repository dependencies as shown in the central page
         # http://rlworkman.net/pkgs/
         dependencies = {
             "abiword": "wv",
             "claws-mail": "libetpan",
             "inkscape": "gtkmm atkmm pangomm cairomm mm-common libsigc++ "
                         "libwpg lxml gsl numpy BeautifulSoup",
             "texlive": "libsigsegv texi2html",
             "xfburn": "libburn libisofs"
         }
         if self.name in dependencies.keys():
             return dependencies[self.name].split()
         else:
             return ""
     else:
         PACKAGES_TXT = Utils().read_file("{0}{1}_repo/PACKAGES.TXT".format(
             _meta_.lib_path, self.repo))
         for line in PACKAGES_TXT.splitlines():
             if line.startswith("PACKAGE NAME:"):
                 pkg_name = split_package(line[14:].strip())[0]
             if line.startswith("PACKAGE REQUIRED:"):
                 if pkg_name == self.name:
                     if line[18:].strip():
                         return self._req_fix(line)
Exemplo n.º 4
0
 def _sizes(self, package):
     """Package size summary
     """
     data = Utils().read_file(self.meta.pkg_path + package)
     for line in data.splitlines():
         if line.startswith("UNCOMPRESSED PACKAGE SIZE:"):
             if "M" in line[26:]:
                 self.size += float(line[26:-1]) * 1024
             else:
                 self.size += float(line[26:-1])
                 break
Exemplo n.º 5
0
 def check_used(self, pkg):
     """Check if dependencies used
     """
     used = []
     dep_path = self.meta.log_path + "dep/"
     logs = find_package("", dep_path)
     for log in logs:
         deps = Utils().read_file(dep_path + log)
         for dep in deps.splitlines():
             if pkg == dep:
                 used.append(log)
     return used
Exemplo n.º 6
0
 def check_used(self, pkg):
     """Check if dependencies used
     """
     used = []
     dep_path = self.meta.log_path + "dep/"
     logs = find_package("", dep_path)
     for log in logs:
         deps = Utils().read_file(dep_path + log)
         for dep in deps.splitlines():
             if pkg == dep:
                 used.append(log)
     return used
Exemplo n.º 7
0
 def _view_deps(self, path, package):
     """View dependencies for before remove
     """
     dependencies = Utils().read_file(path + package)
     print("")   # new line at start
     Msg().template(78)
     print("| Found dependencies for package {0}:".format(package))
     Msg().template(78)
     for dep in dependencies.splitlines():
         print("| {0}{1}{2}".format(self.meta.color["RED"], dep,
                                    self.meta.color["ENDC"]))
     Msg().template(78)
     return dependencies
Exemplo n.º 8
0
 def _sizes(self, package):
     """Package size summary
     """
     data = Utils().read_file(self.meta.pkg_path + package)
     for line in data.splitlines():
         if line.startswith("UNCOMPRESSED PACKAGE SIZE:"):
             digit = float((''.join(
                 re.findall("[-+]?\d+[\.]?\d*[eE]?[-+]?\d*", line[26:]))))
             if "M" in line[26:]:
                 self.size += digit * 1024
             else:
                 self.size += digit
                 break
Exemplo n.º 9
0
 def _sizes(self, package):
     """Package size summary
     """
     data = Utils().read_file(self.meta.pkg_path + package)
     for line in data.splitlines():
         if line.startswith("UNCOMPRESSED PACKAGE SIZE:"):
             digit = float((''.join(re.findall(
                 "[-+]?\d+[\.]?\d*[eE]?[-+]?\d*", line[26:]))))
             self.file_size = line[26:].strip()
             if "M" in line[26:]:
                 self.size += digit * 1024
             else:
                 self.size += digit
                 break
Exemplo n.º 10
0
def sbo_search_pkg(name):
    """Search for package path from SLACKBUILDS.TXT file and
    return url
    """
    repo = Repo().default_repository()["sbo"]
    sbo_url = "{0}{1}/".format(repo, slack_ver())
    SLACKBUILDS_TXT = Utils().read_file(
        _meta_.lib_path + "sbo_repo/SLACKBUILDS.TXT")
    for line in SLACKBUILDS_TXT.splitlines():
        if line.startswith("SLACKBUILD LOCATION"):
            sbo_name = (line[23:].split("/")[-1].replace("\n", "")).strip()
            if name == sbo_name:
                return (sbo_url + line[23:].strip() + "/")
    return ""
Exemplo n.º 11
0
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
Exemplo n.º 12
0
def sbo_search_pkg(name):
    """Search for package path from SLACKBUILDS.TXT file and
    return url
    """
    repo = Repo().default_repository()["sbo"]
    sbo_url = "{0}{1}/".format(repo, slack_ver())
    SLACKBUILDS_TXT = Utils().read_file(_meta_.lib_path +
                                        "sbo_repo/SLACKBUILDS.TXT")
    for line in SLACKBUILDS_TXT.splitlines():
        if line.startswith("SLACKBUILD LOCATION"):
            sbo_name = (line[23:].split("/")[-1].replace("\n", "")).strip()
            if name == sbo_name:
                return (sbo_url + line[23:].strip() + "/")
    return ""
Exemplo n.º 13
0
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
Exemplo n.º 14
0
 def get_deps(self):
     """Grap package requirements from repositories
     """
     if self.repo == "rlw":
         dependencies = {}
         rlw_deps = Utils().read_file(_meta_.conf_path + "rlworkman.deps")
         for line in rlw_deps.splitlines():
             if line and not line.startswith("#"):
                 pkgs = line.split(":")
                 dependencies[pkgs[0]] = pkgs[1]
         if self.name in dependencies.keys():
             return dependencies[self.name].split()
         else:
             return ""
     else:
         PACKAGES_TXT = Utils().read_file("{0}{1}_repo/PACKAGES.TXT".format(
             _meta_.lib_path, self.repo))
         for line in PACKAGES_TXT.splitlines():
             if line.startswith("PACKAGE NAME:"):
                 pkg_name = split_package(line[14:].strip())[0]
             if line.startswith("PACKAGE REQUIRED:"):
                 if pkg_name == self.name:
                     if line[18:].strip():
                         return self._req_fix(line)
Exemplo n.º 15
0
def pkg_security(pkgs):
    """Check packages before install or upgrade for security
    reasons. Configuration file in the /etc/slpkg/pkg_security"""
    security_packages = Utils().read_file("/etc/slpkg/pkg_security")
    packages = []
    for read in security_packages.splitlines():
        read = read.lstrip()
        if not read.startswith("#"):
            packages.append(read.replace("\n", ""))
    for p in pkgs:
        for pkg in packages:
            if p == pkg:
                Msg().security_pkg(p)
                if not Msg().answer() in ["y", "Y"]:
                    raise SystemExit()
Exemplo n.º 16
0
def pkg_security(pkgs):
    """Check packages before install or upgrade for security
    reasons. Configuration file in the /etc/slpkg/pkg_security"""
    security_packages = Utils().read_file("/etc/slpkg/pkg_security")
    packages = []
    for read in security_packages.splitlines():
        read = read.lstrip()
        if not read.startswith("#"):
            packages.append(read.replace("\n", ""))
    for p in pkgs:
        for pkg in packages:
            if p == pkg:
                Msg().security_pkg(p)
                if not Msg().answer() in ["y", "Y"]:
                    raise SystemExit()
Exemplo n.º 17
0
 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
Exemplo n.º 18
0
 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
Exemplo n.º 19
0
 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]
                             self.count_dep += 1
                         else:
                             self.dmap[name] += [log]
                             self.count_pkg += 1
Exemplo n.º 20
0
 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()
Exemplo n.º 21
0
def sbo_search_pkg(name):
    """
    Search for package path from SLACKBUILDS.TXT file
    """
    try:
        repo = Repo().sbo()
        sbo_url = "{0}{1}/".format(repo, slack_ver())
        SLACKBUILDS_TXT = Utils().read_file(
            _meta_.lib_path + "sbo_repo/SLACKBUILDS.TXT")
        for line in SLACKBUILDS_TXT.splitlines():
            if line.startswith("SLACKBUILD LOCATION"):
                sbo_name = (line[23:].split("/")[-1].replace("\n", "")).strip()
                if name == sbo_name:
                    return (sbo_url + line[23:].strip() + "/")
        return ""
    except KeyboardInterrupt:
        print("")   # new line at exit
        sys.exit(0)
Exemplo n.º 22
0
 def view(self):
     """View slpkg config file
     """
     print("")  # new line at start
     conf_args = [
         "RELEASE", "SLACKWARE_VERSION", "COMP_ARCH", "BUILD_PATH",
         "PACKAGES", "PATCHES", "CHECKMD5", "DEL_ALL", "DEL_BUILD",
         "SBO_BUILD_LOG", "MAKEFLAGS", "DEFAULT_ANSWER",
         "REMOVE_DEPS_ANSWER", "SKIP_UNST", "RSL_DEPS", "DEL_DEPS",
         "USE_COLORS", "DOWNDER", "DOWNDER_OPTIONS", "SLACKPKG_LOG",
         "ONLY_INSTALLED", "PRG_BAR", "EDITOR", "NOT_DOWNGRADE"
     ]
     read_conf = Utils().read_file(self.config_file)
     for line in read_conf.splitlines():
         if not line.startswith("#") and line.split("=")[0] in conf_args:
             print("{0}".format(line))
         else:
             print("{0}{1}{2}".format(self.meta.color["CYAN"], line,
                                      self.meta.color["ENDC"]))
     print("")  # new line at end
Exemplo n.º 23
0
 def view(self):
     """Print package description by repository
     """
     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")
     if description and self.repo == "sbo":
         print("")
Exemplo n.º 24
0
 def view(self):
     """Print package description by repository
     """
     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("")
Exemplo n.º 25
0
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
Exemplo n.º 26
0
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
Exemplo n.º 27
0
class SBoGrep(object):
    """Grab data from SLACKBUILDS.TXT file
    """
    def __init__(self, name):
        self.name = name
        self.meta = _meta_
        arch64 = "x86_64"
        self.line_name = "SLACKBUILD NAME: "
        self.line_files = "SLACKBUILD FILES: "
        self.line_down = "SLACKBUILD DOWNLOAD: "
        self.line_down_64 = "SLACKBUILD DOWNLOAD_{0}: ".format(arch64)
        self.line_req = "SLACKBUILD REQUIRES: "
        self.line_ver = "SLACKBUILD VERSION: "
        self.line_md5 = "SLACKBUILD MD5SUM: "
        self.line_md5_64 = "SLACKBUILD MD5SUM_{0}: ".format(arch64)
        self.line_des = "SLACKBUILD SHORT DESCRIPTION: "
        self.sbo_txt = self.meta.lib_path + "sbo_repo/SLACKBUILDS.TXT"
        self.answer = ["y", "Y"]
        self.unst = ["UNSUPPORTED", "UNTESTED"]
        self.SLACKBUILDS_TXT = Utils().read_file(self.sbo_txt)

    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

    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)

    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

    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()

    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()

    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)

    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

    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()

    def files(self):
        """Grab files
        """
        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()
Exemplo n.º 28
0
class BlackList(object):
    """Blacklist class to add, remove or listed packages
    in blacklist file."""
    def __init__(self):
        self.meta = _meta_
        self.quit = False
        self.blackfile = "/etc/slpkg/blacklist"
        self.black_conf = ""
        if os.path.isfile(self.blackfile):
            self.black_conf = Utils().read_file(self.blackfile)

    def get_black(self):
        """Return blacklist packages from /etc/slpkg/blacklist
        configuration file."""
        blacklist = []
        for read in self.black_conf.splitlines():
            read = read.lstrip()
            if not read.startswith("#"):
                blacklist.append(read.replace("\n", ""))
        return blacklist

    def listed(self):
        """Print blacklist packages
        """
        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("")   # new line at exit

    def add(self, pkgs):
        """Add blacklist packages if not exist
        """
        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("")   # new line at exit

    def remove(self, pkgs):
        """Remove packages from blacklist
        """
        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("")   # new line at exit

    def packages(self, pkgs, repo):
        """Return packages in blacklist or by repository
        """
        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

    def __add(self, repo, pkg):
        """Split packages by repository
        """
        if repo == "sbo":
            return pkg
        else:
            return split_package(pkg)[0]

    def __priority(self, pr, repo, pkg):
        """Add packages in blacklist by priority
        """
        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))

    def __blackpkg(self, bl, repo, pkg):
        """Add packages in blacklist
        """
        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)
Exemplo n.º 29
0
class Repo(object):
    """Central repository urls
    """
    def __init__(self):
        self.meta = _meta_
        self.DEFAULT_REPOS_NAMES = self.meta.default_repositories
        self.custom_repo_file = "/etc/slpkg/custom-repositories"
        self.default_repo_file = "/etc/slpkg/default-repositories"
        self.custom_repositories_list = Utils().read_file(self.custom_repo_file)
        self.default_repositories_list = Utils().read_file(
            self.default_repo_file)
        self.default_repository()

    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()

    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()

    def custom_repository(self):
        """Return dictionary with repo name and url (used external)
        """
        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

    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 name.\n              Please check file: "
                          "/etc/slpkg/default-repositories\n".format(
                              line.split()[0]))
                    raise SystemExit()
        return default_dict_repo

    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
Exemplo n.º 30
0
class QueuePkgs(object):
    """Manage SBo packages, add or remove for building or
    installation
    """
    def __init__(self):
        queue_file = [
            "# In this file you can create a list of\n",
            "# packages you want to build or install.\n",
            "#\n"
        ]
        self.meta = _meta_
        self.quit = False
        self.queue = self.meta.lib_path + "queue/"
        self.queue_list = self.queue + "queue_list"
        if not os.path.exists(self.meta.lib_path):
            os.mkdir(self.meta.lib_path)
        if not os.path.exists(self.queue):
            os.mkdir(self.queue)
        if not os.path.isfile(self.queue_list):
            with open(self.queue_list, "w") as queue:
                for line in queue_file:
                    queue.write(line)
                queue.close()
        self.queued = Utils().read_file(self.queue_list)

    def packages(self):
        """Return queue list from /var/lib/queue/queue_list
        file.
        """
        queue_list = []
        for read in self.queued.splitlines():
            read = read.lstrip()
            if not read.startswith("#"):
                queue_list.append(read.replace("\n", ""))
        return queue_list

    def listed(self):
        """Print packages from queue
        """
        print("\nPackages in 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("")   # new line at exit

    def add(self, pkgs):
        """Add packages in queue if not exist
        """
        queue_list = self.packages()
        pkgs = list(OrderedDict.fromkeys(pkgs))
        print("\nAdd packages in 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("")   # new line at exit

    def remove(self, pkgs):
        """Remove packages from queue
        """
        print("\nRemove packages from 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("")   # new line at exit

    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)
                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.meta.build_path, src.split(),
                             repo="sbo").start()
                    sources.append(src.split("/")[-1])
                BuildPackage(script, sources, self.meta.build_path).build()
        else:
            print("\nPackages not found in the queue for building\n")

    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.sp, 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")
Exemplo n.º 31
0
class RepoEnable(object):
    """Read repositories.conf file and update with new enabled or
    disabled repositories
    """
    def __init__(self):
        self.meta = _meta_
        self.msg = Msg()
        self.tag = "[REPOSITORIES]"
        self.tag_line = False
        self.repositories_conf = "repositories.conf"
        self.conf = Utils().read_file(
            self.meta.conf_path + self.repositories_conf)
        self.enabled = []
        self.disabled = []
        self.selected = []

    def choose(self):
        """Choose repositories
        """
        keys = """
Choose repositories at the right side for enable or to the
left side for disable.

Keys: SPACE   select or deselect the highlighted repositories,
             move it between the left and right lists
          ^       move the focus to the left list
          $       move the focus to the right list
        TAB     move focus
      ENTER   press the focused button

      Disabled  <-------- REPOSITORIES ------->  Enabled"""
        self.read_enabled()
        self.read_disabled()
        text, title, backtitle, status = keys, " Repositories ", "", False
        self.selected = DialogUtil(self.disabled, text, title, backtitle,
                                   status).buildlist(self.enabled)
        if self.selected is not None:
            self.update_repos()
        else:
            self.selected = self.enabled
        self.clear_screen()
        self.reference()

    def read_enabled(self):
        """Read enable repositories
        """
        for line in self.conf.splitlines():
            line = line.lstrip()
            if self.tag in line:
                self.tag_line = True
            if (line and self.tag_line and not line.startswith("#") and
                    self.tag not in line):
                self.enabled.append(line)
        self.tag_line = False

    def read_disabled(self):
        """Read disable repositories
        """
        for line in self.conf.splitlines():
            line = line.lstrip()
            if self.tag in line:
                self.tag_line = True
            if self.tag_line and line.startswith("#"):
                line = "".join(line.split("#")).strip()
                self.disabled.append(line)
        self.tag_line = False

    def update_repos(self):
        """Update repositories.conf file with enabled or disabled
        repositories
        """
        with open("{0}{1}".format(self.meta.conf_path,
                                  self.repositories_conf), "w") as new_conf:
            for line in self.conf.splitlines():
                line = line.lstrip()
                if self.tag in line:
                    self.tag_line = True
                if self.tag_line and line.startswith("#"):
                    repo = "".join(line.split("#")).strip()
                    if repo in self.selected:
                        new_conf.write(line.replace(line, repo + "\n"))
                        continue
                if (self.tag_line and not line.startswith("#") and
                        line != self.tag):
                    repo = line.strip()
                    if repo not in self.selected:
                        new_conf.write(line.replace(line, "# " + line + "\n"))
                        continue
                new_conf.write(line + "\n")

    def clear_screen(self):
        """Clear screen
        """
        os.system("clear")

    def reference(self):
        """Reference enable repositories
        """
        total_enabled = ", ".join(self.selected)
        if len(total_enabled) < 1:
            total_enabled = ("{0}Are you crazy? This is a package "
                             "manager for packages :p{1}".format(
                                 self.meta.color["RED"],
                                 self.meta.color["ENDC"]))
        self.msg.template(78)
        print("| Enabled repositories:")
        self.msg.template(78)
        print("| {0}".format(total_enabled))
        self.msg.template(78)
        print("{0}Total {1}/{2} repositories enabled.{3}\n".format(
            self.meta.color["GREY"], len(self.selected),
            len(self.enabled + self.disabled), self.meta.color["ENDC"]))
Exemplo n.º 32
0
class RepoEnable(object):
    """Read repositories.conf file and update with new enabled or
    disabled repositories
    """
    def __init__(self):
        self.meta = _meta_
        self.msg = Msg()
        self.tag = "[REPOSITORIES]"
        self.tag_line = False
        self.repositories_conf = "repositories.conf"
        self.conf = Utils().read_file(
            self.meta.conf_path + self.repositories_conf)
        self.enabled = []
        self.disabled = []
        self.selected = []

    def choose(self):
        """Choose repositories
        """
        keys = """
Choose repositories at the right side for enable or to the
left side for disable.

Keys: SPACE   select or deselect the highlighted repositories,
             move it between the left and right lists
          ^       move the focus to the left list
          $       move the focus to the right list
        TAB     move focus
      ENTER   press the focused button

      Disabled  <-------- REPOSITORIES ------->  Enabled"""
        self.read_enabled()
        self.read_disabled()
        text, title, backtitle, status = keys, "Repositories", "", False
        self.selected = DialogUtil(self.disabled, text, title, backtitle,
                                   status).buildlist(self.enabled)
        if self.selected is not None:
            self.update_repos()
        else:
            self.selected = self.enabled
        self.clear_screen()
        self.reference()

    def read_enabled(self):
        """Read enable repositories
        """
        for line in self.conf.splitlines():
            line = line.lstrip()
            if self.tag in line:
                self.tag_line = True
            if (line and self.tag_line and not line.startswith("#") and
                    self.tag not in line):
                self.enabled.append(line)
        self.tag_line = False

    def read_disabled(self):
        """Read disable repositories
        """
        for line in self.conf.splitlines():
            line = line.lstrip()
            if self.tag in line:
                self.tag_line = True
            if self.tag_line and line.startswith("#"):
                line = "".join(line.split("#")).strip()
                self.disabled.append(line)
        self.tag_line = False

    def update_repos(self):
        """Update repositories.conf file with enabled or disabled
        repositories
        """
        with open("{0}{1}".format(self.meta.conf_path,
                                  self.repositories_conf), "w") as new_conf:
            for line in self.conf.splitlines():
                line = line.lstrip()
                if self.tag in line:
                    self.tag_line = True
                if self.tag_line and line.startswith("#"):
                    repo = "".join(line.split("#")).strip()
                    if repo in self.selected:
                        new_conf.write(line.replace(line, repo + "\n"))
                        continue
                if (self.tag_line and not line.startswith("#") and
                        line != self.tag):
                    repo = line.strip()
                    if repo not in self.selected:
                        new_conf.write(line.replace(line, "# " + line + "\n"))
                        continue
                new_conf.write(line + "\n")

    def clear_screen(self):
        """Clear screen
        """
        os.system("clear")

    def reference(self):
        """Reference enable repositories
        """
        total_enabled = ", ".join(self.selected)
        if len(total_enabled) < 1:
            total_enabled = ("{0}Are you crazy? This is a package "
                             "manager for packages :p{1}".format(
                                 self.meta.color["RED"],
                                 self.meta.color["ENDC"]))
        self.msg.template(78)
        print("| Enabled repositories:")
        self.msg.template(78)
        print("| {0}".format(total_enabled))
        self.msg.template(78)
        print("{0}Total {1}/{2} repositories enabled.{3}\n".format(
            self.meta.color["GREY"], len(self.selected),
            len(self.enabled + self.disabled), self.meta.color["ENDC"]))
Exemplo n.º 33
0
class Repo(object):
    """Manage repositories configuration files
    """
    def __init__(self):
        self.meta = _meta_
        self.DEFAULT_REPOS_NAMES = self.meta.default_repositories
        self.custom_repo_file = "/etc/slpkg/custom-repositories"
        self.default_repo_file = "/etc/slpkg/default-repositories"
        self.custom_repositories_list = Utils().read_file(self.custom_repo_file)
        self.default_repositories_list = Utils().read_file(
            self.default_repo_file)
        self.default_repository()

    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()

    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()

    def custom_repository(self):
        """Return dictionary with repo name and url (used external)
        """
        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

    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

    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
Exemplo n.º 34
0
class Repo(object):
    """Central repository urls
    """
    def __init__(self):
        self.meta = _meta_
        self.repo_file = "/etc/slpkg/custom-repositories"
        self.repositories_list = Utils().read_file(self.repo_file)

    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.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("\nMaximum repository name length must be six (6) "
                  "characters\n")
            raise SystemExit()
        with open(self.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()

    def remove(self, repo):
        """
        Remove custom repository
        """
        rem_repo = False
        with open(self.repo_file, "w") as repos:
            for line in self.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()

    def custom_repository(self):
        """
        Return dictionary with repo name and url
        """
        dict_repo = {}
        for line in self.repositories_list.splitlines():
            line = line.lstrip()
            if not line.startswith("#"):
                dict_repo[line.split()[0]] = line.split()[1]
        return dict_repo

    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

    def sbo(self):
        """
        SlackBuilds.org repository
        """
        return "http://slackbuilds.org/slackbuilds/"

    def rlw(self):
        """
        Robby"s repoisitory
        """
        return "http://rlworkman.net/pkgs/"

    def alien(self):
        """
        Alien"s slackbuilds repository
        """
        return "http://taper.alienbase.nl/mirrors/people/alien/sbrepos/"

    def slacky(self):
        """
        Slacky.eu repository
        """
        return "http://repository.slacky.eu/"

    def studioware(self):
        """
        Studioware repository
        """
        return "http://studioware.org/files/packages/"

    def slackers(self):
        """
        Slackers.it repository
        """
        return "http://ponce.cc/slackers/repository/"

    def slackonly(self):
        """
        Slackonly.com repository
        """
        return "https://slackonly.com/pub/packages/"

    def ktown(self):
        """
        Alien"s ktown repository
        """
        return "http://alien.slackbook.org/ktown/"

    def multi(self):
        """
        Alien"s multilib repository
        """
        return "http://www.slackware.com/~alien/multilib/"

    def slacke(self):
        """
        Slacke slacke{17|18} repository
        """
        return "http://ngc891.blogdns.net/pub/"

    def salix(self):
        """
        SalixOS salix repository
        """
        return "http://download.salixos.org/"

    def slackel(self):
        """
        Slackel.gr slackel repository
        """
        return "http://www.slackel.gr/repo/"

    def restricted(self):
        """
        Slackel.gr slackel repository
        """
        return ("http://taper.alienbase.nl/mirrors/people/alien/"
                "restricted_slackbuilds/")

    def msb(self):
        """
        MSB mate repository
        """
        return "http://slackware.org.uk/msb/"
Exemplo n.º 35
0
class QueuePkgs(object):
    """Manage SBo packages, add or remove for building or
    installation
    """
    def __init__(self):
        queue_file = [
            "# In this file you can create a list of\n",
            "# packages you want to build or install.\n",
            "#\n"
        ]
        self.meta = _meta_
        self.quit = False
        self.queue = self.meta.lib_path + "queue/"
        self.queue_list = self.queue + "queue_list"
        self._SOURCES = self.meta.SBo_SOURCES
        if not os.path.exists(self.meta.lib_path):
            os.mkdir(self.meta.lib_path)
        if not os.path.exists(self.queue):
            os.mkdir(self.queue)
        if not os.path.isfile(self.queue_list):
            with open(self.queue_list, "w") as queue:
                for line in queue_file:
                    queue.write(line)
                queue.close()
        self.queued = Utils().read_file(self.queue_list)

    def packages(self):
        """Return queue list from /var/lib/queue/queue_list
        file.
        """
        queue_list = []
        for read in self.queued.splitlines():
            read = read.lstrip()
            if not read.startswith("#"):
                queue_list.append(read.replace("\n", ""))
        return queue_list

    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("")   # new line at exit

    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("")   # new line at exit

    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("")   # new line at exit

    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)

    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)