Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/certbot/certbot.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilip Lajszczak <filip.lajszczak@gmail.com>2020-02-06 18:14:17 +0300
committerFilip Lajszczak <filip.lajszczak@gmail.com>2020-02-06 18:14:17 +0300
commit2b051dd197804b5c93b6e38aae91c991278afdba (patch)
treee2872c7a8e89f03e0e4675e2d217c595d50a768c /tools/strip_hashes.py
parentb27e5804b9671e28f37a6da7e2f1f7fa9455d24a (diff)
parent7da5196206b33d5593bd15cd1dcce4d790db7e6d (diff)
Merge branch 'master' of https://github.com/certbot/certbot
Diffstat (limited to 'tools/strip_hashes.py')
-rwxr-xr-xtools/strip_hashes.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/strip_hashes.py b/tools/strip_hashes.py
new file mode 100755
index 000000000..988e72eb8
--- /dev/null
+++ b/tools/strip_hashes.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+"""Removes hash information from requirement files passed to it as file path
+arguments or simply piped to stdin."""
+
+import re
+import sys
+
+
+def process_entries(entries):
+ """Strips off hash strings from dependencies.
+
+ :param list entries: List of entries
+
+ :returns: list of dependencies without hashes
+ :rtype: list
+ """
+ out_lines = []
+ for e in entries:
+ e = e.strip()
+ search = re.search(r'^(\S*==\S*).*$', e)
+ if search:
+ out_lines.append(search.group(1))
+ return out_lines
+
+def main(*paths):
+ """
+ Reads dependency definitions from a (list of) file(s) provided on the
+ command line. If no command line arguments are present, data is read from
+ stdin instead.
+
+ Hashes are removed from returned entries.
+ """
+
+ deps = []
+ if paths:
+ for path in paths:
+ with open(path) as file_h:
+ deps += process_entries(file_h.readlines())
+ else:
+ # Need to check if interactive to avoid blocking if nothing is piped
+ if not sys.stdin.isatty():
+ stdin_data = []
+ for line in sys.stdin:
+ stdin_data.append(line)
+ deps += process_entries(stdin_data)
+
+ return "\n".join(deps)
+
+if __name__ == '__main__':
+ print(main(*sys.argv[1:])) # pylint: disable=star-args