From: Scott Worley Date: Wed, 17 Jun 2020 17:48:37 +0000 (-0700) Subject: Factor out pin check X-Git-Tag: 2.0.0~5 X-Git-Url: http://git.scottworley.com/pinch/commitdiff_plain/e8bd4979a02d7bb9e8fb7d978fd0e986d7ee60d1 Factor out pin check --- diff --git a/pinch.py b/pinch.py index 125fa63..1959f45 100644 --- a/pinch.py +++ b/pinch.py @@ -618,6 +618,16 @@ def read_config_section( return SP(**remaining_fields), pin +def read_pinned_config_section( + section: str, conf: configparser.SectionProxy) -> Tuple[SearchPath, Pin]: + sp, pin = read_config_section(conf) + if pin is None: + raise Exception( + 'Cannot update unpinned channel "%s" (Run "pin" before "update")' % + section) + return sp, pin + + def read_config(filename: str) -> configparser.ConfigParser: config = configparser.ConfigParser() config.read_file(open(filename), filename) @@ -656,11 +666,7 @@ def updateCommand(args: argparse.Namespace) -> None: exprs: Dict[str, str] = {} config = read_config_files(args.channels_file) for section in config: - sp, pin = read_config_section(config[section]) - if pin is None: - raise Exception( - 'Cannot update unpinned channel "%s" (Run "pin" before "update")' % - section) + sp, pin = read_pinned_config_section(section, config[section]) if isinstance(sp, AliasSearchPath): continue tarball = sp.fetch(v, pin)