def main(): """Main function.""" if len(sys.argv) < 3: print >> sys.stderr, "Usage:", __file__, "package.deb outdir" sys.exit(1) if not os.path.exists(sys.argv[2]): print >> sys.stderr, "The directory %s does not exist" % sys.argv[2] sys.exit(1) fobj = open(sys.argv[1]) try: apt_inst.debExtractArchive(fobj, sys.argv[2]) finally: fobj.close()
def debExtract(filename,tempdir=None): # print "debExtract:: filename = ",filename dirname = pkgnameFromPath(filename) cwd = os.getcwd() if tempdir: # print "* tempdir specified ", tempdir fsMisc.ensure_path(True,tempdir) # print "* changing dir to ", tempdir os.chdir(tempdir) print "* Creating dir ",dirname os.mkdir(dirname) print "* Changing dir to",dirname os.chdir(dirname) pkgdir = os.getcwd() # pkgf = file(cwd+"/"+filename) pkgf = file(filename) # print "trying to extract ",cwd+"/"+filename # print "* trying to extract ", filename apt_inst.debExtractArchive(pkgf) os.chdir(cwd) return pkgdir # returning the path where we extracted
sys.exit(1) file = sys.argv[1] print "Working on: %s" % file print "Displaying data.tar.gz:" apt_inst.debExtract(open(file), Callback, "data.tar.gz") print "Now extracting the control file:" control = apt_inst.debExtractControl(open(file)) sections = apt_pkg.ParseSection(control) print "Maintainer is: " print sections["Maintainer"] print print "DependsOn: " depends = sections["Depends"] print apt_pkg.ParseDepends(depends) print "extracting archive" dir = "/tmp/deb" os.mkdir(dir) apt_inst.debExtractArchive(open(file), dir) def visit(arg, dirname, names): print "%s/" % dirname for file in names: print "\t%s" % file os.path.walk(dir, visit, None)
file = sys.argv[1] print "Working on: %s" % file print "Displaying data.tar.gz:" apt_inst.debExtract(open(file), Callback, "data.tar.gz") print "Now extracting the control file:" control = apt_inst.debExtractControl(open(file)) sections = apt_pkg.ParseSection(control) print "Maintainer is: " print sections["Maintainer"] print print "DependsOn: " depends = sections["Depends"] print apt_pkg.ParseDepends(depends) print "extracting archive" dir = "/tmp/deb" os.mkdir(dir) apt_inst.debExtractArchive(open(file), dir) def visit(arg, dirname, names): print "%s/" % dirname for file in names: print "\t%s" % file os.path.walk(dir, visit, None)
#!/usr/bin/python import apt import apt_inst import os import sys print os.getcwd() apt_inst.debExtractArchive(open(sys.argv[1]), "/tmp/") print os.getcwd()