forked from iterorganization/IMAS-Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdsplusIMASDB4to5
More file actions
executable file
·87 lines (68 loc) · 3.43 KB
/
mdsplusIMASDB4to5
File metadata and controls
executable file
·87 lines (68 loc) · 3.43 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/env python
from pathlib import Path
import os
import argparse
parser = argparse.ArgumentParser(description='Maps MDS+ backend imasdb layout from AL4 to AL5 by creating new directory layout and links to original data files (does not remove data)')
parser.add_argument('--dry-run',action='store_true',help='print actions but do not perform them')
parser.add_argument('-p','--path',default=Path.home()/'public',
help='specify path where imasdb to map (by default $HOME/public)')
parser.add_argument('-d','--database',default=None,
help='specify a database to be map (by default all)')
parser.add_argument('-f','--force',action='store_true',
help='force the creation of symlink even if the file exists')
args = parser.parse_args()
imasdbdir = Path(args.path)/'imasdb'
if not imasdbdir.is_dir():
print(f"could not find imasdb in specified path={imasdbdir.parent}")
exit(1)
if args.database==None:
ldb = [d for d in imasdbdir.iterdir() if d.is_dir()]
else:
dbdir = imasdbdir/args.database
if dbdir.is_dir():
ldb = [dbdir]
else:
print(f"could not find database={args.database} in {imasdbdir}")
exit(1)
for db in ldb:
print(f"============ {db.name} ============")
lver = [d for d in db.iterdir() if d.is_dir()]
for ver in lver:
lmdsbr = [d for d in ver.iterdir() if (d.is_dir() and len(d.name)==1)]
for batchrun in lmdsbr:
lpulse = [f for f in batchrun.iterdir() if (f.is_file() and f.suffix==".datafile")]
addtorun = int(batchrun.name)*10000
for pulse in lpulse:
p = pulse.stem[4:]
if len(p)<=4:
pulse_number=0
else:
pulse_number=int(p[0:-4])
run=int(p[-4:])+addtorun
newpulsedir = ver/str(pulse_number)/str(run)
datafile = pulse
treefile = pulse.with_suffix('.tree')
charfile = pulse.with_suffix('.characteristics')
newfilename = newpulsedir/'ids_001'
newdatafile = newfilename.with_suffix('.datafile')
newtreefile = newfilename.with_suffix('.tree')
newcharfile = newfilename.with_suffix('.characteristics')
print(f"mapping pulse={pulse_number} run={run} to {newpulsedir}")
if args.dry_run:
print(f"make dir {newpulsedir}")
print(f"link {newdatafile} --> ../../{datafile.relative_to(ver)}")
print(f"link {newtreefile} --> ../../{treefile.relative_to(ver)}")
print(f"link {newcharfile} --> ../../{charfile.relative_to(ver)}")
else:
newpulsedir.mkdir(parents=True,exist_ok=True)
if newdatafile.exists():
if args.force:
newdatafile.unlink()
newtreefile.unlink()
newcharfile.unlink()
else:
print(f"{newdatafile} exists already, skip")
continue
newdatafile.symlink_to(f'../../{datafile.relative_to(ver)}')
newtreefile.symlink_to(f'../../{treefile.relative_to(ver)}')
newcharfile.symlink_to(f'../../{charfile.relative_to(ver)}')