def delete_old_files_1(): """ delete old files from previous versions of freevo which are not needed anymore """ #TODO Add WWW_LINK_CACHE and WWW_IMAGE_CACNE print checking('deleting old cache files from older freevo version'), sys.__stdout__.flush() del_list = [] #for name in ('image-viewer-thumb.jpg', 'thumbnails', 'audio', 'mmpython', 'disc', 'image_cache', 'link_cache'): for name in ('image-viewer-thumb.jpg', 'thumbnails', 'audio', 'mmpython', 'disc'): if os.path.exists(os.path.join(config.FREEVO_CACHEDIR, name)): del_list.append(os.path.join(config.FREEVO_CACHEDIR, name)) del_list += util.recursefolders(config.OVERLAY_DIR, 1, 'mmpython', 1) del_list += util.match_files(os.path.join(config.OVERLAY_DIR, 'disc'), ['mmpython', 'freevo']) for file in util.match_files_recursively(config.OVERLAY_DIR, ['png']): if file.endswith('.fvt.png'): del_list.append(file) for f in del_list: if os.path.isdir(f): util.rmrf(f) else: os.unlink(f) print 'deleted %s file%s' % (len(del_list), len(del_list) != 1 and 's' or '')
def addPathDB(path, dirtitle, type='*.mp3;*.ogg;*.flac', verbose=True): logger.log( 9, 'addPathDB(path=%r, dirtitle=%r, type=%r, verbose=%r)', path, dirtitle, type, verbose) # Get some stuff ready count = 0 db = MetaDatabase(); if not db.checkTable('music'): db.runQuery(dbschema) # Compare and contrast the db to the disc songs = util.recursefolders(path, 1, type, 1) for row in db.runQuery('SELECT path, filename FROM music'): try: songs.remove(os.path.join(row['path'], row['filename'])) count = count + 1 except ValueError: # Why doesn't it just give a return code pass if count > 0 and verbose: print " Skipped %i songs already in the database..." % (count) for song in songs: db.runQuery(make_query(song, dirtitle)) db.close()
def delete_old_files_2(): """ delete cachfiles/entries for files which don't exists anymore """ print checking('deleting old web-server thumbnails'), sys.__stdout__.flush() num = 0 for file in util.match_files_recursively(vfs.www_image_cachedir(), config.IMAGE_SUFFIX): if not vfs.isfile( file[len(vfs.www_image_cachedir()):file.rindex('.')]): os.unlink(file) num += 1 print 'deleted %s file%s' % (num, num != 1 and 's' or '') print checking('deleting old cache files'), sys.__stdout__.flush() num = 0 for file in util.match_files_recursively(config.OVERLAY_DIR, ['raw']): if file.startswith(os.path.join(config.OVERLAY_DIR, 'disc')): continue if not vfs.isfile(file[len(config.OVERLAY_DIR):-4]): os.unlink(file) num += 1 print 'deleted %s file%s' % (num, num != 1 and 's' or '') print checking('deleting cache for directories not existing anymore'), subdirs = util.get_subdirs_recursively(config.OVERLAY_DIR) subdirs.reverse() for file in subdirs: if not os.path.isdir(file[len(config.OVERLAY_DIR):]) and not \ file.startswith(os.path.join(config.OVERLAY_DIR, 'disc')): for metafile in ('cover.png', 'cover.png.raw', 'cover.jpg', 'cover.jpg.raw', 'mmpython.cache', 'freevo.cache'): if os.path.isfile(os.path.join(file, metafile)): os.unlink(os.path.join(file, metafile)) if not os.listdir(file): os.rmdir(file) print 'done' print checking('deleting old entries in meta-info'), sys.__stdout__.flush() for filename in util.recursefolders(config.OVERLAY_DIR, 1, 'freevo.cache', 1): if filename.startswith(os.path.join(config.OVERLAY_DIR, 'disc')): continue sinfo = os.stat(filename) if not sinfo[ST_SIZE]: #print '%s is empty' % filename continue dirname = os.path.dirname(filename)[len(config.OVERLAY_DIR):] data = util.read_pickle(filename) for key in copy.copy(data): if not os.path.exists(os.path.join(dirname, str(key))): del data[key] util.save_pickle(data, filename) print 'done'
def del_cache(): """ delete all cache files because kaa metadata got updated """ for f in util.recursefolders(config.OVERLAY_DIR,1,'mmpython.cache',1): os.unlink(f) for f in util.match_files(config.OVERLAY_DIR + '/disc/metadata', ['mmpython']): os.unlink(f) cachefile = os.path.join(config.FREEVO_CACHEDIR, 'mediainfo') util.save_pickle((mmpython.version.VERSION, 0, 0, 0), cachefile)
def parse_plugins2(): """ The idea is to extract the PluginInterface class or classes from the source module and then to import it and extract the __doc__ string from the Class and the config() from the class instance. This does't quite work, neither does import PluginInterface from <m> as <a> nor do any of the import methods that I've tried. I've left this code in to remind any that this techique does work in all cases, it does work in come cases and from the freevo prompt. """ import time import pygame from screensaver import ScreenSaverPlugin from idlebar import IdleBarPlugin from util import Rendezvous import osd osd = osd.get_singleton() all_plugins = [] print "FREEVO_PYTHON", os.environ["FREEVO_PYTHON"] print "PYTHONPATH", os.environ["PYTHONPATH"] for file in util.recursefolders(os.environ["FREEVO_PYTHON"], 1, "*.py", 1): if file.find("plugin.py") > 0: continue data = open(file, "r").read() for plugin_interface in find_plugin_interface(data): if not plugin_interface: print "Can't find interface in %s" % file continue try: exec plugin_interface except Exception, e: print "Error:1:%s: %s" % (file, e) break print "<<<%s>>>" % file print PluginInterface.__bases__ for base in PluginInterface.__bases__: print base.__name__ print PluginInterface.__doc__ try: interface = PluginInterface() print interface.config() except Exception, e: print "Error:2:%s: %s" % (file, e) continue interface = None PluginInterface = None
def delete_old_files_2(): """ delete cachfiles/entries for files which don't exists anymore """ print checking('deleting old web-server thumbnails'), sys.__stdout__.flush() num = 0 for file in util.match_files_recursively(vfs.www_image_cachedir(), config.IMAGE_SUFFIX): if not vfs.isfile(file[len(vfs.www_image_cachedir()):file.rindex('.')]): os.unlink(file) num += 1 print 'deleted %s file%s' % (num, num != 1 and 's' or '') print checking('deleting old cache files'), sys.__stdout__.flush() num = 0 for file in util.match_files_recursively(config.OVERLAY_DIR, ['raw']): if file.startswith(os.path.join(config.OVERLAY_DIR, 'disc')): continue if not vfs.isfile(file[len(config.OVERLAY_DIR):-4]): os.unlink(file) num += 1 print 'deleted %s file%s' % (num, num != 1 and 's' or '') print checking('deleting cache for directories not existing anymore'), subdirs = util.get_subdirs_recursively(config.OVERLAY_DIR) subdirs.reverse() for file in subdirs: if not os.path.isdir(file[len(config.OVERLAY_DIR):]) and not \ file.startswith(os.path.join(config.OVERLAY_DIR, 'disc')): for metafile in ('cover.png', 'cover.png.raw', 'cover.jpg', 'cover.jpg.raw', 'mmpython.cache', 'freevo.cache'): if os.path.isfile(os.path.join(file, metafile)): os.unlink(os.path.join(file, metafile)) if not os.listdir(file): os.rmdir(file) print 'done' print checking('deleting old entries in meta-info'), sys.__stdout__.flush() for filename in util.recursefolders(config.OVERLAY_DIR, 1, 'freevo.cache', 1): if filename.startswith(os.path.join(config.OVERLAY_DIR, 'disc')): continue sinfo = os.stat(filename) if not sinfo[ST_SIZE]: #print '%s is empty' % filename continue dirname = os.path.dirname(filename)[len(config.OVERLAY_DIR):] data = util.read_pickle(filename) for key in copy.copy(data): if not os.path.exists(os.path.join(dirname, str(key))): del data[key] util.save_pickle(data, filename) print 'done'
def parse_plugins2(): """ The idea is to extract the PluginInterface class or classes from the source module and then to import it and extract the __doc__ string from the Class and the config() from the class instance. This does't quite work, neither does import PluginInterface from <m> as <a> nor do any of the import methods that I've tried. I've left this code in to remind any that this techique does work in all cases, it does work in come cases and from the freevo prompt. """ import time import pygame from screensaver import ScreenSaverPlugin from idlebar import IdleBarPlugin from util import Rendezvous import osd osd = osd.get_singleton() all_plugins = [] print 'FREEVO_PYTHON', os.environ['FREEVO_PYTHON'] print 'PYTHONPATH', os.environ['PYTHONPATH'] for file in util.recursefolders(os.environ['FREEVO_PYTHON'], 1, '*.py', 1): if file.find('plugin.py') > 0: continue data = open(file, 'r').read() for plugin_interface in find_plugin_interface(data): if not plugin_interface: print 'Can\'t find interface in %s' % file continue try: exec plugin_interface except Exception, e: print 'Error:1:%s: %s' % (file, e) break print '<<<%s>>>' % file print PluginInterface.__bases__ for base in PluginInterface.__bases__: print base.__name__ print PluginInterface.__doc__ try: interface = PluginInterface() print interface.config() except Exception, e: print 'Error:2:%s: %s' % (file, e) continue interface = None PluginInterface = None
def hash_fxd_movie_database(): """ hash fxd movie files in some directories. This is used e.g. by the rom drive plugin, but also for a directory and a videoitem. """ import fxditem global tv_show_information global discset_information global fxd_database fxd_database['id'] = {} fxd_database['label'] = [] discset_information = {} tv_show_information = {} rebuild_file = os.path.join(config.FREEVO_CACHEDIR, 'freevo-rebuild-database') if vfs.exists(rebuild_file): try: os.remove(rebuild_file) except OSError: print '*********************************************************' print print '*********************************************************' print 'ERROR: unable to remove %s' % rebuild_file print 'please fix permissions' print '*********************************************************' print return 0 logger.log(9, "Building the xml hash database...") files = [] if not config.VIDEO_ONLY_SCAN_DATADIR: if len(config.VIDEO_ITEMS) == 2: for name, dir in config.VIDEO_ITEMS: files += util.recursefolders(dir, 1, '*.fxd', 1) for subdir in ('disc', 'disc-set'): files += util.recursefolders(vfs.join(config.OVERLAY_DIR, subdir), 1, '*.fxd', 1) for info in fxditem.mimetype.parse(None, files, display_type='video'): if hasattr(info, '__fxd_rom_info__'): for i in info.__fxd_rom_id__: fxd_database['id'][i] = info for l in info.__fxd_rom_label__: fxd_database['label'].append((re.compile(l), info)) for fo in info.__fxd_files_options__: discset_information[fo['file-id']] = fo['mplayer-options'] if config.VIDEO_SHOW_DATA_DIR: files = util.recursefolders(config.VIDEO_SHOW_DATA_DIR, 1, '*.fxd', 1) for info in fxditem.mimetype.parse(None, files, display_type='video'): if info.type != 'video': continue k = vfs.splitext(vfs.basename(info.files.fxd_file))[0] tv_show_information[k] = (info.image, info.info, info.mplayer_options, info.skin_fxd) if hasattr(info, '__fxd_rom_info__'): for fo in info.__fxd_files_options__: discset_information[fo['file-id']] = fo['mplayer-options'] logger.log(9, 'done') return 1
def hash_fxd_movie_database(): """ hash fxd movie files in some directories. This is used e.g. by the rom drive plugin, but also for a directory and a videoitem. """ import fxditem global tv_show_information global discset_information global fxd_database fxd_database['id'] = {} fxd_database['label'] = [] discset_information = {} tv_show_information = {} rebuild_file = os.path.join(config.FREEVO_CACHEDIR, 'freevo-rebuild-database') if vfs.exists(rebuild_file): try: os.remove(rebuild_file) except OSError: print '*********************************************************' print print '*********************************************************' print 'ERROR: unable to remove %s' % rebuild_file print 'please fix permissions' print '*********************************************************' print return 0 logger.log( 9, "Building the xml hash database...") files = [] if not config.VIDEO_ONLY_SCAN_DATADIR: if len(config.VIDEO_ITEMS) == 2: for name, dir in config.VIDEO_ITEMS: files += util.recursefolders(dir, 1, '*.fxd', 1) for subdir in ('disc', 'disc-set'): files += util.recursefolders(vfs.join(config.OVERLAY_DIR, subdir), 1, '*.fxd', 1) for info in fxditem.mimetype.parse(None, files, display_type='video'): if hasattr(info, '__fxd_rom_info__'): for i in info.__fxd_rom_id__: fxd_database['id'][i] = info for l in info.__fxd_rom_label__: fxd_database['label'].append((re.compile(l), info)) for fo in info.__fxd_files_options__: discset_information[fo['file-id']] = fo['mplayer-options'] if config.VIDEO_SHOW_DATA_DIR: files = util.recursefolders(config.VIDEO_SHOW_DATA_DIR, 1, '*.fxd', 1) for info in fxditem.mimetype.parse(None, files, display_type='video'): if info.type != 'video': continue k = vfs.splitext(vfs.basename(info.files.fxd_file))[0] tv_show_information[k] = (info.image, info.info, info.mplayer_options, info.skin_fxd) if hasattr(info, '__fxd_rom_info__'): for fo in info.__fxd_files_options__: discset_information[fo['file-id']] = fo['mplayer-options'] logger.log( 9, 'done') return 1
def parse_plugins(plugin_name=''): start = re.compile('^class *(.*)\((.*Plugin\s*).:') stop = re.compile('^[\t ]*def.*:') comment = re.compile('^[\t ]*"""') config_start = re.compile('^[ \t]+def +config *\( *self *\) *:') config_end = re.compile(' *(class|def|@)') print_line = 0 ptypes = {} all_plugins = [] active = [] for p in plugin.__all_plugins__: active.append(p[0]) plugin_shortname = plugin_name.split('.')[-1] + '.py' plugin_init_name = os.path.join(plugin_name.split('.')[-1], '__init__.py') for file in util.recursefolders(os.environ['FREEVO_PYTHON'], 1, '*.py', 1): if file.find('plugin.py') > 0: continue if plugin_name: if file.find(plugin_shortname) < 0 and file.find( plugin_init_name) < 0: continue parse_status = 0 whitespaces = 0 scan_config = 0 for line in util.readfile(file) + ['class Foo']: if config_end.match(line) and scan_config: scan_config = 0 all_plugins[-1][-1] = config if scan_config: config += line + '\n' if config_start.match(line): config = 'def return_config():\n' scan_config = line.find('def') if (comment.match(line) and parse_status == 2) or (stop.match(line) and parse_status == 1): parse_status = 0 all_plugins[-1][-2] = desc if parse_status == 2: if desc: desc += '\n' if not whitespaces: tmp = line.lstrip() whitespaces = line.find(tmp) desc += line[whitespaces:].rstrip() if comment.match(line) and parse_status == 1: parse_status = 2 whitespaces = 0 if start.match(line): fname = re.sub('^src.', '', file) fname = re.sub('^%s.' % os.environ['FREEVO_PYTHON'], '', fname) fname = re.sub('/', '.', os.path.splitext(fname)[0]) fname = re.sub('^plugins.', '', fname) fname = re.sub('.__init__', '', fname) type = start.match(line).group(2).strip() if re.match('^plugin.(.*)', type): type = re.match('^plugin.(.*)', type).group(1) if start.match(line).group(1) == 'PluginInterface': name = fname else: name = '%s.%s' % (fname, start.match(line).group(1)) if name in active: status = 'active' else: status = 'not loaded' parse_status = 1 desc = '' if not name in ('idlebar.IdleBarPlugin', ): all_plugins.append([name, file, type, status, '', '']) return all_plugins
def parse_plugins(plugin_name=""): start = re.compile("^class *(.*)\((.*Plugin\s*).:") stop = re.compile("^[\t ]*def.*:") comment = re.compile('^[\t ]*"""') config_start = re.compile("^[ \t]+def +config *\( *self *\) *:") config_end = re.compile(" *(class|def|@)") print_line = 0 ptypes = {} all_plugins = [] active = [] for p in plugin.__all_plugins__: active.append(p[0]) plugin_shortname = plugin_name.split(".")[-1] + ".py" plugin_init_name = os.path.join(plugin_name.split(".")[-1], "__init__.py") for file in util.recursefolders(os.environ["FREEVO_PYTHON"], 1, "*.py", 1): if file.find("plugin.py") > 0: continue if plugin_name: if file.find(plugin_shortname) < 0 and file.find(plugin_init_name) < 0: continue parse_status = 0 whitespaces = 0 scan_config = 0 for line in util.readfile(file) + ["class Foo"]: if config_end.match(line) and scan_config: scan_config = 0 all_plugins[-1][-1] = config if scan_config: config += line + "\n" if config_start.match(line): config = "def return_config():\n" scan_config = line.find("def") if (comment.match(line) and parse_status == 2) or (stop.match(line) and parse_status == 1): parse_status = 0 all_plugins[-1][-2] = desc if parse_status == 2: if desc: desc += "\n" if not whitespaces: tmp = line.lstrip() whitespaces = line.find(tmp) desc += line[whitespaces:].rstrip() if comment.match(line) and parse_status == 1: parse_status = 2 whitespaces = 0 if start.match(line): fname = re.sub("^src.", "", file) fname = re.sub("^%s." % os.environ["FREEVO_PYTHON"], "", fname) fname = re.sub("/", ".", os.path.splitext(fname)[0]) fname = re.sub("^plugins.", "", fname) fname = re.sub(".__init__", "", fname) type = start.match(line).group(2).strip() if re.match("^plugin.(.*)", type): type = re.match("^plugin.(.*)", type).group(1) if start.match(line).group(1) == "PluginInterface": name = fname else: name = "%s.%s" % (fname, start.match(line).group(1)) if name in active: status = "active" else: status = "not loaded" parse_status = 1 desc = "" if not name in ("idlebar.IdleBarPlugin",): all_plugins.append([name, file, type, status, "", ""]) return all_plugins