From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id E52531382C5 for ; Fri, 29 Jan 2021 23:50:55 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BD6F7E0AD1; Fri, 29 Jan 2021 23:50:54 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 8638FE0AD1 for ; Fri, 29 Jan 2021 23:50:54 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 29804340FF5 for ; Fri, 29 Jan 2021 23:50:53 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 201844B6 for ; Fri, 29 Jan 2021 23:50:50 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1611964082.e40f31c10a79499a822596948b68fcf6ea3f647f.mattst88@gentoo> Subject: [gentoo-commits] proj/catalyst:wip/mattst88 commit in: catalyst/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/config.py catalyst/main.py X-VCS-Directories: catalyst/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: e40f31c10a79499a822596948b68fcf6ea3f647f X-VCS-Branch: wip/mattst88 Date: Fri, 29 Jan 2021 23:50:50 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 274c1436-f550-42ed-a30e-d20cbbe8bdb1 X-Archives-Hash: 008b6ec16068c3425343fb96e804d8d8 commit: e40f31c10a79499a822596948b68fcf6ea3f647f Author: Matt Turner gentoo org> AuthorDate: Mon Nov 2 17:43:34 2020 +0000 Commit: Matt Turner gentoo org> CommitDate: Fri Jan 29 23:48:02 2021 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=e40f31c1 catalyst: Switch spec files to TOML Signed-off-by: Matt Turner gentoo.org> catalyst/config.py | 120 ----------------------------------------------------- catalyst/main.py | 26 ++++-------- 2 files changed, 9 insertions(+), 137 deletions(-) diff --git a/catalyst/config.py b/catalyst/config.py deleted file mode 100644 index e1963f71..00000000 --- a/catalyst/config.py +++ /dev/null @@ -1,120 +0,0 @@ - -import re - -from catalyst import log -from catalyst.support import CatalystError - - -class ParserBase(): - - filename = "" - lines = None - values = None - key_value_separator = "=" - multiple_values = False - empty_values = True - eval_none = False - - def __getitem__(self, key): - return self.values[key] - - def get_values(self): - return self.values - - def dump(self): - dump = "" - for x in self.values: - dump += x + " = " + repr(self.values[x]) + "\n" - return dump - - def parse_file(self, filename): - try: - with open(filename, "r") as myf: - self.lines = myf.readlines() - except: - raise CatalystError("Could not open file " + filename, - print_traceback=True) - self.filename = filename - self.parse() - - def parse_lines(self, lines): - self.lines = lines - self.parse() - - def parse(self): - values = {} - cur_array = [] - - trailing_comment = re.compile(r'\s*#.*$') - - for x, myline in enumerate(self.lines): - myline = myline.strip() - - # Force the line to be clean - # Remove Comments ( anything following # ) - myline = trailing_comment.sub("", myline) - - # Skip any blank lines - if not myline: - continue - - if self.key_value_separator in myline: - # Split on the first occurence of the separator creating two strings in the array mobjs - mobjs = myline.split(self.key_value_separator, 1) - mobjs[1] = mobjs[1].strip().strip('"') - - # Start a new array using the first element of mobjs - cur_array = [mobjs[0]] - if mobjs[1]: - # do any variable substitiution embeded in it with - # the values already obtained - mobjs[1] = mobjs[1] % values - if self.multiple_values: - # split on white space creating additional array elements - subarray = mobjs[1].split() - cur_array += subarray - else: - cur_array += [mobjs[1]] - - # Else add on to the last key we were working on - else: - if self.multiple_values: - cur_array += myline.split() - else: - raise CatalystError("Syntax error: %s" % - x, print_traceback=True) - - # XXX: Do we really still need this "single value is a string" behavior? - if len(cur_array) == 2: - values[cur_array[0]] = cur_array[1] - else: - values[cur_array[0]] = cur_array[1:] - - if not self.empty_values: - # Make sure the list of keys is static since we modify inside the loop. - for x in list(values.keys()): - # Delete empty key pairs - if not values[x]: - log.warning('No value set for key "%s"; deleting', x) - del values[x] - - if self.eval_none: - # Make sure the list of keys is static since we modify inside the loop. - for x in list(values.keys()): - # reset None values - if isinstance(values[x], str) and values[x].lower() in ['none']: - log.info('None value found for key "%s"; reseting', x) - values[x] = None - self.values = values - - -class SpecParser(ParserBase): - - key_value_separator = ':' - multiple_values = True - empty_values = False - eval_none = True - - def __init__(self, filename=""): - if filename: - self.parse_file(filename) diff --git a/catalyst/main.py b/catalyst/main.py index 0de1040f..81495c62 100644 --- a/catalyst/main.py +++ b/catalyst/main.py @@ -13,7 +13,6 @@ from DeComp.definitions import (COMPRESS_DEFINITIONS, DECOMPRESS_DEFINITIONS, from DeComp.contents import ContentsMap from catalyst import log -import catalyst.config from catalyst.context import namespace from catalyst.defaults import (confdefaults, option_messages, DEFAULT_CONFIG_FILE, valid_config_file_values) @@ -276,11 +275,6 @@ def _main(parser, opts): myconfigs = [DEFAULT_CONFIG_FILE] myspecfile = opts.file - mycmdline = list() - if opts.snapshot: - mycmdline.append('target: snapshot') - mycmdline.append('snapshot_treeish: ' + opts.snapshot) - conf_values['DEBUG'] = opts.debug conf_values['VERBOSE'] = opts.debug or opts.verbose @@ -299,7 +293,7 @@ def _main(parser, opts): options.append('enter-chroot') # Make sure we have some work before moving further. - if not myspecfile and not mycmdline: + if not myspecfile and not opts.snapshot: parser.error('please specify one of either -f or -C or -s') # made it this far so start by outputting our version info @@ -320,7 +314,6 @@ def _main(parser, opts): # initialize our (de)compression definitions conf_values['decompress_definitions'] = DECOMPRESS_DEFINITIONS conf_values['compress_definitions'] = COMPRESS_DEFINITIONS - # TODO add capability to config/spec new definitions if "digests" in conf_values: valid_digests = hashlib.algorithms_available @@ -338,16 +331,15 @@ def _main(parser, opts): if myspecfile: log.notice("Processing spec file: %s", myspecfile) - spec = catalyst.config.SpecParser(myspecfile) - addlargs.update(spec.get_values()) - - if mycmdline: try: - cmdline = catalyst.config.SpecParser() - cmdline.parse_lines(mycmdline) - addlargs.update(cmdline.get_values()) - except CatalystError: - log.critical('Could not parse commandline') + addlargs.update(toml.load(myspecfile)) + except Exception as e: + log.critical('Could not find parse spec file: %s: %s', + myspecfile, e) + + if opts.snapshot: + addlargs['target'] = 'snapshot' + addlargs['snapshot_treeish'] = opts.snapshot if "target" not in addlargs: raise CatalystError("Required value \"target\" not specified.")