[library-web] [modtypes] new create_from_tar constructor



commit 6cf6daa87bb5b9f37b9354420b4f08891e95d532
Author: Frédéric Péters <fpeters 0d be>
Date:   Sat Aug 8 14:02:28 2009 +0200

    [modtypes] new create_from_tar constructor
    
    This will allow to create alternate constructors that do not depend on the
    module coming from a source tarball.

 src/lgo.py                |   10 +++++-----
 src/modtypes/base.py      |    7 +++++--
 src/modtypes/htmlfiles.py |    6 ++++--
 3 files changed, 14 insertions(+), 9 deletions(-)
---
diff --git a/src/lgo.py b/src/lgo.py
index 36f20b1..5ec080f 100755
--- a/src/lgo.py
+++ b/src/lgo.py
@@ -414,19 +414,19 @@ class Lgo(App):
                 makefile_am = makefile_am.replace('\\\n', ' ')
                 if 'DOC_ID' in makefile_am and regex_gdu.findall(makefile_am):
                     logging.debug('found usage of mallard in %s' % tarinfo.name)
-                    doc = MallardModule(tar, tarinfo, makefile_am, nightly)
+                    doc = MallardModule.create_from_tar(tar, tarinfo, makefile_am, nightly)
                 elif 'DOC_MODULE' in makefile_am and regex_gdu.findall(makefile_am):
                     logging.debug('found usage of docbook in %s' % tarinfo.name)
-                    doc = GnomeDocbookModule(tar, tarinfo, makefile_am, nightly)
+                    doc = GnomeDocbookModule.create_from_tar(tar, tarinfo, makefile_am, nightly)
                 elif 'include $(top_srcdir)/gtk-doc.make' in makefile_am or \
                         ('gtkdoc-scan' in makefile_am and not 'gtk-doc' in tarinfo.name):
                     logging.debug('found usage of gtk-doc in %s' % tarinfo.name)
-                    doc = GtkDocModule(tar, tarinfo, makefile_am, nightly)
+                    doc = GtkDocModule.create_from_tar(tar, tarinfo, makefile_am, nightly)
                 elif 'SUBDIRS = C' in makefile_am and \
                         os.path.basename(filename).startswith('gtk-doc-'):
                     logging.debug('found gtk-doc almost gnome-doc-utils manual in %s' % tarinfo.name)
                     makefile_am += '\nDOC_MODULE = gtk-doc-manual\n'
-                    doc = GnomeDocbookModule(tar, tarinfo, makefile_am, nightly)
+                    doc = GnomeDocbookModule.create_from_tar(tar, tarinfo, makefile_am, nightly)
                 else:
                     continue
 
@@ -439,7 +439,7 @@ class Lgo(App):
                             more_tarball_docs.remove(more_doc)
                             continue
                     if tarinfo.name.endswith(more_doc.attrib.get('dir')):
-                        doc = HtmlFilesModule(tar, tarinfo, more_doc)
+                        doc = HtmlFilesModule.create_from_tar(tar, tarinfo, more_doc)
                         more_tarball_docs.remove(more_doc)
                         continue
 
diff --git a/src/modtypes/base.py b/src/modtypes/base.py
index f839e17..3759821 100644
--- a/src/modtypes/base.py
+++ b/src/modtypes/base.py
@@ -27,7 +27,7 @@ from utils import version_cmp, is_version_number
 licence_modules = ['fdl', 'gpl', 'lgpl']
 
 
-class DocModule:
+class DocModule(object):
     '''Base class for documentation shipped in tarballs'''
     makefile_am = None
 
@@ -40,7 +40,8 @@ class DocModule:
 
     nightly = False
 
-    def __init__(self, tar, tarinfo, makefile_am, nightly = False):
+    def create_from_tar(cls, tar, tarinfo, makefile_am, nightly = False):
+        self = cls()
         self.dirname = os.path.dirname(tarinfo.name)
         if makefile_am:
             self.makefile_am = makefile_am
@@ -72,6 +73,8 @@ class DocModule:
             self.mtime_xslt_files = max([os.stat(
                         os.path.join(data_dir, 'xslt', x))[stat.ST_MTIME] \
                         for x in self.related_xsl_files])
+        return self
+    create_from_tar = classmethod(create_from_tar)
 
     def extract(self):
         ext_dirname = os.path.join(app.config.private_dir, 'extracts')
diff --git a/src/modtypes/htmlfiles.py b/src/modtypes/htmlfiles.py
index 481b2c1..a81aca1 100644
--- a/src/modtypes/htmlfiles.py
+++ b/src/modtypes/htmlfiles.py
@@ -38,12 +38,14 @@ class HtmlFilesModule(DocModule):
 
     related_xsl_files = ['html2html.xsl', 'heading.xsl']
 
-    def __init__(self, tar, tarinfo, tarball_doc_elem):
-        DocModule.__init__(self, tar, tarinfo, None, False)
+    def create_from_tar(cls, tar, tarinfo, tarball_doc_elem):
+        self = super(HtmlFilesModule, cls).create_from_tar(tar, tarinfo, None)
         self.tarball_doc_elem = tarball_doc_elem
         self.modulename = self.tarball_doc_elem.attrib.get('doc_module')
         if self.tarball_doc_elem.find('transform-mode') is not None:
             self.transform_mode = self.tarball_doc_elem.find('transform-mode').text
+        return self
+    create_from_tar = classmethod(create_from_tar)
 
     def setup_channel(self):
         self.channel = self.tarball_doc_elem.attrib.get('channel')



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]