From e8bd4979a02d7bb9e8fb7d978fd0e986d7ee60d1 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Wed, 17 Jun 2020 10:48:37 -0700 Subject: [PATCH] Factor out pin check --- pinch.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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) -- 2.44.1