def run(self): while True: #grabs host from queue downloadImage = self._queue.get() category = downloadImage[0] subcategory = downloadImage[1] album = downloadImage[2] filename = downloadImage[3] id = downloadImage[4] key = downloadImage[5] myLogger.debug("going to smugmug to get image url for %s", filename) response = self._smugmug.images_getURLs(ImageID=id, ImageKey=key) url = response["Image"]["OriginalURL"] myLogger.info("Downloading image from '%s'", url) filepath = fileUtil.buildfilePath(self._configobj.picture_root, category, subcategory, album) fileUtil.mkdir(filepath) filepath = filepath+filename myLogger.info("Saving downloaded image to '%s'", filepath) file = urllib2.urlopen(url) output = open(filepath,'wb') output.write(file.read()) output.close() self._lock.acquire() db.addLocalImage(self._conn, subcategory, category, album, self._sync, fileUtil.md5(filepath), self._configobj.picture_root, filename, format(filepath.lstrip(self._configobj.picture_root)), self._sync) db.insertImageLog(self._conn, id, filename, album, category, subcategory, self._sync, 'Download') self._lock.release() #signals to queue job is done self._queue.task_done()
def _processFoundFile(conn, picture_root, pictureFile, timestamp, lock): myLogger.debug("_processFoundFile(%s,%s)", picture_root, pictureFile) last_updated = datetime.datetime.fromtimestamp(os.path.getmtime(pictureFile)) md5_sum = fileUtil.md5(pictureFile) pictureFile = format(pictureFile.lstrip(picture_root)) path_root = picture_root album = os.path.basename(os.path.dirname(pictureFile)) file_name = os.path.basename(pictureFile) sub_category = os.path.basename(os.path.dirname(os.path.dirname(pictureFile))) category = os.path.basename(os.path.dirname(os.path.dirname(os.path.dirname(pictureFile)))) if category == "" or category == None: category = sub_category sub_category = None myLogger.debug("path_root: '%s', album: '%s', last_updated: '%s', md5_sum: '%s', file_name: '%s', sub_category: '%s', category: '%s', file_path: '%s', timestamp: '%s'", path_root, album ,last_updated,md5_sum,file_name,sub_category,category,pictureFile, timestamp) lock.acquire() db.addLocalImage(conn, sub_category, category, album, last_updated, md5_sum, path_root, file_name, pictureFile, timestamp) lock.release() myLogger.debug("_processFoundFile(%s,%s) completed", picture_root, pictureFile)
def run(self): #smugmug.images_upload(AlbumID=2,File='/Path/To/Image.jpg') while self._run: #grabs host from queue uploadImage = self._queue.get() albumid = uploadImage[0] filepath = uploadImage[1]+"/"+uploadImage[2] myLogger.debug("Starting upload of image '%s'", filepath) try: response = self._smugmug.images_upload(AlbumID=albumid,File=filepath) myLogger.debug("Finished upload of image '%s'. Now getting item info to log in db.", filepath) pictureFile = uploadImage[2] album = os.path.basename(os.path.dirname(pictureFile)) subcategory = os.path.basename(os.path.dirname(os.path.dirname(pictureFile))) category = os.path.basename(os.path.dirname(os.path.dirname(os.path.dirname(pictureFile)))) if category == "" or category == None: category = subcategory subcategory = None imageid = response["Image"]["id"] imagekey = response["Image"]["Key"] myLogger.debug("Image uploaded Key:'{0}' ID:'{1}'".format(imagekey, imageid)) response = self._smugmug.images_getInfo(ImageID=imageid, ImageKey=imagekey) myLogger.debug("Local MD5_SUM: {0} SmugMug: {1}".format(fileUtil.md5(filepath),response["Image"]["MD5Sum"])) self._lock.acquire() db.addSmugImage(self._conn,albumid, datetime.strptime(response["Image"]["LastUpdated"],'%Y-%m-%d %H:%M:%S'), response["Image"]["MD5Sum"], response["Image"]["Key"], response["Image"]["id"], response["Image"]["FileName"]) db.insertImageLog(self._conn, imageid, response["Image"]["FileName"], album, category, subcategory, datetime.now(), 'Upload') self._lock.release() myLogger.debug("Finished queued item.") except Exception, err: myLogger.error("Exception({0}): {1}".format(filepath,err)) traceback.print_exc(file=sys.stdout) #self._queue.put(uploadImage) #signals to queue job is done self._queue.task_done()