]> git.decadent.org.uk Git - dak.git/commitdiff
merge from master
authorMike O'Connor <stew@dhcp-101.dfw1.kickstart.lan>
Sat, 31 Oct 2009 09:52:22 +0000 (09:52 +0000)
committerMike O'Connor <stew@dhcp-101.dfw1.kickstart.lan>
Sat, 31 Oct 2009 09:52:22 +0000 (09:52 +0000)
dak/contents.py
dak/dakdb/update17.py
dak/update_db.py
daklib/config.py
daklib/formats.py [new file with mode: 0644]
daklib/srcformats.py
daklib/utils.py
tests/test_formats.py [new file with mode: 0755]
tests/test_srcformats.py

index 9c9161d181233fa1ca83adf398e4645a0638d2d7..4211e98e1122fd6f5aee8201e75a109b9d15cd7b 100755 (executable)
@@ -92,7 +92,6 @@ log = logging.getLogger()
 
 ################################################################################
 
-
 class EndOfContents(object):
     """
     A sentry object for the end of the filename stream
index 0d7efa9efec6c77e325aaa4c885e1766477452d4..b5bbb3cce22bd805cdfc92a39bc1a55caf7438c9 100644 (file)
@@ -52,6 +52,9 @@ def do_update(self):
 
         c.execute("""CREATE INDEX ind_bin_contents_binary ON bin_contents(binary_id);""" )
 
+        c.execute("GRANT ALL ON bin_contents TO ftpmaster;")
+        c.execute("GRANT SELECT ON bin_contents TO public;")
+
         self.db.commit()
 
     except psycopg2.ProgrammingError, msg:
index 7d7fe9fe596a91082d816d77f8490e1661967c96..88d8e4e66e6425e91a6501c5c09af21a8e395b5a 100755 (executable)
@@ -107,10 +107,9 @@ Updates dak's database schema to the lastest version. You should disable crontab
 
         try:
             # Build a connect string
-#            connect_str = "dbname=%s"% (Cnf["DB::Name"])
-            connect_str = "dbname=%s"% "projectbstew"
-#            if Cnf["DB::Host"] != '': connect_str += " host=%s" % (Cnf["DB::Host"])
-#            if Cnf["DB::Port"] != '-1': connect_str += " port=%d" % (int(Cnf["DB::Port"]))
+            connect_str = "dbname=%s"% (Cnf["DB::Name"])
+            if Cnf["DB::Host"] != '': connect_str += " host=%s" % (Cnf["DB::Host"])
+            if Cnf["DB::Port"] != '-1': connect_str += " port=%d" % (int(Cnf["DB::Port"]))
 
             self.db = psycopg2.connect(connect_str)
 
@@ -177,12 +176,12 @@ Updates dak's database schema to the lastest version. You should disable crontab
 
         self.update_db()
 
-#STU        try:
-#STU            lock_fd = os.open(Cnf["Dinstall::LockFile"], os.O_RDWR | os.O_CREAT)
-#STU            fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
-#STU        except IOError, e:
-#STU            if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[e.errno] == 'EAGAIN':
-#STU                utils.fubar("Couldn't obtain lock; assuming another 'dak process-unchecked' is already running.")
+        try:
+            lock_fd = os.open(Cnf["Dinstall::LockFile"], os.O_RDWR | os.O_CREAT)
+            fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
+        except IOError, e:
+            if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[e.errno] == 'EAGAIN':
+                utils.fubar("Couldn't obtain lock; assuming another 'dak process-unchecked' is already running.")
 
 
 ################################################################################
index b98a6fc9db5e926b7c4871241b22fc8855a0c683..c86c1b36580931bf81427b6f5c0bee48d1acd8df 100755 (executable)
@@ -28,6 +28,7 @@ Config access class
 
 ################################################################################
 
+import os
 import apt_pkg
 import socket
 
@@ -35,13 +36,11 @@ from singleton import Singleton
 
 ################################################################################
 
-#default_config = "/etc/dak/dak.conf"
-default_config = "/home/stew/etc/dak/dak.conf"     #: default dak config, defines host properties
+default_config = "/etc/dak/dak.conf"
 
-def which_conf_file(Cnf):
-    res = socket.gethostbyaddr(socket.gethostname())
-    if Cnf.get("Config::" + res[0] + "::DakConfig"):
-        return Cnf["Config::" + res[0] + "::DakConfig"]
+def which_conf_file():
+    if os.getenv("DAK_CONFIG"):
+        return os.getenv("DAK_CONFIG")
     else:
         return default_config
 
@@ -58,7 +57,7 @@ class Config(Singleton):
 
         self.Cnf = apt_pkg.newConfiguration()
 
-        apt_pkg.ReadConfigFileISC(self.Cnf, default_config)
+        apt_pkg.ReadConfigFileISC(self.Cnf, which_conf_file())
 
         # Check whether our dak.conf was the real one or
         # just a pointer to our main one
diff --git a/daklib/formats.py b/daklib/formats.py
new file mode 100644 (file)
index 0000000..aaad271
--- /dev/null
@@ -0,0 +1,45 @@
+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)
index ade3c45388b6a32d2e27c27d15a4a33a11e98b5a..7d7dd940e3837c1c5c99a7f8708ae3663ae53d44 100644 (file)
@@ -1,6 +1,5 @@
 import re
 
-from regexes import re_verwithext
 from dak_exceptions import UnknownFormatError
 
 srcformats = []
@@ -18,36 +17,6 @@ def get_format_from_string(txt):
 
     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)
@@ -70,15 +39,6 @@ class SourceFormat(type):
             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
 
@@ -101,19 +61,6 @@ class FormatOne(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
 
@@ -123,12 +70,6 @@ class FormatThree(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
 
@@ -137,9 +78,3 @@ class FormatThreeQuilt(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)
index ec1cd36686f8b3f943723b430f9850a1a061e2ab..accf5fdb36b9157c4ad1eb5b86dcb1bbce760e2e 100755 (executable)
@@ -48,13 +48,13 @@ from regexes import re_html_escaping, html_escaping, re_single_line_field, \
                     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
 
 ################################################################################
 
-#default_config = "/etc/dak/dak.conf"     #: default dak config, defines host properties
-default_config = "/home/stew/etc/dak/dak.conf"     #: default dak config, defines host properties
+default_config = "/etc/dak/dak.conf"     #: default dak config, defines host properties
 default_apt_config = "/etc/dak/apt.conf" #: default apt config, not normally used
 
 alias_cache = None        #: Cache for email alias checks
@@ -528,9 +528,8 @@ def build_file_list(changes, is_a_dsc=0, field="files", hashname="md5sum"):
     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"
 
@@ -711,20 +710,24 @@ def where_am_i ():
         return res[0]
 
 def which_conf_file ():
-    res = socket.gethostbyaddr(socket.gethostname())
-    # In case we allow local config files per user, try if one exists
-    if Cnf.FindB("Config::" + res[0] + "::AllowLocalConfig"):
-        homedir = os.getenv("HOME")
-        confpath = os.path.join(homedir, "/etc/dak.conf")
-        if os.path.exists(confpath):
-            apt_pkg.ReadConfigFileISC(Cnf,default_config)
-
-    # We are still in here, so there is no local config file or we do
-    # not allow local files. Do the normal stuff.
-    if Cnf.get("Config::" + res[0] + "::DakConfig"):
-        return Cnf["Config::" + res[0] + "::DakConfig"]
+    if os.getenv("DAK_CONFIG"):
+        print(os.getenv("DAK_CONFIG"))
+        return os.getenv("DAK_CONFIG")
     else:
-        return default_config
+        res = socket.gethostbyaddr(socket.gethostname())
+        # In case we allow local config files per user, try if one exists
+        if Cnf.FindB("Config::" + res[0] + "::AllowLocalConfig"):
+            homedir = os.getenv("HOME")
+            confpath = os.path.join(homedir, "/etc/dak.conf")
+            if os.path.exists(confpath):
+                apt_pkg.ReadConfigFileISC(Cnf,default_config)
+
+        # We are still in here, so there is no local config file or we do
+        # not allow local files. Do the normal stuff.
+        if Cnf.get("Config::" + res[0] + "::DakConfig"):
+            return Cnf["Config::" + res[0] + "::DakConfig"]
+        else:
+            return default_config
 
 def which_apt_conf_file ():
     res = socket.gethostbyaddr(socket.gethostname())
@@ -1505,8 +1508,8 @@ apt_pkg.init()
 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())
 
 ###############################################################################
 
diff --git a/tests/test_formats.py b/tests/test_formats.py
new file mode 100755 (executable)
index 0000000..1ae6860
--- /dev/null
@@ -0,0 +1,58 @@
+#!/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')
index f6d7215fc8daabcd179543ff59691263ccbb9d23..4ecaf8b7fcc83925238f2473ed7961714158eee2 100755 (executable)
@@ -8,6 +8,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 from collections import defaultdict
 
 from daklib import srcformats
+from daklib.formats import parse_format
 from daklib.dak_exceptions import UnknownFormatError
 
 class SourceFormatTestCase(unittest.TestCase):
@@ -103,89 +104,6 @@ class FormatTreeQuiltTestCase(SourceFormatTestCase):
             '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)