← Back to team overview

keryx team mailing list archive

[Merge] lp:~mac9416/keryx/devel into lp:keryx/devel

 

mac9416 has proposed merging lp:~mac9416/keryx/devel into lp:keryx/devel.

Requested reviews:
    Keryx Admins (keryx-admins)

Added PackageListManager to dpkg.py. It currently only loads local packages.
-- 
https://code.launchpad.net/~mac9416/keryx/devel/+merge/10196
Your team Keryx Development Team is subscribed to branch lp:keryx/devel.
=== modified file 'libkeryx/definitions/dpkg.py'
--- libkeryx/definitions/dpkg.py	2009-08-13 01:45:08 +0000
+++ libkeryx/definitions/dpkg.py	2009-08-14 23:24:01 +0000
@@ -1,4 +1,4 @@
-""" Dpkg plugin """
+''' Dpkg plugin '''
 
 __appname__  = 'dpkg'
 __version__  = '1.0.0'
@@ -164,3 +164,80 @@
     def fetch_from_internet(self, url_list, dest_path):
         print 'fetch_from_internet'
 
+class PackageListManager:
+
+    def __init__(self, option):
+        self.option = option
+        if self.option == 'local':
+            self.package_list_dir = '/var/lib/apt/lists/'
+            self.package_file_list = []
+            for list_file in os.listdir(self.package_list_dir):
+                if list_file.endswith('_Packages'):
+                    list_file = os.path.join(self.package_list_dir, list_file)
+                    self.package_file_list.append(list_file)
+        elif self.option == 'internet':
+            print "ERROR: Internet package loading not yet implemented."
+        self.end = False
+        self.list_file = self.open_list_file()
+
+    def open_list_file(self):
+        '''Returns next list file in self.package_file_list as list of package
+           entries.
+        '''
+        # I add one to self.list_file_number now, then subtract one when 
+        # opening so I can return the object, not the obect in a variable.
+        return open(self.package_file_list.pop(0), 'rb').read().split('\n\n')
+
+    def get_next_record(self):
+        '''Returns the next package as an instance of pkg_table.'''
+        pkg_fields = pkg_table
+
+        project = ''  #FIXME
+
+        (project, package_name, version, section, 
+         installed_size, maintainer, original_maintainer, \
+         architecture, replaces, provides, depends, recommends, \
+         suggests, conflicts, filename, size, md5sum, sha256, \
+         shortdesc, longdesc, homepage, bugs, origin, task) = [''] * 24
+
+        record = self.list_file.pop(0)
+
+        for line in record.split('\n'):
+            if line.startswith('Package:'): package_name = line[9:-1]
+            elif line.startswith('Version:'): version = line[9:-1]
+            elif line.startswith('Section:'): section = line[9:-1]
+            elif line.startswith('Installed Size:'): installed_size = line[16:-1]
+            elif line.startswith('Maintainer:'): maintainer = line[12:-1]
+            elif line.startswith('Original Maintainer:'): original_maintainer = line[21:-1]
+            elif line.startswith('Architecture:'): architecture = line[14:-1]
+            elif line.startswith('Replaces:'): replaces = line[10:-1]
+            elif line.startswith('Provides:'): provides = line[10:-1]
+            elif line.startswith('Depends:'): depends = line[9:-1]
+            elif line.startswith('Recommends:'): recommends = line[12:-1]
+            elif line.startswith('Suggests:'): suggests = line[10:-1]
+            elif line.startswith('Conflicts:'): conflicts = line[11:-1]
+            elif line.startswith('Filename:'): filename = line[10:-1]
+            elif line.startswith('Size:'): size = line[6:-1]
+            elif line.startswith('Description:'): shortdesc = line[13:-1]
+            elif line.startswith(' '): longdesc += ' %s' % (line[1:-1])
+            elif line.startswith('Homepage:'): homepage = line[10:-1]
+            elif line.startswith('Bugs:'): bugs = line[6:-1]
+            elif line.startswith('Origin:'): origin = line[8:-1]
+            elif line.startswith('Task:'): size = line[6:-1]
+
+        if len(self.list_file) == 0:
+            if not len(self.package_file_list) == 0:
+                self.list_file = self.open_list_file()
+            else:
+                self.end = True
+
+        return pkg_fields(project, package_name, version, section, \
+                 installed_size, maintainer, original_maintainer, \
+                 architecture, replaces, provides, depends, recommends, \
+                 suggests, conflicts, filename, size, md5sum, sha256, \
+                 shortdesc, longdesc, homepage, bugs, origin, task)
+
+    def at_end(self):
+        '''Returns self.at_end indicating whether we're at the end of the lists
+        '''
+        return self.end


Follow ups