s = DBConn().session()
- # for binary in s.query(DBBinary).all() ):
- binary = s.query(DBBinary).first()
- if binary:
+ for binary in s.query(DBBinary).all() ):
filename = binary.poolfile.filename
# Check for existing contents
existingq = s.execute( "select 1 from bin_contents where binary_id=:id", {'id':binary.binary_id} );
################################################################################
-class BinContents(object):
- def __init__(self, *args, **kwargs):
- pass
-
- def __repr__(self):
- return '<BinContents (%s, %s)>' % (self.binary, self.filename)
-
-__all__.append('BinContents')
-
-################################################################################
-
class DBBinary(object):
def __init__(self, *args, **kwargs):
pass
################################################################################
+class ContentFilename(object):
+ def __init__(self, *args, **kwargs):
+ pass
+
+ def __repr__(self):
+ return '<ContentFilename %s>' % self.filename
+
+__all__.append('ContentFilename')
+
@session_wrapper
def get_or_set_contents_file_id(filename, session=None):
"""
for fullpath in fullpaths:
if fullpath.startswith( './' ):
fullpath = fullpath[2:]
-
+
session.execute( "INSERT INTO bin_contents ( file, binary_id ) VALUES ( :filename, :id )", { 'filename': fullpath, 'id': binary_id} )
session.commit()
binary_id = self.tbl_bin_associations.c.bin,
binary = relation(DBBinary)))
-
mapper(DBBinary, self.tbl_binaries,
properties = dict(binary_id = self.tbl_binaries.c.id,
package = self.tbl_binaries.c.package,
mapper(DBConfig, self.tbl_config,
properties = dict(config_id = self.tbl_config.c.id))
+ mapper(ContentAssociation, self.tbl_content_associations,
+ properties = dict(ca_id = self.tbl_content_associations.c.id,
+ filename_id = self.tbl_content_associations.c.filename,
+ filename = relation(ContentFilename),
+ filepath_id = self.tbl_content_associations.c.filepath,
+ filepath = relation(ContentFilepath),
+ binary_id = self.tbl_content_associations.c.binary_pkg,
+ binary = relation(DBBinary)))
+
+
+ mapper(ContentFilename, self.tbl_content_file_names,
+ properties = dict(cafilename_id = self.tbl_content_file_names.c.id,
+ filename = self.tbl_content_file_names.c.file))
+
+ mapper(ContentFilepath, self.tbl_content_file_paths,
+ properties = dict(cafilepath_id = self.tbl_content_file_paths.c.id,
+ filepath = self.tbl_content_file_paths.c.path))
+
mapper(DSCFile, self.tbl_dsc_files,
properties = dict(dscfile_id = self.tbl_dsc_files.c.id,
source_id = self.tbl_dsc_files.c.source,
properties = dict(overridetype = self.tbl_override_type.c.type,
overridetype_id = self.tbl_override_type.c.id))
+ mapper(PendingContentAssociation, self.tbl_pending_content_associations,
+ properties = dict(pca_id = self.tbl_pending_content_associations.c.id,
+ filepath_id = self.tbl_pending_content_associations.c.filepath,
+ filepath = relation(ContentFilepath),
+ filename_id = self.tbl_pending_content_associations.c.filename,
+ filename = relation(ContentFilename)))
+
mapper(Priority, self.tbl_priority,
properties = dict(priority_id = self.tbl_priority.c.id))
--- /dev/null
+from regexes import re_verwithext
+from dak_exceptions import UnknownFormatError
+
+def parse_format(txt):
+ """
+ Parse a .changes Format string into a tuple representation for easy
+ comparison.
+
+ >>> parse_format('1.0')
+ (1, 0)
+ >>> parse_format('8.4 (hardy)')
+ (8, 4, 'hardy')
+
+ If the format doesn't match these forms, raises UnknownFormatError.
+ """
+
+ format = re_verwithext.search(txt)
+
+ if format is None:
+ raise UnknownFormatError, txt
+
+ format = format.groups()
+
+ if format[1] is None:
+ format = int(float(format[0])), 0, format[2]
+ else:
+ format = int(format[0]), int(format[1]), format[2]
+
+ if format[2] is None:
+ format = format[:2]
+
+ return format
+
+def validate_changes_format(format, field):
+ """
+ Validate a tuple-representation of a .changes Format: field. Raises
+ UnknownFormatError if the field is invalid, otherwise return type is
+ undefined.
+ """
+
+ if (format < (1, 5) or format > (1, 8)):
+ raise UnknownFormatError, repr(format)
+
+ if field != 'files' and format < (1, 8):
+ raise UnknownFormatError, repr(format)
import re
-from regexes import re_verwithext
from dak_exceptions import UnknownFormatError
srcformats = []
raise UnknownFormatError, "Unknown format %r" % txt
-def parse_format(txt):
- """
- Parse a .changes Format string into a tuple representation for easy
- comparison.
-
- >>> parse_format('1.0')
- (1, 0)
- >>> parse_format('8.4 (hardy)')
- (8, 4, 'hardy')
-
- If the format doesn't match these forms, raises UnknownFormatError.
- """
-
- format = re_verwithext.search(txt)
-
- if format is None:
- raise UnknownFormatError, txt
-
- format = format.groups()
-
- if format[1] is None:
- format = int(float(format[0])), 0, format[2]
- else:
- format = int(format[0]), int(format[1]), format[2]
-
- if format[2] is None:
- format = format[:2]
-
- return format
-
class SourceFormat(type):
def __new__(cls, name, bases, attrs):
klass = super(SourceFormat, cls).__new__(cls, name, bases, attrs)
if has[key]:
yield "contains source files not allowed in format %s" % cls.name
- @classmethod
- def validate_format(cls, format, is_a_dsc=False, field='files'):
- """
- Raises UnknownFormatError if the specified format tuple is not valid for
- this format (for example, the format (1, 0) is not valid for the
- "3.0 (quilt)" format). Return value is undefined in all other cases.
- """
- pass
-
class FormatOne(SourceFormat):
__metaclass__ = SourceFormat
for msg in super(FormatOne, cls).reject_msgs(has):
yield msg
- @classmethod
- def validate_format(cls, format, is_a_dsc=False, field='files'):
- msg = "Invalid format %s definition: %r" % (cls.name, format)
-
- if is_a_dsc:
- if format != (1, 0):
- raise UnknownFormatError, msg
- else:
- if (format < (1,5) or format > (1,8)):
- raise UnknownFormatError, msg
- if field != "files" and format < (1,8):
- raise UnknownFormatError, msg
-
class FormatThree(SourceFormat):
__metaclass__ = SourceFormat
requires = ('native_tar',)
disallowed = ('orig_tar', 'debian_diff', 'debian_tar', 'more_orig_tar')
- @classmethod
- def validate_format(cls, format, **kwargs):
- if format != (3, 0, 'native'):
- raise UnknownFormatError, "Invalid format %s definition: %r" % \
- (cls.name, format)
-
class FormatThreeQuilt(SourceFormat):
__metaclass__ = SourceFormat
requires = ('orig_tar', 'debian_tar')
disallowed = ('debian_diff', 'native_tar')
-
- @classmethod
- def validate_format(cls, format, **kwargs):
- if format != (3, 0, 'quilt'):
- raise UnknownFormatError, "Invalid format %s definition: %r" % \
- (cls.name, format)
re_gpg_uid, re_re_mark, re_whitespace_comment, re_issource, \
re_is_orig_source
+from formats import parse_format, validate_changes_format
from srcformats import get_format_from_string
from collections import defaultdict
if not changes.has_key(field):
raise NoFilesFieldError
- # Get SourceFormat object for this Format and validate it
- format = get_format_from_string(changes['format'])
- format.validate_format(is_a_dsc=is_a_dsc, field=field)
+ # Validate .changes Format: field
+ validate_changes_format(parse_format(changes['format']), field)
includes_section = (not is_a_dsc) and field == "files"
Cnf = apt_pkg.newConfiguration()
apt_pkg.ReadConfigFileISC(Cnf,default_config)
-#if which_conf_file() != default_config:
-# apt_pkg.ReadConfigFileISC(Cnf,which_conf_file())
+if which_conf_file() != default_config:
+ apt_pkg.ReadConfigFileISC(Cnf,which_conf_file())
###############################################################################
--- /dev/null
+#!/usr/bin/env python
+
+import unittest
+
+import os, sys
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+from daklib.formats import parse_format, validate_changes_format
+from daklib.dak_exceptions import UnknownFormatError
+
+class ParseFormatTestCase(unittest.TestCase):
+ def assertParse(self, format, expected):
+ self.assertEqual(parse_format(format), expected)
+
+ def assertParseFail(self, format):
+ self.assertRaises(
+ UnknownFormatError,
+ lambda: parse_format(format)
+ )
+
+ def testParse(self):
+ self.assertParse('1.0', (1, 0))
+
+ def testEmpty(self):
+ self.assertParseFail('')
+ self.assertParseFail(' ')
+ self.assertParseFail(' ')
+
+ def textText(self):
+ self.assertParse('1.2 (three)', (1, 2, 'three'))
+ self.assertParseFail('0.0 ()')
+
+class ValidateChangesFormat(unittest.TestCase):
+ def assertValid(self, changes, field='files'):
+ validate_changes_format(changes, field)
+
+ def assertInvalid(self, *args, **kwargs):
+ self.assertRaises(
+ UnknownFormatError,
+ lambda: self.assertValid(*args, **kwargs)
+ )
+
+ ##
+
+ def testBinary(self):
+ self.assertValid((1, 5))
+ self.assertValid((1, 8))
+ self.assertInvalid((1, 0))
+
+ def testRange(self):
+ self.assertInvalid((1, 3))
+ self.assertValid((1, 5))
+ self.assertValid((1, 8))
+ self.assertInvalid((1, 9))
+
+ def testFilesField(self):
+ self.assertInvalid((1, 7), field='notfiles')
+ self.assertValid((1, 8), field='notfiles')
from collections import defaultdict
from daklib import srcformats
+from daklib.formats import parse_format
from daklib.dak_exceptions import UnknownFormatError
class SourceFormatTestCase(unittest.TestCase):
'native_tar': 1,
})
-##
-
-class ParseFormatTestCase(unittest.TestCase):
- def assertParse(self, format, expected):
- self.assertEqual(srcformats.parse_format(format), expected)
-
- def assertParseFail(self, format):
- self.assertRaises(
- UnknownFormatError,
- lambda: srcformats.parse_format(format)
- )
-
- def testParse(self):
- self.assertParse('1.0', (1, 0))
-
- def testEmpty(self):
- self.assertParseFail('')
- self.assertParseFail(' ')
- self.assertParseFail(' ')
-
- def textText(self):
- self.assertParse('1.2 (three)', (1, 2, 'three'))
- self.assertParseFail('0.0 ()')
-
-class ValidateFormatTestCase(unittest.TestCase):
- def assertValid(self, format, **kwargs):
- kwargs['is_a_dsc'] = kwargs.get('is_a_dsc', True)
- self.fmt.validate_format(format, **kwargs)
-
- def assertInvalid(self, *args, **kwargs):
- self.assertRaises(
- UnknownFormatError,
- lambda: self.assertValid(*args, **kwargs),
- )
-
-class ValidateFormatOneTestCase(ValidateFormatTestCase):
- fmt = srcformats.FormatOne
-
- def testValid(self):
- self.assertValid((1, 0))
-
- def testInvalid(self):
- self.assertInvalid((0, 1))
- self.assertInvalid((3, 0, 'quilt'))
-
- ##
-
- def testBinary(self):
- self.assertValid((1, 5), is_a_dsc=False)
- self.assertInvalid((1, 0), is_a_dsc=False)
-
- def testRange(self):
- self.assertInvalid((1, 3), is_a_dsc=False)
- self.assertValid((1, 5), is_a_dsc=False)
- self.assertValid((1, 8), is_a_dsc=False)
- self.assertInvalid((1, 9), is_a_dsc=False)
-
- def testFilesField(self):
- self.assertInvalid((1, 7), is_a_dsc=False, field='notfiles')
- self.assertValid((1, 8), is_a_dsc=False, field='notfiles')
-
-class ValidateFormatThreeTestCase(ValidateFormatTestCase):
- fmt = srcformats.FormatThree
-
- def testValid(self):
- self.assertValid((3, 0, 'native'))
-
- def testInvalid(self):
- self.assertInvalid((1, 0))
- self.assertInvalid((0, 0))
- self.assertInvalid((3, 0, 'quilt'))
-
-class ValidateFormatThreeQuiltTestCase(ValidateFormatTestCase):
- fmt = srcformats.FormatThreeQuilt
-
- def testValid(self):
- self.assertValid((3, 0, 'quilt'))
-
- def testInvalid(self):
- self.assertInvalid((1, 0))
- self.assertInvalid((0, 0))
- self.assertInvalid((3, 0, 'native'))
-
class FormatFromStringTestCase(unittest.TestCase):
def assertFormat(self, txt, klass):
self.assertEqual(srcformats.get_format_from_string(txt), klass)