diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-09-20 19:22:29 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-09-20 19:22:29 -0400 |
commit | 8c9a82e2d80586e6464b1d0a09bb12c769307fc7 (patch) | |
tree | ca21ef129ddef06978814e823fa9f56fc1e9591e /replace_urls.py | |
parent | a71063bd8c083915f73982a55705383fdae616b5 (diff) | |
download | entomb-8c9a82e2d80586e6464b1d0a09bb12c769307fc7.tar.gz |
Find latest-* or *.final.txt
Diffstat (limited to 'replace_urls.py')
-rwxr-xr-x | replace_urls.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/replace_urls.py b/replace_urls.py index 8f9c161..31702ed 100755 --- a/replace_urls.py +++ b/replace_urls.py @@ -4,15 +4,16 @@ import entomb import fnmatch import os +VERBOSE = False def get_input_dirs(d): result = [] for root, dirs, files in os.walk(d): for dname in files: path = os.path.join(root, dname) - if not fnmatch.fnmatch(path, '*/latest-*'): + if fnmatch.fnmatch(path, '*/latest-*') or fnmatch.fnmatch(path, '*/*.final.txt'): + result.append(entomb.channel_dir(path)) continue - result.append(entomb.channel_dir(path)) return set(result) @@ -31,9 +32,6 @@ def get_template_dirs(d): def channel_from_template(templates, needle): - if fnmatch.fnmatch(needle, "*/conda-dev/*"): - needle = needle.replace('conda-dev', 'astroconda-dev') - for dname in templates: if needle in dname: return dname @@ -53,6 +51,7 @@ def replace_urls(spec, prefix, templates, new_url): tail = '/'.join(os.path.dirname(line).rsplit('/', 2)[1:]) needle = prefix + '/' + tail intermediate = channel_from_template(templates, needle) + # TODO: handle absolute paths intermediate = '/'.join(intermediate.split('/')[1:]) url, package = line.rsplit('/', 1) url = '/'.join([new_url, intermediate]) @@ -65,23 +64,29 @@ if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-i', '--input-dir', required=True, help='Path to astroconda-releases') parser.add_argument('-t', '--template-dir', required=True, help='Path to parent of new channel tree') + parser.add_argument('-d', '--dry-run', action='store_true', help='Do not modify files') + parser.add_argument('-v', '--verbose', action='store_true', help='Be verbose') parser.add_argument('new_url') args = parser.parse_args() + VERBOSE = args.verbose input_dir = args.input_dir template_dir = args.template_dir templates = get_template_dirs(template_dir) new_url = args.new_url + dry_run = args.dry_run dirs = get_input_dirs(input_dir) specs = [] for spec_base in dirs: spec_root = os.path.join(input_dir, spec_base) specs.append(entomb.spec_search(spec_root, ['*{}/latest-*'.format(spec_root)])) + specs.append(entomb.spec_search(spec_root, ['*{}/*.final.txt'.format(spec_root)])) for spec_tree in specs: for spec_file in spec_tree: print("Processing: {}".format(spec_file)) tree = '/'.join(spec_file.split(os.sep, 3)[1:-1]) spec_new = replace_urls(spec_file, tree, templates, new_url) - open(spec_file, 'w+').write(spec_new) + if not dry_run: + open(spec_file, 'w+').write(spec_new) |