]> git.scottworley.com Git - pinch/commitdiff
Factor out pin check
authorScott Worley <scottworley@scottworley.com>
Wed, 17 Jun 2020 17:48:37 +0000 (10:48 -0700)
committerScott Worley <scottworley@scottworley.com>
Thu, 18 Jun 2020 06:15:29 +0000 (23:15 -0700)
pinch.py

index 125fa63a1949527b1ab9f1a4c84a330443da2ade..1959f450323f742420eb18c20c447c0815a3b3ee 100644 (file)
--- a/pinch.py
+++ b/pinch.py
@@ -618,6 +618,16 @@ def read_config_section(
     return SP(**remaining_fields), pin
 
 
     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)
 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:
     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)
         if isinstance(sp, AliasSearchPath):
             continue
         tarball = sp.fetch(v, pin)