Skip to content

simulators

admin.simulators

access_key module-attribute

access_key = getenv('S3_ACCESS_KEY')

endpoint module-attribute

endpoint = getenv('S3_ENDPOINT')

fluka_bucket module-attribute

fluka_bucket = getenv('S3_FLUKA_BUCKET')

fluka_key module-attribute

fluka_key = getenv('S3_FLUKA_KEY')

geant4_bucket_name module-attribute

geant4_bucket_name = getenv('S3_GEANT4_BUCKET')

password module-attribute

password = getenv('S3_ENCRYPTION_PASSWORD')

salt module-attribute

salt = getenv('S3_ENCRYPTION_SALT')

secret_key module-attribute

secret_key = getenv('S3_SECRET_KEY')

shieldhit_bucket module-attribute

shieldhit_bucket = getenv('S3_SHIELDHIT_BUCKET')

shieldhit_key module-attribute

shieldhit_key = getenv('S3_SHIELDHIT_KEY')

this_file_path module-attribute

this_file_path = resolve()

topas_bucket_name module-attribute

topas_bucket_name = getenv('S3_TOPAS_BUCKET')

topas_key module-attribute

topas_key = getenv('S3_TOPAS_KEY')

topas_version module-attribute

topas_version = getenv('S3_TOPAS_VERSION')

decrypt

decrypt(**kwargs)

Decrypt a file

Source code in yaptide/admin/simulators.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
@run.command
@click.option('--infile',
              type=click.Path(exists=True, readable=True, file_okay=True, dir_okay=False, path_type=Path),
              required=True,
              help='file to decrypt')
@click.option('--outfile',
              type=click.Path(writable=True, file_okay=True, dir_okay=False, path_type=Path),
              required=True,
              help='Path where decrypted file is saved')
@encryption_options(required=True)
def decrypt(**kwargs):
    """Decrypt a file"""
    decrypted_bytes = decrypt_file(file_path=kwargs['infile'], password=kwargs['password'], salt=kwargs['salt'])
    outfile_path = Path(kwargs['outfile'])
    outfile_path.parent.mkdir(parents=True, exist_ok=True)
    outfile_path.write_bytes(decrypted_bytes)

download_fluka

download_fluka(**kwargs)

Download Fluka simulator

Source code in yaptide/admin/simulators.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
@run.command
@click.option('--dir',
              required=True,
              type=click.Path(writable=True, file_okay=False, dir_okay=True, path_type=Path),
              help='download directory')
@click.option('--bucket', type=click.STRING, envvar='S3_FLUKA_BUCKET', required=True, help='S3 bucket name')
@click.option('--key', type=click.STRING, envvar='S3_FLUKA_KEY', required=True, help='S3 key (filename)')
@s3credentials(required=True)
@encryption_options(required=True)
def download_fluka(**kwargs):
    """Download Fluka simulator"""
    click.echo(f'Downloading Fluka into directory {kwargs["dir"]}')
    download_status = download_fluka_from_s3(download_dir=kwargs['dir'],
                                             endpoint=kwargs['endpoint'],
                                             access_key=kwargs['access_key'],
                                             secret_key=kwargs['secret_key'],
                                             bucket=kwargs['bucket'],
                                             key=kwargs['key'],
                                             password=kwargs['password'],
                                             salt=kwargs['salt'])
    if download_status:
        click.echo('Fluka downloaded')
    else:
        click.echo('Fluka download failed')

download_shieldhit

download_shieldhit(**kwargs)

Download SHIELD-HIT12A

Source code in yaptide/admin/simulators.py
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
@run.command
@click.option('--dir',
              required=True,
              type=click.Path(writable=True, file_okay=False, dir_okay=True, path_type=Path),
              help='download directory')
@click.option('--bucket', type=click.STRING, envvar='S3_SHIELDHIT_BUCKET', help='S3 bucket name')
@click.option('--key', type=click.STRING, envvar='S3_SHIELDHIT_KEY', help='S3 key (filename)')
@click.option('--decrypt', is_flag=True, default=False, help='decrypt file downloaded from S3')
@s3credentials(required=False)
@encryption_options(required=False)
def download_shieldhit(**kwargs):
    """Download SHIELD-HIT12A"""
    click.echo(f'Downloading SHIELD-HIT12A into directory {kwargs["dir"]}')
    download_shieldhit_from_s3_or_from_website(destination_dir=kwargs['dir'],
                                               endpoint=kwargs['endpoint'],
                                               access_key=kwargs['access_key'],
                                               secret_key=kwargs['secret_key'],
                                               password=kwargs['password'],
                                               salt=kwargs['salt'],
                                               bucket=kwargs['bucket'],
                                               key=kwargs['key'],
                                               decrypt=kwargs['decrypt'])

download_topas

download_topas(**kwargs)

Download TOPAS simulator and Geant4 data

Source code in yaptide/admin/simulators.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
@run.command
@click.option('--dir',
              required=True,
              type=click.Path(writable=True, file_okay=False, dir_okay=True, path_type=Path),
              help='download directory')
