5
5
from pathlib import Path
6
6
from subprocess import check_output
7
7
from labscript_profile import LABSCRIPT_SUITE_PROFILE , default_labconfig_path
8
+ import argparse
8
9
9
10
_here = os .path .dirname (os .path .abspath (__file__ ))
10
11
DEFAULT_PROFILE_CONTENTS = os .path .join (_here , 'default_profile' )
@@ -21,7 +22,8 @@ def make_shared_secret(directory):
21
22
raise RuntimeError ("Could not parse output of zprocess.makesecret" )
22
23
23
24
24
- def make_labconfig_file ():
25
+ def make_labconfig_file (apparatus_name ):
26
+
25
27
source_path = os .path .join (LABSCRIPT_SUITE_PROFILE , 'labconfig' , 'example.ini' )
26
28
target_path = default_labconfig_path ()
27
29
if os .path .exists (target_path ):
@@ -47,16 +49,58 @@ def make_labconfig_file():
47
49
'%(labscript_suite)s' , shared_secret .relative_to (LABSCRIPT_SUITE_PROFILE )
48
50
)
49
51
config .set ('security' , 'shared_secret' , str (shared_secret_entry ))
52
+ if apparatus_name is not None :
53
+ config .set ('DEFAULT' , 'apparatus_name' , apparatus_name )
50
54
51
55
with open (target_path , 'w' ) as f :
52
56
config .write (f )
53
57
58
+ def compile_connection_table ():
59
+
60
+ try :
61
+ import runmanager
62
+ except ImportError :
63
+ # if runmanager doesn't import, skip compilation
64
+ return
65
+
66
+ config = configparser .ConfigParser (defaults = {'labscript_suite' : str (LABSCRIPT_SUITE_PROFILE )})
67
+ config .read (default_labconfig_path ())
68
+
69
+ # The path to the user's connection_table.py script
70
+ script_path = config ['paths' ]['connection_table_py' ]
71
+ # path to the connection_table.h5 destination
72
+ output_h5_path = config ['paths' ]['connection_table_h5' ]
73
+ # create output directory, if needed
74
+ Path (output_h5_path ).parent .mkdir (parents = True , exist_ok = True )
75
+ # compile the h5 file
76
+ runmanager .new_globals_file (output_h5_path )
77
+
78
+ def dummy_callback (success ):
79
+ pass
80
+
81
+ runmanager .compile_labscript_async (labscript_file = script_path ,
82
+ run_file = output_h5_path ,
83
+ stream_port = None ,
84
+ done_callback = dummy_callback )
54
85
55
86
def create_profile ():
87
+
88
+ # capture CMD arguments
89
+ parser = argparse .ArgumentParser (prog = 'labscript-profile-create' ,
90
+ description = 'Initialises a default labscript profile'
91
+ )
92
+
93
+ parser .add_argument ('-n' , '--apparatus_name' ,
94
+ type = str ,
95
+ help = 'Sets the apparatus_name in the labconfig file. Defaults to example_apparatus' ,
96
+ )
97
+
98
+ args = parser .parse_args ()
99
+
56
100
src = Path (DEFAULT_PROFILE_CONTENTS )
57
101
dest = Path (LABSCRIPT_SUITE_PROFILE )
58
102
# Profile directory may exist already, but we will error if it contains any of the
59
- # files or directories we want to copy into it:
103
+ # sub- directories we want to copy into it:
60
104
os .makedirs (dest , exist_ok = True )
61
105
# Preferable to raise errors if anything exists before copying anything, rather than
62
106
# do a partial copy before hitting an error:
@@ -71,4 +115,13 @@ def create_profile():
71
115
else :
72
116
shutil .copy2 (src_file , dest_file )
73
117
74
- make_labconfig_file ()
118
+ make_labconfig_file (args .apparatus_name )
119
+
120
+ # rename apparatus directories
121
+ if args .apparatus_name is not None :
122
+ for path in dest .glob ('**/example_apparatus/' ):
123
+ new_path = Path (str (path ).replace ('example_apparatus' , args .apparatus_name ))
124
+ path .rename (new_path )
125
+
126
+ # compile the initial example connection table
127
+ compile_connection_table ()
0 commit comments