]> err.no Git - dak/commitdiff
Merge branch 'master' into contents
authorTorsten Werner <twerner@debian.org>
Thu, 24 Mar 2011 08:35:23 +0000 (09:35 +0100)
committerTorsten Werner <twerner@debian.org>
Thu, 24 Mar 2011 08:35:23 +0000 (09:35 +0100)
Conflicts:
daklib/dbconn.py

1  2 
daklib/dbconn.py

index 014f1082e4b0216f7a74b55c261ff89e95156e6b,6317b5844467a260865d5c7c67996eda537d7822..d4caf01c9176d60980c13933090950efa477aab9
@@@ -2157,18 -2195,60 +2195,72 @@@ __all__.append('get_sections'
  
  ################################################################################
  
 +class SrcContents(ORMObject):
 +    def __init__(self, file = None, source = None):
 +        self.file = file
 +        self.source = source
 +
 +    def properties(self):
 +        return ['file', 'source']
 +
 +__all__.append('SrcContents')
 +
 +################################################################################
 +
+ from debian.debfile import Deb822
+ # Temporary Deb822 subclass to fix bugs with : handling; see #597249
+ class Dak822(Deb822):
+     def _internal_parser(self, sequence, fields=None):
+         # The key is non-whitespace, non-colon characters before any colon.
+         key_part = r"^(?P<key>[^: \t\n\r\f\v]+)\s*:\s*"
+         single = re.compile(key_part + r"(?P<data>\S.*?)\s*$")
+         multi = re.compile(key_part + r"$")
+         multidata = re.compile(r"^\s(?P<data>.+?)\s*$")
+         wanted_field = lambda f: fields is None or f in fields
+         if isinstance(sequence, basestring):
+             sequence = sequence.splitlines()
+         curkey = None
+         content = ""
+         for line in self.gpg_stripped_paragraph(sequence):
+             m = single.match(line)
+             if m:
+                 if curkey:
+                     self[curkey] = content
+                 if not wanted_field(m.group('key')):
+                     curkey = None
+                     continue
+                 curkey = m.group('key')
+                 content = m.group('data')
+                 continue
+             m = multi.match(line)
+             if m:
+                 if curkey:
+                     self[curkey] = content
+                 if not wanted_field(m.group('key')):
+                     curkey = None
+                     continue
+                 curkey = m.group('key')
+                 content = ""
+                 continue
+             m = multidata.match(line)
+             if m:
+                 content += '\n' + line # XXX not m.group('data')?
+                 continue
+         if curkey:
+             self[curkey] = content
  class DBSource(ORMObject):
      def __init__(self, source = None, version = None, maintainer = None, \
          changedby = None, poolfile = None, install_date = None):
          return ['source', 'version', 'install_date', 'maintainer', \
              'changedby', 'poolfile', 'install_date']
  
+     def read_control_fields(self):
+         '''
+         Reads the control information from a dsc
+         @rtype: tuple
+         @return: fields is the dsc information in a dictionary form
+         '''
+         fullpath = self.poolfile.fullpath
+         fields = Dak822(open(self.poolfile.fullpath, 'r'))
+         return fields
      metadata = association_proxy('key', 'value')
  
 +    def scan_contents(self):
 +        '''
 +        Returns a set of names for non directories. The path names are
 +        normalized after converting them from either utf-8 or iso8859-1
 +        encoding.
 +        '''
 +        fullpath = self.poolfile.fullpath
 +        from daklib.contents import UnpackedSource
 +        unpacked = UnpackedSource(fullpath)
 +        fileset = set()
 +        for name in unpacked.get_all_filenames():
 +            # enforce proper utf-8 encoding
 +            try:
 +                name.decode('utf-8')
 +            except UnicodeDecodeError:
 +                name = name.decode('iso8859-1').encode('utf-8')
 +            fileset.add(name)
 +        return fileset
 +
  __all__.append('DBSource')
  
  @session_wrapper