This repository has been archived by the owner on May 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrename.py
executable file
·65 lines (49 loc) · 1.63 KB
/
rename.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
60
61
62
63
64
65
#!/usr/bin/env python3
import json
import os
import sys
import glob
import bse
import numpy as np
src = sys.argv[1]
dest = sys.argv[2]
src_base = os.path.splitext(src)[0]
dest_base = os.path.splitext(dest)[0]
if os.path.isfile(dest):
raise RuntimeError("Destination file exists")
os.rename(src, dest)
src_base2 = os.path.splitext(src_base)[0]
dest_base2 = os.path.splitext(dest_base)[0]
element_files = glob.glob("*.element.json")
table_files = glob.glob("*.table.json")
# Rename description file
if os.path.isfile(src_base + '.txt'):
src_desc_file = src_base + '.txt'
dest_desc_file = dest_base + '.txt'
os.rename(src_desc_file, dest_desc_file)
if src.endswith('.table.json'):
pass
elif src_base.endswith('.element'):
for f in table_files:
changed = False
data = bse.read_json_by_path(f)
for k,v in data['basisSetElements'].items():
if v['elementEntry'] == src_base2:
changed = True
print("Found in {} {}".format(f, k))
v['elementEntry'] = dest_base2
if changed:
os.rename(f, f + ".old")
bse.write_json_basis(f, data)
else:
for f in element_files:
changed = False
data = bse.read_json_by_path(f)
for k,v in data['basisSetElements'].items():
if src_base in v['elementComponents']:
changed = True
print("Found in {} {}".format(f, k))
v['elementComponents'] = [ dest_base if x == src_base else x for x in v['elementComponents'] ]
if changed:
os.rename(f, f + ".old")
bse.write_json_basis(f, data)