diff --git a/workbench b/workbench index 06f572e5..e7cbdf13 100755 --- a/workbench +++ b/workbench @@ -115,16 +115,18 @@ def create(): # Therefore, only tasks whose names are registered there should populate # their objects' 'field_member_of'. secondary_task_data = read_node_ids_tsv(config) - if os.path.abspath(args.config) in json.loads(os.environ["ISLANDORA_WORKBENCH_SECONDARY_TASKS"]): - if len(secondary_task_data) > 0: - if 'field_member_of' in row and 'parent_id' in row and row['parent_id'] in secondary_task_data.keys(): - row['field_member_of'] = secondary_task_data[row['parent_id']] - else: - # If there is no parent ID/nid pair in the secondary_task_data mapping, - # either because it wasn't in the primary CSV or it failed to be created - # in the primary task, skip creating the current secondary node and move on. - logging.warning('Node for row with ID %s in secondary task CSV not created because its parent was not present or not created in the primary task.', id_field) - continue + + if os.environ.get('ISLANDORA_WORKBENCH_SECONDARY_TASKS') is not None: + if os.path.abspath(args.config) in json.loads(os.environ["ISLANDORA_WORKBENCH_SECONDARY_TASKS"]): + if len(secondary_task_data) > 0: + if 'field_member_of' in row and 'parent_id' in row and row['parent_id'] in secondary_task_data.keys(): + row['field_member_of'] = secondary_task_data[row['parent_id']] + else: + # If there is no parent ID/nid pair in the secondary_task_data mapping, + # either because it wasn't in the primary CSV or it failed to be created + # in the primary task, skip creating the current secondary node and move on. + logging.warning('Node for row with ID %s in secondary task CSV not created because its parent was not present or not created in the primary task.', id_field) + continue # Add custom (non-required) CSV fields. entity_fields = get_entity_fields(config, 'node', config['content_type']) diff --git a/workbench_utils.py b/workbench_utils.py index 2f1d039f..16ba157a 100644 --- a/workbench_utils.py +++ b/workbench_utils.py @@ -6096,7 +6096,10 @@ def prep_node_ids_tsv(config): populate their objects' 'field_member_of'. We write the parent ID->nid map to this file as well, in write_to_node_ids_tsv(). """ - path_to_tsv_file = os.path.join(os.environ["ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR"], config['secondary_tasks_data_file']) + if os.environ.get('ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR') is not None: + path_to_tsv_file = os.path.join(os.environ["ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR"], config['secondary_tasks_data_file']) + else: + path_to_tsv_file = os.path.join(config['temp_dir'], config['secondary_tasks_data_file']) if os.path.exists(path_to_tsv_file): os.remove(path_to_tsv_file) if len(config['secondary_tasks']) > 0: @@ -6110,7 +6113,10 @@ def prep_node_ids_tsv(config): def write_to_node_ids_tsv(config, row_id, node_id): - path_to_tsv_file = os.path.join(os.environ["ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR"], config['secondary_tasks_data_file']) + if os.environ.get('ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR') is not None: + path_to_tsv_file = os.path.join(os.environ["ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR"], config['secondary_tasks_data_file']) + else: + path_to_tsv_file = os.path.join(config['temp_dir'], config['secondary_tasks_data_file']) tsv_file = open(path_to_tsv_file, "a+", encoding='utf-8') tsv_file.write(str(row_id) + "\t" + str(node_id) + "\n") tsv_file.close() @@ -6118,7 +6124,10 @@ def write_to_node_ids_tsv(config, row_id, node_id): def read_node_ids_tsv(config): map = dict() - path_to_tsv_file = os.path.join(os.environ["ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR"], config['secondary_tasks_data_file']) + if os.environ.get('ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR') is not None: + path_to_tsv_file = os.path.join(os.environ["ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR"], config['secondary_tasks_data_file']) + else: + path_to_tsv_file = os.path.join(config['temp_dir'], config['secondary_tasks_data_file']) if config['secondary_tasks'] is not None: if not os.path.exists(path_to_tsv_file): message = 'Secondary task data file ' + path_to_tsv_file + ' not found.'