|
9 | 9 | import subprocess |
10 | 10 | import datetime |
11 | 11 | import argparse |
| 12 | +import string |
12 | 13 | from typing import Any |
13 | 14 |
|
14 | 15 | from process import get_process_info |
@@ -53,15 +54,16 @@ def determine_os(fccana_dir: str) -> str | None: |
53 | 54 | def create_condor_config(config: dict[str, Any], |
54 | 55 | batch_dir: str, |
55 | 56 | sample_name: str, |
56 | | - subjob_scripts: list[str]) -> str: |
| 57 | + subjob_scripts: list[str], |
| 58 | + output_dir_eos: str | None) -> str: |
57 | 59 | ''' |
58 | 60 | Creates contents of HTCondor submit description file. |
59 | 61 | ''' |
60 | 62 | cfg = 'executable = $(scriptfile)\n' |
61 | 63 |
|
62 | 64 | cfg += f'log = {batch_dir}/condor_job.{sample_name}.$(ClusterId).log\n' |
63 | 65 |
|
64 | | - if config['output-dir-eos'] is None: |
| 66 | + if output_dir_eos is None: |
65 | 67 | cfg += f'output = {config["output-dir"]}/log/{sample_name}/' |
66 | 68 | cfg += f'condor_job.{sample_name}.$(ClusterId).$(ProcId).out\n' |
67 | 69 | cfg += f'error = {config["output-dir"]}/log/{sample_name}/' |
@@ -95,13 +97,13 @@ def create_condor_config(config: dict[str, Any], |
95 | 97 | cfg += 'when_to_transfer_output = on_exit\n' |
96 | 98 | cfg += f'transfer_output_files = {sample_name}\n' |
97 | 99 |
|
98 | | - if config['output-dir-eos'] is None: |
| 100 | + if output_dir_eos is None: |
99 | 101 | cfg += 'transfer_output_remaps = ' |
100 | 102 | cfg += f'"{sample_name}={config["output-dir"]}/{sample_name}"\n' |
101 | 103 | else: |
102 | 104 | cfg += 'output_destination = ' |
103 | 105 | cfg += f'root://{config["eos-type"]}.cern.ch/' |
104 | | - cfg += f'{config["output-dir-eos"]}\n' |
| 106 | + cfg += f'{output_dir_eos}\n' |
105 | 107 | cfg += 'MY.XRDCP_CREATE_DIR = True\n\n' |
106 | 108 |
|
107 | 109 | # Add user batch configuration if any. |
@@ -292,11 +294,11 @@ def send_sample(config: dict[str, Any], |
292 | 294 | ''' |
293 | 295 | sample_dict = config['sample-list'][sample_name] |
294 | 296 |
|
295 | | - # Create log directory |
296 | | - current_date = datetime.datetime.fromtimestamp( |
| 297 | + timestamp = datetime.datetime.fromtimestamp( |
297 | 298 | datetime.datetime.now().timestamp()).strftime('%Y-%m-%d_%H-%M-%S') |
298 | | - batch_dir = os.path.join('batch-submission-files', |
299 | | - current_date, sample_name) |
| 299 | + |
| 300 | + # Create log directory |
| 301 | + batch_dir = os.path.join('batch-submission-files', timestamp, sample_name) |
300 | 302 | if not os.path.exists(batch_dir): |
301 | 303 | os.system(f'mkdir -p {batch_dir}') |
302 | 304 |
|
@@ -373,21 +375,24 @@ def send_sample(config: dict[str, Any], |
373 | 375 |
|
374 | 376 | condor_config_path = f'{batch_dir}/job_desc_{sample_name}.cfg' |
375 | 377 |
|
376 | | - for i in range(3): |
377 | | - try: |
378 | | - with open(condor_config_path, 'w', encoding='utf-8') as cfgfile: |
379 | | - condor_config = create_condor_config(config, |
380 | | - batch_dir, |
381 | | - sample_name, |
382 | | - subjob_scripts) |
383 | | - cfgfile.write(condor_config) |
384 | | - except IOError as err: |
385 | | - LOGGER.warning('I/O error(%i): %s', err.errno, err.strerror) |
386 | | - if i == 2: |
387 | | - sys.exit(3) |
388 | | - else: |
389 | | - break |
390 | | - time.sleep(10) |
| 378 | + # Convert possible output-dir-eos template to string |
| 379 | + if isinstance(config['output-dir-eos'], string.Template): |
| 380 | + output_dir_eos = config['output-dir-eos'].substitute( |
| 381 | + timestamp=timestamp) |
| 382 | + else: |
| 383 | + output_dir_eos = config['output-dir-eos'] |
| 384 | + |
| 385 | + # Check if EOS output directory exist and if not create it |
| 386 | + if output_dir_eos is not None and not os.path.exists(output_dir_eos): |
| 387 | + os.system(f'mkdir -p {output_dir_eos}') |
| 388 | + |
| 389 | + with open(condor_config_path, 'w', encoding='utf-8') as cfgfile: |
| 390 | + condor_config = create_condor_config(config, |
| 391 | + batch_dir, |
| 392 | + sample_name, |
| 393 | + subjob_scripts, |
| 394 | + output_dir_eos) |
| 395 | + cfgfile.write(condor_config) |
391 | 396 |
|
392 | 397 | if config['submission-filesystem-type'] == 'eos': |
393 | 398 | batch_cmd = f'condor_submit -spool {condor_config_path}' |
|
0 commit comments