コード例 #1
0
ファイル: syncUtil.py プロジェクト: softeng13/Smuggler
 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()
コード例 #2
0
ファイル: fileScan.py プロジェクト: softeng13/Smuggler
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)