Beispiel #1
0
def store_original(pth, storedat=None):
    '''Store a copy of the original and return the copy's location'''
    if not storedat:
        # get an unused file name to store the original
        storedat = find_storage_space(pth)
    logging.debug('pushing original to %s', storedat)
    ignore_file(storedat)
    pth.copy(storedat)
    # check if the copy was successful
    if not same_file(pth, storedat):
        raise AttributeError('copy seems to differ from original')
    return storedat
Beispiel #2
0
def store_original(pth, storedat=None):
    '''Store a copy of the original and return the copy's location'''
    if not storedat:
        # get an unused file name to store the original
        storedat = find_storage_space(pth)
    logging.debug('pushing original to %s', storedat)
    ignore_file(storedat)
    pth.copy(storedat)
    # check if the copy was successful
    if not same_file(pth, storedat):
        raise AttributeError('copy seems to differ from original')
    return storedat
Beispiel #3
0
def handle_file(pth):
    '''Optimizes an image and stores an original if KEEP_ORIGINALS is set'''
    logging.info('Optimizing file %s', pth)
    if KEEP_ORIGINALS:
        if pth in store.originals:
            # we have previously optimized this file and know where to store it
            storedat = store_original(pth, store.originals[pth])
        else:
            storedat = store_original(pth)
    # the original gets briefly added to ignore so watchdog doesnt pick it up
    ignore_file(pth)
    optimize_with_touch(pth)
    if KEEP_ORIGINALS:
        # only keep the file if we actually optimized it
        if same_file(storedat, pth):
            storedat.remove()
        else:
            store_original_location(pth, storedat)
Beispiel #4
0
def handle_file(pth):
    '''Optimizes an image and stores an original if KEEP_ORIGINALS is set'''
    logging.info('Optimizing file %s', pth)
    if KEEP_ORIGINALS:
        if pth in store.originals:
            # we have previously optimized this file and know where to store it
            storedat = store_original(pth, store.originals[pth])
        else:
            storedat = store_original(pth)
    # the original gets briefly added to ignore so watchdog doesnt pick it up
    ignore_file(pth)
    optimize_with_touch(pth)
    if KEEP_ORIGINALS:
        # only keep the file if we actually optimized it
        if same_file(storedat, pth):
            storedat.remove()
        else:
            store_original_location(pth, storedat)
Beispiel #5
0
 def test_store_original(self):
     img = self.img_path('jpg')
     orig = store_original(img)
     self.assertTrue(same_file(img, orig))
     orig.remove()