@click.option('--topas_bucket',
              type=click.STRING,
              envvar='S3_TOPAS_BUCKET',
              required=True,
              help='S3 bucket name with TOPAS binary')
@click.option('--geant4_bucket',
              type=click.STRING,
              envvar='S3_GEANT4_BUCKET',
              required=True,
              help='S3 bucket name with Geant4 data')
@click.option('--topas_key', type=click.STRING, envvar='S3_TOPAS_KEY', required=True, help='S3 key (filename)')
@click.option('--topas_version', type=click.STRING, envvar='S3_TOPAS_VERSION', required=True, help='TOPAS version')
@s3credentials(required=True)
def download_topas(**kwargs):
    """Download TOPAS simulator and Geant4 data"""
    click.echo(f'Downloading TOPAS into directory {kwargs["dir"]}')
    installation_status = download_topas_from_s3(
        download_dir=kwargs['dir'],
        endpoint=kwargs['endpoint'],
        access_key=kwargs['access_key'],
        secret_key=kwargs['secret_key'],
        bucket=kwargs['topas_bucket'],
        key=kwargs['topas_key'],
        version=kwargs['topas_version'],
        geant4_bucket=kwargs['geant4_bucket'],
    )
    if installation_status:
        click.echo('TOPAS installed')
    else:
        click.echo('TOPAS installation failed')

encrypt

encrypt(**kwargs)

Encrypt a file

Source code in yaptide/admin/simulators.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@run.command
@click.option('--infile',
              type=click.Path(exists=True, readable=True, file_okay=True, dir_okay=False, path_type=Path),
              required=True,
              help='file to encrypt')
@click.option('--outfile',
              type=click.Path(writable=True, file_okay=True, dir_okay=False, path_type=Path),
              required=True,
              help='Path where encrypted file is saved')
@encryption_options(required=True)
def encrypt(**kwargs):
    """Encrypt a file"""
    encrypted_bytes = encrypt_file(file_path=kwargs['infile'], password=kwargs['password'], salt=kwargs['salt'])
    outfile_path = Path(kwargs['outfile'])
    outfile_path.parent.mkdir(parents=True, exist_ok=True)
    outfile_path.write_bytes(encrypted_bytes)

encryption_options

encryption_options(required=False)

Collection of options for encryption

Source code in yaptide/admin/simulators.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def encryption_options(required: bool = False):
    """Collection of options for encryption"""

    def decorator(func):
        """Decorator for encryption options"""

        @click.option('--password',
                      type=click.STRING,
                      envvar='S3_ENCRYPTION_PASSWORD',
                      default=password,
                      required=required,
                      help='encryption password')
        @click.option('--salt',
                      type=click.STRING,
                      envvar='S3_ENCRYPTION_SALT',
                      default=password,
                      required=required,
                      help='encryption salt')
        @wraps(func)
        def wrapper(*args, **kwargs):
            return func(*args, **kwargs)

        return wrapper

    return decorator

run

run()

Manage simulators

Source code in yaptide/admin/simulators.py
35
36
37
@click.group()
def run():
    """Manage simulators"""

s3credentials

s3credentials(required=False)

Collection of options for S3 credentials

Source code in yaptide/admin/simulators.py
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
def s3credentials(required: bool = False):
    """Collection of options for S3 credentials"""

    def decorator(func):
        """Decorator for S3 credentials options"""

        @click.option('--endpoint',
                      type=click.STRING,
                      required=required,
                      envvar='S3_ENDPOINT',
                      default=endpoint,
                      help='S3 endpoint')
        @click.option('--access_key',
                      type=click.STRING,
                      required=required,
                      envvar='S3_ACCESS_KEY',
                      default=access_key,
                      help='S3 access key')
        @click.option('--secret_key',
                      type=click.STRING,
                      required=required,
                      envvar='S3_SECRET_KEY',
                      default=secret_key,
                      help='S3 secret key')
        @wraps(func)
        def wrapper(*args, **kwargs):
            return func(*args, **kwargs)

        return wrapper

    return decorator

upload

upload(**kwargs)

Upload simulator file to S3 bucket

Source code in yaptide/admin/simulators.py
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
@run.command
@click.option('--bucket', type=click.STRING, required=True, help='S3 bucket name')
@click.option('--file',
              type=click.Path(exists=True, readable=True, file_okay=True, dir_okay=False, path_type=Path),
              required=True,
              help='file to upload')
@click.option('--encrypt', is_flag=True, default=False, help='encrypt file uploaded to S3')
@s3credentials(required=True)
@encryption_options(required=False)
def upload(**kwargs):
    """Upload simulator file to S3 bucket"""
    click.echo(f'Uploading file {kwargs["file"]} to bucket {kwargs["bucket"]}')
    upload_status = upload_file_to_s3(bucket=kwargs['bucket'],
                                      file_path=kwargs['file'],
                                      endpoint=kwargs['endpoint'],
                                      access_key=kwargs['access_key'],
                                      secret_key=kwargs['secret_key'],
                                      encrypt=kwargs['encrypt'],
                                      encryption_password=kwargs['password'],
                                      encryption_salt=kwargs['salt'])
    if upload_status:
        click.echo('File uploaded successfully')