aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMichał Górny <gentoo@mgorny.alt.pl>2010-08-28 23:59:34 +0200
committerZac Medico <zmedico@gentoo.org>2010-08-28 15:00:44 -0700
commit126fe9a6de1493f0dfcd0707cf6e36d3620026d5 (patch)
tree5b90537250f34a1d92866aae4b2c22861c5ca2b4 /bin
parentWhen evaluating USE conditional metadata for /var/db/pkg inside (diff)
downloadportage-126fe9a6de1493f0dfcd0707cf6e36d3620026d5.tar.gz
portage-126fe9a6de1493f0dfcd0707cf6e36d3620026d5.tar.bz2
portage-126fe9a6de1493f0dfcd0707cf6e36d3620026d5.zip
egencache: Add comment preserving to --update-use-local-desc.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/egencache37
1 files changed, 32 insertions, 5 deletions
diff --git a/bin/egencache b/bin/egencache
index 5ae15bc4f..b0d727e96 100755
--- a/bin/egencache
+++ b/bin/egencache
@@ -98,6 +98,9 @@ def parse_args(args):
parser.add_option_group(update)
uld = optparse.OptionGroup(parser, '--update-use-local-desc options')
+ uld.add_option("--preserve-comments",
+ action="store_true",
+ help="preserve the comments from the existing use.local.desc file")
uld.add_option("--use-local-desc-output",
help="output file for use.local.desc data (or '-' for stdout)",
dest="uld_output")
@@ -161,6 +164,9 @@ def parse_args(args):
except NameError:
parser.error('--update-use-local-desc requires python with USE=xml!')
+ if options.uld_output == '-' and options.preserve_comments:
+ parser.error('--preserve-comments can not be used when outputting to stdout')
+
return parser, options, args
class GenCache(object):
@@ -313,10 +319,12 @@ class GenCache(object):
level=logging.ERROR, noiselevel=-1)
class GenUseLocalDesc(object):
- def __init__(self, portdb, output=None):
+ def __init__(self, portdb, output=None,
+ preserve_comments=False):
self.returncode = os.EX_OK
self._portdb = portdb
self._output = output
+ self._preserve_comments = preserve_comments
def run(self):
repo_path = self._portdb.porttrees[0]
@@ -333,18 +341,36 @@ class GenUseLocalDesc(object):
else:
desc_path = self._output
+ if self._preserve_comments:
+ output_mode = 'r+'
+ else:
+ output_mode = 'w'
+
try:
- output = open(desc_path, 'w')
+ output = open(desc_path, output_mode)
except IOError as e:
writemsg_level(
- "ERROR: failed to open output file: %s\n" % (e,),
+ "ERROR: failed to open output file %s: %s\n" % (output_mode,e,),
level=logging.ERROR, noiselevel=-1)
self.returncode |= 2
return
else:
output = sys.stdout
- output.write('''
+ if self._preserve_comments:
+ while True:
+ l = output.readline()
+ # Seek through comments, until the first non-comment.
+ # If we hit empty line, then great.
+ # Otherwise, we need to seek back and add an empty line.
+ if not l.startswith('#'):
+ if l.rstrip() != '':
+ output.seek(-len(l), os.SEEK_CUR)
+ output.write('\n')
+ break
+ output.truncate()
+ else:
+ output.write('''
# This file is deprecated as per GLEP 56 in favor of metadata.xml. Please add
# your descriptions to your package's metadata.xml ONLY.
# * generated automatically using egencache *
@@ -498,7 +524,8 @@ def egencache_main(args):
if options.update_use_local_desc:
gen_desc = GenUseLocalDesc(portdb,
- output=options.uld_output)
+ output=options.uld_output,
+ preserve_comments=options.preserve_comments)
gen_desc.run()
ret.append(gen_desc.returncode)