diff options
author | Mykyta Holubakha <hilobakho@gmail.com> | 2017-07-05 20:53:10 +0300 |
---|---|---|
committer | Mykyta Holubakha <hilobakho@gmail.com> | 2017-07-05 20:53:10 +0300 |
commit | 89ea936652960049bf6ad307df83f52733819683 (patch) | |
tree | 13a6d07b3a27d0e31bbe7dd63a2b6a1fc189c31a | |
parent | Added the manpage (diff) | |
download | pomu-89ea936652960049bf6ad307df83f52733819683.tar.gz pomu-89ea936652960049bf6ad307df83f52733819683.tar.bz2 pomu-89ea936652960049bf6ad307df83f52733819683.zip |
Some fixes
-rw-r--r-- | pomu/source/file.py | 10 | ||||
-rw-r--r-- | pomu/source/portage.py | 6 | ||||
-rw-r--r-- | pomu/util/pkg.py | 6 | ||||
-rw-r--r-- | pomu/util/query.py | 78 | ||||
-rw-r--r-- | pomu/util/str.py | 2 |
5 files changed, 70 insertions, 32 deletions
diff --git a/pomu/source/file.py b/pomu/source/file.py index ffd7c07..f42474d 100644 --- a/pomu/source/file.py +++ b/pomu/source/file.py @@ -31,8 +31,8 @@ class LocalEbuild(): ) : self.path}) @staticmethod - def from_data_file(path): - with open(path, 'r') as f: + def from_data_dir(pkgdir): + with open(path.join(pkgdir, 'FS_ORIG_PATH'), 'r') as f: return LocalEbuildSource.parse_ebuild_path(f.readline()).unwrap() def write_meta(self, pkgdir): @@ -66,4 +66,8 @@ class LocalEbuildSource(): def parse_full(uri): if not uri.startswith('fs:'): return Result.Err() - return LocalEbuildSource.parse_ebuild_path(uri) + return LocalEbuildSource.parse_ebuild_path(uri[3:]) + + @classmethod + def from_meta_dir(cls, metadir): + return LocalEbuild.from_data_dir(cls, metadir) diff --git a/pomu/source/portage.py b/pomu/source/portage.py index 1dc740b..f4f112c 100644 --- a/pomu/source/portage.py +++ b/pomu/source/portage.py @@ -39,9 +39,9 @@ class PortagePackage(): f.write(self.slot + '\n') @staticmethod - def from_data_file(path): + def from_data_dir(pkgdir): try: - lines = [x.strip() for x in open(path, 'r')] + 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: @@ -125,7 +125,7 @@ class PortageSource(): @classmethod def from_meta_dir(cls, metadir): - return PortagePackage.from_data_dir(cls, path.join(metadir, 'PORTAGE_DATA')) + return PortagePackage.from_data_dir(cls, metadir) def sanity_check(repo, category, name, vernum, suff, rev, slot, ver=None): diff --git a/pomu/util/pkg.py b/pomu/util/pkg.py index 7ff3a7c..7544e42 100644 --- a/pomu/util/pkg.py +++ b/pomu/util/pkg.py @@ -24,19 +24,19 @@ def cpv_split(pkg): # openssl-0.9.8z_p8-r100 m = re.search(r'-r\d+$', pkg) # revision is optional if m: - pkg, rev = pivot(pkg, m.start(0), False) + pkg, rev = pivot(pkg, m.start(0)) else: rev = None # openssl-0.9.8z_p8 m = re.search(r'_({})(\d*)$'.format('|'.join(suffixes)), pkg) if m: - pkg, suff = pivot(pkg, m.start(0), False) + pkg, suff = pivot(pkg, m.start(0)) else: suff = None # openssl-0.9.8z m = re.search(r'-(\d+(\.\d+)*)([a-z])?$', pkg) if m: - pkg, vernum = pivot(pkg, m.start(0), False) + pkg, vernum = pivot(pkg, m.start(0)) else: vernum = None # openssl diff --git a/pomu/util/query.py b/pomu/util/query.py index d9dc09e..872e0a3 100644 --- a/pomu/util/query.py +++ b/pomu/util/query.py @@ -3,25 +3,59 @@ A module to (non)interactively query the user for impure values """ from pomu.util.result import Result -def query(name, prompt=None, default=None): - """ - Queries the impure world for name - Parameters: - name - the name - prompt - prompt text - default - default value used for errors, forced non-interactive etc. - TODO: non-interactive - """ - if not prompt: - prompt = 'Please enter ' + name - if default: prompt += ' ({})'.format(default) - prompt += ' > ' - res = None - try: - res = input(prompt) - except EOFError: pass - if not res: - res = default - if not res: - return Result.Err('No {} or default provided'.format(name)) - return Result.Ok() +class _query: + def __init__(self): + self.map = {} + self.interactive = True + + def __call__(self, name, prompt=None, default=None): + """ + Queries the impure world for name + Parameters: + name - the name + prompt - prompt text + default - default value used for errors, forced non-interactive etc. + TODO: non-interactive + """ + if name in self.map: + return Result.Ok(self.map[name]) + if not prompt: + prompt = 'Please enter ' + name + if default: prompt += ' ({})'.format(default) + prompt += ' > ' + res = None + if self.interactive: + try: + res = input(prompt) + except EOFError: pass + if not res: + res = default + if not res: + return Result.Err('No {} or default provided'.format(name)) + return Result.Ok(res) + + def set(self, name, val): + old = None + if name in self.map: + old = self.map[name] + if val is None: + self.unset(name) + self.map[name] = val + return old + + def unset(self, name): + if name in self.map: + del self.map[name] + +query = _query() + +class QueryContext: + def __init__(self, **kwargs): + self.map = kwargs + + def __enter__(self): + self.map_old = {x: query.set(x, self.map[x]) for x in self.map} + + def __exit__(self): + for x, y in self.map_old.items(): + query.set(x, y) diff --git a/pomu/util/str.py b/pomu/util/str.py index 96a7c81..11fc514 100644 --- a/pomu/util/str.py +++ b/pomu/util/str.py @@ -1,5 +1,5 @@ """String processing utilities""" -def pivot(string, idx, keep_pivot=True): +def pivot(string, idx, keep_pivot=False): """ A function to split a string in two, pivoting at string[idx]. If keep_pivot is set, the pivot character is included in the second string. |