about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJörg Thalheim <Mic92@users.noreply.github.com>2019-11-19 11:12:14 +0000
committerGitHub <noreply@github.com>2019-11-19 11:12:14 +0000
commitf82832e2f42fd9d8e80cceb243ae8539244cc4ee (patch)
tree76fc899e09b2a5329d78d9c4cf310e180a03ddc8
parent93e6dcb398936c458c65e18a8e9f8cd042411f5e (diff)
parent3820ff9c8be01aecb5976996ae7d4eb3ef4c4b5c (diff)
downloadnixlib-f82832e2f42fd9d8e80cceb243ae8539244cc4ee.tar
nixlib-f82832e2f42fd9d8e80cceb243ae8539244cc4ee.tar.gz
nixlib-f82832e2f42fd9d8e80cceb243ae8539244cc4ee.tar.bz2
nixlib-f82832e2f42fd9d8e80cceb243ae8539244cc4ee.tar.lz
nixlib-f82832e2f42fd9d8e80cceb243ae8539244cc4ee.tar.xz
nixlib-f82832e2f42fd9d8e80cceb243ae8539244cc4ee.tar.zst
nixlib-f82832e2f42fd9d8e80cceb243ae8539244cc4ee.zip
vim update.py: allow different in and out files (#71798)
vim update.py: allow different in and out files
-rwxr-xr-xpkgs/misc/vim-plugins/update.py53
1 files changed, 42 insertions, 11 deletions
diff --git a/pkgs/misc/vim-plugins/update.py b/pkgs/misc/vim-plugins/update.py
index 78abdbd6ab27..92a47bc5d131 100755
--- a/pkgs/misc/vim-plugins/update.py
+++ b/pkgs/misc/vim-plugins/update.py
@@ -8,6 +8,7 @@
 # linted:
 # $ nix run nixpkgs.python3Packages.flake8 -c flake8 --ignore E501,E265 update.py
 
+import argparse
 import functools
 import json
 import os
@@ -29,6 +30,8 @@ ATOM_LINK = "{http://www.w3.org/2005/Atom}link"
 ATOM_UPDATED = "{http://www.w3.org/2005/Atom}updated"
 
 ROOT = Path(__file__).parent
+DEFAULT_IN = ROOT.joinpath("vim-plugin-names")
+DEFAULT_OUT = ROOT.joinpath("generated.nix")
 
 
 class Repo:
@@ -209,9 +212,9 @@ def check_results(
 
 def parse_plugin_line(line: str) -> Tuple[str, str, str]:
     try:
-        name, repo = line.split('/')
+        name, repo = line.split("/")
         try:
-            repo, alias = repo.split(' as ')
+            repo, alias = repo.split(" as ")
             return (name, repo, alias.strip())
         except ValueError:
             # no alias defined
@@ -220,8 +223,7 @@ def parse_plugin_line(line: str) -> Tuple[str, str, str]:
         return (None, None, None)
 
 
-def load_plugin_spec() -> List[Tuple[str, str]]:
-    plugin_file = ROOT.joinpath("vim-plugin-names")
+def load_plugin_spec(plugin_file: str) -> List[Tuple[str, str]]:
     plugins = []
     with open(plugin_file) as f:
         for line in f:
@@ -305,10 +307,10 @@ header = (
 )
 
 
-def generate_nix(plugins: List[Tuple[str, str, Plugin]]):
+def generate_nix(plugins: List[Tuple[str, str, Plugin]], outfile: str):
     sorted_plugins = sorted(plugins, key=lambda v: v[2].name.lower())
 
-    with open(ROOT.joinpath("generated.nix"), "w+") as f:
+    with open(outfile, "w+") as f:
         f.write(header)
         f.write(
             """
@@ -338,15 +340,44 @@ let
   }};
 """
             )
-        f.write("""
+        f.write(
+            """
 });
 in lib.fix' (lib.extends overrides packages)
-""")
-    print("updated generated.nix")
+"""
+        )
+    print(f"updated {outfile}")
+
+
+def parse_args():
+    parser = argparse.ArgumentParser(
+        description=(
+            "Updates nix derivations for vim plugins"
+            f"By default from {DEFAULT_IN} to {DEFAULT_OUT}"
+        )
+    )
+    parser.add_argument(
+        "--input-names",
+        "-i",
+        dest="input_file",
+        default=DEFAULT_IN,
+        help="A list of plugins in the form owner/repo",
+    )
+    parser.add_argument(
+        "--out",
+        "-o",
+        dest="outfile",
+        default=DEFAULT_OUT,
+        help="Filename to save generated nix code",
+    )
+
+    return parser.parse_args()
 
 
 def main() -> None:
-    plugin_names = load_plugin_spec()
+
+    args = parse_args()
+    plugin_names = load_plugin_spec(args.input_file)
     current_plugins = get_current_plugins()
     cache = Cache(current_plugins)
 
@@ -362,7 +393,7 @@ def main() -> None:
 
     plugins = check_results(results)
 
-    generate_nix(plugins)
+    generate_nix(plugins, args.outfile)
 
 
 if __name__ == "__main__":