apt-plus/main

148 lines
4.6 KiB
Python
Executable File

#!/usr/bin/env python
###########
# 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
#========================================================#
def showhelp():
print "\033[1mNAME\033[0m"
print "\tapt-plus 1.0.0 (amd64)";
print;
print "\033[1mSYNOPSIS\033[0m"
print "\tapt-plus <command> <packages>";
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-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";
print;
# [2] Command dispatch (if at least 1 arg)
#========================================================#
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" ):
# 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" ):
# 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/install %s" % (path, packages) );
# (5) --remove, -r
#--------------------------------------------------------#
elif ( command == "-r" or command == "--remove" ):
# 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/remove %s" % (path, packages) );
# (6) --purge, -p
#--------------------------------------------------------#
elif ( command == "-p" or command == "--purge" ):
# 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 #
elif ( not ospath.isfile(sys.argv[2]) ):
sys.exit("Given path isn't a file");
# (3) Store absolute path in ./manifest file #
file = ospath.realpath(sys.argv[2]);
with open( ("%s/manifest" % path), "w") as f:
f.write(file);
# (8) If no match -> show help message
#--------------------------------------------------------#
else:
showhelp();
# [3] If not enough arguments -> show help message
#========================================================#
else:
showhelp();