public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/g-sorcery:master commit in: g_sorcery/, g_elpa/, g_elpa/data/
@ 2013-07-13 14:50 Jauhien Piatlicki
  0 siblings, 0 replies; 3+ messages in thread
From: Jauhien Piatlicki @ 2013-07-13 14:50 UTC (permalink / raw
  To: gentoo-commits

commit:     185b2d04ab606fc34297a85234cf0dcf67ad2016
Author:     Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Sat Jul 13 14:42:44 2013 +0000
Commit:     Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Sat Jul 13 14:42:44 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=185b2d04

ebuild string substitution modified as suggested by Brian Dolbec

---
 g_elpa/data/ebuild_with_digest.tmpl    | 16 +++++-----
 g_elpa/data/ebuild_without_digest.tmpl | 14 ++++-----
 g_elpa/elpa_db.py                      |  3 +-
 g_sorcery/backend.py                   |  4 +--
 g_sorcery/collections.py               | 47 +++++++++++++++++++++++++++++
 g_sorcery/ebuild.py                    | 54 ++++++----------------------------
 g_sorcery/fileutils.py                 | 31 ++++++++++++++++++-
 g_sorcery/package_db.py                | 20 ++++++++-----
 8 files changed, 117 insertions(+), 72 deletions(-)

diff --git a/g_elpa/data/ebuild_with_digest.tmpl b/g_elpa/data/ebuild_with_digest.tmpl
index 6d599e6..4a77430 100644
--- a/g_elpa/data/ebuild_with_digest.tmpl
+++ b/g_elpa/data/ebuild_with_digest.tmpl
@@ -3,21 +3,21 @@
 
 EAPI=5
 
-REPO_URI="$repo_uri"
-PKG_TYPE="$source_type"
-REALNAME="$realname"
+REPO_URI="%(repo_uri)s"
+PKG_TYPE="%(source_type)s"
+REALNAME="%(realname)s"
 DIGEST_SOURCES="yes"
 
 inherit g-elpa
 
-DESCRIPTION="$description"
-HOMEPAGE="$homepage"
-SRC_URI="$${REPO_URI}$${REALNAME}-$${PV}.$${SUFFIX}"
+DESCRIPTION="%(description)s"
+HOMEPAGE="%(homepage)s"
+SRC_URI="${REPO_URI}${REALNAME}-${PV}.${SUFFIX}"
 LICENSE="GPL-2"
 
 SLOT="0"
 KEYWORDS="~amd64 ~x86"
 IUSE=""
 
-DEPEND="#n#depend#"
-RDEPEND="#n#rdepend#"
+DEPEND="%(depend)s"
+RDEPEND="%(rdepend)s"

diff --git a/g_elpa/data/ebuild_without_digest.tmpl b/g_elpa/data/ebuild_without_digest.tmpl
index 6c0a895..37f709f 100644
--- a/g_elpa/data/ebuild_without_digest.tmpl
+++ b/g_elpa/data/ebuild_without_digest.tmpl
@@ -3,14 +3,14 @@
 
 EAPI=5
 
-REPO_URI="$repo_uri"
-PKG_TYPE="$source_type"
-REALNAME="$realname"
+REPO_URI="%(repo_uri)s"
+PKG_TYPE="%(source_type)s"
+REALNAME="%(realname)s"
 
 inherit g-elpa
 
-DESCRIPTION="$description"
-HOMEPAGE="$homepage"
+DESCRIPTION="%(description)s"
+HOMEPAGE="%(homepage)s"
 SRC_URI=""
 LICENSE="GPL-2"
 
@@ -18,5 +18,5 @@ SLOT="0"
 KEYWORDS="~amd64 ~x86"
 IUSE=""
 
-DEPEND="#n#depend#"
-RDEPEND="#n#rdepend#"
+DEPEND="%(depend)s"
+RDEPEND="%(rdepend)s"

diff --git a/g_elpa/elpa_db.py b/g_elpa/elpa_db.py
index 070d830..59f30a1 100644
--- a/g_elpa/elpa_db.py
+++ b/g_elpa/elpa_db.py
@@ -22,7 +22,8 @@ if py2k:
 else:
     from urllib.parse import urljoin
 
-from g_sorcery.package_db import Package, PackageDB
+from g_sorcery.collections import Package
+from g_sorcery.package_db import PackageDB
 from g_sorcery.fileutils import wget
 from g_sorcery.exceptions import SyncError
 

diff --git a/g_sorcery/backend.py b/g_sorcery/backend.py
index dbb509d..65d7e90 100644
--- a/g_sorcery/backend.py
+++ b/g_sorcery/backend.py
@@ -16,7 +16,7 @@ import glob
 import os
 import sys
 
-from .package_db import Package
+from .collections import Package
 from .exceptions import DependencyError, DigestError
 
 class Backend(object):
@@ -263,7 +263,7 @@ class Backend(object):
         dependencies = desc["dependencies"]
         for pkg in dependencies:
             solved_deps, unsolved_deps = self.solve_dependencies(package_db,
-                                                                 Package(pkg[0], pkg[1], pkg[2]),
+                                                                 pkg,
                                                                  solved_deps, unsolved_deps)
         
         solved_deps.add(package)

diff --git a/g_sorcery/collections.py b/g_sorcery/collections.py
new file mode 100644
index 0000000..abc1c14
--- /dev/null
+++ b/g_sorcery/collections.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+    collections.py
+    ~~~~~~~~~~~~~~
+    
+    Customized classes of standard python data types
+    for use withing g-sorcery for custom formatted string output
+    substitution in our ebuild templates.
+    
+    :copyright: (c) 2013 by Brian Dolbec
+    :copyright: (c) 2013 by Jauhien Piatlicki
+    :license: GPL-2, see LICENSE for more details.
+"""
+
+import collections
+
+class elist(list):
+    '''Custom list type which adds a customized __str__()
+    and takes an optional separator argument
+
+    elist() -> new empty elist
+    elist(iterable) -> new elist initialized from iterable's items
+    elist(separator='\\n\\t') -> new empty elist with
+        newline & tab indented str(x) output
+    elist(iterable, ' ') -> new elist initialized from iterable's items
+        with space separated str(x) output
+    '''
+
+    __slots__ = ('_sep_')
+
+    def __init__(self, iterable=None, separator=' '):
+        '''
+        iterable: initialize from iterable's items
+        separator: string used to join list members with for __str__()
+        '''
+        list.__init__(self, iterable or [])
+        self._sep_ = separator
+
+    def __str__(self):
+        '''Custom output function
+        'x.__str__() <==> str(separator.join(x))'
+        '''
+        return self._sep_.join(self)
+
+Package = collections.namedtuple("Package", "category name version")

diff --git a/g_sorcery/ebuild.py b/g_sorcery/ebuild.py
index cc8e4f6..dd552aa 100644
--- a/g_sorcery/ebuild.py
+++ b/g_sorcery/ebuild.py
@@ -11,48 +11,7 @@
     :license: GPL-2, see LICENSE for more details.
 """
 
-import copy
-import re
-import string
-
-from .exceptions import DescriptionError
-
-def substitute_list(string, values):
-    """
-    Performs the template substitution. Variables are
-    substituted by lists.
-
-    Variable format.
-    ~~~~~~~~~~~~~~~~
-
-    #[n ]#name#
-    'n': Separate list entries with '\n'.
-    ' ': Separate list entries with ' '.
-    name: Key in values dict.
-
-    Args:
-        text: Template string.
-        values: Dictionary with values.
-    """
-    regex = re.compile('#[n ]#\w+#')
-    match = regex.search(string)
-    if not match:
-        return string
-    group = match.group()
-    new_line = (group[1] == 'n')
-    key = group[3:-1]
-    if not key in values:
-        error = "missing key: " + key
-        raise DescriptionError(error)
-    lst = values[key]
-    if new_line:
-        sep = '\n'
-    else:
-        sep = ' '
-    repl = sep.join(lst)
-    result = regex.sub(repl, string)
-    return result
-
+from .exceptions import DependencyError
 
 class EbuildGenerator(object):
     """
@@ -95,9 +54,14 @@ class EbuildGenerator(object):
         """
         result = []
         for line in ebuild:
-            tmpl = string.Template(line)
-            line = tmpl.substitute(description)
-            line = substitute_list(line, description)
+            error = ""
+            try:
+                line = line % description
+            except ValueError as e:
+                error = str(e)
+            if error:
+                error = "sunstitution failed in line '" + line + "': " + error
+                raise DependencyError(error)
             result.append(line)
             
         return result

diff --git a/g_sorcery/fileutils.py b/g_sorcery/fileutils.py
index 659df41..72b2355 100644
--- a/g_sorcery/fileutils.py
+++ b/g_sorcery/fileutils.py
@@ -14,22 +14,25 @@
 import json, os, shutil
 
 from .exceptions import FileJSONError
+from .collections import Package, elist
 
 class FileJSON(object):
     """
     Class for JSON files.
     """
-    def __init__(self, directory, name, mandatories):
+    def __init__(self, directory, name, mandatories, loadconv=None):
         """
         Args:
             directory: File directory.
             name: File name.
             mandatories: List of requiered keys.
+            loadconv: Type change values on loading.
         """
         self.directory = os.path.abspath(directory)
         self.name = name
         self.path = os.path.join(directory, name)
         self.mandatories = mandatories
+        self.loadconv = loadconv
 
     def read(self):
         """
@@ -49,6 +52,12 @@ class FileJSON(object):
             for key in self.mandatories:
                 if not key in content:
                     raise FileJSONError('lack of mandatory key: ' + key)
+                
+        if self.loadconv:
+            for key, conv in self.loadconv.items():
+                if key in content:
+                    content[key] = conv(content[key])
+        
         return content
 
     def write(self, content):
@@ -63,6 +72,26 @@ class FileJSON(object):
         with open(self.path, 'w') as f:
             json.dump(content, f, indent=2, sort_keys=True)
 
+            
+def package_conv(lst):
+    return Package(lst[0], lst[1], lst[2])
+
+def dependencies_conv(dependencies):
+    result = []
+    for dependency in dependencies:
+        result.append(package_conv(dependency))
+    return result
+
+def depend_conv(depend):
+    return elist(depend, separator='\n\t')
+            
+class FilePkgDesc(FileJSON):
+    def __init__(self, directory, name, mandatories):
+        loadconv = {'dependencies' : dependencies_conv,
+                    'depend' : depend_conv,
+                    'rdepend' : depend_conv}
+        super(FilePkgDesc, self).__init__(directory, name, mandatories, loadconv)
+
 
 def hash_file(name, hasher, blocksize=65536):
     """

diff --git a/g_sorcery/package_db.py b/g_sorcery/package_db.py
index f7ab3f8..4e0b46a 100644
--- a/g_sorcery/package_db.py
+++ b/g_sorcery/package_db.py
@@ -11,18 +11,22 @@
     :license: GPL-2, see LICENSE for more details.
 """
 
+import glob
+import hashlib
+import os
+import shutil
+import tarfile
+
+import portage
+
 from .compatibility import TemporaryDirectory
 
 from .exceptions import DBStructureError, IntegrityError, \
      InvalidKeyError, SyncError
 
-from .fileutils import FileJSON, hash_file, copy_all, wget
-
-import portage
-
-import collections, glob, hashlib, os, shutil, tarfile
+from .fileutils import FileJSON, FilePkgDesc, hash_file, copy_all, wget
 
-Package = collections.namedtuple("Package", "category name version")
+from .collections import Package
 
 class PackageDB(object):
     """
@@ -242,7 +246,7 @@ class PackageDB(object):
             if not category or (not category in self.categories):
                 raise DBStructureError('Non existent: ' + category)
             for version, content in versions.items():
-                f = FileJSON(os.path.join(self.directory, category, name),
+                f = FilePkgDesc(os.path.join(self.directory, category, name),
                     version + '.json', [])
                 f.write(content)
                 self.additional_write_version(category, name, version)
@@ -323,7 +327,7 @@ class PackageDB(object):
                 pkgname = category + '/' + name
                 self.database[pkgname] = {}
                 for version in versions:
-                    f = FileJSON(package_path, version + '.json', [])
+                    f = FilePkgDesc(package_path, version + '.json', [])
                     description = f.read()
                     self.database[pkgname][version] = description
                     self.additional_read_version(category, name, version)


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/g-sorcery:master commit in: g_sorcery/, g_elpa/, g_elpa/data/
@ 2013-07-16 21:59 Jauhien Piatlicki
  0 siblings, 0 replies; 3+ messages in thread
From: Jauhien Piatlicki @ 2013-07-16 21:59 UTC (permalink / raw
  To: gentoo-commits

commit:     21e5d5a2fdcb646decd1577bd10db76199e1c09c
Author:     Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Tue Jul 16 21:59:34 2013 +0000
Commit:     Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Tue Jul 16 21:59:34 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=21e5d5a2

better template generation

---
 g_elpa/data/ebuild_with_digest.tmpl    | 23 -------------
 g_elpa/data/ebuild_without_digest.tmpl | 22 -------------
 g_elpa/ebuild.py                       | 45 +++++++++++++++++++++----
 g_sorcery/ebuild.py                    | 60 ++++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+), 52 deletions(-)

diff --git a/g_elpa/data/ebuild_with_digest.tmpl b/g_elpa/data/ebuild_with_digest.tmpl
deleted file mode 100644
index 4a77430..0000000
--- a/g_elpa/data/ebuild_with_digest.tmpl
+++ /dev/null
@@ -1,23 +0,0 @@
-# automatically generated by g-elpa
-# please do not edit this file
-
-EAPI=5
-
-REPO_URI="%(repo_uri)s"
-PKG_TYPE="%(source_type)s"
-REALNAME="%(realname)s"
-DIGEST_SOURCES="yes"
-
-inherit g-elpa
-
-DESCRIPTION="%(description)s"
-HOMEPAGE="%(homepage)s"
-SRC_URI="${REPO_URI}${REALNAME}-${PV}.${SUFFIX}"
-LICENSE="GPL-2"
-
-SLOT="0"
-KEYWORDS="~amd64 ~x86"
-IUSE=""
-
-DEPEND="%(depend)s"
-RDEPEND="%(rdepend)s"

diff --git a/g_elpa/data/ebuild_without_digest.tmpl b/g_elpa/data/ebuild_without_digest.tmpl
deleted file mode 100644
index 37f709f..0000000
--- a/g_elpa/data/ebuild_without_digest.tmpl
+++ /dev/null
@@ -1,22 +0,0 @@
-# automatically generated by g-elpa
-# please do not edit this file
-
-EAPI=5
-
-REPO_URI="%(repo_uri)s"
-PKG_TYPE="%(source_type)s"
-REALNAME="%(realname)s"
-
-inherit g-elpa
-
-DESCRIPTION="%(description)s"
-HOMEPAGE="%(homepage)s"
-SRC_URI=""
-LICENSE="GPL-2"
-
-SLOT="0"
-KEYWORDS="~amd64 ~x86"
-IUSE=""
-
-DEPEND="%(depend)s"
-RDEPEND="%(rdepend)s"

diff --git a/g_elpa/ebuild.py b/g_elpa/ebuild.py
index a9df7ed..cdb6bd7 100644
--- a/g_elpa/ebuild.py
+++ b/g_elpa/ebuild.py
@@ -11,17 +11,48 @@
     :license: GPL-2, see LICENSE for more details.
 """
 
+import collections
 import os
 
-from g_sorcery.ebuild import EbuildGeneratorFromFile
+from g_sorcery.ebuild import DefaultEbuildGenerator
 from g_sorcery.fileutils import get_pkgpath
 
-class ElpaEbuildWithDigestGenerator(EbuildGeneratorFromFile):
+Layout = collections.namedtuple("Layout",
+    ["vars_before_inherit", "inherit", "vars_after_description", "vars_after_keywords"])
+  
+
+class ElpaEbuildWithDigestGenerator(DefaultEbuildGenerator):
     def __init__(self, package_db):
-        name = os.path.join(get_pkgpath(__file__), 'data/ebuild_with_digest.tmpl')
-        super(ElpaEbuildWithDigestGenerator, self).__init__(package_db, filename = name)
 
-class ElpaEbuildWithoutDigestGenerator(EbuildGeneratorFromFile):
+        vars_before_inherit = \
+          ["repo_uri", "source_type", "realname", ("digest_sources", "yes")]
+
+        inherit = ["g-elpa"]
+        
+        vars_after_description = \
+          ["homepage", ("src_uri", "${REPO_URI}${REALNAME}-${PV}.${SUFFIX}")]
+
+        vars_after_keywords = \
+          ["depend", "rdepend"]
+
+        layout = Layout(vars_before_inherit, inherit, vars_after_description, vars_after_keywords)
+
+        super(ElpaEbuildWithDigestGenerator, self).__init__(package_db, layout)
+
+class ElpaEbuildWithoutDigestGenerator(DefaultEbuildGenerator):
     def __init__(self, package_db):
-        name = os.path.join(get_pkgpath(__file__), 'data/ebuild_without_digest.tmpl')
-        super(ElpaEbuildWithoutDigestGenerator, self).__init__(package_db, filename = name)
+
+        vars_before_inherit = \
+          ["repo_uri", "source_type", "realname", ("digest_sources", "yes")]
+
+        inherit = ["g-elpa"]
+        
+        vars_after_description = \
+          ["homepage"]
+
+        vars_after_keywords = \
+          ["depend", "rdepend"]
+
+        layout = Layout(vars_before_inherit, inherit, vars_after_description, vars_after_keywords)
+
+        super(ElpaEbuildWithoutDigestGenerator, self).__init__(package_db, layout)

diff --git a/g_sorcery/ebuild.py b/g_sorcery/ebuild.py
index c1f9116..6fbc7cb 100644
--- a/g_sorcery/ebuild.py
+++ b/g_sorcery/ebuild.py
@@ -38,11 +38,15 @@ class EbuildGenerator(object):
         #a possible exception should be catched in the caller
         if not ebuild_data:
             ebuild_data = self.package_db.get_package_description(package)
+        ebuild_data = self.process_ebuild_data(ebuild_data)
         ebuild = self.get_template(package, ebuild_data)
         ebuild = self.process(ebuild, ebuild_data)
         ebuild = self.postprocess(ebuild, ebuild_data)
         return ebuild
 
+    def process_ebuild_data(self, ebuild_data):
+        return ebuild_data
+
     def process(self, ebuild, ebuild_data):
         """
         Fill ebuild tamplate with data.
@@ -133,3 +137,59 @@ class EbuildGeneratorFromFile(EbuildGenerator):
             Template filename.
         """
         return self.filename
+
+
+class DefaultEbuildGenerator(EbuildGenerator):
+    def __init__(self, package_db, layout):
+        super(DefaultEbuildGenerator, self).__init__(package_db)
+        self.template = ["# automatically generated by g-elpa",
+                         "# please do not edit this file",
+                         ""]
+
+        if hasattr(layout, "eapi"):
+            self.template.append("EAPI=%s" % layout.eapi)
+        else:
+            self.template.append("EAPI=5")
+        self.template.append("")
+
+        if hasattr(layout, "vars_before_inherit"):
+            self._append_vars_to_tamplate(layout.vars_before_inherit)
+            self.template.append("")
+
+        if hasattr(layout, "inherit"):
+            self.template.append("inherit " + " ".join(layout.inherit))
+            self.template.append("")
+
+        if hasattr(layout, "vars_after_inherit"):
+            self._append_vars_to_tamplate(layout.vars_after_inherit)
+            self.template.append("")
+
+        self.template.append('DESCRIPTION="%(description)s"')
+        self.template.append("")
+
+        if hasattr(layout, "vars_after_description"):
+            self._append_vars_to_tamplate(layout.vars_after_description)
+            self.template.append("")
+
+        self.template.append('SLOT="0"')
+        self.template.append('KEYWORDS="~amd64 ~x86"')
+        self.template.append("")
+
+        if hasattr(layout, "vars_after_keywords"):
+            self._append_vars_to_tamplate(layout.vars_after_keywords)
+            self.template.append("")
+        
+
+    def _append_vars_to_tamplate(self, variables):
+        VAR_NAME = 0
+        VAR_VALUE = 1
+
+        for var in variables:
+            if isinstance(var, basestring):
+                self.template.append(var.upper() + '="%(' + var + ')s"')
+            else:
+                self.template.append(var[VAR_NAME].upper() + '="' + var[VAR_VALUE] + '"')
+
+
+    def get_template(self, package, ebuild_data):
+        return self.template


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/g-sorcery:master commit in: g_sorcery/, g_elpa/, g_elpa/data/
@ 2013-07-16 23:09 Jauhien Piatlicki
  0 siblings, 0 replies; 3+ messages in thread
From: Jauhien Piatlicki @ 2013-07-16 23:09 UTC (permalink / raw
  To: gentoo-commits

commit:     cb6cd5ed08df4b5bbb8fb14d131fa0540edc3f69
Author:     Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Tue Jul 16 21:59:34 2013 +0000
Commit:     Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Tue Jul 16 21:59:34 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=cb6cd5ed

better template generation

---
 g_elpa/data/ebuild_with_digest.tmpl    | 23 -------------
 g_elpa/data/ebuild_without_digest.tmpl | 22 -------------
 g_elpa/ebuild.py                       | 45 +++++++++++++++++++++----
 g_sorcery/ebuild.py                    | 60 ++++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+), 52 deletions(-)

diff --git a/g_elpa/data/ebuild_with_digest.tmpl b/g_elpa/data/ebuild_with_digest.tmpl
deleted file mode 100644
index 4a77430..0000000
--- a/g_elpa/data/ebuild_with_digest.tmpl
+++ /dev/null
@@ -1,23 +0,0 @@
-# automatically generated by g-elpa
-# please do not edit this file
-
-EAPI=5
-
-REPO_URI="%(repo_uri)s"
-PKG_TYPE="%(source_type)s"
-REALNAME="%(realname)s"
-DIGEST_SOURCES="yes"
-
-inherit g-elpa
-
-DESCRIPTION="%(description)s"
-HOMEPAGE="%(homepage)s"
-SRC_URI="${REPO_URI}${REALNAME}-${PV}.${SUFFIX}"
-LICENSE="GPL-2"
-
-SLOT="0"
-KEYWORDS="~amd64 ~x86"
-IUSE=""
-
-DEPEND="%(depend)s"
-RDEPEND="%(rdepend)s"

diff --git a/g_elpa/data/ebuild_without_digest.tmpl b/g_elpa/data/ebuild_without_digest.tmpl
deleted file mode 100644
index 37f709f..0000000
--- a/g_elpa/data/ebuild_without_digest.tmpl
+++ /dev/null
@@ -1,22 +0,0 @@
-# automatically generated by g-elpa
-# please do not edit this file
-
-EAPI=5
-
-REPO_URI="%(repo_uri)s"
-PKG_TYPE="%(source_type)s"
-REALNAME="%(realname)s"
-
-inherit g-elpa
-
-DESCRIPTION="%(description)s"
-HOMEPAGE="%(homepage)s"
-SRC_URI=""
-LICENSE="GPL-2"
-
-SLOT="0"
-KEYWORDS="~amd64 ~x86"
-IUSE=""
-
-DEPEND="%(depend)s"
-RDEPEND="%(rdepend)s"

diff --git a/g_elpa/ebuild.py b/g_elpa/ebuild.py
index a9df7ed..cdb6bd7 100644
--- a/g_elpa/ebuild.py
+++ b/g_elpa/ebuild.py
@@ -11,17 +11,48 @@
     :license: GPL-2, see LICENSE for more details.
 """
 
+import collections
 import os
 
-from g_sorcery.ebuild import EbuildGeneratorFromFile
+from g_sorcery.ebuild import DefaultEbuildGenerator
 from g_sorcery.fileutils import get_pkgpath
 
-class ElpaEbuildWithDigestGenerator(EbuildGeneratorFromFile):
+Layout = collections.namedtuple("Layout",
+    ["vars_before_inherit", "inherit", "vars_after_description", "vars_after_keywords"])
+  
+
+class ElpaEbuildWithDigestGenerator(DefaultEbuildGenerator):
     def __init__(self, package_db):
-        name = os.path.join(get_pkgpath(__file__), 'data/ebuild_with_digest.tmpl')
-        super(ElpaEbuildWithDigestGenerator, self).__init__(package_db, filename = name)
 
-class ElpaEbuildWithoutDigestGenerator(EbuildGeneratorFromFile):
+        vars_before_inherit = \
+          ["repo_uri", "source_type", "realname", ("digest_sources", "yes")]
+
+        inherit = ["g-elpa"]
+        
+        vars_after_description = \
+          ["homepage", ("src_uri", "${REPO_URI}${REALNAME}-${PV}.${SUFFIX}")]
+
+        vars_after_keywords = \
+          ["depend", "rdepend"]
+
+        layout = Layout(vars_before_inherit, inherit, vars_after_description, vars_after_keywords)
+
+        super(ElpaEbuildWithDigestGenerator, self).__init__(package_db, layout)
+
+class ElpaEbuildWithoutDigestGenerator(DefaultEbuildGenerator):
     def __init__(self, package_db):
-        name = os.path.join(get_pkgpath(__file__), 'data/ebuild_without_digest.tmpl')
-        super(ElpaEbuildWithoutDigestGenerator, self).__init__(package_db, filename = name)
+
+        vars_before_inherit = \
+          ["repo_uri", "source_type", "realname", ("digest_sources", "yes")]
+
+        inherit = ["g-elpa"]
+        
+        vars_after_description = \
+          ["homepage"]
+
+        vars_after_keywords = \
+          ["depend", "rdepend"]
+
+        layout = Layout(vars_before_inherit, inherit, vars_after_description, vars_after_keywords)
+
+        super(ElpaEbuildWithoutDigestGenerator, self).__init__(package_db, layout)

diff --git a/g_sorcery/ebuild.py b/g_sorcery/ebuild.py
index c1f9116..6fbc7cb 100644
--- a/g_sorcery/ebuild.py
+++ b/g_sorcery/ebuild.py
@@ -38,11 +38,15 @@ class EbuildGenerator(object):
         #a possible exception should be catched in the caller
         if not ebuild_data:
             ebuild_data = self.package_db.get_package_description(package)
+        ebuild_data = self.process_ebuild_data(ebuild_data)
         ebuild = self.get_template(package, ebuild_data)
         ebuild = self.process(ebuild, ebuild_data)
         ebuild = self.postprocess(ebuild, ebuild_data)
         return ebuild
 
+    def process_ebuild_data(self, ebuild_data):
+        return ebuild_data
+
     def process(self, ebuild, ebuild_data):
         """
         Fill ebuild tamplate with data.
@@ -133,3 +137,59 @@ class EbuildGeneratorFromFile(EbuildGenerator):
             Template filename.
         """
         return self.filename
+
+
+class DefaultEbuildGenerator(EbuildGenerator):
+    def __init__(self, package_db, layout):
+        super(DefaultEbuildGenerator, self).__init__(package_db)
+        self.template = ["# automatically generated by g-elpa",
+                         "# please do not edit this file",
+                         ""]
+
+        if hasattr(layout, "eapi"):
+            self.template.append("EAPI=%s" % layout.eapi)
+        else:
+            self.template.append("EAPI=5")
+        self.template.append("")
+
+        if hasattr(layout, "vars_before_inherit"):
+            self._append_vars_to_tamplate(layout.vars_before_inherit)
+            self.template.append("")
+
+        if hasattr(layout, "inherit"):
+            self.template.append("inherit " + " ".join(layout.inherit))
+            self.template.append("")
+
+        if hasattr(layout, "vars_after_inherit"):
+            self._append_vars_to_tamplate(layout.vars_after_inherit)
+            self.template.append("")
+
+        self.template.append('DESCRIPTION="%(description)s"')
+        self.template.append("")
+
+        if hasattr(layout, "vars_after_description"):
+            self._append_vars_to_tamplate(layout.vars_after_description)
+            self.template.append("")
+
+        self.template.append('SLOT="0"')
+        self.template.append('KEYWORDS="~amd64 ~x86"')
+        self.template.append("")
+
+        if hasattr(layout, "vars_after_keywords"):
+            self._append_vars_to_tamplate(layout.vars_after_keywords)
+            self.template.append("")
+        
+
+    def _append_vars_to_tamplate(self, variables):
+        VAR_NAME = 0
+        VAR_VALUE = 1
+
+        for var in variables:
+            if isinstance(var, basestring):
+                self.template.append(var.upper() + '="%(' + var + ')s"')
+            else:
+                self.template.append(var[VAR_NAME].upper() + '="' + var[VAR_VALUE] + '"')
+
+
+    def get_template(self, package, ebuild_data):
+        return self.template


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-07-16 23:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-16 23:09 [gentoo-commits] proj/g-sorcery:master commit in: g_sorcery/, g_elpa/, g_elpa/data/ Jauhien Piatlicki
  -- strict thread matches above, loose matches on Subject: below --
2013-07-16 21:59 Jauhien Piatlicki
2013-07-13 14:50 Jauhien Piatlicki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox