From 5445f5a9e4a8af26d5a2a159365318c46de22f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sat, 28 Aug 2010 16:46:17 +0200 Subject: Support specifying an alternate output file for --update-use-local-desc. --- bin/egencache | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'bin') diff --git a/bin/egencache b/bin/egencache index b8c2c82a2..5ae15bc4f 100755 --- a/bin/egencache +++ b/bin/egencache @@ -97,6 +97,12 @@ def parse_args(args): "for bug 139134 (use with --update)") parser.add_option_group(update) + uld = optparse.OptionGroup(parser, '--update-use-local-desc options') + uld.add_option("--use-local-desc-output", + help="output file for use.local.desc data (or '-' for stdout)", + dest="uld_output") + parser.add_option_group(uld) + options, args = parser.parse_args(args) if options.jobs: @@ -307,28 +313,36 @@ class GenCache(object): level=logging.ERROR, noiselevel=-1) class GenUseLocalDesc(object): - def __init__(self, portdb): + def __init__(self, portdb, output=None): self.returncode = os.EX_OK self._portdb = portdb + self._output = output def run(self): repo_path = self._portdb.porttrees[0] - prof_path = os.path.join(repo_path, 'profiles') - desc_path = os.path.join(prof_path, 'use.local.desc') ops = {'<':0, '<=':1, '=':2, '>=':3, '>':4} - try: - os.mkdir(prof_path) - except OSError: - pass - try: - output = open(desc_path, 'w') - except IOError as e: - writemsg_level( - "ERROR: failed to open output file: %s\n" % (e,), - level=logging.ERROR, noiselevel=-1) - self.returncode |= 2 - return + if self._output is None or self._output != '-': + if self._output is None: + prof_path = os.path.join(repo_path, 'profiles') + desc_path = os.path.join(prof_path, 'use.local.desc') + try: + os.mkdir(prof_path) + except OSError: + pass + else: + desc_path = self._output + + try: + output = open(desc_path, 'w') + except IOError as e: + writemsg_level( + "ERROR: failed to open output file: %s\n" % (e,), + level=logging.ERROR, noiselevel=-1) + self.returncode |= 2 + return + else: + output = sys.stdout output.write(''' # This file is deprecated as per GLEP 56 in favor of metadata.xml. Please add @@ -483,7 +497,8 @@ def egencache_main(args): ret.append(gen_cache.returncode) if options.update_use_local_desc: - gen_desc = GenUseLocalDesc(portdb) + gen_desc = GenUseLocalDesc(portdb, + output=options.uld_output) gen_desc.run() ret.append(gen_desc.returncode) -- cgit v1.2.3-1-g7c22