-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.py
41 lines (30 loc) · 1.61 KB
/
convert.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
37
38
39
40
41
import argparse
from csv import DictReader
from processor.process_rows import process_rows
from processor.validate_input import validate
def process_input(parent_directory, saf_directory, alt_bundle, validate_input):
input_file = parent_directory + '/' + 'input.csv'
# Open the input CSV file for reading
with open(input_file, mode='r', newline='') as infile:
reader = DictReader(infile)
# creates a list of dictionaries
list_of_dict = list(reader)
if not validate_input:
process_rows(list_of_dict, parent_directory, saf_directory, alt_bundle)
else:
validate(list_of_dict, parent_directory)
parser = argparse.ArgumentParser(
description='Convert a directory containing a csv metadata file and bitstreams to DSpace Simple Archive Format.')
parser.add_argument('dir', metavar='Parent directory', type=str,
help='full path to the directory (you can omit the final "/")')
parser.add_argument('saf', metavar='Output SAF directory', type=str,
help='full path to the output directory that will contain the SAF subdirectories')
parser.add_argument('-b', "--bundle",
help='images can be added to an alternate bundle if you do not want them included in the default '
'(ORIGINAL) bundle')
parser.add_argument('-v', "--validate", action="store_true",
help='Checks the metadata fields and file names for accuracy.')
args = parser.parse_args()
directory = args.dir
saf = args.saf
process_input(directory.rstrip('/'), saf.rstrip('/'), args.bundle, args.validate)