Skip to content
Snippets Groups Projects
Commit b759b074 authored by Alessandro Cerioni's avatar Alessandro Cerioni
Browse files

Code refactoring

parent f2445b97
No related branches found
No related tags found
No related merge requests found
......@@ -190,6 +190,31 @@ def delete_dataset_from_dest_index( the_cfg, the_uuid ):
return
def get_metadata_records_processor( the_root_url,
the_no_records_per_page,
the_uuid_to_get,
the_uuids_to_filter_out=None,
the_username=None,
the_password=None):
for record in get_metadata_records( root_url=the_root_url,
no_records_per_page=the_no_records_per_page,
uuid=the_uuid_to_get,
the_filter=the_uuids_to_filter_out,
username=the_username, password=the_password ):
the_uuid = record['geonet:info']['uuid']
if is_locked( cfg['session']['working_directory'], the_uuid ):
logging.info("Dataset with uuid = %s is already being indexed: skipping." % the_uuid)
continue
else:
logging.info("Setting lock for dataset with uuid = %s" % the_uuid)
lock(cfg['session']['working_directory'], the_uuid)
# delete_dataset_from_indices(cfg, record['geonet:info']['uuid'])
delete_dataset_from_dest_index(cfg, the_uuid)
send_record_to_the_metadata_processor(cfg, record)
def main(cfg):
......@@ -209,48 +234,63 @@ def main(cfg):
password = cfg['geonetwork']['password']
del cfg['geonetwork']['password'] # <- as this info is no longer needed
if 'all' not in uuids_to_get:
# get some datasets only
for uuid_to_get in uuids_to_get:
for record in get_metadata_records( cfg['geonetwork']['url'],
cfg['geonetwork']['records_per_page'],
uuid=uuid_to_get,
the_filter=uuids_to_filter_out,
username=username, password=password ):
the_uuid = record['geonet:info']['uuid']
if is_locked( cfg['session']['working_directory'], the_uuid ):
logging.info("Dataset with uuid = %s is already being indexed: skipping." % the_uuid)
continue
else:
lock(cfg['session']['working_directory'], the_uuid)
# delete_dataset_from_indices(cfg, record['geonet:info']['uuid'])
delete_dataset_from_dest_index(cfg, the_uuid)
send_record_to_the_metadata_processor(cfg, record)
else:
# get all the datasets
for record in get_metadata_records( cfg['geonetwork']['url'],
cfg['geonetwork']['records_per_page'],
uuid=None,
the_filter=uuids_to_filter_out,
username=username, password=password ):
the_uuid = record['geonet:info']['uuid']
if is_locked( cfg['session']['working_directory'], the_uuid ):
logging.info("Dataset with uuid = %s is already being indexed: skipping." % the_uuid)
continue
else:
lock(cfg['session']['working_directory'], the_uuid)
# delete_dataset_from_indices(cfg, record['geonet:info']['uuid'])
delete_dataset_from_dest_index(cfg, record['geonet:info']['uuid'])
send_record_to_the_metadata_processor(cfg, record)
if 'all' in uuids_to_get:
uuids_to_get = [None]
for uuid_to_get in uuids_to_get:
get_metadata_records_processor(
the_root_url = cfg['geonetwork']['url'],
the_no_records_per_page = cfg['geonetwork']['records_per_page'],
the_uuid_to_get = uuid_to_get,
the_uuids_to_filter_out = uuids_to_filter_out,
the_username = username,
the_password = password)
# if 'all' not in uuids_to_get:
#
# # get some datasets only
# for uuid_to_get in uuids_to_get:
# for record in get_metadata_records( cfg['geonetwork']['url'],
# cfg['geonetwork']['records_per_page'],
# uuid=uuid_to_get,
# the_filter=uuids_to_filter_out,
# username=username, password=password ):
#
# the_uuid = record['geonet:info']['uuid']
#
# if is_locked( cfg['session']['working_directory'], the_uuid ):
# logging.info("Dataset with uuid = %s is already being indexed: skipping." % the_uuid)
# continue
# else:
# lock(cfg['session']['working_directory'], the_uuid)
#
# # delete_dataset_from_indices(cfg, record['geonet:info']['uuid'])
# delete_dataset_from_dest_index(cfg, the_uuid)
# send_record_to_the_metadata_processor(cfg, record)
#
# else:
#
# # get all the datasets
# for record in get_metadata_records( cfg['geonetwork']['url'],
# cfg['geonetwork']['records_per_page'],
# uuid=None,
# the_filter=uuids_to_filter_out,
# username=username, password=password ):
#
# the_uuid = record['geonet:info']['uuid']
#
# if is_locked( cfg['session']['working_directory'], the_uuid ):
# logging.info("Dataset with uuid = %s is already being indexed: skipping." % the_uuid)
# continue
# else:
# lock(cfg['session']['working_directory'], the_uuid)
#
# # delete_dataset_from_indices(cfg, record['geonet:info']['uuid'])
# delete_dataset_from_dest_index(cfg, record['geonet:info']['uuid'])
# send_record_to_the_metadata_processor(cfg, record)
#connection.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment