#!/usr/bin/env python ################################################################## # apt-o.py # Copyright (c) 2007, Anuj Bhatt , Srichand Pendyala # Free to use and distribute under the GPLv3 license terms ################################################################## import sys,os import getpass class AptO: aptgetlist = ['update','upgrade','install','remove','build-dep','dist-upgrade','dselect-upgrade','clean','autoclean','check'] aptcachelist = ['add','gencaches','showpkg','showsrc','stats','dump','dumpavail','unmet','search','show','depends','rdepends','pkgnames','dotty','xvcg','policy'] helpstr="apt-o is a wrapper tweak over apt-get and apt-cache. You don't have to worry about which (like install, search, update et cetera) belongs to which of the two: apt-get or apt-cache. The syntax simply becomes: $ apt-o . Makes lives easy doesn't it?" command = None def usage(self): print "USAGE: apt-o []" sys.exit(1) def not_supported(self): print "Your option is not supported by the apt package!" sys.exit(1) def prepare_command(self): if (len(sys.argv) == 2): if(sys.argv[1]=="help"): print self.helpstr sys.exit(1) elif (sys.argv[1] in self.aptgetlist): if getpass.getuser() != "root": print "The option you've asked for seems to require priviliges that are beyond those your username. Try with a sudo prefix?" sys.exit(1) else: self.command = "apt-get "+sys.argv[1] elif (sys.argv[1] in self.aptcachelist): self.command = "apt-cache "+sys.argv[1] else: self.not_supported() elif (len(sys.argv) > 2): if (sys.argv[1] == "source"): self.command = "apt-get " + sys.argv[1] elif (sys.argv[1] in self.aptgetlist): if getpass.getuser() != "root": print "The option you've asked for seems to require priviliges that are beyond those your username. Try with a sudo prefix?" sys.exit(1) else: self.command = "apt-get" for i in range (1,len(sys.argv)): self.command = self.command+" "+sys.argv[i] #os.system(str) elif (sys.argv[1] in self.aptcachelist): self.command = "apt-cache "+sys.argv[1]+" "+sys.argv[2] #os.system(str2) else: print "Your option is not supported by the apt package!" else: self.not_supported() def execute_command(self): os.system(self.command) def go_do_what_the_user_wants(self): self.prepare_command() self.execute_command() if __name__ == "__main__": thing = AptO() thing.go_do_what_the_user_wants() sys.exit(0)