Add support full Slackware options

This commit is contained in:
Dimitris Zlatanidis 2015-06-10 22:14:40 +03:00
parent 8d80ff97ac
commit f80032cc5a
8 changed files with 96 additions and 107 deletions

View file

@ -88,7 +88,7 @@ class MetaData(object):
__all__ = "slpkg" __all__ = "slpkg"
__author__ = "dslackw" __author__ = "dslackw"
__version_info__ = (2, 4, 4) __version_info__ = (2, 5, 0)
__version__ = "{0}.{1}.{2}".format(*__version_info__) __version__ = "{0}.{1}.{2}".format(*__version_info__)
__license__ = "GNU General Public License v3 (GPLv3)" __license__ = "GNU General Public License v3 (GPLv3)"
__email__ = "d.zlatanidis@gmail.com" __email__ = "d.zlatanidis@gmail.com"

View file

@ -99,16 +99,17 @@ Optional arguments:
and prints results. and prints results.
-f, --find, [package...] Find and print installed packages -f, --find, [package...] Find and print installed packages
reporting the size and the sum. reporting the size and the sum.
-i, --install, [package...] Installs single or multiple -i, --installpkg, [options] [package...] Installs single or multiple
Slackware binary packages. options=[--warn, --md5sum, --root, Slackware binary packages designed
-u, --install-new, [package...] Upgrade single or multiple Slackware --infobox, --menu, --terse, for use with the Slackware Linux
binary packages from a older to a --ask, --priority, distribution onto your system.
newer one. --tagfile]
-o, --reinstall, [package...] Reinstall signle or multiple -u, --upgradepkg, [options] [package...] Upgrade single or multiple Slackware
Slackware binary packages with the options=[--dry-run, --install-new, binary packages from an older
same packages if the exact. --reinstall, --verbose] version to a newer one.
-r, --remove, [package...] Removes a previously installed -r, --removepkg, [options] [package...] Removes a previously installed
Slackware binary packages. options=[-warn, -preserve, copy, Slackware binary packages.
-keep]
-d, --display, [package...] Display the installed packages -d, --display, [package...] Display the installed packages
contents and file list. contents and file list.
@ -137,7 +138,7 @@ def usage(repo):
[-t [repository] [package]] [-t [repository] [package]]
[-p [repository] [package], --color=[]] [-p [repository] [package], --color=[]]
[-n [SBo package]] [-F [...]] [-f [...]] [-i [...]] [-n [SBo package]] [-F [...]] [-f [...]] [-i [...]]
[-u [...]] [-o [...]] [-r [...]] [-d [...]] [-u [...]] [-r [...]] [-d [...]]
""" """
error_repo = "" error_repo = ""
if repo and repo not in _meta_.repositories: if repo and repo not in _meta_.repositories:

View file

@ -173,18 +173,18 @@ class BinaryInstall(object):
print("[ {0}reinstalling{1} ] --> {2}".format( print("[ {0}reinstalling{1} ] --> {2}".format(
self.meta.color["GREEN"], self.meta.color["ENDC"], inst)) self.meta.color["GREEN"], self.meta.color["ENDC"], inst))
installs.append(pkg_ver) installs.append(pkg_ver)
PackageManager(package).reinstall() PackageManager(package).upgrade("--reinstall")
elif find_package(split_package(inst)[0] + self.meta.sp, elif find_package(split_package(inst)[0] + self.meta.sp,
self.meta.pkg_path): self.meta.pkg_path):
print("[ {0}upgrading{1} ] --> {2}".format( print("[ {0}upgrading{1} ] --> {2}".format(
self.meta.color["YELLOW"], self.meta.color["ENDC"], inst)) self.meta.color["YELLOW"], self.meta.color["ENDC"], inst))
upgraded.append(pkg_ver) upgraded.append(pkg_ver)
PackageManager(package).upgrade() PackageManager(package).upgrade("--install-new")
else: else:
print("[ {0}installing{1} ] --> {2}".format( print("[ {0}installing{1} ] --> {2}".format(
self.meta.color["GREEN"], self.meta.color["ENDC"], inst)) self.meta.color["GREEN"], self.meta.color["ENDC"], inst))
installs.append(pkg_ver) installs.append(pkg_ver)
PackageManager(package).upgrade() PackageManager(package).upgrade("--install-new")
return [installs, upgraded] return [installs, upgraded]
def checksums(self, install): def checksums(self, install):

