forked from QuantumKeLab/QCoDeS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_database_v2.py
36 lines (27 loc) · 879 Bytes
/
init_database_v2.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
import os, sys
import datetime as dt
from qcodes import initialise_or_create_database_at
dirpath = os.getcwd()
sample_name = dirpath.split('\\')[-1]
date = str(dt.date.today())
db_name = f"{sample_name}_{date}"
db_path = dirpath.rsplit('\\', 1)[0] +'\\'+ sample_name
db_full_path = db_path + '\\' + db_name
i = 1
while os.path.exists(db_full_path + '_%02d.db' %i):
i += 1
reuse = eval(sys.argv[1])
files = []
for r, d, f in os.walk(db_path):
for file in f:
if ('.db' in file) and not ('Thumbs' in file):
files.append(os.path.join(r, file))
files.sort()
if reuse and len(files) > 0:
db_full_path = files[-1].rsplit('.',1)[0] + '.db'
print('Using existing database file:')
else:
db_full_path = db_full_path + '_%02d.db' %i
print('Creating a new database file:')
print(db_full_path)
initialise_or_create_database_at(db_full_path)