def snap(self): try: config = Configurator.instance(); imagefile = config.getDefaultImageFilename() install_dir = config.getInstallDir() imagefilepath = install_dir+"/" + imagefile # Get flash object... flash = CameraFlash.instance() flash.fireFlash()#...and fire flash ON time.sleep(config.getFlashOnTime()) self.capture(imagefilepath) # Turn flash off flash.flashOff() new_filename, fun_filename = archiveImage(imagefilepath) return new_filename, fun_filename except Exception as e: printExceptionTrace("BoothCamera.snap(): exception! ", e) new_filename = None return new_filename
def __init__(self): if CameraFlash.__instance__ != None: raise Exception( "CameraFlash is a Singleton! Please use 'instance()' to get an object." ) CameraFlash.__instance__ = self self.gpio_pin = Configurator.instance().getFlashGPIOAssignment()
def funStuff(sourceimage, idx): logging.info("In funStuff()...") config = Configurator.instance() cmd = config.getFunCMD() if cmd == None or cmd == "pass": return None sourceimage = resizeImage(sourceimage) archive_dir = config.getArchiveFolder() ext = config.getBaseImageExt() if os.path.exists(archive_dir) and os.path.exists(sourceimage): out_filename = archive_dir + "/" + '%s_%s.%s' % ("picture", "fun_" + str(idx), ext) #out_filename = '%s_%s.%s' % (image_filename[:-4], "fun_"+str(idx),ext) logging.info("out_filename: " + out_filename) install_dir = config.getInstallDir() cmd = install_dir + "/scripts/" + cmd + " " + sourceimage + " " + out_filename logging.info("FunCMD: " + cmd) os.system(cmd) logging.info("In funStuff(): Exiting...") return out_filename
def archiveImage(image_filename): logging.info("In archiveImage()...") config = Configurator.instance() archive_dir = config.getArchiveFolder() ext = config.getBaseImageExt() next_idx = UniqueIndex.instance().getNextIndex() logging.info("archive_dir: " + archive_dir) logging.info("image_filepath.ext: " + image_filename) logging.info("next_idx: " + str(next_idx)) if os.path.exists(archive_dir) and os.path.exists(image_filename): new_filename = archive_dir + "/" + '%s_%s.%s' % ("picture", str(next_idx), ext) logging.info("new_filename: " + new_filename) command = (['cp', image_filename, new_filename]) call(command) fun_filename = funStuff(image_filename, next_idx) logging.info("In archiveImage(): Exiting...") return new_filename, fun_filename
def doUpload(self, images_array): logging.info("In PicasaUploader.doUpload():...") album = Configurator.instance().getGoogleAlbum() if album == -1: logging.error( "NO ALBUM ID present in configuration. Please select Google album using the configuration tool" ) return album_url = '/data/feed/api/user/%s/albumid/%s' % ( credentials.username, album) logging.info( "PicasaUploader.doUpload(): Uploading to album. URL = [%s]" % (album_url)) i = 0 while i < len(images_array): imgfile = images_array[i] s = "PicasaUploader.doUpload(): Uploading image file: [%s]..." % ( imgfile) logging.info(s) self.client.InsertPhotoSimple(album_url, 'VKSnap', "", imgfile, content_type='image/jpeg') s = "PicasaUploader.doUpload(): DONE with [%s]..." % (imgfile) logging.info(s) i = i + 1
def initGoogleSetup(self): if Configurator.instance().getIsUploadNeeded() == False: return self.is_successful_signin = True try: print "Signing in to Google..." # Create a client class which will make HTTP requests with Google Docs server. configdir = os.path.expanduser('./') client_secrets = os.path.join(configdir, 'OpenSelfie.json') credential_store = os.path.join(configdir, 'credentials.dat') self.client = credentials.OAuth2Login(client_secrets, credential_store, credentials.username) logging.info("Successfully signed into Google!") print "Signed in" except KeyboardInterrupt as ki: printExceptionTrace("KeyboardInterrupt", ki) except Exception as e: printExceptionTrace("Error signing into Google. Check credentials", e) self.is_successful_signin = False
def resizeImage(sourceimage): logging.info("In resizeImage...") config = Configurator.instance() install_dir = config.getInstallDir() image = PIL.Image.open(sourceimage) cover = resizeimage.resize_cover(image, [800, 480]) cover.save(install_dir + "/res_picture.jpg", image.format) logging.info("Resized image successfully!") return install_dir + "/res_picture.jpg"
def fireFlash(self): config = Configurator.instance() # If flash is configured to be ON... if config.getFlashDisposition(): GPIO.setmode(GPIO.BOARD) GPIO.setup(self.gpio_pin, GPIO.OUT) #...then set the appropriate GPIO pin to HIGH GPIO.output(self.gpio_pin, GPIO.HIGH)
def __init__(self): if BoothCamera.__instance__ is not None: raise Exception("BoothCamera is a Singleton! Try using the 'instance()' method.") BoothCamera.__instance__ = self super(BoothCamera, self).__init__() config = Configurator.instance() self.resolution = config.getResolution() # Resolution of preview as well as capture self.preview_alpha = config.getPreviewAlpha() # Opacity of the preview screen self.preview_fullscreen = False self.preview_window = (0, 40, config.getScreenWidth(), config.getScreenHeight() - 93) self.iso = config.getISO() self.sharpness = config.getSharpness()
def snap(self): try: config = Configurator.instance() imagefile = config.getDefaultImageFilename() self.capture(imagefile) new_filename = archiveImage(imagefile) return new_filename except Exception as e: printExceptionTrace("BoothCamera.snap(): exception! ", e) new_filename = None return new_filename
def prepUpload(self, images_array): logging.info("In PicasaUploader.prepUpload()...") if self.is_successful_signin: if Configurator.instance().getGoogleAlbum() == -1: logging.info( "Need for first select an album. Select album using the 'Configure' button" ) logging.error("NOTHING Uploaded!") else: return True else: logging.info( "There was no successful signin! Please perform the necessary setups" ) return False
def workFunction(self, files_array): logging.info("GoogleDriveUploader.workFunction()...") # Get name of folder to upload from configuration and... folder=Configurator.instance().getGoogleDriveUploadFolder() if folder == None: raise Exception("GoogleDriveUploader.workFunction(): Invalid Google Drive folder") # ...try to find the folder on google drive. upload_folder_id = self.findFolder(folder) if upload_folder_id == None: raise Exception("Invalid folder: [%s]. Please create this folder on the drive." % (folder)) # Iterate and upload. Simple. for filepath in files_array: logging.info("GoogleDriveUploader.workFunction(): Uploading to folder: [%s], thefile: [%s]..." % (folder, filepath)) self.upload(filepath, upload_folder_id) logging.info("GoogleDriveUploader.workFunction(): DONE with [%s]" % (filepath))
def uploadImages(picsarray): global picasa_uploader, drive_uploader config= Configurator.instance() if config.isUploadToPicasa(): logging.info("Uploading to Picasa...") # if picasa_uploader == None: # picasa_uploader = PicasaUploader.instance() # picasa_uploader.kickOff(picsarray) else: logging.info("Upload to Picasa OFF in configuration") if config.isUploadToDrive(): logging.info("Uploading to Google Drive...") if drive_uploader == None: drive_uploader = GoogleDriveUploader.instance() drive_uploader.kickOff(picsarray) else: logging.info("Upload to Google OFF in configuration")
def doUpload(self, files_array): logging.info("GoogleDriveUploader.doUpload()...") # Get name of folder to upload from configuration and... folder = Configurator.instance().getGoogleDriveUploadFolder() if folder == None: raise Exception( "GoogleDriveUploader.doUpload(): Invalid Google Drive folder") #...try to find the folder on google drive. upload_folder_id = None file_list = self.drive.ListFile({ 'q': "'root' in parents and trashed=false" }).GetList() for file in file_list: if file["title"] == folder: # Found folder to upload to... upload_folder_id = file["id"] break if upload_folder_id == None: raise Exception( "Invalid folder: [%s]. Please create this folder on the drive." % (folder)) # Iterate and upload. Simple. for infilepath in files_array: logging.info( "GoogleDriveUploader.doUpload(): Uploading to folder: [%s], file: [%s]..." % (folder, infilepath)) handle = self.drive.CreateFile({ "parents": [{ "kind": "drive#fileLink", "id": upload_folder_id }] }) handle.SetContentFile(infilepath) handle.Upload() logging.info("GoogleDriveUploader.doUpload(): DONE with [%s]" % (infilepath))
def start_preview(self): config = Configurator.instance() super(BoothCamera, self).start_preview()
def capture(self, imagefilename): config = Configurator.instance() logging.info("In BoothCamera.capture(): resolution= %s, ISO=%d, sharpness=%s" % ( str(self.resolution), self.iso, self.sharpness)) return super(BoothCamera, self).capture(imagefilename)
def getNextIndex(self): return calendar.timegm( time.gmtime()) % (Configurator.instance().getModuloBaseline())