]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
Fix inclusion of macros.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 28 Jan 2012 19:40:14 +0000 (20:40 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 28 Jan 2012 19:40:14 +0000 (20:40 +0100)
python/pakfire/constants.py
python/pakfire/packages/lexer.py

index 7e3867f617fe152188565c38cb5d90a026f4eaa5..389e3b0059cb851978c64342834ed7341a8b3cd7 100644 (file)
@@ -52,8 +52,7 @@ BUFFER_SIZE = 102400
 MIRRORLIST_MAXSIZE = 1024**2
 
 MACRO_FILE_DIR = "/usr/lib/pakfire/macros"
-MACRO_FILES = \
-       (os.path.join(MACRO_FILE_DIR, f) for f in sorted(os.listdir(MACRO_FILE_DIR)) if f.endswith(".macro"))
+MACRO_EXTENSION = ".macro"
 
 METADATA_FORMAT = 0
 METADATA_DOWNLOAD_LIMIT = 1024**2
index 66d94d8d8abbe8dd19c81f87aa213b208f7ade6e..16ae0eaf2cc9483a62cd281d02f5739959904aa8 100644 (file)
@@ -4,6 +4,11 @@ import os
 import re
 
 from pakfire.constants import *
+from pakfire.i18n import _
+
+import logging
+#log = logging.getLogger("pakfire.lexer")
+log = logging.getLogger("pakfire")
 
 class LexerError(Exception):
        pass
@@ -128,6 +133,8 @@ class Lexer(object):
 
        @classmethod
        def open(cls, filename, *args, **kwargs):
+               log.debug("Opening file for parsing: %s" % filename)
+
                f = open(filename)
                lines = f.readlines()
                f.close()
@@ -688,10 +695,7 @@ class PackageLexer(TemplateLexer):
                        return None
 
                # Get template from parent.
-               try:
-                       return self.parent.templates[self._template]
-               except KeyError:
-                       raise LexerError, "Template does not exist: %s" % self._template
+               return self.parent.templates.get(self._template, None)
 
        def get_parsers(self):
                parsers = [
@@ -712,7 +716,8 @@ class PackageLexer(TemplateLexer):
                self._template = m.group(1)
 
                # Check if template exists.
-               assert self.template
+               if not self.template:
+                       log.warning(_("Template does not exist: %s") % self._template)
 
        def get_scriptlet(self, name):
                scriptlet = self.scriptlets.get(name, None)
@@ -825,12 +830,23 @@ class RootLexer(ExportLexer):
 
                # Include all macros.
                if not self.parent:
-                       for macro in MACRO_FILES:
-                               self.include(macro)
+                       self.include_macros()
+
+       def include_macros(self):
+               log.debug("Including all macros...")
+
+               for file in sorted(os.listdir(MACRO_FILE_DIR)):
+                       if not file.endswith(MACRO_EXTENSION):
+                               continue
+
+                       file = os.path.join(MACRO_FILE_DIR, file)
+                       self.include(file)
+
+       def include(self, filename):
+               log.debug("Including file: %s" % filename)
 
-       def include(self, file):
                # Create a new lexer, and parse the whole file.
-               include = RootLexer.open(file, parent=self)
+               include = RootLexer.open(filename, parent=self)
 
                # Copy all data from the included file.
                self.inherit(include)