aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMykyta Holubakha <hilobakho@gmail.com>2017-11-25 02:05:24 +0200
committerMykyta Holubakha <hilobakho@gmail.com>2017-11-25 02:05:24 +0200
commit2d352778e43f2d098674b4ddb32562199af6c82f (patch)
tree435c4c3ccd221218cf9c9c7b7c29ac15005e72f8
parentUnified package source constructors (diff)
downloadpomu-2d352778e43f2d098674b4ddb32562199af6c82f.tar.gz
pomu-2d352778e43f2d098674b4ddb32562199af6c82f.tar.bz2
pomu-2d352778e43f2d098674b4ddb32562199af6c82f.zip
Separated core package metadata from auxillary
inherited base classes in bugz backend
-rw-r--r--pomu/source/base.py31
-rw-r--r--pomu/source/bugz.py27
-rw-r--r--pomu/source/file.py20
-rw-r--r--pomu/source/portage.py34
-rw-r--r--pomu/source/url.py15
5 files changed, 78 insertions, 49 deletions
diff --git a/pomu/source/base.py b/pomu/source/base.py
index 5d110db..712f2e6 100644
--- a/pomu/source/base.py
+++ b/pomu/source/base.py
@@ -7,7 +7,10 @@ package specifications and fetching the specified package, as well as
instantiating specific packages from the metadata directory.
"""
+from os import path
+
from pomu.source import dispatcher
+from pomu.util.result import Result
class PackageBase():
"""
@@ -20,6 +23,15 @@ class PackageBase():
"""The implementation shall provide a name for the package type"""
__name__ = None
+ def __init__(self, category, name, version, slot='0'):
+ """
+ Unified basic metadata storage for all the sources
+ """
+ self.category = category
+ self.name = name
+ self.version = version
+ self.slot = slot
+
def fetch(self):
"""
A method which is responsible for fetching the package: it should return a Package object (specifying set of files with sufficient metadata), and specify this package object as the backend for the Package object (to store source-specific metadata).
@@ -34,23 +46,32 @@ class PackageBase():
It shall return an instance of this class, and take a path to the meta
directory.
"""
- raise NotImplementedError()
+ try:
+ lines = [x.strip() for x in open(path.join(pkgdir, 'PACKAGE_BASE_DATA'), 'r')]
+ except:
+ return Result.Err('Could not read data file')
+ if len(lines) < 4:
+ return Result.Err('Invalid data provided')
+ category, name, version, slot, *_ = lines
+ return Result.Ok(PackageBase(category, name, version, slot))
def write_meta(self, pkgdir):
"""
This method shall write source-specific metadata to the provided
metadata directory.
"""
- raise NotImplementedError()
+ with open(path.join(pkgdir, 'PACKAGE_BASE_DATA'), 'w') as f:
+ f.write(self.category + '\n')
+ f.write(self.name + '\n')
+ f.write(self.version + '\n')
+ f.write(self.slot + '\n')
def __str__(self):
"""
The implementation shall provide a method to pretty-print
package-specific metadata (displayed in show command).
- Example:
- return '{}/{}-{} (from {})'.format(self.category, self.name, self.version, self.path)
"""
- raise NotImplementedError()
+ return '{}/{}:{}-{}'.format(self.category, self.name, '' if self.slot == '0' else ':' + self.slot, self.version)
@dispatcher.source
class BaseSource:
diff --git a/pomu/source/bugz.py b/pomu/source/bugz.py
index 87721a2..bd0d887 100644
--- a/pomu/source/bugz.py
+++ b/pomu/source/bugz.py
@@ -8,42 +8,47 @@ from urllib.parse import urlparse
from pomu.package import Package
from pomu.source import dispatcher
+from pomu.source.base import PackageBase, BaseSource
from pomu.util.iquery import EditSelectPrompt
from pomu.util.misc import extract_urls
-from pomu.util.query import query
+from pomu.util.query import query, QueryContext
from pomu.util.result import Result
-class BzEbuild():
+class BzEbuild(PackageBase):
"""A class to represent a local ebuild"""
__name__ = 'fs'
def __init__(self, bug_id, filemap, category, name, version, slot='0'):
+ super().__init__(category, name, version, slot)
self.bug_id = bug_id
self.filemap = filemap
- self.category = category
- self.name = name
- self.version = version
- self.slot = slot
def fetch(self):
return Package(self.name, '/', self, self.category, self.version, filemap=self.filemap)
@staticmethod
def from_data_dir(pkgdir):
- with open(path.join(pkgdir, 'BZ_BUG_ID'), 'r') as f:
- return BugzillaSource.parse_bug(f.readline()).unwrap()
+ pkg = PackageBase.from_data_dir(pkgdir)
+ if pkg.is_err():
+ return pkg
+ pkg = pkg.unwrap()
+
+ with QueryContext(category=pkg.category, name=pkg.name, version=pkg.version, slot=pkg.slot):
+ with open(path.join(pkgdir, 'BZ_BUG_ID'), 'r') as f:
+ return BugzillaSource.parse_bug(f.readline()).unwrap()
def write_meta(self, pkgdir):
+ super().write_meta(pkgdir)
with open(path.join(pkgdir, 'BZ_BUG_ID'), 'w') as f:
f.write(self.bug_id + '\n')
def __str__(self):
- return '{}/{}-{} (from {})'.format(self.category, self.name, self.version, self.path)
+ return super().__str__() + ' (from {})'.format(self.path)
CLIENT_BASE = 'https://bugs.gentoo.org/xmlrpc.cgi'
@dispatcher.source
-class BugzillaSource():
+class BugzillaSource(BaseSource):
"""The source module responsible for importing ebuilds and patches from bugzilla tickets"""
@dispatcher.handler(priority=1)
def parse_bug(uri):
@@ -53,7 +58,7 @@ class BugzillaSource():
proxy = xmlrpc.client.ServerProxy(CLIENT_BASE).Bug
payload = {'ids': [uri]}
try:
- bug = proxy.get(payload)
+ proxy.get(payload)
except (xmlrpc.client.Fault, OverflowError) as err:
return Result.Err(str(err))
attachments = proxy.attachments(payload)['bugs'][str(uri)]
diff --git a/pomu/source/file.py b/pomu/source/file.py
index 25f57c5..a573cda 100644
--- a/pomu/source/file.py
+++ b/pomu/source/file.py
@@ -8,7 +8,7 @@ from pomu.package import Package
from pomu.source import dispatcher
from pomu.source.base import PackageBase, BaseSource
from pomu.util.pkg import cpv_split, ver_str
-from pomu.util.query import query
+from pomu.util.query import query, QueryContext
from pomu.util.result import Result
class LocalEbuild(PackageBase):
@@ -16,11 +16,8 @@ class LocalEbuild(PackageBase):
__name__ = 'fs'
def __init__(self, path, category, name, version, slot='0'):
+ super().__init__(category, name, version, slot)
self.path = path
- self.category = category
- self.name = name
- self.version = version
- self.slot = slot
def fetch(self):
return Package(self.name, '/', self, self.category, self.version,
@@ -33,15 +30,22 @@ class LocalEbuild(PackageBase):
@staticmethod
def from_data_dir(pkgdir):
- with open(path.join(pkgdir, 'FS_ORIG_PATH'), 'r') as f:
- return LocalEbuildSource.parse_ebuild_path(f.readline()).unwrap()
+ pkg = PackageBase.from_data_dir(pkgdir)
+ if pkg.is_err():
+ return pkg
+ pkg = pkg.unwrap()
+
+ with QueryContext(category=pkg.category, name=pkg.name, version=pkg.version, slot=pkg.slot):
+ with open(path.join(pkgdir, 'FS_ORIG_PATH'), 'r') as f:
+ return LocalEbuildSource.parse_ebuild_path(f.readline()).unwrap()
def write_meta(self, pkgdir):
+ super().write_meta(pkgdir)
with open(path.join(pkgdir, 'FS_ORIG_PATH'), 'w') as f:
f.write(self.path + '\n')
def __str__(self):
- return '{}/{}-{} (from {})'.format(self.category, self.name, self.version, self.path)
+ return super().__str__() + ' (from {})'.format(self.path)
@dispatcher.source
class LocalEbuildSource(BaseSource):
diff --git a/pomu/source/portage.py b/pomu/source/portage.py
index 89eca7e..39336ee 100644
--- a/pomu/source/portage.py
+++ b/pomu/source/portage.py
@@ -19,11 +19,8 @@ class PortagePackage(PackageBase):
__name__ = 'portage'
def __init__(self, repo, category, name, version, slot='0'):
+ super().__init__(category, name, version, slot)
self.repo = repo
- self.category = category
- self.name = name
- self.version = version
- self.slot = slot
def fetch(self):
return Package(self.name, portage_repo_path(self.repo), self,
@@ -32,30 +29,25 @@ class PortagePackage(PackageBase):
path.join(self.category, self.name, self.name + '-' + self.version + '.ebuild')])
def write_meta(self, pkgdir):
+ super().write_meta(pkgdir)
with open(path.join(pkgdir, 'PORTAGE_DATA'), 'w') as f:
f.write(self.repo + '\n')
- f.write(self.category + '\n')
- f.write(self.name + '\n')
- f.write(self.version + '\n')
- f.write(self.slot + '\n')
@staticmethod
def from_data_dir(pkgdir):
- try:
- lines = [x.strip() for x in open(path.join(pkgdir, 'PORTAGE_DATA'), 'r')]
- except:
- return Result.Err('Could not read data file')
- if len(lines) < 5:
- return Result.Err('Invalid data provided')
- res = PortagePackage()
- res.repo, res.category, res.name, res.version, res.slot, *_ = lines
- if sanity_check(res.repo, res.category, res.name, None, None, None, res.slot, ver=res.version):
- return Result.Ok(res)
- return Result.Err('Package {} not found'.format(res))
+ pkg = PackageBase.from_data_dir(pkgdir)
+ if pkg.is_err():
+ return pkg
+ pkg = pkg.unwrap()
+
+ with open(path.join(pkgdir, 'PORTAGE_DATA'), 'r') as f:
+ repo = f.readline()
+ if sanity_check(repo, pkg.category, pkg.name, None, None, None, pkg.slot, ver=pkg.version):
+ return Result.Ok(PortagePackage(repo, pkg.category, pkg.name, pkg.slot, pkg.version))
+ return Result.Err('Package {} not found'.format(pkg))
def __str__(self):
- return '{}/{}-{}{}::{}'.format(self.category, self.name, self.version,
- '' if self.slot == '0' else ':' + self.slot, self.repo)
+ return super().__str__() + '::' + self.repo
@dispatcher.source
diff --git a/pomu/source/url.py b/pomu/source/url.py
index 4e8b277..0759e5c 100644
--- a/pomu/source/url.py
+++ b/pomu/source/url.py
@@ -9,7 +9,7 @@ from pbraw import grab
from pomu.package import Package
from pomu.source import dispatcher
from pomu.source.base import PackageBase, BaseSource
-from pomu.util.query import query
+from pomu.util.query import query, QueryContext
from pomu.util.result import Result
class URLEbuild(PackageBase):
@@ -41,15 +41,22 @@ class URLEbuild(PackageBase):
@staticmethod
def from_data_dir(pkgdir):
- with open(path.join(pkgdir, 'ORIG_URL'), 'r') as f:
- return URLGrabberSource.parse_link(f.readline()).unwrap()
+ pkg = PackageBase.from_data_dir(pkgdir)
+ if pkg.is_err():
+ return pkg
+ pkg = pkg.unwrap()
+
+ with QueryContext(category=pkg.category, name=pkg.name, version=pkg.version, slot=pkg.slot):
+ with open(path.join(pkgdir, 'ORIG_URL'), 'r') as f:
+ return URLGrabberSource.parse_link(f.readline()).unwrap()
def write_meta(self, pkgdir):
+ super().write_meta(pkgdir)
with open(path.join(pkgdir, 'ORIG_URL'), 'w') as f:
f.write(self.path + '\n')
def __str__(self):
- return '{}/{}-{} (from {})'.format(self.category, self.name, self.version, self.path)
+ return super().__str__() + ' (from {})'.format(self.url)
@dispatcher.source
class URLGrabberSource(BaseSource):