Update of /cvsroot/freevo/freevo/src/helpers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31788
Modified Files: cache.py Log Message: add more caching: o playlist metainfo o directory metainfo (e.g. number of items) cleanup Index: cache.py =================================================================== RCS file: /cvsroot/freevo/freevo/src/helpers/cache.py,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** cache.py 7 Feb 2004 20:46:21 -0000 1.20 --- cache.py 8 Feb 2004 17:41:55 -0000 1.21 *************** *** 12,15 **** --- 12,21 ---- # ----------------------------------------------------------------------- # $Log$ + # Revision 1.21 2004/02/08 17:41:55 dischi + # add more caching: + # o playlist metainfo + # o directory metainfo (e.g. number of items) + # cleanup + # # Revision 1.20 2004/02/07 20:46:21 dischi # more old files to remove *************** *** 79,82 **** --- 85,98 ---- import copy + import util.mediainfo + import plugin + import directory + import playlist + import fxditem + + # use this number to keep track of changes in + # this helper. Check this against util/mediainfo + VERSION =1 + def delete_old_files_1(): """ *************** *** 156,184 **** 2 like 1, but also delete discinfo data """ - import util.mediainfo - try: - import mmpython.version - - info = None - cachefile = os.path.join(config.FREEVO_CACHEDIR, 'mediainfo') - if os.path.isfile(cachefile): - info = util.read_pickle(cachefile) - if not info: - print - print 'Unable to detect last complete rebuild, forcing rebuild' - rebuild = 2 - complete_update = int(time.time()) - else: - mmchanged, part_update, complete_update = info - except ImportError: - print - print 'Error: unable to read mmpython version information' - print 'Please update mmpython to the latest release or if you use' - print 'Freevo CVS versions, please also use mmpython CVS.' - print - print 'Some functions in Freevo may not work or even crash!' - print - print - if rebuild: print 'deleting cache files..................................', --- 172,175 ---- *************** *** 192,211 **** print 'done' - print all_dirs = [] ! print 'caching directories...' for d in config.VIDEO_ITEMS + config.AUDIO_ITEMS + config.IMAGE_ITEMS: if os.path.isdir(d[1]): all_dirs.append(d[1]) util.mediainfo.cache_recursive(all_dirs, verbose=True) - print - - try: - import mmpython.version - util.save_pickle((mmpython.version.CHANGED, int(time.time()), complete_update), - cachefile) - print - except ImportError: - pass --- 183,193 ---- print 'done' all_dirs = [] ! print 'checking mmpython cache files.........................', ! sys.__stdout__.flush() for d in config.VIDEO_ITEMS + config.AUDIO_ITEMS + config.IMAGE_ITEMS: if os.path.isdir(d[1]): all_dirs.append(d[1]) util.mediainfo.cache_recursive(all_dirs, verbose=True) *************** *** 218,222 **** import Image ! print 'caching thumbnails...' files = [] --- 200,205 ---- import Image ! print 'checking thumbnails...................................', ! sys.__stdout__.flush() files = [] *************** *** 241,244 **** --- 224,229 ---- pass + print '%s file(s)' % len(files) + for filename in files: fname = filename *************** *** 275,280 **** except: print 'error caching image %s' % filename ! print ! --- 260,265 ---- except: print 'error caching image %s' % filename ! if files: ! print *************** *** 284,309 **** """ import util.extendedmeta ! print 'create audio metadata...' for dir in config.AUDIO_ITEMS: if os.path.isdir(dir[1]): - print " Scanning %s" % dir[0] util.extendedmeta.AudioParser(dir[1], rescan=True) ! print try: # The DB stuff import sqlite - except: - print 'no pysqlite installed, skipping db support' - print - return ! print 'checking database...' ! for dir in config.AUDIO_ITEMS: ! if os.path.isdir(dir[1]): ! print " Scanning %s" % dir[0] ! util.extendedmeta.addPathDB(dir[1], dir[0]) ! print if __name__ == "__main__": --- 269,371 ---- """ import util.extendedmeta ! print 'creating audio metadata...............................', ! sys.__stdout__.flush() for dir in config.AUDIO_ITEMS: if os.path.isdir(dir[1]): util.extendedmeta.AudioParser(dir[1], rescan=True) ! print 'done' ! ! print 'creating playlist metadata............................', ! sys.__stdout__.flush() ! pl = [] ! fxd = [] ! for dir in config.AUDIO_ITEMS: ! if os.path.isdir(dir[1]): ! pl += util.match_files_recursively(dir[1], playlist.mimetype.suffix()) ! fxd += util.match_files_recursively(dir[1], fxditem.mimetype.suffix()) ! elif util.match_suffix(dir, playlist.mimetype.suffix()): ! pl.append(dir) ! elif util.match_suffix(dir, fxditem.mimetype.suffix()): ! fxd.append(dir) ! elif util.match_suffix(dir[1], playlist.mimetype.suffix()): ! pl.append(dir[1]) ! elif util.match_suffix(dir[1], fxditem.mimetype.suffix()): ! fxd.append(dir[1]) ! ! ! items = playlist.mimetype.get(None, util.misc.unique(pl)) ! ! # ignore fxd files for now, they can't store metainfo ! # for f in fxditem.mimetype.get(None, util.misc.unique(fxd)): ! # if f.type == 'playlist': ! # items.append(f) ! ! for i in items: ! util.extendedmeta.PlaylistParser(i) ! print 'done' ! ! print 'checking database.....................................', ! sys.__stdout__.flush() try: # The DB stuff import sqlite ! for dir in config.AUDIO_ITEMS: ! if os.path.isdir(dir[1]): ! util.extendedmeta.addPathDB(dir[1], dir[0], verbose=False) ! print 'done' ! except ImportError: ! print 'skipping' ! pass + print 'creating directory metadata...........................', + sys.__stdout__.flush() + + subdirs = { 'all': [] } + + # get all subdirs for each type + for type in activate_plugins: + subdirs[type] = [] + for d in getattr(config, '%s_ITEMS' % type.upper()): + try: + d = d[1] + except: + pass + if not os.path.isdir(d): + continue + rec = util.get_subdirs_recursively(d) + subdirs['all'] += rec + subdirs[type] += rec + + subdirs['all'] = util.misc.unique(subdirs['all']) + subdirs['all'].sort(lambda l, o: cmp(l.upper(), o.upper())) + + # walk though each directory + for s in subdirs['all']: + if s.find('/.') > 0: + continue + + # create the DirItems + d = directory.DirItem(s, None) + + # remove all infos starting with 'num_' to force rebuild + for k in copy.copy(d.info.metadata): + if k.startswith('num_'): + d.info.delete(k) + + # rebuild metainfo + d.create_metainfo() + for type in activate_plugins: + if subdirs.has_key(type) and s in subdirs[type]: + # reset num_timestamp and set the display_type + d['num_timestamp'] = 0 + d.display_type = type + d.autovars.append(('num_%s_items' % type, 0)) + # scan again with display_type + d.create_metainfo() + + print 'done' + if __name__ == "__main__": *************** *** 347,351 **** print sys.exit(0) ! delete_old_files_1() delete_old_files_2() --- 409,450 ---- print sys.exit(0) ! ! ! # check for current cache informations ! if (len(sys.argv)>1 and sys.argv[1] == '--rebuild'): ! rebuild = 1 ! else: ! rebuild = 0 ! try: ! import mmpython.version ! ! info = None ! cachefile = os.path.join(config.FREEVO_CACHEDIR, 'mediainfo') ! if os.path.isfile(cachefile): ! info = util.read_pickle(cachefile) ! if not info: ! print ! print 'Unable to detect last complete rebuild, forcing rebuild' ! rebuild = 2 ! complete_update = int(time.time()) ! else: ! complete_update = info[-1] ! except ImportError: ! print ! print 'Error: unable to read mmpython version information' ! print 'Please update mmpython to the latest release or if you use' ! print 'Freevo CVS versions, please also use mmpython CVS.' ! print ! print 'Some functions in Freevo may not work or even crash!' ! print ! print ! ! activate_plugins = [] ! for type in ('video', 'audio', 'image', 'games'): ! if plugin.is_active(type): ! # activate all mimetype plugins ! plugin.init_special_plugin(type) ! activate_plugins.append(type) ! delete_old_files_1() delete_old_files_2() *************** *** 359,371 **** setattr(config, '%s_ITEMS' % type, []) ! if len(sys.argv)>1 and sys.argv[1] == '--rebuild': ! cache_directories(1) ! else: ! cache_directories(0) ! ! create_metadata() cache_thumbnails() # close db util.mediainfo.sync() --- 458,474 ---- setattr(config, '%s_ITEMS' % type, []) ! cache_directories(rebuild) cache_thumbnails() + create_metadata() + # close db util.mediainfo.sync() + # save cache info + try: + import mmpython.version + util.save_pickle((mmpython.version.CHANGED, VERSION, + int(time.time()), complete_update), cachefile) + except ImportError: + print 'WARNING: please update mmpython' ------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ Freevo-cvslog mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/freevo-cvslog