def main(): """Main program""" logger.info('Starting Import') if args.photoset: photoset_id = photosetsCreate(args.photoset) for filename in args.files: # log what we're doing logger.info('Processing file %s', filename) # set some variables dateTaken=getDateTaken(filename) fileType = getfileType(os.path.basename(filename)) sha1=util.hashfile(filename) # insert pic into db photo_id = addPhotoToDB(sha1=sha1,fileType=fileType,dateTaken=dateTaken) # set photo privacy if args.privacy: setPhotoPrivacy(photo_id=photo_id,privacy=args.privacy) # archive the photo archivedPhoto=archivePhoto(filename,sha1,fileType,localArchivePath,args.S3,photo_id) # generate thumbnails thumbFilenames = util.genThumbnails(sha1,fileType,app.config,regen=args.regen) # send thumbnails to S3 S3success = False if args.S3 == True: if checkImportStatusS3(photo_id) == False: for thumbFilename in thumbFilenames: S3success = aws.uploadToS3(localArchivePath+'/'+thumbFilename,thumbFilename,app.config,regen=args.regen,policy='public-read') # save import meta saveImportMeta(photo_id,filename,importSource=args.importsource,S3=S3success) # add tags if args.tags: tags = args.tags.split(',') for tag in tags: photosAddTag(photo_id,tag) # add dirtags if args.dirtags: ignoreTags=app.config['IGNORETAGS'] dirTags(photo_id,filename,ignoreTags) # add parent dir tag if args.parentdirphotoset: parentDirPhotoSet(photo_id,filename) # add to photoset if args.photoset: photosetsAddPhoto(photoset_id,photo_id) # main logger.info('Import Finished')
def processPhoto(filename,localSha1='0'): # log what we're doing logger.info('Processing file %s', filename) # set some variables dateTaken=getDateTaken(filename) fileType = getfileType(os.path.basename(filename)) sha1=util.hashfile(filename) # check sha1 local against sha1 server if localSha1 == '0': logger.info('no SHA1 sent. oh well.') elif localSha1 != sha1: logger.error('SHA1 signatures DO NOT MATCH!') elif localSha1 == sha1: logger.info('SHA1 verified.') else: logger.info('SHA1 unknown state') # insert pic into db photo_id = addPhotoToDB(sha1=sha1,fileType=fileType,dateTaken=dateTaken) # archive the photo archivedPhoto=archivePhoto(filename,sha1,fileType,localArchivePath,uploadToS3,photo_id) # generate thumbnails thumbFilenames = util.genThumbnails(sha1,fileType,app.config) # send thumbnails to S3 if checkImportStatusS3(photo_id) == False: for thumbFilename in thumbFilenames: S3success = aws.uploadToS3(localArchivePath+'/'+thumbFilename,thumbFilename,app.config,regen=True,policy='public-read') else: S3success = False # save import meta saveImportMeta(photo_id,filename,importSource=os.uname()[1],S3=S3success,sha1=sha1) return(photo_id)
def archivePhoto(file,sha1,fileType,localArchivePath,uploadToS3,photo_id): """store the photo in the archive""" (sha1Path,sha1Filename)=util.getSha1Path(sha1) archivedPhoto='%s/%s/%s.%s' % (localArchivePath,sha1Path,sha1Filename,fileType) if not os.path.isdir(localArchivePath+'/'+sha1Path): os.makedirs(localArchivePath+'/'+sha1Path) if not os.path.isfile(archivedPhoto): try: logger.info('Copying %s -> %s',file,archivedPhoto) shutil.copy2(file,archivedPhoto) except Exception, e: raise e if uploadToS3 == True: if checkImportStatusS3(photo_id) == False: S3Key='%s/%s.%s' % (sha1Path,sha1Filename,fileType) aws.uploadToS3(file,S3Key,app.config,policy=app.config['AWSPOLICY']) return(archivedPhoto) def dirTags(photo_id,file,ignoreTags): """add tags based on directory structure""" osPathDirnames = os.path.dirname(file).split('/') dirTags = [] for osPathDirname in osPathDirnames: tag = str(osPathDirname) if tag != '': if tag not in ignoreTags: dirTags.append(tag) photosAddTag(photo_id,tag) return dirTags def parentDirPhotoSet(photo_id,file):