def copy(self, destdir): for f in self.files + [self.fxd_file, self.image, self.edl_file]: if f: error_msg = '' if vfs.isoverlay(f): d = vfs.getoverlay(destdir) else: d = destdir if not os.path.isdir(d): os.makedirs(d) if os.path.isdir(f): dst = os.path.join(d, os.path.split(f)[1]) shutil.copytree(f, dst) else: dst = os.path.join(d, os.path.split(f)[1]) if os.path.exists(dst): if config.SHOPPINGCART_CLOBBER: try: os.unlink(dst) except IOError, e: error_msg = 'Can\'t delete "%s": %s' % (dst, e) else: error_msg = 'Can\'t copy "%s", destination exists' % dst else: try: shutil.copy2(f, d) except IOError, e: error_msg = 'Can\'t copy "%s": %s' % (f, e)
def __init__(self, directory, parent, name='', display_type=None, add_args=None, create_metainfo=True, use_temp=False, cleanup=True): logger.log(9, '%s.__init__(directory=%r, parent=%r, name=%r, display_type=%r, add_args=%r, create_metainfo=%r, use_temp=%r, cleanup=%r)', self.__class__, directory, parent, name, display_type, add_args, create_metainfo, use_temp, cleanup) self.archive = os.path.abspath(directory) self.cleanup = cleanup self.valid = False fname = os.path.splitext(os.path.basename(self.archive))[0] # create the tmp directory that we will extract the content of the archive to if use_temp: dir = os.path.join(tempfile.gettempdir(), fname) else: dir = vfs.getoverlay(self.archive) try: if not os.path.exists(dir): os.makedirs(dir) except (OSError) as exc: logger.error('OS Error %s creating dir %s, skipping this archive...', exc, dir) return self.valid = True self.cover = self.set_cover_image(dir) # now we substitute the original dir/file name with the tmp dir location DirItem.__init__(self, dir, parent=parent, name=fname, display_type=display_type)
def copy(self, destdir): for f in self.files + [ self.fxd_file, self.image, self.edl_file ]: if f: error_msg='' if vfs.isoverlay(f): d = vfs.getoverlay(destdir) else: d = destdir if not os.path.isdir(d): os.makedirs(d) if os.path.isdir(f): dst = os.path.join(d, os.path.split(f)[1]) shutil.copytree(f, dst) else: dst = os.path.join(d, os.path.split(f)[1]) if os.path.exists(dst): if config.SHOPPINGCART_CLOBBER: try: os.unlink(dst) except IOError, e: error_msg='Can\'t delete "%s": %s' % (dst, e) else: error_msg='Can\'t copy "%s", destination exists' % dst else: try: shutil.copy2(f, d) except IOError, e: error_msg='Can\'t copy "%s": %s' % (f, e)
def move(self, destdir): for f in self.files + [ self.fxd_file, self.image, self.edl_file ]: if f: if vfs.isoverlay(f): d = vfs.getoverlay(destdir) else: d = destdir if not os.path.isdir(d): os.makedirs(d) os.system('mv "%s" "%s"' % (f, d))
def copy(self, destdir): for f in self.files + [ self.fxd_file, self.image, self.edl_file ]: if f: if vfs.isoverlay(f): d = vfs.getoverlay(destdir) else: d = destdir if not os.path.isdir(d): os.makedirs(d) if os.path.isdir(f): dst = os.path.join(d, os.path.split(f)[1]) shutil.copytree(f, dst) else: shutil.copy2(f, d)
def __init__(self, directory, parent, name='', display_type=None, add_args=None, create_metainfo=True, use_temp=False, cleanup=True): logger.log( 9, '%s.__init__(directory=%r, parent=%r, name=%r, display_type=%r, add_args=%r, create_metainfo=%r, use_temp=%r, cleanup=%r)', self.__class__, directory, parent, name, display_type, add_args, create_metainfo, use_temp, cleanup) self.archive = os.path.abspath(directory) self.cleanup = cleanup self.valid = False fname = os.path.splitext(os.path.basename(self.archive))[0] # create the tmp directory that we will extract the content of the archive to if use_temp: dir = os.path.join(tempfile.gettempdir(), fname) else: dir = vfs.getoverlay(self.archive) try: if not os.path.exists(dir): os.makedirs(dir) except (OSError) as exc: logger.error( 'OS Error %s creating dir %s, skipping this archive...', exc, dir) return self.valid = True self.cover = self.set_cover_image(dir) # now we substitute the original dir/file name with the tmp dir location DirItem.__init__(self, dir, parent=parent, name=fname, display_type=display_type)
def scale_and_save_image(filename, scale): if scale == (1.0, 1.0): return filename root,ext = os.path.splitext(filename) cache_dir = vfs.getoverlay(filename) cache_file = '%dx%d%s' % (skin.USABLE_WIDTH, skin.USABLE_HEIGHT, ext) cache_filename = os.path.join(cache_dir, cache_file) logger.debug('Looking for %s', cache_filename) if vfs.exists(cache_filename) and vfs.mtime(cache_filename) > vfs.mtime(filename): return cache_filename image = imlib2.open_without_cache(filename) new_width = int(float(image.width) * scale[0]) new_height = int(float(image.height) * scale[1]) image = image.scale((new_width, new_height)) # Make sure the file can be created. if not vfs.exists(cache_dir): os.makedirs(cache_dir) image.save(cache_filename) return cache_filename
def scale_and_save_image(filename, scale): if scale == (1.0, 1.0): return filename root, ext = os.path.splitext(filename) cache_dir = vfs.getoverlay(filename) cache_file = '%dx%d%s' % (skin.USABLE_WIDTH, skin.USABLE_HEIGHT, ext) cache_filename = os.path.join(cache_dir, cache_file) logger.debug('Looking for %s', cache_filename) if vfs.exists(cache_filename ) and vfs.mtime(cache_filename) > vfs.mtime(filename): return cache_filename image = imlib2.open_without_cache(filename) new_width = int(float(image.width) * scale[0]) new_height = int(float(image.height) * scale[1]) image = image.scale((new_width, new_height)) # Make sure the file can be created. if not vfs.exists(cache_dir): os.makedirs(cache_dir) image.save(cache_filename) return cache_filename
def get_image(filename, scale, size): cache_key = '%s-%s-%dx%d' % (filename, scale, size[0], size[1]) # First check the loaded image cache image = image_cache[cache_key] # Second check the on disk cache if config.CACHE_IMAGES and not image: if vfs.isoverlay(filename): cache_dir = os.path.dirname(filename) else: cache_dir = vfs.getoverlay(filename) root,ext = os.path.splitext(filename) cache_file = '%s-%s-%dx%d%s' % (USABLE_RESOLUTION, scale, size[0], size[1], ext) cache_filename = os.path.join(cache_dir, cache_file) if vfs.exists(cache_filename) and vfs.mtime(cache_filename) > vfs.mtime(filename): image = imlib2.open(cache_filename) image_cache[cache_key] = image # Finally load the image and scale it as required. if not image: if filename.startswith('http://') or filename.startswith('https://'): fp = webcache.get_default_cache().get(filename) image = imlib2.open_from_memory(fp.read()) fp.close() else: image = imlib2.open(filename) w = image.width h = image.height src_size = (image.width, image.height) if scale == 'horizontal': w = size[0] dst_size = (w, h) elif scale == 'vertical': h = size[1] dst_size = (w, h) elif scale == 'both': w = size[0] h = size[1] dst_size = (w, h) elif scale == 'aspect': aspect_ratio = float(w) / float(h) w = size[0] h = int(float(w) / aspect_ratio) if h > size[1]: w = int(float(size[1]) * aspect_ratio) h = size[1] dst_size = (w, h) else: if w > size[0]: w = size[0] if h > size[1]: h = size[1] size = (w, h) src_size = size dst_size = size logger.log( 9, 'Creating image %s (%dx%d) of size %dx%d using scale %s', filename, src_size[0], src_size[1], dst_size[0], dst_size[1], scale) image = image.scale(dst_size, src_size=src_size) image_cache[cache_key] = image if config.CACHE_IMAGES: if not vfs.exists(cache_dir): os.makedirs(cache_dir) image.save(cache_filename) logger.debug('Saved to %s', cache_filename) return image
def get_image(filename, scale, size): cache_key = '%s-%s-%dx%d' % (filename, scale, size[0], size[1]) # First check the loaded image cache image = image_cache[cache_key] # Second check the on disk cache if config.CACHE_IMAGES and not image: if vfs.isoverlay(filename): cache_dir = os.path.dirname(filename) else: cache_dir = vfs.getoverlay(filename) root, ext = os.path.splitext(filename) cache_file = '%s-%s-%dx%d%s' % (USABLE_RESOLUTION, scale, size[0], size[1], ext) cache_filename = os.path.join(cache_dir, cache_file) if vfs.exists(cache_filename ) and vfs.mtime(cache_filename) > vfs.mtime(filename): image = imlib2.open(cache_filename) image_cache[cache_key] = image # Finally load the image and scale it as required. if not image: if filename.startswith('http://') or filename.startswith('https://'): fp = webcache.get_default_cache().get(filename) image = imlib2.open_from_memory(fp.read()) fp.close() else: image = imlib2.open(filename) w = image.width h = image.height src_size = (image.width, image.height) if scale == 'horizontal': w = size[0] dst_size = (w, h) elif scale == 'vertical': h = size[1] dst_size = (w, h) elif scale == 'both': w = size[0] h = size[1] dst_size = (w, h) elif scale == 'aspect': aspect_ratio = float(w) / float(h) w = size[0] h = int(float(w) / aspect_ratio) if h > size[1]: w = int(float(size[1]) * aspect_ratio) h = size[1] dst_size = (w, h) else: if w > size[0]: w = size[0] if h > size[1]: h = size[1] size = (w, h) src_size = size dst_size = size logger.log(9, 'Creating image %s (%dx%d) of size %dx%d using scale %s', filename, src_size[0], src_size[1], dst_size[0], dst_size[1], scale) image = image.scale(dst_size, src_size=src_size) image_cache[cache_key] = image if config.CACHE_IMAGES: if not vfs.exists(cache_dir): os.makedirs(cache_dir) image.save(cache_filename) logger.debug('Saved to %s', cache_filename) return image