Skip to content

Commit 85a70f3

Browse files
committed
⬇️ 🐍 Make script Python 2 version
1 parent 8ba0fd8 commit 85a70f3

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

scripts/link_to_set_version.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
"""This script takes a version string as a commandline argument and updates
1+
"""Python 2 version
2+
3+
This script takes a version string as a commandline argument and updates
24
the links in `docs/{version}` that point to code in the `master` branch of
35
FCP-INDI/C-PAC to code in the tagged version.
46
@@ -10,7 +12,20 @@
1012
import os
1113
import sys
1214

13-
from glob import glob
15+
from fnmatch import filter as fnfilter
16+
17+
18+
def glob(pattern, recursive=True):
19+
split_pattern = pattern.split('/')
20+
filepath = '/'.join(split_pattern[0:-1])
21+
pattern = split_pattern[-1]
22+
del split_pattern
23+
24+
matches = []
25+
for root, dirnames, filenames in os.walk(filepath):
26+
for filename in fnfilter(filenames, pattern):
27+
matches.append(os.path.join(root, filename))
28+
return matches
1429

1530

1631
def set_version(version):
@@ -25,9 +40,9 @@ def set_version(version):
2540
# Replace links to master branch with links to specified branch
2641
with open(filepath, 'r') as openfile:
2742
file = openfile.read().replace(
28-
patterns[0], f'FCP-INDI/C-PAC/blob/{version}'
43+
patterns[0], 'FCP-INDI/C-PAC/blob/{}'.format(version)
2944
).replace(
30-
patterns[1], f'FCP-INDI/C-PAC/{version}'
45+
patterns[1], 'FCP-INDI/C-PAC/{}'.format(version)
3146
)
3247
with open(filepath, 'w') as openfile:
3348
openfile.write(file)

0 commit comments

Comments
 (0)