apt-plus/main

157 lines
4.9 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python
2017-01-01 18:17:29 +00:00
###########
# IMPORTS #
###########
from os import path as ospath;
from os import system as ossystem;
import sys;
# get absolute path
path = ospath.dirname(ospath.realpath(__file__));
# [1] Help function
#========================================================#
2017-01-01 18:17:29 +00:00
def showhelp():
print "\033[1mNAME\033[0m"
print "\tapt-plus 1.0.0 (amd64)";
2017-01-01 18:17:29 +00:00
print;
print "\033[1mSYNOPSIS\033[0m"
print "\tapt-plus <command> <packages>";
2017-01-01 18:17:29 +00:00
print;
print "\033[1mDESCRIPTION\033[0m"
print ""
print "\tapt-plus is top-level wrapper of apt-get and dpkg, also";
print "\tit logs every package you have installed, removed, purged.";
print "\tThese logs are stored in the manifest file (default is ~/.x-migration).";
print;
print "\033[1mOPTIONS\033[0m"
print "\t-l, --list";
print "\t\tList all the packages stored in the manifest.";
print;
print "\t-d, --deb <deb_file>";
print "\t\tInstalls a package from a .deb file and notice it in the manifest.";
print;
print "\t-i, --install <packages>";
print "\t\tInstalls one or more packages and notice it in the manifest, note that";
print "\t\tthe <packages> argument is a list of packages' names separated by spaces.";
print;
print "\t-f, --fetch";
print "\t\tFetches packages from remote to local.";
print;
print "\t-m --manifest <manifest_file>";
print "\t\tSet the global manifest file for registering packages\n";
print;
print "\t-p, --purge <packages>";
print "\t\tPurges one or more packages and notice it in the manifest, note that";
print "\t\tthe <packages> is a list of packages' names separated by spaces.";
print "\t\tThe packages configurations won't be kept, --remove will keep them.";
print;
print "\t-r, --remove <packages>";
print "\t\tRemoves one or more packages and notice it in the manifest, note that";
print "\t\tthe <packages> is a list of packages' names separated by spaces.";
print "\t\tThe packages configurations will be kept, --purge won't keep them.";
print;
print "\t-u, --update";
print "\t\tUpgrades packages and kernel and cleans after";
2017-01-01 18:17:29 +00:00
print;
# [2] Command dispatch (if at least 1 arg)
#========================================================#
2017-01-01 18:17:29 +00:00
if ( len(sys.argv) > 1 ):
# (1) Get the command argument (first) #
command = sys.argv[1];
# (1) --update, -u
#--------------------------------------------------------#
if ( command == "-u" or command == "--update" ):
ossystem("/usr/bin/env sh %s/command/update;" % path);
# (2) --fetch, -f
#--------------------------------------------------------#
elif ( command == "-f" or command == "--fetch" ):
ossystem("/usr/bin/env sh %s/command/fetch;" % path);
# (3) --deb-install, -d
#--------------------------------------------------------#
elif ( command == "-d" or command == "--deb" ):
2017-01-01 18:17:29 +00:00
# if package/s given
if ( len(sys.argv) < 3 ):
sys.exit("\n(!) Missing argument <deb_file>");
ossystem("/usr/bin/env python %s/command/debinstall %s" % (path, sys.argv[2]) );
# (4) --install, -i
#--------------------------------------------------------#
elif ( command == "-i" or command == "--install" ):
2017-01-01 18:17:29 +00:00
# if package/s given
if ( len(sys.argv) < 3 ):
sys.exit("\n(!) Missing argument <packages>");
2017-01-01 18:17:29 +00:00
packages = " ".join(sys.argv[2:]);
ossystem("/usr/bin/env python %s/command/install %s" % (path, packages) );
# (5) --remove, -r
#--------------------------------------------------------#
elif ( command == "-r" or command == "--remove" ):
2017-01-01 18:17:29 +00:00
# if package/s given
if ( len(sys.argv) < 3 ):
sys.exit("\n(!) Missing argument <packages>");
2017-01-01 18:17:29 +00:00
packages = " ".join(sys.argv[2:]);
ossystem("/usr/bin/env python %s/command/remove %s" % (path, packages) );
# (6) --purge, -p
#--------------------------------------------------------#
elif ( command == "-p" or command == "--purge" ):
2017-01-01 18:17:29 +00:00
# if package/s given
if ( len(sys.argv) < 3 ):
sys.exit("\n(!) Missing argument <packages>");
packages = " ".join(sys.argv[2:]);
ossystem("/usr/bin/env python %s/command/purge %s" % (path, packages) );
# (7) --manifest, -m
#--------------------------------------------------------#
elif ( command == "-m" or command == "--manifest" ):
# (1) If argument missing -> abort #
if ( len(sys.argv) < 3 ):
sys.exit("\n(!) Missing argument <manifest_file>");
# (2) If argument is not a valid file -> abort #
2017-01-01 18:17:29 +00:00
elif ( not ospath.isfile(sys.argv[2]) ):
sys.exit("Given path isn't a file");
# (3) Store absolute path in ./manifest file #
2017-01-01 18:17:29 +00:00
file = ospath.realpath(sys.argv[2]);
with open( ("%s/manifest" % path), "w") as f:
f.write(file);
# (8) --list, -l
#--------------------------------------------------------#
elif ( command == "-l" or command == "--list" ):
ossystem("/usr/bin/env python %s/command/list" % path );
# (9) If no match -> show help message
#--------------------------------------------------------#
2017-01-01 18:17:29 +00:00
else:
showhelp();
# [3] If not enough arguments -> show help message
#========================================================#
2017-01-01 18:17:29 +00:00
else:
showhelp();