diff options
author | Mykyta Holubakha <hilobakho@gmail.com> | 2017-07-13 04:41:32 +0300 |
---|---|---|
committer | Mykyta Holubakha <hilobakho@gmail.com> | 2017-07-18 23:26:27 +0300 |
commit | e668f263de1ba7f9e557c76341dd9d467dc08397 (patch) | |
tree | df679f20dd5a88c0f1d66efb7b6186a1832ab1b8 /pomu | |
parent | Further work on patching (diff) | |
download | pomu-e668f263de1ba7f9e557c76341dd9d467dc08397.tar.gz pomu-e668f263de1ba7f9e557c76341dd9d467dc08397.tar.bz2 pomu-e668f263de1ba7f9e557c76341dd9d467dc08397.zip |
Added a module to fetch ebuilds via URLs
it is still disabled though
Diffstat (limited to 'pomu')
-rw-r--r-- | pomu/source/__init__.py | 2 | ||||
-rw-r--r-- | pomu/source/url.py | 86 |
2 files changed, 88 insertions, 0 deletions
diff --git a/pomu/source/__init__.py b/pomu/source/__init__.py index 3e78150..c54447c 100644 --- a/pomu/source/__init__.py +++ b/pomu/source/__init__.py @@ -4,3 +4,5 @@ dispatcher = PackageDispatcher() import pomu.source.portage import pomu.source.file +# sealed until pbraw is released +#import pomu.source.url diff --git a/pomu/source/url.py b/pomu/source/url.py new file mode 100644 index 0000000..fe346a4 --- /dev/null +++ b/pomu/source/url.py @@ -0,0 +1,86 @@ +""" +A package source module to import packages from URLs +""" + +from os import path, close +from tempfile import mkstemp + +from pbraw import grab + +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.result import Result + +class URLEbuild(PackageBase): + """A class to represent an ebuild fetched from a url""" + __name__ = 'fs' + + def __init__(self, category, name, version, url, contents=None): + self.category = category + self.name = name + self.version = version + self.url = url + self.contents = contents + + def fetch(self): + fd, tfile = tempfile.mkstemp() + os.close(fd) + with open(tfile, 'w') as f: + if self.contents: + f.write(self.contents) + else: + fs = grab(self.url) + f.write(fs[0][1]) + return Package(self.name, '/', self, self.category, self.version, + filemap = { + path.join( + self.category, + self.name, + '{}/{}-{}.ebuild'.format(self.category, self.name, self.version) + ) : tfile}) + + @staticmethod + def from_data_dir(pkgdir): + with open(path.join(pkgdir, 'ORIG_URL'), 'r') as f: + return URLGrabberSource.parse_link(f.readline()).unwrap() + + def write_meta(self, 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) + +@dispatcher.source +class URLGrabberSource(BaseSource): + """ + The source module responsible for grabbing modules from URLs, + including pastebins + """ + @dispatcher.handler(priority=5) + def parse_link(uri): + if not (uri.startswith('http://') or uri.startswith('https://')): + return Result.Err() + + name = query('name', 'Please specify package name'.expect()) + category, _, name = name.rpartition('/') + ver = query('version', 'Please specify package version for {}'.format(name)).expect() + if not category: + category = query('category', 'Please enter category for {}'.format(name), parent).expect() + files = grab(uri) + if not files: + return Result.Err() + return Result.Ok(URLEbuild(category, name, ver, uri, files[0][1])) + + @dispatcher.handler() + def parse_full(url): + if not url.startswith('url:'): + return Result.Err() + return URLGrabberSource.parse_ebuild_path(uri[3:]) + + @classmethod + def from_meta_dir(cls, metadir): + return LocalEbuild.from_data_dir(cls, metadir) |