aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMykyta Holubakha <hilobakho@gmail.com>2017-06-25 03:08:42 +0300
committerMykyta Holubakha <hilobakho@gmail.com>2017-06-25 03:08:42 +0300
commit5c7ba584fc0075aa6cc9008a941dfdd27774f997 (patch)
treea02f92a419dbe3bbe65fc003c93905563f1e3b48
parentStore backend name in the metadata dir (diff)
downloadpomu-5c7ba584fc0075aa6cc9008a941dfdd27774f997.tar.gz
pomu-5c7ba584fc0075aa6cc9008a941dfdd27774f997.tar.bz2
pomu-5c7ba584fc0075aa6cc9008a941dfdd27774f997.zip
Integrate metadata with the module interface/repo
-rw-r--r--pomu/repo/repo.py23
-rw-r--r--pomu/source/manager.py2
-rw-r--r--pomu/source/portage.py4
3 files changed, 29 insertions, 0 deletions
diff --git a/pomu/repo/repo.py b/pomu/repo/repo.py
index 480510b..9b02edb 100644
--- a/pomu/repo/repo.py
+++ b/pomu/repo/repo.py
@@ -86,6 +86,29 @@ class Repository():
r.commit('Removed package ' + name + ' successfully')
return Result.Ok('Removed package ' + name + ' successfully')
+ def get_package(self, category, name, slot='0'):
+ """Get a package by name"""
+ with open(path.join(self.pomu_dir, 'world'), 'r') as f:
+ lines = [x.strip() for x in f]
+ if slot == '0':
+ spec = '{}/{}'.format(category, name)
+ else:
+ spec = '{}/{}:{}'.format(category, name, slot)
+ if not lines.has(spec):
+ return Result.Err('Package not found')
+ if slot == '0':
+ pkgdir = path.join(self.pomu_dir, category, name)
+ else:
+ pkgdir = path.join(self.pomu_dir, category, name, slot)
+ with open(path.join(pkgdir, 'BACKEND'), 'r') as f:
+ bname = f.readline().strip()
+ backend = dispatcher.backends[bname].from_meta_dir(pkgdir)
+ with open(path.join(pkgdir, 'VERSION'), 'r') as f:
+ version = f.readline().strip()
+ with open(path.join(pkgdir, 'FILES'), 'r') as f:
+ files = [x.strip() for x in f]
+ return Package(backend, name, self.root, category=category, version=version, slot=slot, files=files)
+
def portage_repos():
"""Yield the repositories configured for portage"""
diff --git a/pomu/source/manager.py b/pomu/source/manager.py
index 9d3e2de..47c4953 100644
--- a/pomu/source/manager.py
+++ b/pomu/source/manager.py
@@ -35,6 +35,7 @@ from pomu.util.result import Result
class PackageDispatcher():
def __init__(self):
self.handlers = []
+ self.backends = {}
def source(self, cls):
"""
@@ -42,6 +43,7 @@ class PackageDispatcher():
It would register all the methods of the class marked by @handler
with the dispatcher.
"""
+ self.backends[cls.__name__] = cls
for m, obj in inspect.getmembers(cls):
if isinstance(obj, self.handler._handler):
self.register_package_handler(cls, obj.handler, obj.priority)
diff --git a/pomu/source/portage.py b/pomu/source/portage.py
index 8bb7d3a..dde9330 100644
--- a/pomu/source/portage.py
+++ b/pomu/source/portage.py
@@ -101,6 +101,10 @@ class PortageSource():
def fetch_package(cls, pkg):
return pkg.fetch()
+ @classmethod
+ def from_meta_dir(cls, metadir):
+ return PortagePackage.from_data_dir(cls, path.join(metadir, 'PORTAGE_DATA'))
+
def sanity_check(repo, category, name, vernum, suff, rev, slot, ver=None):
"""