From e4e52927dae0c03a0af22843b7d69dde60f5ba3e Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Thu, 8 Mar 2018 14:12:32 +0900 Subject: [PATCH] New option to only list unset data With the -u flag only XMP data that has unset or missing data will be listed --- README.md | 3 ++- bin/reverse_geolocate.py | 49 +++++++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index a61c47f..c6793e9 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ reverse_geolocate.py [-h] -i [-l LIGHTROOM FOLDER] [-s] [-f ] [-g GOOGLE API KEY] [-o] [-e EMIL ADDRESS] [-w] - [-r] [-a] [-c] [-n] [-v] [--debug] [--test] + [-r] [-u] [-a] [-c] [-n] [-v] [--debug] [--test] ### Arguments @@ -43,6 +43,7 @@ Argument | Argument Value | Description -e, --email | email address | For OpenStreetMap with a large number of access -g, --google | Google Maps API Key | If available, to avoid the access limitations to the reverse location lookup -r, --read-only | | Read only data from the XMP files and print them out. No LR DB connection is done or any map lookups +-u, --unset-only | | Only list XMP files with missing data -a, --no-autoadjust | | Do not try to auto adjust column width to terminal column width -c, --compact | | Do extra compact view -w, --write-settings | | Write the Google API key or the OpenStreetMap email into the settings file diff --git a/bin/reverse_geolocate.py b/bin/reverse_geolocate.py index 1ceb94e..09c3824 100755 --- a/bin/reverse_geolocate.py +++ b/bin/reverse_geolocate.py @@ -474,6 +474,13 @@ parser.add_argument('-r', '--read-only', help = 'Read current values from the XMP file only, do not read from LR or lookup any data and write back' ) +# only list unset ones +parser.add_argument('-u', '--unset-only', + dest = 'unset_only', + action = 'store_true', + help = 'Only list unset XMP files' +) + # don't try to do auto adjust in list view parser.add_argument('-a', '--no-autoadjust', dest = 'no_autoadjust', @@ -520,9 +527,12 @@ if not args.verbose: # init exclude source to list if not set if not args.exclude_sources: args.exclude_sources = [] +# init args unset (for list view) with 0 if unset +# if not args.unset_only: +# args.unset = 0 if args.debug: - print("### ARGUMENT VARS: I: {incl}, X: {excl}, L: {lr}, F: {fc}, M: {osm}, G: {gp}, E: {em}, R: {read}, A: {adj}, C: {cmp}, N: {nbk}, W: {wrc}, V: {v}, D: {d}, T: {t}".format( + print("### ARGUMENT VARS: I: {incl}, X: {excl}, L: {lr}, F: {fc}, M: {osm}, G: {gp}, E: {em}, R: {read}, U: {us}, A: {adj}, C: {cmp}, N: {nbk}, W: {wrc}, V: {v}, D: {d}, T: {t}".format( incl = args.xmp_sources, excl = args.exclude_sources, lr = args.lightroom_folder, @@ -531,6 +541,7 @@ if args.debug: gp = args.google_api_key, em = args.email, read = args.read_only, + us = args.unset, adj = args.no_autoadjust, cmp = args.compact_view, nbk = args.no_xmp_backup, @@ -651,6 +662,7 @@ cur = '' # count variables count = { 'all': 0, + 'listed': 0, 'read': 0, 'map': 0, 'cache': 0, @@ -904,21 +916,24 @@ for xmp_file in work_files: if args.debug: print("### => XMP: {}:{} => {}".format(xmp_fields[xmp_field], xmp_field, data_set[xmp_field])) if args.read_only: - # for read only we print out the data formatted - # headline check, do we need to print that - count['read'] = printHeader(header_line.format(page_no = page_no, page_all = page_all), count['read'], header_repeat) - # the data content - print(format_line.format( - filename = shortenPath(xmp_file, format_length['filename'], file_only = True), # shorten from the left - latitude = str(convertDMStoLat(data_set['GPSLatitude']))[:format_length['latitude']], # cut off from the right - longitude = str(convertDMStoLong(data_set['GPSLongitude']))[:format_length['longitude']], - code = data_set['CountryCode'][:2].center(4), # is only 2 chars - country = shortenString(data_set['Country'], width = format_length['country']), # shorten from the right - state = shortenString(data_set['State'], width = format_length['state']), - city = shortenString(data_set['City'], width = format_length['city']), - location = shortenString(data_set['Location'], width = format_length['location']), - path = shortenPath(xmp_file, format_length['path'], path_only = True) - )) + # view only if list all or if data is unset + if not args.unset_only or (args.unset_only and '' in data_set.values()): + # for read only we print out the data formatted + # headline check, do we need to print that + count['read'] = printHeader(header_line.format(page_no = page_no, page_all = page_all), count['read'], header_repeat) + # the data content + print(format_line.format( + filename = shortenPath(xmp_file, format_length['filename'], file_only = True), # shorten from the left + latitude = str(convertDMStoLat(data_set['GPSLatitude']))[:format_length['latitude']], # cut off from the right + longitude = str(convertDMStoLong(data_set['GPSLongitude']))[:format_length['longitude']], + code = data_set['CountryCode'][:2].center(4), # is only 2 chars + country = shortenString(data_set['Country'], width = format_length['country']), # shorten from the right + state = shortenString(data_set['State'], width = format_length['state']), + city = shortenString(data_set['City'], width = format_length['city']), + location = shortenString(data_set['Location'], width = format_length['location']), + path = shortenPath(xmp_file, format_length['path'], path_only = True) + )) + count['listed'] += 1 else: # create a duplicate copy for later checking if something changed data_set_original = data_set.copy() @@ -1043,6 +1058,8 @@ if use_lightroom: # end stats only if we write print("{}".format('=' * 39)) print("XMP Files found : {:9,}".format(count['all'])) +if args.read_only: + print("XMP Files listed : {:9,}".format(count['listed'])) if not args.read_only: print("Updated : {:9,}".format(count['changed'])) print("Skipped : {:9,}".format(count['skipped']))