bin/slpkg: Updated for version 0.0.2

This commit is contained in:
dslackw 2014-05-08 15:47:39 +03:00
parent 484ab840c6
commit 8d3bff5cc2

View file

@ -7,40 +7,46 @@ import sys
import argparse
import subprocess
__version__ = "0.0.1"
__version__ = "0.0.2"
__packages__ = "/var/log/packages/"
""" main function """
# main function
def main():
description = "Slackware tool to upgrade, remove, find and view packages contents"
parser = argparse.ArgumentParser(description=description)
parser.add_argument("-v", "--verbose", help="print version and exit", action="store_true")
parser.add_argument("-u", "--upgrade", help="exec command upgradepkg --install-new", type=str)
parser.add_argument("-r", "--remove", help="exec command slackpkg remove", type=str)
parser.add_argument("-u", "--upgrade", help="upgrade package with new", type=str)
parser.add_argument("-a", "--reinstall", help="upgrade the same package", type=str)
parser.add_argument("-r", "--remove", help="remove package", type=str)
parser.add_argument("-l", "--list", help="list of installed packages", action="store_true")
parser.add_argument("-f", "--find", help="find if package installed", type=str)
parser.add_argument("-d", "--display", help="display the contents of the package", type=str)
args = parser.parse_args()
""" print version and exit """
# print version and exit
if args.verbose:
print (__version__)
print ("Version: " + __version__)
sys.exit()
""" execute slackware command 'upgradepkg --install-new' """
# upgrade package with new
if args.upgrade:
os.system("upgradepkg --install-new {}".format(args.upgrade))
os.system("upgradepkg --install-new {}".format(args.upgrade))
""" execute slackware command 'slackpkg remove' """
# upgrade package with the same
if args.reinstall:
os.system("upgradepkg --reinstall {}".format(args.reinstall))
# uninstall package
if args.remove:
os.system("slackpkg remove {}".format(args.remove))
""" view list of installed packages """
# view list of installed packages
if args.list:
os.system("ls " + __packages__ + "* | more")
""" find if packages installed on your system """
# find if packages installed on your system
if args.find:
find_pkg = subprocess.check_output(["find " + __packages__ + " -name '{}*' 2> /dev/null".format(args.find)],shell=True)
if find_pkg == "":
@ -48,13 +54,13 @@ def main():
else:
os.system("echo -e '\e[32mThe package is installed on your system\e[39m'")
""" print the package contents """
# print the package contents
if args.display:
display_pkg = subprocess.check_output(["find " + __packages__ + " -name '{}*' 2> /dev/null".format(args.display)],shell=True)
if display_pkg == "":
find_pkg = subprocess.check_output(["find " + __packages__ + " -name '{}*' 2> /dev/null".format(args.display)],shell=True)
if find_pkg == "":
os.system("echo -e '\e[31mThe package is not found\e[39m'")
else:
os.system("cat {}".format(display_pkg))
os.system("cat {}".format(find_pkg))
main()