forked from AnacondaRecipes/repodata-hotfixes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-hotfix.py
59 lines (51 loc) · 2.51 KB
/
test-hotfix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import json
import os
import difflib
import subprocess
from six.moves import urllib
from conda.exports import subdir
from conda_build.index import _apply_instructions
html_differ = difflib.HtmlDiff()
diff_options = {'unified': difflib.unified_diff,
'context': difflib.context_diff,
'html': html_differ.make_file}
diff_context_keyword = {'unified': 'n',
'context': 'n',
'html': 'numlines'}
channel_map = {
'main': 'https://repo.anaconda.com/pkgs/main',
'free': 'https://repo.anaconda.com/pkgs/free',
'r': 'https://repo.anaconda.com/pkgs/r',
}
def clone_subdir(channel_base_url, subdir):
out_file = os.path.join(channel_base_url.rsplit('/', 1)[-1], subdir, 'repodata-clone.json')
url = "%s/%s/repodata.json" % (channel_base_url, subdir)
print("downloading repodata from {}".format(url))
urllib.request.urlretrieve(url, out_file)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('channel', help='channel name or url to download repodata from')
parser.add_argument('--subdir', help='subdir to download/diff', default=subdir)
parser.add_argument('--diff-format', help='format to save diff as',
choices=('unified', 'context', 'html'), default='html')
parser.add_argument('--context-numlines', help='context lines to show around diff',
type=int, default=5)
args = parser.parse_args()
if not os.path.isdir(os.path.join(args.channel, args.subdir)):
os.makedirs(os.path.join(args.channel, args.subdir))
if '/' not in args.channel:
channel_base_url = channel_map[args.channel]
clone_subdir(channel_base_url, args.subdir)
subprocess.check_call(['python', args.channel + '.py'])
repodata_file = os.path.join(args.channel, args.subdir, 'repodata-clone.json')
with open(repodata_file) as f:
repodata = json.load(f)
out_instructions = os.path.join(args.channel, args.subdir, 'patch_instructions.json')
with open(out_instructions) as f:
instructions = json.load(f)
patched_repodata = _apply_instructions(args.subdir, repodata, instructions)
patched_repodata_file = os.path.join(args.channel, args.subdir, 'repodata-patched.json')
with open(patched_repodata_file, 'w') as f:
json.dump(patched_repodata, f, indent=2, sort_keys=True, separators=(',', ': '))
subprocess.call(['diff', repodata_file, patched_repodata_file])