Added dry-run optional parameter.

This commit is contained in:
Marcus Scholz 2020-03-07 19:10:56 +01:00
parent 3eb17f53b5
commit 940da3a772
2 changed files with 13 additions and 4 deletions

View File

@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
- Added GPX parser
- Added optional dry-run modifier
## [0.2] - 2020-02-05
### Added

View File

@ -30,6 +30,8 @@ parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFo
them into the Exif tags of given photos.''')
parser.add_argument('-si', '--sifactor', type=float, default=0.0065,
help='Factor to multiply recorded CPM with.')
parser.add_argument('-d', '--dry', action='store_true',
help='Dry-run, do not actually write anything.')
parser.add_argument('csv', metavar='CSV', type=str,
help='Geiger counter history file in CSV format.')
parser.add_argument('-g', '--gpx', metavar='GPX', type=str,
@ -60,8 +62,13 @@ for srcphoto in args.photos:
else:
# be os aware and use the correct directory delimiter for destfile
dstphoto = os.path.join(args.outdir, photo_basename)
shutil.copy(srcphoto, dstphoto)
photo = dstphoto
print('dry-run:', args.dry)
if args.dry == 'True':
print('Copying file!')
shutil.copy(srcphoto, dstphoto)
photo = dstphoto
else:
photo = srcphoto
# Load Exif data from image
metadata = pyexiv2.ImageMetadata(photo)
@ -89,7 +96,8 @@ for srcphoto in args.photos:
# print found radiation levels
print('{:<15} {:<20} {:<22}'.format(photo_basename, str(pictime), new_comment))
# Write Exif tags to file
metadata.write()
if args.dry == 'True':
metadata.write()
break
else:
print('{:<15} {:<20} {:<22}'.format(photo_basename, str(pictime), 'NOT FOUND!'))
@ -97,7 +105,7 @@ for srcphoto in args.photos:
f.close()
# Import GPX track(s)
if hasattr(args, 'gpx'):
if args.gpx is not None:
gpx_file = open(args.gpx, 'r')
gpxreader = gpxpy.parse(gpx_file)