From: Frank Brehm Date: Mon, 6 Mar 2017 12:55:11 +0000 (+0100) Subject: Adding rewrite in cleanup-pkg-keywords X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=4dbb4fe94e04bc8aefff3040499c7a745eef40cb;p=scripts%2Froot-bin.git Adding rewrite in cleanup-pkg-keywords --- diff --git a/cleanup-pkg-keywords b/cleanup-pkg-keywords index eb08618..0355237 100755 --- a/cleanup-pkg-keywords +++ b/cleanup-pkg-keywords @@ -16,6 +16,9 @@ import re import logging import glob +# Third party modules +import six + from distutils.version import LooseVersion # portage stuff @@ -188,18 +191,22 @@ class CleanupPkgKeywordsApp(PbApplication): print('---------------------------------------------------') log.info("Performing %r ...", filename) + new_lines = [] + with open(filename, 'rt') as fh: line_nr = 0 for line in fh.readlines(): line_nr += 1 if self.re_empty_line.search(line) or self.re_comment.search(line): + new_lines.append(line.strip()) continue match = self.re_line_keywords.search(line) if not match: log.error( 'Invalid line %r in %r (%d) found.', line.rstrip(), filename, line_nr) + new_lines.append('# ' + line.strip()) continue mypkg = match.group(1) if self.verbose: @@ -208,6 +215,7 @@ class CleanupPkgKeywordsApp(PbApplication): log.error( 'Invalid atom %r in %r (%d) found.', mypkg, filename, line_nr) + new_lines.append('# ' + line.strip()) continue log.debug("Checking atom %r in %r (%d) ...", mypkg, filename, line_nr) @@ -221,6 +229,7 @@ class CleanupPkgKeywordsApp(PbApplication): log.error( 'Invalid Package name %r in %r (%d) found.', mypkg, filename, line_nr) + new_lines.append('# ' + line.strip()) continue valid = None if isjustname(my_cpv): @@ -235,9 +244,28 @@ class CleanupPkgKeywordsApp(PbApplication): if valid: log.debug("Atom %r in %r (%d) seems to be valid.", mypkg, filename, line_nr) + new_lines.append(line.strip()) else: log.warning("Atom %r in %r (%d) seems to be invalid.", mypkg, filename, line_nr) + new_lines.append('# ' + line.strip()) + + print('') + print('----------') + log.info("Rewriting %r ...", filename) + if self.simulate: + if self.verbose: + for line in new_lines: + print(line) + else: + open_opts = {} + if six.PY3: + open_opts['encoding'] = 'utf-8' + with open(filename, 'wt', **open_opts) as fh: + for line in new_lines: + if self.verbose: + print(line) + fh.write(line + '\n') # ------------------------------------------------------------------------- def check_package(self, package, slot, version, release, operator): @@ -247,6 +275,8 @@ class CleanupPkgKeywordsApp(PbApplication): package, slot, version, release, operator) pkg_dirs_glob = os.path.join(self.pkg_dir, package + '-[0-9]*') + if self.verbose > 2: + log.info("Searching installed package by %r ...", pkg_dirs_glob) pkg_dirs = glob.glob(pkg_dirs_glob) if not pkg_dirs: log.info("Package %r seems not to be installed.", package)