View file

@ -25,7 +25,6 @@
import sys import sys
import getpass import getpass
from utils import Utils
from messages import Msg from messages import Msg
from desc import PkgDesc from desc import PkgDesc
from config import Config from config import Config
@ -63,33 +62,6 @@ class ArgParse(object):
def __init__(self, args): def __init__(self, args):
self.args = args self.args = args
self.meta = _meta_ self.meta = _meta_
self.packages = self.args[1:]
if len(self.args) > 1 and self.args[0] in ["-q", "--queue", "-b",
"--blacklist"]:
self.packages = self.args[1:-1]
elif len(self.packages) > 1 and self.args[0] in ["-s", "--sync", "-t",
"--tracking", "-p",
"--print", "-F",
"--FIND"]:
self.packages = self.args[2:]
if (len(self.args) > 1 and
self.args[0] in ["-f", "--find", "-i", "--install", "-u",
"--install-new", "-o", "--reinstall", "-r",
"--remove", "-d", "--display", "-n",
"--network"] and
self.args[1].endswith(".pkg")):
self.packages = Utils().read_file_pkg(self.args[1])
elif (len(self.args) >= 3 and
self.args[0] in ["-s", "--sync", "-t", "--tracking", "-p",
"--print", "-F", "--FIND"] and
self.args[1] in self.meta.repositories and
self.args[2].endswith(".pkg")):
self.packages = Utils().read_file_pkg(self.args[2])
elif (len(self.args) == 3 and self.args[0] in ["-q", "--queue",
"-b", "--blacklist"] and
self.args[1].endswith(".pkg")):
self.packages = Utils().read_file_pkg(self.args[1])
# checking if repositories exists # checking if repositories exists
if len(self.args) > 1 and self.args[0] not in [ if len(self.args) > 1 and self.args[0] not in [
@ -231,6 +203,7 @@ class ArgParse(object):
def pkg_install(self): def pkg_install(self):
""" install packages by repository """ """ install packages by repository """
packages = self.args[2:]
options = ["-s", "--sync"] options = ["-s", "--sync"]
flag = ["--resolve-off"] flag = ["--resolve-off"]
resolve = True resolve = True
@ -239,10 +212,10 @@ class ArgParse(object):
if len(self.args) >= 3 and self.args[0] in options: if len(self.args) >= 3 and self.args[0] in options:
if (self.args[1] in self.meta.repositories and if (self.args[1] in self.meta.repositories and
self.args[1] not in ["sbo"]): self.args[1] not in ["sbo"]):
BinaryInstall(self.packages, self.args[1], resolve).start( BinaryInstall(packages, self.args[1], resolve).start(
if_upgrade=False) if_upgrade=False)
elif self.args[1] == "sbo": elif self.args[1] == "sbo":
SBoInstall(self.packages, resolve).start( SBoInstall(packages, resolve).start(
if_upgrade=False) if_upgrade=False)
else: else:
usage(self.args[1]) usage(self.args[1])
@ -251,12 +224,8 @@ class ArgParse(object):
def pkg_tracking(self): def pkg_tracking(self):
""" tracking package dependencies """ """ tracking package dependencies """
packages = "".join(self.packages) packages = self.args[2:]
options = ["-t", "--tracking"] options = ["-t", "--tracking"]
if len(self.packages) > 1:
packages = self.packages[1]
if self.args[2].endswith(".pkg"):
packages = self.packages[0]
if (len(self.args) == 3 and self.args[0] in options and if (len(self.args) == 3 and self.args[0] in options and
self.args[1] in self.meta.repositories): self.args[1] in self.meta.repositories):
track_dep(packages, self.args[1]) track_dep(packages, self.args[1])
@ -268,10 +237,8 @@ class ArgParse(object):
def sbo_network(self): def sbo_network(self):
""" view slackbuilds packages """ """ view slackbuilds packages """
packages = "".join(self.packages) packages = self.args[1]
options = ["-n", "--network"] options = ["-n", "--network"]
if len(self.packages) > 1:
packages = self.packages[0]
if (len(self.args) == 2 and self.args[0] in options and if (len(self.args) == 2 and self.args[0] in options and
"sbo" in self.meta.repositories): "sbo" in self.meta.repositories):
SBoNetwork(packages).view() SBoNetwork(packages).view()
@ -280,6 +247,7 @@ class ArgParse(object):
def pkg_blacklist(self): def pkg_blacklist(self):
""" manage blacklist packages """ """ manage blacklist packages """
packages = self.args[1:]
blacklist = BlackList() blacklist = BlackList()
options = ["-b", "--blacklist"] options = ["-b", "--blacklist"]
flag = ["--add", "--remove"] flag = ["--add", "--remove"]
@ -289,25 +257,26 @@ class ArgParse(object):
blacklist.listed() blacklist.listed()
elif (len(self.args) > 2 and self.args[0] in options and elif (len(self.args) > 2 and self.args[0] in options and
self.args[-1] == flag[0]): self.args[-1] == flag[0]):
blacklist.add(self.packages) blacklist.add(packages)
elif (len(self.args) > 2 and self.args[0] in options and elif (len(self.args) > 2 and self.args[0] in options and
self.args[-1] == flag[1]): self.args[-1] == flag[1]):
blacklist.remove(self.packages) blacklist.remove(packages)
else: else:
usage("") usage("")
def pkg_queue(self): def pkg_queue(self):
""" manage packages in queue """ """ manage packages in queue """
packages = self.args[1:]
queue = QueuePkgs() queue = QueuePkgs()
options = ["-q", "--queue"] options = ["-q", "--queue"]
flag = ["--add", "--remove"] flag = ["--add", "--remove"]
command = ["list", "build", "install", "build-install"] command = ["list", "build", "install", "build-install"]
if (len(self.args) > 2 and self.args[0] in options and if (len(self.args) > 2 and self.args[0] in options and
self.args[-1] == flag[0]): self.args[-1] == flag[0]):
queue.add(self.packages) queue.add(packages)
elif (len(self.args) > 2 and self.args[0] in options and elif (len(self.args) > 2 and self.args[0] in options and
self.args[-1] == flag[1]): self.args[-1] == flag[1]):
queue.remove(self.packages) queue.remove(packages)
elif (len(self.args) == 2 and self.args[0] in options and elif (len(self.args) == 2 and self.args[0] in options and
self.args[1] == command[0]): self.args[1] == command[0]):
queue.listed() queue.listed()
@ -326,52 +295,81 @@ class ArgParse(object):
def bin_install(self): def bin_install(self):
""" install Slackware binary packages """ """ install Slackware binary packages """
options = ["-i", "--install"] packages = self.args[1:]
options = ["-i", "--installpkg"]
flag = ""
flags = [
"--warn",
"--md5sum",
"--root",
"--infobox",
"--menu",
"--terse",
"--ask",
"--priority",
"--tagfile"
]
if self.args[1] in flags:
flag = self.args[1]
packages = self.args[2:]
if len(self.args) > 1 and self.args[0] in options: if len(self.args) > 1 and self.args[0] in options:
PackageManager(self.packages).install() PackageManager(packages).install(flag)
else: else:
usage("") usage("")
def bin_upgrade(self): def bin_upgrade(self):
""" install-upgrade Slackware binary packages """ """ install-upgrade Slackware binary packages """
options = ["-u", "--install-new"] packages = self.args[1:]
options = ["-u", "--upgradepkg"]
flag = ""
flags = [
"--dry-run",
"--install-new",
"--reinstall",
"--verbose"
]
if self.args[1] in flags:
flag = self.args[1]
packages = self.args[2:]
if len(self.args) > 1 and self.args[0] in options: if len(self.args) > 1 and self.args[0] in options:
PackageManager(self.packages).upgrade() PackageManager(packages).upgrade(flag)
else:
usage("")
def bin_reinstall(self):
""" reinstall Slackware binary packages """
options = ["-o", "--reinstall"]
if len(self.args) > 1 and self.args[0] in options:
PackageManager(self.packages).reinstall()
else: else:
usage("") usage("")
def bin_remove(self): def bin_remove(self):
""" remove Slackware packages """ """ remove Slackware packages """
options = ["-r", "--remove"] packages = self.args[1:]
options = ["-r", "--removepkg"]
flag = ""
flags = [
"-warn",
"-preserve",
"-copy",
"-keep"
]
if self.args[1] in flags:
flag = self.args[1]
packages = self.args[2:]
if len(self.args) > 1 and self.args[0] in options: if len(self.args) > 1 and self.args[0] in options:
PackageManager(self.packages).remove() PackageManager(packages).remove(flag)
else: else:
usage("") usage("")
def bin_find(self): def bin_find(self):
""" find installed packages """ """ find installed packages """
packages = self.args[1:]
options = ["-f", "--find"] options = ["-f", "--find"]
if len(self.args) > 1 and self.args[0] in options: if len(self.args) > 1 and self.args[0] in options:
PackageManager(self.packages).find() PackageManager(packages).find()
else: else:
usage("") usage("")
def pkg_desc(self): def pkg_desc(self):
""" print slack-desc by repository""" """ print slack-desc by repository"""
packages = "".join(self.packages) packages = self.args[2]
options = ["-p", "--print"] options = ["-p", "--print"]
flag = ["--color="] flag = ["--color="]
colors = ["red", "green", "yellow", "cyan", "grey"] colors = ["red", "green", "yellow", "cyan", "grey"]
if len(self.packages) > 1:
packages = self.packages[0]
if (len(self.args) == 3 and self.args[0] in options and if (len(self.args) == 3 and self.args[0] in options and
self.args[1] in self.meta.repositories): self.args[1] in self.meta.repositories):
PkgDesc(packages, self.args[1], "").view() PkgDesc(packages, self.args[1], "").view()
@ -398,9 +396,10 @@ class ArgParse(object):
def pkg_contents(self): def pkg_contents(self):
""" print packages contents """ """ print packages contents """
packages = self.args[1:]
options = ["-d", "--display"] options = ["-d", "--display"]
if len(self.args) > 1 and self.args[0] in options: if len(self.args) > 1 and self.args[0] in options:
PackageManager(self.packages).display() PackageManager(packages).display()
else: else:
usage("") usage("")
@ -466,10 +465,8 @@ def main():
"--install": argparse.bin_install, "--install": argparse.bin_install,
"-u": argparse.bin_upgrade, "-u": argparse.bin_upgrade,
"--install-new": argparse.bin_upgrade, "--install-new": argparse.bin_upgrade,
"-o": argparse.bin_reinstall,
"--reinstall": argparse.bin_reinstall,
"-r": argparse.bin_remove, "-r": argparse.bin_remove,
"--remove": argparse.bin_remove, "--removepkg": argparse.bin_remove,
"-f": argparse.bin_find, "-f": argparse.bin_find,
"--find": argparse.bin_find, "--find": argparse.bin_find,
"-F": argparse.pkg_find, "-F": argparse.pkg_find,

View file

@ -44,42 +44,30 @@ class PackageManager(object):
self.binary = binary self.binary = binary
self.meta = _meta_ self.meta = _meta_
def install(self): def install(self, flag):
""" """
Install Slackware binary packages Install Slackware binary packages
""" """
for pkg in self.binary: for pkg in self.binary:
try: try:
print(subprocess.check_output("installpkg {0}".format( subprocess.call("installpkg {0} {1}".format(flag, pkg),
pkg), shell=True)) shell=True)
print("Completed!\n") print("Completed!\n")
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
self._not_found("Can't install", self.binary, pkg) self._not_found("Can't install", self.binary, pkg)
def upgrade(self): def upgrade(self, flag):
""" """
Upgrade Slackware binary packages Upgrade Slackware binary packages with new
""" """
for pkg in self.binary: for pkg in self.binary:
try: try:
print(subprocess.check_output("upgradepkg --install-new " subprocess.call("upgradepkg {0} {1}".format(flag, pkg),
"{0}".format(pkg), shell=True)) shell=True)
print("Completed!\n") print("Completed!\n")
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
self._not_found("Can't upgrade", self.binary, pkg) self._not_found("Can't upgrade", self.binary, pkg)
def reinstall(self):
"""
Reinstall Slackware binary packages
"""
for pkg in self.binary:
try:
print(subprocess.check_output(
"upgradepkg --reinstall {0}".format(pkg), shell=True))
print("Completed!\n")
except subprocess.CalledProcessError:
self._not_found("Can't reinstall", self.binary, pkg)
def _not_found(self, message, binary, pkg): def _not_found(self, message, binary, pkg):
if len(binary) > 1: if len(binary) > 1:
bol = eol = "" bol = eol = ""
@ -87,10 +75,11 @@ class PackageManager(object):
bol = eol = "\n" bol = eol = "\n"
Msg().pkg_not_found(bol, pkg, message, eol) Msg().pkg_not_found(bol, pkg, message, eol)
def remove(self): def remove(self, flag):
""" """
Remove Slackware binary packages Remove Slackware binary packages
""" """
self.flag = flag
dep_path = self.meta.log_path + "dep/" dep_path = self.meta.log_path + "dep/"
dependencies, rmv_list = [], [] dependencies, rmv_list = [], []
removed = self._view_removed() removed = self._view_removed()
@ -188,8 +177,8 @@ class PackageManager(object):
deps.append(package) deps.append(package)
for dep in deps: for dep in deps:
if find_package(dep + self.meta.sp, self.meta.pkg_path): if find_package(dep + self.meta.sp, self.meta.pkg_path):
print(subprocess.check_output("removepkg {0}".format(dep), subprocess.call("removepkg {0} {1}".format(self.flag, dep),
shell=True)) shell=True)
removes.append(dep) removes.append(dep)
os.remove(path + package) os.remove(path + package)
return removes return removes
@ -199,8 +188,8 @@ class PackageManager(object):
Remove one signle package Remove one signle package
""" """
if find_package(package + self.meta.sp, self.meta.pkg_path): if find_package(package + self.meta.sp, self.meta.pkg_path):
print(subprocess.check_output("removepkg {0}".format(package), subprocess.call("removepkg {0} {1}".format(self.flag, package),
shell=True)) shell=True)
return package.split() return package.split()
def _reference_rmvs(self, removes): def _reference_rmvs(self, removes):

View file

@ -337,5 +337,5 @@ class SBoInstall(object):
print("{0}[ Installing ] --> {1}{2}".format( print("{0}[ Installing ] --> {1}{2}".format(
self.meta.color["GREEN"], self.meta.color["ENDC"], pkg)) self.meta.color["GREEN"], self.meta.color["ENDC"], pkg))
installs.append(prgnam) installs.append(prgnam)
PackageManager(binary).upgrade() PackageManager(binary).upgrade("--install-new")
return installs, upgraded return installs, upgraded

View file

@ -222,4 +222,4 @@ class SBoNetwork(object):
print("[ {0}Installing{1} ] --> {2}".format(_meta_.color["GREEN"], print("[ {0}Installing{1} ] --> {2}".format(_meta_.color["GREEN"],
_meta_.color["ENDC"], _meta_.color["ENDC"],
self.name)) self.name))
PackageManager(binary).upgrade() PackageManager(binary).upgrade("--install-new")

View file

@ -178,13 +178,15 @@ class Patches(object):
print("[ {0}upgrading{1} ] --> {2}".format( print("[ {0}upgrading{1} ] --> {2}".format(
self.meta.color["YELLOW"], self.meta.color["ENDC"], self.meta.color["YELLOW"], self.meta.color["ENDC"],
pkg[:-4])) pkg[:-4]))
PackageManager((self.patch_path + pkg).split()).upgrade() PackageManager((self.patch_path + pkg).split()).upgrade(
"--install-new")
self.upgraded.append(pkg_ver) self.upgraded.append(pkg_ver)
else: else:
print("[ {0}installing{1} ] --> {2}".format( print("[ {0}installing{1} ] --> {2}".format(
self.meta.color["GREEN"], self.meta.color["ENDC"], self.meta.color["GREEN"], self.meta.color["ENDC"],
pkg[:-4])) pkg[:-4]))
PackageManager((self.patch_path + pkg).split()).upgrade() PackageManager((self.patch_path + pkg).split()).upgrade(
"--install-new")
self.installed.append(pkg_ver) self.installed.append(pkg_ver)
def kernel(self): def kernel(self):