#!/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 "; print "\tapt-plus -g "; print "\tapt-plus --gropu "; print; print "\t-g, --group "; print "\t\tProccess actions within a specific group (applies to: install, purge, remove, list, deb install)."; 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 "; print "\t\tInstalls a package from a .deb file and notice it in the manifest."; print; print "\t-i, --install "; print "\t\tInstalls one or more packages and notice it in the manifest, note that"; print "\t\tthe 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 "; print "\t\tSet the global manifest file for registering packages\n"; print; print "\t-p, --purge "; print "\t\tPurges one or more packages and notice it in the manifest, note that"; print "\t\tthe 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 "; print "\t\tRemoves one or more packages and notice it in the manifest, note that"; print "\t\tthe 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; print "\t-a, --add-ppa "; print "\t\tAdds the repository to dpkg then update it"; print; # [2] Command dispatch (if at least 1 arg) #========================================================# if ( len(sys.argv) > 1 ): # (1) Manage optional -g --group modifier #--------------------------------------------------------# OPTGROUP = None; ARGS = sys.argv; if( len(sys.argv) > 2 and sys.argv[1] == "-g" or sys.argv[1] == "--group" ): OPTGROUP = sys.argv[2]; ARGS = ARGS[0:1] + ARGS[3:]; # (2) Normal arguments #--------------------------------------------------------# # (1) Get the command argument (first) # command = ARGS[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(ARGS) < 3 ): sys.exit("\n(!) Missing argument "); if( OPTGROUP != None ): ossystem("/usr/bin/env python %s/command/debinstall -g %s %s" % (path, OPTGROUP, ARGS[2]) ); else: ossystem("/usr/bin/env python %s/command/debinstall %s" % (path, ARGS[2]) ); # (4) --install, -i #--------------------------------------------------------# elif ( command == "-i" or command == "--install" ): # if package/s given if ( len(ARGS) < 3 ): sys.exit("\n(!) Missing argument "); packages = " ".join(ARGS[2:]); if( OPTGROUP != None ): ossystem("/usr/bin/env python %s/command/install -g %s %s" % (path, OPTGROUP, packages) ); else: 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(ARGS) < 3 ): sys.exit("\n(!) Missing argument "); packages = " ".join(ARGS[2:]); if( OPTGROUP != None ): ossystem("/usr/bin/env python %s/command/remove -g %s %s" % (path, OPTGROUP, packages) ); else: 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(ARGS) < 3 ): sys.exit("\n(!) Missing argument "); packages = " ".join(ARGS[2:]); if( OPTGROUP != None ): ossystem("/usr/bin/env python %s/command/purge -g %s %s" % (path, OPTGROUP, packages) ); else: 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(ARGS) < 3 ): sys.exit("\n(!) Missing argument "); # (2) If argument is not a valid file -> abort # elif ( not ospath.isfile(ARGS[2]) ): sys.exit("Given path isn't a file"); # (3) Store absolute path in ./manifest file # file = ospath.realpath(ARGS[2]); with open( ("%s/manifest" % path), "w") as f: f.write(file); # (8) --list, -l #--------------------------------------------------------# elif ( command == "-l" or command == "--list" ): if( OPTGROUP != None ): ossystem("/usr/bin/env python %s/command/list -g %s" % (path, OPTGROUP) ); else: ossystem("/usr/bin/env python %s/command/list" % path ); # (9) --add-ppa, -a #--------------------------------------------------------# elif ( command == "-a" or command == "--add-ppa" ): # if ppa is given if ( len(ARGS) < 3 ): sys.exit("\n(!) Missing argument "); ossystem("/usr/bin/env python %s/command/addppa %s" % (path, ARGS[2]) ); # (10) If no match -> show help message #--------------------------------------------------------# else: showhelp(); # [3] If not enough arguments -> show help message #========================================================# else: showhelp();