diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2022-11-10 16:19:19 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2022-11-10 16:19:19 +0100 |
commit | ad8426c463b24b4b39b722b4d28949f2080182fc (patch) | |
tree | 10c008c730ee4e1f6fd3b790068b55a04707ea2d /scripts | |
parent | e390ffea34f9b9d2243e80ed47e7954dd4c4d930 (diff) | |
download | psutil-ad8426c463b24b4b39b722b4d28949f2080182fc.tar.gz |
use argparse module in 3 scripts/internal scripts
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/internal/check_broken_links.py | 12 | ||||
-rwxr-xr-x | scripts/internal/convert_readme.py | 10 | ||||
-rwxr-xr-x | scripts/internal/print_hashes.py | 26 |
3 files changed, 30 insertions, 18 deletions
diff --git a/scripts/internal/check_broken_links.py b/scripts/internal/check_broken_links.py index 1a076116..8ceab1c7 100755 --- a/scripts/internal/check_broken_links.py +++ b/scripts/internal/check_broken_links.py @@ -41,6 +41,7 @@ Author: Himanshu Shekhar <https://github.com/himanshub16> (2017) from __future__ import print_function +import argparse import concurrent.futures import functools import os @@ -227,13 +228,14 @@ def parallel_validator(urls): def main(): - files = sys.argv[1:] - if not files: - print("usage: %s <FILES...>" % sys.argv[0], file=sys.stderr) - return sys.exit(1) + parser = argparse.ArgumentParser( + description=__doc__, formatter_class=argparse.RawTextHelpFormatter) + parser.add_argument('files', nargs="+") + parser.parse_args() + args = parser.parse_args() all_urls = [] - for fname in files: + for fname in args.files: urls = get_urls(fname) if urls: print("%4s %s" % (len(urls), fname)) diff --git a/scripts/internal/convert_readme.py b/scripts/internal/convert_readme.py index 81f7bdb6..d96c6c5d 100755 --- a/scripts/internal/convert_readme.py +++ b/scripts/internal/convert_readme.py @@ -5,11 +5,12 @@ # found in the LICENSE file. """ -Convert README.rst format to make it compatible with PyPI (no raw html). +Remove raw HTML from README.rst to make it compatible with PyPI on +dist upload. """ +import argparse import re -import sys summary = """\ @@ -40,7 +41,10 @@ Example usages""" # noqa def main(): - with open(sys.argv[1]) as f: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('file', type=str) + args = parser.parse_args() + with open(args.file) as f: data = f.read() data = re.sub(r".. raw:: html\n+\s+<div align[\s\S]*?/div>", summary, data) data = re.sub(r"Sponsors\n========[\s\S]*?Example usages", funding, data) diff --git a/scripts/internal/print_hashes.py b/scripts/internal/print_hashes.py index 434c43d5..69bc9edb 100755 --- a/scripts/internal/print_hashes.py +++ b/scripts/internal/print_hashes.py @@ -5,13 +5,13 @@ # found in the LICENSE file. """ -Prints files hashes. -See: https://pip.pypa.io/en/stable/reference/pip_install/#hash-checking-mode +Prints files hashes, see: +https://pip.pypa.io/en/stable/reference/pip_install/#hash-checking-mode """ +import argparse import hashlib import os -import sys def csum(file, kind): @@ -22,13 +22,19 @@ def csum(file, kind): def main(): - dir = sys.argv[1] - for name in sorted(os.listdir(dir)): - file = os.path.join(dir, name) - md5 = csum(file, "md5") - sha256 = csum(file, "sha256") - print("%s\nmd5: %s\nsha256: %s\n" % ( - os.path.basename(file), md5, sha256)) + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('dir', type=str, + help='directory containing tar.gz or wheel files') + args = parser.parse_args() + for name in sorted(os.listdir(args.dir)): + file = os.path.join(args.dir, name) + if os.path.isfile(file): + md5 = csum(file, "md5") + sha256 = csum(file, "sha256") + print("%s\nmd5: %s\nsha256: %s\n" % ( + os.path.basename(file), md5, sha256)) + else: + print("skipping %r (not a file)" % file) if __name__ == "__main__": |