-
Notifications
You must be signed in to change notification settings - Fork 2
/
fix_filenames.py
37 lines (29 loc) · 1018 Bytes
/
fix_filenames.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
import glob
import os
import shutil
RENAME = {
"BIOMD0000000864": ("Proctoe", "Proctor"),
"BIOMD0000000917": ("Orignal", "Original"),
"BIOMD0000000923": ("Liò", "Lio"),
}
def run(id, working_dir):
""" Fix the namespaces in a SED-ML file and save the file in place
* Remove duplicate SED-ML namespace declarations -- automatically fixed by LXML
* Add namespaces for models
Args:
id (:obj:`str`): id of BioModels entry
working_dir (:obj:`str`): directory of entries to change (e.g., ``final``, ``original``)
Returns:
:obj:`list` of :obj:`str`: list of corrected files
"""
changed = []
if id not in RENAME:
return changed
filenames = glob.glob(os.path.join(working_dir, '**', '**'), recursive=True)
filenames.sort()
for filename in filenames:
(orig, new) = RENAME[id]
if orig in filename:
shutil.move(filename, filename.replace(orig, new))
changed.append(filename)
return changed