1414logger = structlog .get_logger ()
1515
1616
17- @click .group ()
17+ @click .group (chain = True )
1818@click .option ('--url' , envvar = 'DSPACE_URL' )
1919@click .option ('-e' , '--email' , envvar = 'TEST_EMAIL' ,
2020 help = 'The email of the user for authentication.' )
@@ -50,9 +50,6 @@ def main(ctx, url, email, password):
5050
5151
5252@main .command ()
53- @click .option ('-c' , '--collection-handle' , required = True ,
54- help = 'The handle of the collection to which items are being '
55- 'added.' )
5653@click .option ('-m' , '--metadata-csv' , required = True ,
5754 help = 'The full path to the CSV file of metadata for the items.' )
5855@click .option ('--field-map' , required = True ,
@@ -66,64 +63,50 @@ def main(ctx, url, email, password):
6663@click .option ('-r' , '--ingest-report' , is_flag = True ,
6764 help = 'Create ingest report for updating other systems.' )
6865@click .pass_context
69- def additems (ctx , collection_handle , metadata_csv , field_map ,
70- directory , file_type , ingest_report ):
66+ def additems (ctx , metadata_csv , field_map , directory , file_type ,
67+ ingest_report ):
7168 client = ctx .obj ['client' ]
7269 start_time = ctx .obj ['start_time' ]
70+ collection_uuid = ctx .obj ['collection_uuid' ]
7371 with open (metadata_csv , 'r' ) as csvfile , open (field_map , 'r' ) as jsonfile :
7472 metadata = csv .DictReader (csvfile )
7573 mapping = json .load (jsonfile )
7674 collection = Collection .from_csv (metadata , mapping )
7775 for item in collection .items :
7876 item .bitstreams_from_directory (directory , file_type )
79- collection_uuid = client .get_id_from_handle (collection_handle )
80- collection .handle = collection_handle
8177 collection .uuid = collection_uuid
82- collection .post_items (client )
78+ items = collection .post_items (client )
79+ if ingest_report :
80+ report_name = metadata_csv .replace ('.csv' , '-ingest.csv' )
81+ helpers .create_ingest_report (items , report_name )
8382 helpers .elapsed_time (start_time , 'Total runtime:' )
8483
85- #
86- # @main.command()
87- # @click.option('-c', '--comm_handle', prompt='Enter the community handle',
88- # help='The handle of the community in which to create the ,'
89- # 'collection.')
90- # @click.option('-n', '--coll_name', prompt='Enter the name of the collection',
91- # help='The name of the collection to be created.')
92- # @click.option('-m', '--metadata_csv', prompt='Enter the metadata CSV file',
93- # help='The path of the CSV file of metadata.')
94- # @click.option('-f', '--file_path', prompt='Enter the path',
95- # help='The path of the content, a URL or local drive path.')
96- # @click.option('-t', '--file_type', prompt='Enter the file type',
97- # help='The file type to be uploaded.')
98- # @click.option('-i', '--ingest_type', prompt='Enter the type of ingest',
99- # help='The type of ingest to perform: local, remote.',
100- # type=click.Choice(['local', 'remote']), default='remote')
101- # @click.option('-r', '--ingest_report', prompt='Create an ingest report?',
102- # help='Create ingest report for updating other systems',
103- # default=False)
104- # @click.option('-u', '--multiple_terms', prompt='Method of separating terms?',
105- # help='The way multiple terms are separated in the metadata CSV.',
106- # type=click.Choice(['delimited', 'num_columns']),
107- # default='delimited')
108- # @click.pass_context
109- # def newcoll(ctx, comm_handle, coll_name, metadata_csv, file_path, file_type,
110- # ingest_type, ingest_report, multiple_terms):
111- # client = ctx.obj['client']
112- # start_time = ctx.obj['start_time']
113- # ingest_data = {}
114- # json_metadata = metadata.create_json_metadata(metadata_csv, multiple_terms)
115- # items = workflows.populate_new_coll(client, comm_handle, coll_name,
116- # ingest_type, file_path, file_type,
117- # json_metadata, ingest_report,
118- # ingest_data)
119- # for item in items:
120- # logger.info(f'Item posted: {item}')
121- # if ingest_report == 'True':
122- # report_name = metadata_csv.replace('.csv', '-ingest.csv')
123- # helpers.create_ingest_report(ingest_data, report_name)
124- # helpers.elapsed_time(start_time, 'Total runtime:')
125- #
126- #
84+
85+ @main .command ()
86+ @click .option ('-c' , '--collection-handle' , required = True ,
87+ help = 'The handle of the collection to which items are being '
88+ 'added.' )
89+ @click .pass_context
90+ def existingcollection (ctx , collection_handle ):
91+ client = ctx .obj ['client' ]
92+ collection_uuid = client .get_id_from_handle (collection_handle )
93+ ctx .obj ['collection_uuid' ] = collection_uuid
94+
95+
96+ @main .command ()
97+ @click .option ('-c' , '--community-handle' , required = True ,
98+ help = 'The handle of the community in which to create the ,'
99+ 'collection.' )
100+ @click .option ('-n' , '--collection-name' , required = True ,
101+ help = 'The name of the collection to be created.' )
102+ @click .pass_context
103+ def newcollection (ctx , community_handle , collection_name ):
104+ client = ctx .obj ['client' ]
105+ collection_uuid = client .post_coll_to_comm (community_handle ,
106+ collection_name )
107+ ctx .obj ['collection_uuid' ] = collection_uuid
108+
109+
127110# @main.command()
128111# @click.option('-m', '--metadata_csv', prompt='Enter the metadata CSV file',
129112# help='The path of the CSV file of metadata.')
0 commit comments