Example #1
0
def main():
    """Main function."""
    if len(sys.argv) < 3:
        print >> sys.stderr, 'Usage: tool file.deb control-file'
        sys.exit(0)
    fobj = open(sys.argv[1])
    try:
        print debExtractControl(fobj, sys.argv[2])
    finally:
        fobj.close()
Example #2
0
def readMetapackageFile(filename):
    """
    Reads a metapackage file and returns a dictionary with the values.
    """
    
    try:
        metapackage = {}
        controlFile = apt_inst.debExtractControl(open(filename))
        sections = apt_pkg.ParseSection(controlFile)
        
        depends = aptutil.stripDepends(apt_pkg.ParseDepends(sections["Depends"])).split(", ")
        
        #obter o postinst se existir
        
        #tratar as varias sections e criar o metapackage com os dados obtidos
        metapackage['Package'] = sections["Package"]
        metapackage['Priority'] = sections["Priority"]
        metapackage['Section'] = sections["Section"]
        metapackage['Version'] = sections["Version"]
        metapackage['Architecture'] = sections["Architecture"]
        metapackage['Maintainer'] = sections["Maintainer"]
        metapackage['Description'] = sections["Description"]
        metapackage['Depends'] = depends
        
        return metapackage
    except:
        print "readMetapackageFile: error\n"
        return {}           
Example #3
0
 def open(self, filename):
     " open given debfile "
     self.filename = filename
     if not arCheckMember(open(self.filename), "debian-binary"):
         raise NoDebArchiveException, _("This is not a valid DEB archive, missing '%s' member" % "debian-binary")
     control = apt_inst.debExtractControl(open(self.filename))
     self._sections = apt_pkg.ParseSection(control)
     self.pkgname = self._sections["Package"]
Example #4
0
 def open(self, filename):
     " open given debfile "
     self.filename = filename
     if not arCheckMember(open(self.filename), "debian-binary"):
         raise NoDebArchiveException, _(
             "This is not a valid DEB archive, missing '%s' member" %
             "debian-binary")
     control = apt_inst.debExtractControl(open(self.filename))
     self._sections = apt_pkg.ParseSection(control)
     self.pkgname = self._sections["Package"]
Example #5
0
def pkgInfo(package, info):
    """
    Returns the info for a certain package section.
    """
    try:
        controlFile = apt_inst.debExtractControl(open(package))
        sections = apt_pkg.ParseSection(controlFile)
        
        if info == "Depends":
            return  apt_pkg.ParseDepends(sections["Depends"])
        else:
            return sections[info]
    except:
        return ""
Example #6
0
 def __init__(self, filename):
     UserDict.UserDict.__init__(self)
     try:
         filehandle = open(filename);
         try:
             self.control = apt_inst.debExtractControl(filehandle)
         finally:
             # Make sure that file is always closed.
             filehandle.close()
     except SystemError:
         log.debug("Had problems reading: %s"%(filename), 'AptDpkgInfo')
         raise
     for line in self.control.split('\n'):
         if line.find(': ') != -1:
             key, value = line.split(': ', 1)
             self.data[key] = value
Example #7
0
    def blankinfo(self, tempdir, pkg):
        """Create Package Info file

        Arguments:
        temdir - A String, destination of temporary directory
        pkg - A String, main deb package

        Results:
        control - A String, info file

        """
        abs_pkg = os.path.abspath(pkg)
        controlfile = debExtractControl(abs_pkg)
        infofile = os.path.join(tempdir, 'blank.info')
        control = open(infofile, "a")
        control.write(controlfile)
        control.close()

        return control
Example #8
0
 def importDebInfo(self,path):
     
     file = open(path,"r")
     #Getting size from the file
     size = os.stat(path).st_size.__int__()
     #Getting md5sum
     content = file.read()
     file.close()
     md5_sum = md5.new(content).hexdigest()
     file = open(path,"r")
     try:
        debinfo = apt_pkg.ParseSection(apt_inst.debExtractControl(file))
        for key in debinfo.keys():
            value = debinfo.get(key)
            self.set(key, value)
     except:
         self.getFromDpkg(path)
     file.close()
     self.set('Size', size)
     self.set('MD5sum', md5_sum)
Example #9
0
 def loadLocalKits(self):
     """
     Reads the packages files that are in the local dir.
     """
     
     try:
         self._localKits = []
         for root, dirs, files in os.walk(self._localDir):
             for name in files:       
                filename = os.path.join(root, name)
                #check if extension is .deb
                tmpFilename = os.path.splitext(filename)
                if tmpFilename[1] == ".deb":
                    try:
                        tmpDic = {}
                        controlFile = apt_inst.debExtractControl(open(filename))
                        sections = apt_pkg.ParseSection(controlFile)
                        #criar o dicionario
                        tmpDic['Installed'] = False
                        tmpDic['Package'] = sections["Package"]
                        tmpDic['Priority'] = sections["Priority"]
                        tmpDic['Section'] = sections["Section"]
                        tmpDic['Version'] = sections["Version"]
                        tmpDic['Architecture'] = sections["Architecture"]
                        tmpDic['Maintainer'] = sections["Maintainer"]
                        #tmpDic['Description'] = sections["Description"]
                        tmpDic['ShortDesc'] = aptutil.getShortDesc(sections["Description"])
                        tmpDic['LongDesc'] = aptutil.getLongDesc(sections["Description"])
                        tmpDic['Depends'] = aptutil.stripDepends(apt_pkg.ParseDepends(sections["Depends"]))
                        self._localKits.append(tmpDic)
                    except:
                        pass
         return True       
     except IOError:
         print "error\n"
         return False
Example #10
0
    print "%s '%s','%s',%u,%u,%u,%u,%u,%u,%u"\
          % (What,Name,Link,Mode,UID,GID,Size, MTime, Major, Minor)


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print "need filename argumnet"
        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)
    print "%s '%s','%s',%u,%u,%u,%u,%u,%u,%u" \
          % (What, Name, Link, Mode, UID, GID, Size, MTime, Major, Minor)


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print "need filename argumnet"
        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)
Example #12
0
 def extract_header(self, filename):
     """Extract control file contents from a deb package."""
     handle = open(filename)
     control = apt_inst.debExtractControl(handle)
     handle.close()
     return sanitize_deb_header(control)
Example #13
0
 def getControlFile(self, name):
     """ Returns the contents of given file in debian/ or None if it does not exits """
     return apt_inst.debExtractControl(file(self.filename), name)