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/
@ 2013-07-02 14:48 Jauhien Piatlicki
  0 siblings, 0 replies; 9+ messages in thread
From: Jauhien Piatlicki @ 2013-07-02 14:48 UTC (permalink / raw
  To: gentoo-commits

commit:     ff09e8f87f97a1a3ba407c8c9bea5150bdc3cb3d
Author:     Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Tue Jul  2 14:25:11 2013 +0000
Commit:     Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Tue Jul  2 14:25:11 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=ff09e8f8

py2: TemporaryDirectory

---
 g_elpa/elpa_db.py       | 4 +++-
 g_sorcery/package_db.py | 8 +++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/g_elpa/elpa_db.py b/g_elpa/elpa_db.py
index b2859dd..87e7095 100644
--- a/g_elpa/elpa_db.py
+++ b/g_elpa/elpa_db.py
@@ -15,6 +15,8 @@ import os, tempfile, urllib.parse
 
 import sexpdata
 
+from g_sorcery.compatibility import TemporaryDirectory
+
 from g_sorcery.package_db import Package, PackageDB
 from g_sorcery.fileutils import wget
 from g_sorcery.exceptions import SyncError
@@ -24,7 +26,7 @@ class ElpaDB(PackageDB):
         super(ElpaDB, self).__init__(directory, repo_uri, db_uri)
 
     def generate_tree(self):
-        tempdir = tempfile.TemporaryDirectory()
+        tempdir = TemporaryDirectory()
         
         ac_uri = urllib.parse.urljoin(self.repo_uri, 'archive-contents')
         if wget(ac_uri, tempdir.name):

diff --git a/g_sorcery/package_db.py b/g_sorcery/package_db.py
index 032c118..763ea30 100644
--- a/g_sorcery/package_db.py
+++ b/g_sorcery/package_db.py
@@ -11,6 +11,8 @@
     :license: GPL-2, see LICENSE for more details.
 """
 
+from .compatibility import TemporaryDirectory
+
 from .exceptions import DBStructureError, IntegrityError, \
      InvalidKeyError, SyncError
 
@@ -80,16 +82,16 @@ class PackageDB(object):
             self.db_uri = db_uri
         self.clean()
         real_db_uri = self.get_real_db_uri()
-        download_dir = tempfile.TemporaryDirectory()
+        download_dir = TemporaryDirectory()
         if wget(real_db_uri, download_dir.name):
             raise SyncError('sync failed: ' + real_db_uri)
         
-        temp_dir = tempfile.TemporaryDirectory()
+        temp_dir = TemporaryDirectory()
         for f_name in glob.iglob(os.path.join(download_dir.name, '*.tar.gz')):
             with tarfile.open(f_name) as f:
                 f.extractall(temp_dir.name)
 
-        tempdb_dir = tempfile.TemporaryDirectory()
+        tempdb_dir = TemporaryDirectory()
         tempdb = PackageDB(tempdb_dir.name)
 
         for d_name in os.listdir(temp_dir.name):


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

* [gentoo-commits] proj/g-sorcery:master commit in: g_sorcery/, g_elpa/
@ 2013-07-13 14:50 Jauhien Piatlicki
  0 siblings, 0 replies; 9+ messages in thread
From: Jauhien Piatlicki @ 2013-07-13 14:50 UTC (permalink / raw
  To: gentoo-commits

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

get_pkgpath modified as suggested by Brian Dolbec

---
 g_elpa/backend.py      |  5 +++--
 g_elpa/ebuild.py       |  7 +++----
 g_elpa/fileutils.py    | 14 --------------
 g_sorcery/fileutils.py |  5 +++--
 4 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/g_elpa/backend.py b/g_elpa/backend.py
index e3406ba..b77ed2e 100644
--- a/g_elpa/backend.py
+++ b/g_elpa/backend.py
@@ -16,14 +16,15 @@ import os
 from g_sorcery.backend import Backend
 from g_sorcery.metadata import MetadataGenerator
 from g_sorcery.eclass import EclassGenerator
+from g_sorcery.fileutils import get_pkgpath
 
 from .elpa_db import ElpaDB
 from .ebuild import ElpaEbuildWithDigestGenerator, ElpaEbuildWithoutDigestGenerator
-from .fileutils import get_pkgpath
+
 
 class ElpaEclassGenerator(EclassGenerator):
     def __init__(self):
-        super(ElpaEclassGenerator, self).__init__(os.path.join(get_pkgpath(), 'data'))
+        super(ElpaEclassGenerator, self).__init__(os.path.join(get_pkgpath(__file__), 'data'))
         
 
 instance = Backend(ElpaDB,

diff --git a/g_elpa/ebuild.py b/g_elpa/ebuild.py
index 8e20ee3..a9df7ed 100644
--- a/g_elpa/ebuild.py
+++ b/g_elpa/ebuild.py
@@ -14,15 +14,14 @@
 import os
 
 from g_sorcery.ebuild import EbuildGeneratorFromFile
-
-from .fileutils import get_pkgpath
+from g_sorcery.fileutils import get_pkgpath
 
 class ElpaEbuildWithDigestGenerator(EbuildGeneratorFromFile):
     def __init__(self, package_db):
-        name = os.path.join(get_pkgpath(), 'data/ebuild_with_digest.tmpl')
+        name = os.path.join(get_pkgpath(__file__), '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')
+        name = os.path.join(get_pkgpath(__file__), 'data/ebuild_without_digest.tmpl')
         super(ElpaEbuildWithoutDigestGenerator, self).__init__(package_db, filename = name)

diff --git a/g_elpa/fileutils.py b/g_elpa/fileutils.py
index 685ef2f..035274c 100644
--- a/g_elpa/fileutils.py
+++ b/g_elpa/fileutils.py
@@ -10,17 +10,3 @@
     :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/fileutils.py b/g_sorcery/fileutils.py
index 72b2355..1db9dc9 100644
--- a/g_sorcery/fileutils.py
+++ b/g_sorcery/fileutils.py
@@ -141,14 +141,15 @@ def wget(uri, directory):
     """
     return os.system('wget -P ' + directory + ' ' + uri)
 
-def get_pkgpath():
+def get_pkgpath(root = None):
     """
     Get package path.
 
     Returns:
         Package path.
     """
-    root = __file__
+    if not root:
+        root = __file__
     if os.path.islink(root):
         root = os.path.realpath(root)
     return os.path.dirname(os.path.abspath(root))


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

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

commit:     4bda8acf022c698d18edb07686d579d8a0e2cb4a
Author:     Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Sat Jul 13 15:07:12 2013 +0000
Commit:     Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Sat Jul 13 15:07:12 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=4bda8acf

g_sorcery/collections -> g_sorcery/g_collections

---
 g_elpa/elpa_db.py          |  2 +-
 g_sorcery/backend.py       |  2 +-
 g_sorcery/fileutils.py     |  2 +-
 g_sorcery/g_collections.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++
 g_sorcery/package_db.py    |  2 +-
 5 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/g_elpa/elpa_db.py b/g_elpa/elpa_db.py
index 59f30a1..82f0a3a 100644
--- a/g_elpa/elpa_db.py
+++ b/g_elpa/elpa_db.py
@@ -22,7 +22,7 @@ if py2k:
 else:
     from urllib.parse import urljoin
 
-from g_sorcery.collections import Package
+from g_sorcery.g_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 65d7e90..d077d30 100644
--- a/g_sorcery/backend.py
+++ b/g_sorcery/backend.py
@@ -16,7 +16,7 @@ import glob
 import os
 import sys
 
-from .collections import Package
+from .g_collections import Package
 from .exceptions import DependencyError, DigestError
 
 class Backend(object):

diff --git a/g_sorcery/fileutils.py b/g_sorcery/fileutils.py
index 1db9dc9..478570d 100644
--- a/g_sorcery/fileutils.py
+++ b/g_sorcery/fileutils.py
@@ -14,7 +14,7 @@
 import json, os, shutil
 
 from .exceptions import FileJSONError
-from .collections import Package, elist
+from .g_collections import Package, elist
 
 class FileJSON(object):
     """

diff --git a/g_sorcery/g_collections.py b/g_sorcery/g_collections.py
new file mode 100644
index 0000000..3ecc373
--- /dev/null
+++ b/g_sorcery/g_collections.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+    g_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/package_db.py b/g_sorcery/package_db.py
index 4e0b46a..f8155dc 100644
--- a/g_sorcery/package_db.py
+++ b/g_sorcery/package_db.py
@@ -26,7 +26,7 @@ from .exceptions import DBStructureError, IntegrityError, \
 
 from .fileutils import FileJSON, FilePkgDesc, hash_file, copy_all, wget
 
-from .collections import Package
+from .g_collections import Package
 
 class PackageDB(object):
     """


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

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

commit:     cc74cbeeaf6c465122dc6388f05cf8ebe0e43305
Author:     Jauhien Piatlicki <jpiatlicki <AT> zertisa <DOT> com>
AuthorDate: Tue Jul 16 15:01:44 2013 +0000
Commit:     Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Tue Jul 16 15:01:44 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=cc74cbee

g_sorcery/package_db: better variable name, g_elpa/elpa_db: meaningful variable names for indeces

---
 g_elpa/elpa_db.py       | 25 ++++++++++++++++++-------
 g_sorcery/package_db.py | 14 +++++++-------
 2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/g_elpa/elpa_db.py b/g_elpa/elpa_db.py
index 8a83bbc..8e0554f 100644
--- a/g_elpa/elpa_db.py
+++ b/g_elpa/elpa_db.py
@@ -50,23 +50,34 @@ class ElpaDB(PackageDB):
             raise SyncError('sync failed: ' + self.repo_uri + ' bad archive contents format')
 
         self.add_category('app-emacs')
+
+        PKG_INFO = 2
+        PKG_NAME = 0
+
+        INFO_VERSION = 0
+        INFO_DEPENDENCIES = 1
+        INFO_DESCRIPTION = 2
+        INFO_SRC_TYPE = 3
+
+        DEP_NAME = 0
+        DEP_VERSION = 1
         
         for entry in sexpdata.cdr(archive_contents):
-            desc = entry[2].value()
-            pkg = self._s_get_package(entry[0], desc[0])
-            source_type = desc[3].value()
+            desc = entry[PKG_INFO].value()
+            pkg = self._s_get_package(entry[PKG_NAME], desc[INFO_VERSION])
+            source_type = desc[INFO_SRC_TYPE].value()
 
             allowed_ords = set(range(ord('a'), ord('z'))) | set(range(ord('A'), ord('Z'))) | \
               set(range(ord('0'), ord('9'))) | set(list(map(ord,
                     ['+', '_', '-', ' ', '.', '(', ')', '[', ']', '{', '}', ','])))            
-            description = "".join([x for x in desc[2] if ord(x) in allowed_ords])
+            description = "".join([x for x in desc[INFO_DESCRIPTION] if ord(x) in allowed_ords])
             
-            deps = desc[1]
+            deps = desc[INFO_DEPENDENCIES]
             dependencies = []
             depend = []
-            realname = entry[0].value()
+            realname = entry[PKG_NAME].value()
             for dep in deps:
-                dep_pkg = self._s_get_package(dep[0], dep[1])
+                dep_pkg = self._s_get_package(dep[DEP_NAME], dep[DEP_VERSION])
                 dependencies.append(dep_pkg)
                 depend.append(dep_pkg.category + '/' + dep_pkg.name)
                 

diff --git a/g_sorcery/package_db.py b/g_sorcery/package_db.py
index b6db2ba..51a6103 100644
--- a/g_sorcery/package_db.py
+++ b/g_sorcery/package_db.py
@@ -387,8 +387,8 @@ class PackageDB(object):
                 self.database[pkgname] = {}
                 for version in versions:
                     f = FilePkgDesc(package_path, version + '.json', [])
-                    description = f.read()
-                    self.database[pkgname][version] = description
+                    ebuild_data = f.read()
+                    self.database[pkgname][version] = ebuild_data
                     self.additional_read_version(category, name, version)
                 self.additional_read_package(category, name)
             self.additional_read_category(category)
@@ -430,16 +430,16 @@ class PackageDB(object):
             description = {}
         self.categories[category] = description
 
-    def add_package(self, package, description=None):
+    def add_package(self, package, ebuild_data=None):
         """
         Add a package.
 
         Args:
             package: package_db.Package instance.
-            description: Dictionary with package description.
+            ebuild_data: Dictionary with package description.
         """
-        if not description:
-            description = {}
+        if not ebuild_data:
+            ebuild_data = {}
         category = package.category
         name = package.name
         version = package.version
@@ -448,7 +448,7 @@ class PackageDB(object):
             raise InvalidKeyError('Non-existent category: ' + category)
         if pkgname and not pkgname in self.database:
             self.database[pkgname] = {}
-        self.database[pkgname][version] = description
+        self.database[pkgname][version] = ebuild_data
 
     def list_categories(self):
         """


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

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

commit:     8aeaf9cbc7a47a33b6e216ba8521bd5f4f71d25b
Author:     Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
AuthorDate: Tue Jul 16 15:01:44 2013 +0000
Commit:     Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Tue Jul 16 15:01:44 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=8aeaf9cb

g_sorcery/package_db: better variable name, g_elpa/elpa_db: meaningful variable names for indeces

---
 g_elpa/elpa_db.py       | 25 ++++++++++++++++++-------
 g_sorcery/package_db.py | 14 +++++++-------
 2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/g_elpa/elpa_db.py b/g_elpa/elpa_db.py
index 8a83bbc..8e0554f 100644
--- a/g_elpa/elpa_db.py
+++ b/g_elpa/elpa_db.py
@@ -50,23 +50,34 @@ class ElpaDB(PackageDB):
             raise SyncError('sync failed: ' + self.repo_uri + ' bad archive contents format')
 
         self.add_category('app-emacs')
+
+        PKG_INFO = 2
+        PKG_NAME = 0
+
+        INFO_VERSION = 0
+        INFO_DEPENDENCIES = 1
+        INFO_DESCRIPTION = 2
+        INFO_SRC_TYPE = 3
+
+        DEP_NAME = 0
+        DEP_VERSION = 1
         
         for entry in sexpdata.cdr(archive_contents):
-            desc = entry[2].value()
-            pkg = self._s_get_package(entry[0], desc[0])
-            source_type = desc[3].value()
+            desc = entry[PKG_INFO].value()
+            pkg = self._s_get_package(entry[PKG_NAME], desc[INFO_VERSION])
+            source_type = desc[INFO_SRC_TYPE].value()
 
             allowed_ords = set(range(ord('a'), ord('z'))) | set(range(ord('A'), ord('Z'))) | \
               set(range(ord('0'), ord('9'))) | set(list(map(ord,
                     ['+', '_', '-', ' ', '.', '(', ')', '[', ']', '{', '}', ','])))            
-            description = "".join([x for x in desc[2] if ord(x) in allowed_ords])
+            description = "".join([x for x in desc[INFO_DESCRIPTION] if ord(x) in allowed_ords])
             
-            deps = desc[1]
+            deps = desc[INFO_DEPENDENCIES]
             dependencies = []
             depend = []
-            realname = entry[0].value()
+            realname = entry[PKG_NAME].value()
             for dep in deps:
-                dep_pkg = self._s_get_package(dep[0], dep[1])
+                dep_pkg = self._s_get_package(dep[DEP_NAME], dep[DEP_VERSION])
                 dependencies.append(dep_pkg)
                 depend.append(dep_pkg.category + '/' + dep_pkg.name)
                 

diff --git a/g_sorcery/package_db.py b/g_sorcery/package_db.py
index b6db2ba..51a6103 100644
--- a/g_sorcery/package_db.py
+++ b/g_sorcery/package_db.py
@@ -387,8 +387,8 @@ class PackageDB(object):
                 self.database[pkgname] = {}
                 for version in versions:
                     f = FilePkgDesc(package_path, version + '.json', [])
-                    description = f.read()
-                    self.database[pkgname][version] = description
+                    ebuild_data = f.read()
+                    self.database[pkgname][version] = ebuild_data
                     self.additional_read_version(category, name, version)
                 self.additional_read_package(category, name)
             self.additional_read_category(category)
@@ -430,16 +430,16 @@ class PackageDB(object):
             description = {}
         self.categories[category] = description
 
-    def add_package(self, package, description=None):
+    def add_package(self, package, ebuild_data=None):
         """
         Add a package.
 
         Args:
             package: package_db.Package instance.
-            description: Dictionary with package description.
+            ebuild_data: Dictionary with package description.
         """
-        if not description:
-            description = {}
+        if not ebuild_data:
+            ebuild_data = {}
         category = package.category
         name = package.name
         version = package.version
@@ -448,7 +448,7 @@ class PackageDB(object):
             raise InvalidKeyError('Non-existent category: ' + category)
         if pkgname and not pkgname in self.database:
             self.database[pkgname] = {}
-        self.database[pkgname][version] = description
+        self.database[pkgname][version] = ebuild_data
 
     def list_categories(self):
         """


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

* [gentoo-commits] proj/g-sorcery:master commit in: g_sorcery/, g_elpa/
@ 2013-07-17 14:42 Jauhien Piatlicki
  0 siblings, 0 replies; 9+ messages in thread
From: Jauhien Piatlicki @ 2013-07-17 14:42 UTC (permalink / raw
  To: gentoo-commits

commit:     f6c46c1d62917c81e6655b62b8630e4474ba0c8f
Author:     Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Wed Jul 17 14:42:10 2013 +0000
Commit:     Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Wed Jul 17 14:42:10 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=f6c46c1d

load remote file functionality added

---
 g_elpa/elpa_db.py       | 21 +++++++++------------
 g_sorcery/exceptions.py |  3 +++
 g_sorcery/fileutils.py  | 39 ++++++++++++++++++++++++++++++++++++++-
 3 files changed, 50 insertions(+), 13 deletions(-)

diff --git a/g_elpa/elpa_db.py b/g_elpa/elpa_db.py
index 8e0554f..c2b7865 100644
--- a/g_elpa/elpa_db.py
+++ b/g_elpa/elpa_db.py
@@ -24,28 +24,25 @@ else:
 
 from g_sorcery.g_collections import Package
 from g_sorcery.package_db import PackageDB
-from g_sorcery.fileutils import wget
+from g_sorcery.fileutils import load_remote_file
 from g_sorcery.exceptions import SyncError
 
 class ElpaDB(PackageDB):
     def __init__(self, directory, repo_uri="", db_uri=""):
         super(ElpaDB, self).__init__(directory, repo_uri, db_uri)
 
-    def generate_tree(self):
-        tempdir = TemporaryDirectory()
-        
-        ac_uri = urljoin(self.repo_uri, 'archive-contents')
-        if wget(ac_uri, tempdir.name):
-            raise SyncError('sync failed: ' + self.repo_uri)
-
+    def _load_archive_contents(self, archive_contents_f):
         try:
-            with open(os.path.join(tempdir.name, 'archive-contents')) as f:
-                archive_contents = sexpdata.load(f)
+            archive_contents = sexpdata.load(archive_contents_f)
         except Exception as e:
             raise SyncError('sync failed: ' + self.repo_uri + ': ' + str(e))
-
-        del tempdir
+        return archive_contents
         
+    def generate_tree(self):
+        ac_uri = urljoin(self.repo_uri, 'archive-contents')
+
+        archive_contents = load_remote_file(ac_uri, self._load_archive_contents)['archive-contents']
+
         if sexpdata.car(archive_contents) != 1:
             raise SyncError('sync failed: ' + self.repo_uri + ' bad archive contents format')
 

diff --git a/g_sorcery/exceptions.py b/g_sorcery/exceptions.py
index d50ca75..a8d7238 100644
--- a/g_sorcery/exceptions.py
+++ b/g_sorcery/exceptions.py
@@ -46,3 +46,6 @@ class EclassError(GSorceryError):
 
 class DigestError(GSorceryError):
     pass
+
+class DownloadingError(GSorceryError):
+    pass

diff --git a/g_sorcery/fileutils.py b/g_sorcery/fileutils.py
index d0d154a..115f330 100644
--- a/g_sorcery/fileutils.py
+++ b/g_sorcery/fileutils.py
@@ -16,8 +16,10 @@ import json
 import hashlib
 import os
 import shutil
+import tarfile
 
-from .exceptions import FileJSONError
+from .compatibility import TemporaryDirectory
+from .exceptions import FileJSONError, DownloadingError
 from .g_collections import Package, elist
 
 class FileJSON(object):
@@ -198,3 +200,38 @@ def fast_manifest(directory):
 
     with open(os.path.join(directory, "Manifest"), 'w') as f:
         f.write('\n'.join(manifest) + '\n')
+
+
+def _call_loader(f_name, loader, open_file = True, open_mode = 'r'):
+    data = None
+    if open_file:
+        with open(f_name, open_mode) as f:
+            data = loader(f)
+    else:
+        data = loader(f_name)
+    return {os.path.basename(f_name): data}
+
+
+def load_remote_file(uri, loader, open_file = True, open_mode='r',
+                     process_unpacked_as_directory = False):
+    download_dir = TemporaryDirectory()
+    loaded_data = {}
+    if wget(uri, download_dir.name):
+        raise DownloadingError("wget failed: " + uri)
+    for f_name in glob.glob(os.path.join(download_dir.name, "*")):
+        if tarfile.is_tarfile(f_name):
+            unpack_dir = TemporaryDirectory()
+            with tarfile.open(f_name) as f:
+                f.extractall(unpack_dir.name)
+            if process_unpacked_as_directory:
+                loaded_data.update(_call_loader(unpack_dir.name, loader, open_file=False))
+            else:
+                for uf_name in glob.glob(os.path.join(unpack_dir, "*")):
+                    loaded_data.update(_call_loader(uf_name, loader,
+                                    open_file=open_file, open_mode=open_mode))
+            del unpack_dir
+        else:
+            loaded_data.update(_call_loader(f_name, loader,
+                                open_file=open_file, open_mode=open_mode))
+    del download_dir
+    return loaded_data


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

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

commit:     5b431dca96a0cda390df9e3eb4650d6b4ae4ea52
Author:     Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Wed Jul 17 16:20:51 2013 +0000
Commit:     Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Wed Jul 17 16:20:51 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=5b431dca

g_sorcery/package_db: split generate_tree function

---
 g_elpa/elpa_db.py       | 10 ++++++----
 g_sorcery/package_db.py | 45 ++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 48 insertions(+), 7 deletions(-)

diff --git a/g_elpa/elpa_db.py b/g_elpa/elpa_db.py
index c55a947..6f3931c 100644
--- a/g_elpa/elpa_db.py
+++ b/g_elpa/elpa_db.py
@@ -31,12 +31,14 @@ class ElpaDB(PackageDB):
     def __init__(self, directory, repo_uri="", db_uri=""):
         super(ElpaDB, self).__init__(directory, repo_uri, db_uri)
 
-
-    def generate_tree(self):
+    def get_download_uries(self):
         ac_uri = urljoin(self.repo_uri, 'archive-contents')
+        return [{"uri" : ac_uri, "loader" : sexpdata.load}]
+
+    def parse_data(self, data):
+
+        archive_contents = data['archive-contents']
 
-        archive_contents = load_remote_file(ac_uri, sexpdata.load)['archive-contents']
-        
         if sexpdata.car(archive_contents) != 1:
             raise SyncError('sync failed: ' + self.repo_uri + ' bad archive contents format')
 

diff --git a/g_sorcery/package_db.py b/g_sorcery/package_db.py
index 51a6103..8b256e0 100644
--- a/g_sorcery/package_db.py
+++ b/g_sorcery/package_db.py
@@ -24,7 +24,7 @@ from .compatibility import py2k, TemporaryDirectory
 from .exceptions import DBStructureError, IntegrityError, \
      InvalidKeyError, SyncError
 
-from .fileutils import FileJSON, FilePkgDesc, hash_file, copy_all, wget
+from .fileutils import FileJSON, FilePkgDesc, hash_file, load_remote_file, copy_all, wget
 
 from .g_collections import Package
 
@@ -175,11 +175,50 @@ class PackageDB(object):
     def generate_tree(self):
         """
         Generate tree
-
-        Should be implemented in a subclass
         """
+        data = self.download_data()
+        self.parse_data(data)
+
+    def load_data(self):
         pass
 
+    def parse_data(data):
+        pass
+
+    def get_download_uries(self):
+        pass
+
+    def decode_download_uries(self, uries):
+        decoded = []
+        for uri in uries:
+            decuri = {}
+            if isinstance(uri, basestring):
+                decuri["uri"] = uri
+                decuri["loader"] = self.load_data
+                decuri["open_file"] = True
+                decuri["open_mode"] = "r"
+                decuri["process_unpacked_as_directory"] = False
+            else:
+                decuri = uri
+                if not "loader" in decuri:
+                    decuri["loader"] = self.load_data
+                if not "open_file" in decuri:
+                    decuri["open_file"] = True
+                if not "open_mode" in decuri:
+                    decuri["open_mode"] = "r"
+                if not "process_unpacked_as_directory" in decuri:
+                    decuri["process_unpacked_as_directory"] = False
+            decoded.append(decuri)
+        return decoded
+        
+    def download_data(self):
+        uries = self.get_download_uries()
+        uries = self.decode_download_uries(uries)
+        data = {}
+        for uri in uries:
+            data.update(load_remote_file(**uri))
+        return data
+
     def sync(self, db_uri=""):
         """
         Synchronize local database with remote database.


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

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

commit:     8f36770c8386a8315a13f047d3742339237f47c5
Author:     Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Thu Jul 18 17:06:47 2013 +0000
Commit:     Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Thu Jul 18 17:06:47 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=8f36770c

new mechanism fro JSON serialization

---
 g_elpa/elpa_db.py          |  4 +--
 g_sorcery/fileutils.py     | 36 ++++---------------------
 g_sorcery/g_collections.py | 66 +++++++++++++++++++++++++++++++++++++++++++++-
 g_sorcery/package_db.py    |  6 ++---
 g_sorcery/serialization.py | 39 +++++++++++++++++++++++++++
 5 files changed, 114 insertions(+), 37 deletions(-)

diff --git a/g_elpa/elpa_db.py b/g_elpa/elpa_db.py
index 149cbe5..16d7f1f 100644
--- a/g_elpa/elpa_db.py
+++ b/g_elpa/elpa_db.py
@@ -22,7 +22,7 @@ if py2k:
 else:
     from urllib.parse import urljoin
 
-from g_sorcery.g_collections import Package
+from g_sorcery.g_collections import Package, serializable_elist
 from g_sorcery.package_db import PackageDB
 from g_sorcery.fileutils import load_remote_file
 from g_sorcery.exceptions import SyncError
@@ -67,7 +67,7 @@ class ElpaDB(PackageDB):
             
             deps = desc[INFO_DEPENDENCIES]
             dependencies = []
-            depend = []
+            depend = serializable_elist(separator="\n\t")
             realname = entry[PKG_NAME].value()
             for dep in deps:
                 dep_pkg = self._s_get_package(dep[DEP_NAME], dep[DEP_VERSION])

diff --git a/g_sorcery/fileutils.py b/g_sorcery/fileutils.py
index f77da4a..6ead317 100644
--- a/g_sorcery/fileutils.py
+++ b/g_sorcery/fileutils.py
@@ -20,13 +20,13 @@ import tarfile
 
 from .compatibility import TemporaryDirectory
 from .exceptions import FileJSONError, DownloadingError
-from .g_collections import Package, elist
+from .serialization import JSONSerializer, deserializeHook
 
 class FileJSON(object):
     """
     Class for JSON files.
     """
-    def __init__(self, directory, name, mandatories, loadconv=None):
+    def __init__(self, directory, name, mandatories=[]):
         """
         Args:
             directory: File directory.
@@ -38,7 +38,6 @@ class FileJSON(object):
         self.name = name
         self.path = os.path.join(directory, name)
         self.mandatories = mandatories
-        self.loadconv = loadconv
 
     def read(self):
         """
@@ -51,18 +50,13 @@ class FileJSON(object):
             for key in self.mandatories:
                 content[key] = ""
             with open(self.path, 'w') as f:
-                json.dump(content, f, indent=2, sort_keys=True)
+                json.dump(content, f, indent=2, sort_keys=True, cls=JSONSerializer)
         else:
             with open(self.path, 'r') as f:
-                content = json.load(f)
+                content = json.load(f, object_hook=deserializeHook)
             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
 
@@ -76,27 +70,7 @@ class FileJSON(object):
         if not os.path.exists(self.directory):
             os.makedirs(self.directory)
         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)
+            json.dump(content, f, indent=2, sort_keys=True, cls=JSONSerializer)
 
 
 def hash_file(name, hasher, blocksize=65536):

diff --git a/g_sorcery/g_collections.py b/g_sorcery/g_collections.py
index 6af88ee..138e239 100644
--- a/g_sorcery/g_collections.py
+++ b/g_sorcery/g_collections.py
@@ -46,7 +46,52 @@ class elist(list):
         '''
         return self._sep_.join(map(str, self))
 
-Package = collections.namedtuple("Package", "category name version")
+
+class serializable_elist(object):
+
+    __slots__ = ('data')
+    
+    def __init__(self, iterable=None, separator=' '):
+        '''
+        iterable: initialize from iterable's items
+        separator: string used to join list members with for __str__()
+        '''
+        self.data = elist(iterable or [], separator)
+
+    def __iter__(self):
+        return iter(self.data)
+
+    def __str__(self):
+        '''Custom output function
+        '''
+        return str(self.data)
+
+    def append(self, x):
+        self.data.append(x)
+
+    def serialize(self):
+        return {"separator": self.data._sep_, "data" : self.data}
+
+    @classmethod
+    def deserialize(cls, value):
+        return serializable_elist(value["data"], separator = value["separator"])
+
+
+class Package(object):
+
+    __slots__ = ('category', 'name', 'version')
+
+    def __init__(self, category, package, version):
+        self.category = category
+        self.name = package
+        self.version = version
+
+    def serialize(self):
+        return [self.category, self.name, self.version]
+
+    @classmethod
+    def deserialize(cls, value):
+        return Package(*value)
 
 
 class Dependency(object):
@@ -69,3 +114,22 @@ class Dependency(object):
 
     def __str__(self):
         return str(self.atom)
+
+    def serialize(self):
+        return str(self)
+
+    @classmethod
+    def deserialize(cls, value):
+        atom = portage.dep.Atom(value)
+        operator = portage.dep.get_operator(atom)
+        cpv = portage.dep.dep_getcpv(atom)
+        category, rest = portage.catsplit(cpv)
+
+        if operator:
+            package, version, revision = portage.pkgsplit(rest)
+        else:
+            package = rest
+            version = ""
+            operator = ""
+
+        return Dependency(category, package, version, operator)

diff --git a/g_sorcery/package_db.py b/g_sorcery/package_db.py
index 313162f..bb7824a 100644
--- a/g_sorcery/package_db.py
+++ b/g_sorcery/package_db.py
@@ -24,7 +24,7 @@ from .compatibility import basestring, py2k, TemporaryDirectory
 from .exceptions import DBStructureError, IntegrityError, \
      InvalidKeyError, SyncError
 
-from .fileutils import FileJSON, FilePkgDesc, hash_file, load_remote_file, copy_all, wget
+from .fileutils import FileJSON, hash_file, load_remote_file, copy_all, wget
 
 from .g_collections import Package
 
@@ -341,7 +341,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 = FilePkgDesc(os.path.join(self.directory, category, name),
+                f = FileJSON(os.path.join(self.directory, category, name),
                     version + '.json', [])
                 f.write(content)
                 self.additional_write_version(category, name, version)
@@ -422,7 +422,7 @@ class PackageDB(object):
                 pkgname = category + '/' + name
                 self.database[pkgname] = {}
                 for version in versions:
-                    f = FilePkgDesc(package_path, version + '.json', [])
+                    f = FileJSON(package_path, version + '.json', [])
                     ebuild_data = f.read()
                     self.database[pkgname][version] = ebuild_data
                     self.additional_read_version(category, name, version)

diff --git a/g_sorcery/serialization.py b/g_sorcery/serialization.py
new file mode 100644
index 0000000..28e29e5
--- /dev/null
+++ b/g_sorcery/serialization.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+    serialization.py
+    ~~~~~~~~~~~~~~~~
+    
+    json serialization
+    
+    :copyright: (c) 2013 by Jauhien Piatlicki
+    :license: GPL-2, see LICENSE for more details.
+"""
+
+import json
+import importlib
+
+
+class JSONSerializer(json.JSONEncoder):
+
+    def default(self, obj):
+        if hasattr(obj, "serialize"):
+            if hasattr(obj, "deserialize"):
+                module = obj.__class__.__module__
+                name = obj.__class__.__name__
+                value = obj.serialize()
+                return {"python_module" : module,
+                        "python_class" : name,
+                        "value" : value}
+            else:
+                return obj.serialize()
+        return json.JSONEncoder.default(self, obj)
+
+
+def deserializeHook(json_object):
+    if "python_class" in json_object:
+        module = importlib.import_module(json_object["python_module"])
+        cls = getattr(module, json_object["python_class"])
+        return cls.deserialize(json_object["value"])
+    return json_object


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

* [gentoo-commits] proj/g-sorcery:master commit in: g_sorcery/, g_elpa/
@ 2013-07-22  1:29 Jauhien Piatlicki
  0 siblings, 0 replies; 9+ messages in thread
From: Jauhien Piatlicki @ 2013-07-22  1:29 UTC (permalink / raw
  To: gentoo-commits

commit:     c022b97b63d8f01f912b6938d8815269d733e944
Author:     Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Mon Jul 22 01:25:41 2013 +0000
Commit:     Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Mon Jul 22 01:25:41 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=c022b97b

g_sorcery/backend: using Dependency in dependencies list

---
 g_elpa/elpa_db.py    | 11 ++++-------
 g_sorcery/backend.py |  6 ++++--
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/g_elpa/elpa_db.py b/g_elpa/elpa_db.py
index 0196b89..8ca6531 100644
--- a/g_elpa/elpa_db.py
+++ b/g_elpa/elpa_db.py
@@ -62,19 +62,16 @@ class ElpaDBGenerator(DBGenerator):
             description = "".join([x for x in desc[INFO_DESCRIPTION] if ord(x) in allowed_ords])
             
             deps = desc[INFO_DEPENDENCIES]
-            dependencies = []
-            depend = serializable_elist(separator="\n\t")
+            dependencies = serializable_elist(separator="\n\t")
             realname = entry[PKG_NAME].value()
             for dep in deps:
-                dep_pkg = self._s_get_package(dep[DEP_NAME], dep[DEP_VERSION])
-                dependencies.append(dep_pkg)
-                depend.append(Dependency(dep_pkg.category, dep_pkg.name))
+                dependencies.append(Dependency("app-emacs", dep[DEP_NAME].value()))
                 
             properties = {'source_type' : source_type,
                           'description' : description,
                           'dependencies' : dependencies,
-                          'depend' : depend,
-                          'rdepend' : depend,
+                          'depend' : dependencies,
+                          'rdepend' : dependencies,
                           'homepage' : repo_uri,
                           'repo_uri' : repo_uri,
                           'realname' : realname,

diff --git a/g_sorcery/backend.py b/g_sorcery/backend.py
index cd32c9c..97c36ce 100644
--- a/g_sorcery/backend.py
+++ b/g_sorcery/backend.py
@@ -284,8 +284,10 @@ class Backend(object):
         
         dependencies = desc["dependencies"]
         for pkg in dependencies:
-            solved_deps, unsolved_deps = self.solve_dependencies(package_db,
-                                                                 pkg,
+            versions = package_db.list_package_versions(pkg.category, pkg.package)
+            for version in versions:            
+                solved_deps, unsolved_deps = self.solve_dependencies(package_db,
+                                                                 Package(pkg.category, pkg.package, version),
                                                                  solved_deps, unsolved_deps)
         
         solved_deps.add(package)


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

end of thread, other threads:[~2013-07-22  1:29 UTC | newest]

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

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