* [gentoo-commits] proj/g-sorcery:master commit in: g_sorcery/, g_elpa/, tests/, g_elpa/data/
@ 2013-07-04 21:26 Jauhien Piatlicki
0 siblings, 0 replies; only message in thread
From: Jauhien Piatlicki @ 2013-07-04 21:26 UTC (permalink / raw
To: gentoo-commits
commit: 3981c9bea9b4ddb464051e50f4d5357d0159072e
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Thu Jul 4 21:27:30 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Thu Jul 4 21:27:30 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=3981c9be
ebuild generation for ELPA backend added, different fixes in ebuild generator
---
g_elpa/data/ebuild_without_digest.tmpl | 22 +++++
g_elpa/data/g-elpa.eclass | 84 +++++++++++++++++
g_elpa/ebuild.py | 28 ++++++
g_elpa/elpa_db.py | 7 +-
g_elpa/fileutils.py | 26 ++++++
g_sorcery/ebuild.py | 38 ++++----
tests/test_ebuild.py | 5 +-
tests/test_elpa_db.py | 160 ++++++++++++++++++---------------
tests/test_elpa_ebuild.py | 58 ++++++++++++
9 files changed, 334 insertions(+), 94 deletions(-)
diff --git a/g_elpa/data/ebuild_without_digest.tmpl b/g_elpa/data/ebuild_without_digest.tmpl
new file mode 100644
index 0000000..985c406
--- /dev/null
+++ b/g_elpa/data/ebuild_without_digest.tmpl
@@ -0,0 +1,22 @@
+# automatically generated by g-elpa
+# please do not edit this file
+
+EAPI=5
+
+inherit g-elpa
+
+DESCRIPTION="$description"
+HOMEPAGE="$homepage"
+SRC_URI=""
+LICENSE="GPL-2"
+
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+IUSE=""
+
+REPO_URI="$repo_uri"
+PKG_TYPE="$source_type"
+REALNAME="$realname"
+
+DEPEND="#n#depend#"
+RDEPEND="#n#rdepend#"
diff --git a/g_elpa/data/g-elpa.eclass b/g_elpa/data/g-elpa.eclass
new file mode 100644
index 0000000..de52313
--- /dev/null
+++ b/g_elpa/data/g-elpa.eclass
@@ -0,0 +1,84 @@
+# Copyright 1999-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+# automatically generated by g-elpa
+# please do not edit this file
+#
+# Original Author: Jauhien Piatlicki <piatlicki@gmail.com>
+# Purpose: support installation of elisp packages for emacs
+# from overlays generated by g-elpa
+#
+# Bugs to piatlicki@gmail.com
+#
+# @ECLASS: g-elpa.eclass
+#
+# @ECLASS-VARIABLE: REPO_URI
+# @DESCRIPTION: address of a repository of elisp packages
+#
+# @ECLASS-VARIABLE: PKG_TYPE
+# @DESCRIPTION: type of a package (single or tar)
+#
+# @ECLASS-VARIABLE: DIGEST_SOURCES
+# @DESCRIPTION: whether manifest for sources exists
+#
+# @ECLASS-VARIABLE: REALNAME
+# @DESCRIPTION: real name of a package in the repository
+#
+# @ECLASS-VARIABLE: GELPA_STORE_DIR
+# @DESCRIPTION: store location for downloaded sources
+GELPA_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}"
+#
+# @ECLASS-VARIABLE: GELPA_FETCH_CMD
+# @DESCRIPTION: fetch command
+GELPA_FETCH_CMD="wget"
+
+inherit elisp
+
+if [ x${DIGEST_SOURCES} = x]; then
+ EXPORT_FUNCTIONS src_{compile,install}
+else
+ EXPORT_FUNCTIONS src_{unpack,compile,install}
+fi
+
+g-elpa_fetch() {
+ if [[ ${PKG_TYPE} != "single" ]]; then
+ SUFFIX="${PKG_TYPE}"
+ else
+ SUFFIX="el"
+ fi
+ addwrite "${GELPA_STORE_DIR}"
+ pushd "${GELPA_STORE_DIR}" >/dev/null || die "can't chdir to ${GELPA_STORE_DIR}"
+ local SOURCEFILE=${REALNAME}-${PV}.${SUFFIX}
+ if [[ ! -f "${SOURCEFILE}" ]]; then
+ $GELPA_FETCH_CMD ${REPO_URI}${SOURCEFILE} || die
+ fi
+ cp ${SOURCEFILE} ${DISTDIR}/${P}.${SUFFIX} || die
+ popd >/dev/null || die
+}
+
+g-elpa_src_unpack() {
+ g-elpa_fetch
+ if [[ ${PKG_TYPE} != "single" ]]; then
+ unpack ${P}.${PKG_TYPE}
+ else
+ cp ${DISTDIR}/${P}.el . || die
+ fi
+ elisp_src_unpack || die
+}
+
+g-elpa_src_compile() {
+ rm -f ${PN}-pkg.el || die
+ elisp-make-autoload-file || die
+ elisp_src_compile || die
+}
+
+g-elpa_src_install() {
+ local sitefile="50${PN}-gentoo.el"
+ cat <<EOF >> ${sitefile} || die
+(add-to-list 'load-path "@SITELISP@")
+(load "${PN}-autoloads" nil t)
+EOF
+ elisp-site-file-install ${sitefile} || die
+ rm -f ${sitefile} || die
+ elisp_src_install || die
+}
diff --git a/g_elpa/ebuild.py b/g_elpa/ebuild.py
new file mode 100644
index 0000000..8e20ee3
--- /dev/null
+++ b/g_elpa/ebuild.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+ ebuild.py
+ ~~~~~~~~~~~~~
+
+ ebuild generation
+
+ :copyright: (c) 2013 by Jauhien Piatlicki
+ :license: GPL-2, see LICENSE for more details.
+"""
+
+import os
+
+from g_sorcery.ebuild import EbuildGeneratorFromFile
+
+from .fileutils import get_pkgpath
+
+class ElpaEbuildWithDigestGenerator(EbuildGeneratorFromFile):
+ def __init__(self, package_db):
+ name = os.path.join(get_pkgpath(), 'data/ebuild_with_digest.tmpl')
+ super(ElpaEbuildWithDigestGenerator, self).__init__(package_db, filename = name)
+
+class ElpaEbuildWithoutDigestGenerator(EbuildGeneratorFromFile):
+ def __init__(self, package_db):
+ name = os.path.join(get_pkgpath(), 'data/ebuild_without_digest.tmpl')
+ super(ElpaEbuildWithoutDigestGenerator, self).__init__(package_db, filename = name)
diff --git a/g_elpa/elpa_db.py b/g_elpa/elpa_db.py
index 89c2d91..d5dcc2d 100644
--- a/g_elpa/elpa_db.py
+++ b/g_elpa/elpa_db.py
@@ -57,15 +57,18 @@ class ElpaDB(PackageDB):
description = desc[2]
deps = desc[1]
dependencies = []
+ depend = []
realname = entry[0].value()
for dep in deps:
dep_pkg = self._s_get_package(dep[0], dep[1])
dependencies.append(dep_pkg)
+ depend.append(dep_pkg.category + '/' + dep_pkg.name + '-' + dep_pkg.version)
properties = {'source_type' : source_type,
'description' : description,
- 'depend' : dependencies,
- 'rdepend' : dependencies,
+ 'dependencies' : dependencies,
+ 'depend' : depend,
+ 'rdepend' : depend,
'homepage' : self.repo_uri,
'repo_uri' : self.repo_uri,
'realname' : realname
diff --git a/g_elpa/fileutils.py b/g_elpa/fileutils.py
new file mode 100644
index 0000000..685ef2f
--- /dev/null
+++ b/g_elpa/fileutils.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+ fileutils.py
+ ~~~~~~~~~~~~
+
+ file utilities
+
+ :copyright: (c) 2013 by Jauhien Piatlicki
+ :license: GPL-2, see LICENSE for more details.
+"""
+
+import os
+
+def get_pkgpath():
+ """
+ Get package path.
+
+ Returns:
+ Package path.
+ """
+ root = __file__
+ if os.path.islink(root):
+ root = os.path.realpath(root)
+ return os.path.dirname(os.path.abspath(root))
diff --git a/g_sorcery/ebuild.py b/g_sorcery/ebuild.py
index 2737577..cc8e4f6 100644
--- a/g_sorcery/ebuild.py
+++ b/g_sorcery/ebuild.py
@@ -17,7 +17,7 @@ import string
from .exceptions import DescriptionError
-def substitute_list(text, values):
+def substitute_list(string, values):
"""
Performs the template substitution. Variables are
substituted by lists.
@@ -31,28 +31,26 @@ def substitute_list(text, values):
name: Key in values dict.
Args:
- text: List with template strings.
+ text: Template string.
values: Dictionary with values.
"""
- result = copy.deepcopy(text)
regex = re.compile('#[n ]#\w+#')
- for idx, line in enumerate(result):
- match = regex.search(line)
- if not match:
- continue
- 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[idx] = regex.sub(repl, line)
+ 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
diff --git a/tests/test_ebuild.py b/tests/test_ebuild.py
index 6a97249..47c4e40 100644
--- a/tests/test_ebuild.py
+++ b/tests/test_ebuild.py
@@ -89,8 +89,9 @@ class TestSubstituteList(BaseTest):
desc = {'depend' : ['app-test/test1', 'app-test/test2'],
'iuse' : ['test', 'check']}
result = ['a', 'test', 'DEPEND="app-test/test1\napp-test/test2"', 'IUSE="test check"']
- self.assertEqual(ebuild.substitute_list(text, desc), result)
- self.assertRaises(exceptions.DescriptionError, ebuild.substitute_list, text, {})
+ for idx, string in enumerate(text):
+ self.assertEqual(ebuild.substitute_list(string, desc), result[idx])
+ self.assertRaises(exceptions.DescriptionError, ebuild.substitute_list, text[2], {})
def suite():
diff --git a/tests/test_elpa_db.py b/tests/test_elpa_db.py
index 1ba99c7..ec50b14 100644
--- a/tests/test_elpa_db.py
+++ b/tests/test_elpa_db.py
@@ -11,7 +11,9 @@
:license: GPL-2, see LICENSE for more details.
"""
-import os, unittest
+import os
+
+import unittest
from g_elpa import elpa_db
@@ -21,76 +23,90 @@ from tests.server import Server
from tests.base import BaseTest
+def generate_archive_contents(packages):
+ archive_contents = "(1"
+ for pkg in packages:
+ archive_contents += "\n(" + pkg[0] + ' . [('
+ for v in pkg[1]:
+ archive_contents += ' ' + str(v)
+ archive_contents += ')\n'
+ if pkg[4]:
+ archive_contents += '('
+ for p in pkg[4]:
+ archive_contents += '(' + p[0] + ' ('
+ for v in p[1]:
+ archive_contents += ' ' + str(v)
+ archive_contents += '))\n'
+ archive_contents += ')'
+ else:
+ archive_contents += 'nil'
+ archive_contents += '\n "' + pkg[2] + '" ' + pkg[3] + '])'
+ archive_contents += ')'
+ return archive_contents
+
+packages = [['ack', [1, 2],
+ "Interface to ack-like source code search tools",
+ "tar",
+ []
+ ],
+ ['dict-tree', [0, 12, 8],
+ "Dictionary data structure",
+ "tar",
+ [['trie', [0, 2, 5]],
+ ['tNFA', [0, 1, 1]],
+ ['heap', [0, 3]]]
+ ],
+ ['tNFA', [0, 1, 1],
+ "Tagged non-deterministic finite-state automata",
+ "single",
+ [['queue', [0, 1]]]
+ ],
+ ['trie', [0, 2, 6],
+ "Trie data structure",
+ "single",
+ [['tNFA', [0, 1, 1]],
+ ['queue', [0, 1]]]
+ ],
+ ['heap', [0, 3],
+ "Heap (a.k.a. priority queue) data structure",
+ "single",
+ []
+ ],
+ ['queue', [0, 1],
+ "Queue data structure",
+ "single",
+ []
+ ]
+ ]
+
+def fill_database(database, packages, tempdir):
+ prev = os.getcwd()
+ os.chdir(tempdir)
+
+ archive_contents = generate_archive_contents(packages)
+
+ with open(os.path.join(tempdir, 'archive-contents'), 'w') as f:
+ f.write(archive_contents)
+
+ server = Server()
+ server.start()
+
+ database.generate()
+
+ server.shutdown()
+ server.join()
+
+ os.chdir(prev)
+
+
class TestElpaDB(BaseTest):
def test_generate(self):
- prev = os.getcwd()
- os.chdir(self.tempdir.name)
edb = elpa_db.ElpaDB(os.path.join(self.tempdir.name, 'db'),
repo_uri = 'http://127.0.0.1:8080')
self.assertRaises(exceptions.SyncError, edb.generate)
- packages = [['ack', [1, 2],
- "Interface to ack-like source code search tools",
- "tar",
- []
- ],
- ['dict-tree', [0, 12, 8],
- "Dictionary data structure",
- "tar",
- [['trie', [0, 2, 5]],
- ['tNFA', [0, 1, 1]],
- ['heap', [0, 3]]]
- ],
- ['tNFA', [0, 1, 1],
- "Tagged non-deterministic finite-state automata",
- "single",
- [['queue', [0, 1]]]
- ],
- ['trie', [0, 2, 6],
- "Trie data structure",
- "single",
- [['tNFA', [0, 1, 1]],
- ['queue', [0, 1]]]
- ],
- ['heap', [0, 3],
- "Heap (a.k.a. priority queue) data structure",
- "single",
- []
- ],
- ['queue', [0, 1],
- "Queue data structure",
- "single",
- []
- ]
- ]
-
- archive_contents = "(1"
- for pkg in packages:
- archive_contents += "\n(" + pkg[0] + ' . [('
- for v in pkg[1]:
- archive_contents += ' ' + str(v)
- archive_contents += ')\n'
- if pkg[4]:
- archive_contents += '('
- for p in pkg[4]:
- archive_contents += '(' + p[0] + ' ('
- for v in p[1]:
- archive_contents += ' ' + str(v)
- archive_contents += '))\n'
- archive_contents += ')'
- else:
- archive_contents += 'nil'
- archive_contents += '\n "' + pkg[2] + '" ' + pkg[3] + '])'
- archive_contents += ')'
-
- with open(os.path.join(self.tempdir.name, 'archive-contents'), 'w') as f:
- f.write(archive_contents)
-
- server = Server()
- server.start()
-
- edb.generate()
+ fill_database(edb, packages, self.tempdir.name)
for pkg in packages:
package = package_db.Package('app-emacs',
@@ -100,21 +116,25 @@ class TestElpaDB(BaseTest):
self.assertEqual(description['source_type'], pkg[3])
self.assertEqual(description['description'], pkg[2])
deps = []
+ depend=[]
for d in pkg[4]:
deps.append(package_db.Package('app-emacs',
d[0],
'.'.join(map(str, d[1]))))
+ depend.append('app-emacs' + '/' + d[0] + '-' + '.'.join(map(str, d[1])))
+
+ dependencies = description['dependencies']
+ for d in dependencies:
+ self.assertTrue(d in deps)
+ for d in deps:
+ self.assertTrue(d in dependencies)
for ds in (description['depend'], description['rdepend']):
for d in ds:
- self.assertTrue(d in deps)
- for d in deps:
+ self.assertTrue(d in depend)
+ for d in depend:
self.assertTrue(d in ds)
-
- server.shutdown()
- server.join()
- os.chdir(prev)
def suite():
suite = unittest.TestSuite()
diff --git a/tests/test_elpa_ebuild.py b/tests/test_elpa_ebuild.py
new file mode 100644
index 0000000..2c7cdf5
--- /dev/null
+++ b/tests/test_elpa_ebuild.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+ test_elpa_ebuild.py
+ ~~~~~~~~~~~~~~~~~~~
+
+ ELPA ebuild generator test suite
+
+ :copyright: (c) 2013 by Jauhien Piatlicki
+ :license: GPL-2, see LICENSE for more details.
+"""
+
+import os, unittest
+
+from g_sorcery import package_db
+
+from g_elpa import elpa_db, ebuild
+
+from tests.base import BaseTest
+
+from tests.test_elpa_db import fill_database, packages
+
+class TestElpaEbuildGenerator(BaseTest):
+
+ def test_generate(self):
+ edb = elpa_db.ElpaDB(os.path.join(self.tempdir.name, 'db'),
+ repo_uri = 'http://127.0.0.1:8080')
+ fill_database(edb, packages, self.tempdir.name)
+ ebuild_generator = ebuild.ElpaEbuildWithoutDigestGenerator(edb)
+ src = ebuild_generator.generate(package_db.Package('app-emacs', 'ack', '1.2'))
+ self.assertEqual(src,
+ ['# automatically generated by g-elpa',
+ '# please do not edit this file', '',
+ 'EAPI=5', '', 'inherit g-elpa', '',
+ 'DESCRIPTION="Interface to ack-like source code search tools"',
+ 'HOMEPAGE="http://127.0.0.1:8080"', 'SRC_URI=""',
+ 'LICENSE="GPL-2"', '', 'SLOT="0"', 'KEYWORDS="~amd64 ~x86"',
+ 'IUSE=""', '', 'REPO_URI="http://127.0.0.1:8080"',
+ 'PKG_TYPE="tar"', 'REALNAME="ack"', '', 'DEPEND=""', 'RDEPEND=""'])
+ src = ebuild_generator.generate(package_db.Package('app-emacs', 'dict-tree', '0.12.8'))
+ self.assertEqual(src,
+ ['# automatically generated by g-elpa',
+ '# please do not edit this file', '', 'EAPI=5', '',
+ 'inherit g-elpa', '', 'DESCRIPTION="Dictionary data structure"',
+ 'HOMEPAGE="http://127.0.0.1:8080"', 'SRC_URI=""',
+ 'LICENSE="GPL-2"', '', 'SLOT="0"',
+ 'KEYWORDS="~amd64 ~x86"', 'IUSE=""', '',
+ 'REPO_URI="http://127.0.0.1:8080"', 'PKG_TYPE="tar"',
+ 'REALNAME="dict-tree"', '',
+ 'DEPEND="app-emacs/trie-0.2.5\napp-emacs/tNFA-0.1.1\napp-emacs/heap-0.3"',
+ 'RDEPEND="app-emacs/trie-0.2.5\napp-emacs/tNFA-0.1.1\napp-emacs/heap-0.3"'])
+
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(TestElpaEbuildGenerator('test_generate'))
+ return suite
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2013-07-04 21:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-04 21:26 [gentoo-commits] proj/g-sorcery:master commit in: g_sorcery/, g_elpa/, tests/, g_elpa/data/ Jauhien Piatlicki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox