picseal_pub/picseal.py

68 lines
1.8 KiB
Python

#
#
#
import os
import argparse
import logging
from shutil import copyfile
#from subprocess import Popen, PIPE, check_call
from libs.crypto_pub import PubKey
from libs.img_exif import ImgExif
from libs.toolbox import Toolbox
def main():
parseArgs()
def processImage(image_fn):
img = ImgExif()
img.useImg(image_fn)
key = PubKey()
img.appendKey(key)
img.saveFile()
def copyImage(image_fn):
basename = os.path.basename(image_fn)
(filename, ext) = Toolbox.parseFilenameIncExt(basename)
newFileName = filename + '_' + Toolbox.getTimestampStr() + ext
copyfile(image_fn, newFileName)
return newFileName
def parseArgs():
print("***** ***** ***** *****")
print(" ** Pic * Seal ** ")
print("***** ***** ***** *****\n")
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--image', required=False, help="source image file")
parser.add_argument('-v', '--verbose', action='store_true', help="will set logging level to INFO")
parser.add_argument('-vv', '--vverbose', action='store_true', help="will set logging level to DEBUG")
parser.add_argument('-l', '--logging', action='store_true', help="will supercede the -v option and send all logging to a file, logging.DEBUG")
args = parser.parse_args()
if (args.logging):
logging.basicConfig(filename='dbfp.log', level=logging.DEBUG)
if (args.verbose):
logging.basicConfig(level=logging.INFO)
elif (args.vverbose):
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.CRITICAL)
if (args.image):
newImg = copyImage(args.image)
processImage(newImg)
else:
print('Create PicSeal images')
print(' picseal.py -i <image_file>')
print('\n***** ***** ***** *****\n')
parser.print_help()
if __name__ == "__main__":
main()
print