Author: dmeyer
Date: Fri Oct 27 18:12:35 2006
New Revision: 8484
Added:
trunk/core/src/fxdparser.py
- copied unchanged from r8462, /trunk/ui/src/util/fxdparser2.py
trunk/ui/src/gui/displays/fsocket.py
- copied unchanged from r8462, /trunk/ui/src/util/fsocket.py
trunk/ui/src/gui/fxdparser.py
- copied, changed from r8462, /trunk/ui/src/util/fxdparser.py
Removed:
trunk/ui/src/util/Rendezvous.py
trunk/ui/src/util/amazon.py
trunk/ui/src/util/fileops.py
trunk/ui/src/util/fsocket.py
trunk/ui/src/util/fxdparser.py
trunk/ui/src/util/fxdparser2.py
trunk/ui/src/util/ioctl.py
trunk/ui/src/util/lirc.py
trunk/ui/src/util/objectcache.py
trunk/ui/src/util/pymetar.py
Modified:
trunk/ui/src/fxditem.py
trunk/ui/src/gui/areas/listing_area.py
trunk/ui/src/gui/areas/view_area.py
trunk/ui/src/gui/displays/bmovl.py
trunk/ui/src/gui/theme.py
trunk/ui/src/image/fxdhandler.py
trunk/ui/src/image/viewer.py
trunk/ui/src/input/linux_input.py
trunk/ui/src/menu/__init__.py
trunk/ui/src/menu/item.py
trunk/ui/src/menu/mediaitem.py
trunk/ui/src/menu/menu.py
trunk/ui/src/menu/stack.py
trunk/ui/src/playlist.py
trunk/ui/src/plugin_loader.py
trunk/ui/src/plugins/mixer.py
trunk/ui/src/util/__init__.py
trunk/ui/src/util/misc.py
trunk/ui/src/video/plugins/bookmarker.py
Log:
Cleanup in ui utils dir and remove not needed
import statements. Move fxdparser2 to core and
the old one into gui until the gui code will be
replaced. Move fsocket to displays because it
is only needed there and it will also be
replaced later.
Modified: trunk/ui/src/fxditem.py
==============================================================================
--- trunk/ui/src/fxditem.py (original)
+++ trunk/ui/src/fxditem.py Fri Oct 27 18:12:35 2006
@@ -6,7 +6,7 @@
#
# If you want to expand the fxd file with a new tag below <freevo>, you
# can register a callback here. Create a class based on FXDItem (same
-# __init__ signature). The 'parser' is something from util.fxdparser, which
+# __init__ signature). The 'parser' is something from freevo.fxdparser, which
# gets the real callback. After parsing, the variable 'items' from the
# objects will be returned.
#
@@ -52,7 +52,7 @@
import util
import plugin
import os
-import util.fxdparser2
+import freevo.fxdparser
from menu import Item, Action, Menu
@@ -88,7 +88,7 @@
items = []
for fxd_file in fxd_files:
try:
- doc = util.fxdparser2.FXD(fxd_file.filename)
+ doc = freevo.fxdparser.FXD(fxd_file.filename)
items.extend(self._parse(doc, doc, parent, listing,
display_type))
except:
log.exception("fxd file %s corrupt" % fxd_file.filename)
Modified: trunk/ui/src/gui/areas/listing_area.py
==============================================================================
--- trunk/ui/src/gui/areas/listing_area.py (original)
+++ trunk/ui/src/gui/areas/listing_area.py Fri Oct 27 18:12:35 2006
@@ -47,7 +47,6 @@
# freevo imports
import config
import util
-from util.objectcache import ObjectCache
# gui import
from area import Area
Modified: trunk/ui/src/gui/areas/view_area.py
==============================================================================
--- trunk/ui/src/gui/areas/view_area.py (original)
+++ trunk/ui/src/gui/areas/view_area.py Fri Oct 27 18:12:35 2006
@@ -38,7 +38,6 @@
# area imports
from area import Area
-from util.objectcache import ObjectCache
class ViewArea(Area):
"""
Modified: trunk/ui/src/gui/displays/bmovl.py
==============================================================================
--- trunk/ui/src/gui/displays/bmovl.py (original)
+++ trunk/ui/src/gui/displays/bmovl.py Fri Oct 27 18:12:35 2006
@@ -46,7 +46,7 @@
# freevo imports
import config
-import util.fsocket
+import fsocket
# display imports
from display import Display as Base
@@ -99,7 +99,7 @@
Create and open the fifo and create notifier aware fd wrapper
"""
BmovlCanvas.open_fifo(self)
- self.nbsocket = util.fsocket.Socket(self.fifo)
+ self.nbsocket = fsocket.Socket(self.fifo)
self.send = self.nbsocket.write
Copied: trunk/ui/src/gui/fxdparser.py (from r8462,
/trunk/ui/src/util/fxdparser.py)
==============================================================================
--- /trunk/ui/src/util/fxdparser.py (original)
+++ trunk/ui/src/gui/fxdparser.py Fri Oct 27 18:12:35 2006
@@ -43,8 +43,6 @@
from xml.utils import qp_xml
# freevo utils
-import fileops
-import cache
import sysconfig
class XMLnode(object):
Modified: trunk/ui/src/gui/theme.py
==============================================================================
--- trunk/ui/src/gui/theme.py (original)
+++ trunk/ui/src/gui/theme.py Fri Oct 27 18:12:35 2006
@@ -60,6 +60,7 @@
# gui imports
from font import get as get_font_object
+import fxdparser
import logging
log = logging.getLogger('gui')
@@ -1403,7 +1404,7 @@
if not os.path.isfile(file):
return 0
- parser = util.fxdparser.FXD(file)
+ parser = fxdparser.FXD(file)
parser.setattr(None, 'args', (file))
parser.set_handler('skin', self.fxd_callback)
parser.parse()
Modified: trunk/ui/src/image/fxdhandler.py
==============================================================================
--- trunk/ui/src/image/fxdhandler.py (original)
+++ trunk/ui/src/image/fxdhandler.py Fri Oct 27 18:12:35 2006
@@ -58,7 +58,7 @@
import config
import plugin
-from util.fileops import match_files
+from util import match_files
from playlist import Playlist
# ImageItem
Modified: trunk/ui/src/image/viewer.py
==============================================================================
--- trunk/ui/src/image/viewer.py (original)
+++ trunk/ui/src/image/viewer.py Fri Oct 27 18:12:35 2006
@@ -48,7 +48,7 @@
import gui.theme
# cache for loading images
-from util.objectcache import ObjectCache
+from util import ObjectCache
# Transition/Move/VERTICAL
from gui.animation import *
Modified: trunk/ui/src/input/linux_input.py
==============================================================================
--- trunk/ui/src/input/linux_input.py (original)
+++ trunk/ui/src/input/linux_input.py Fri Oct 27 18:12:35 2006
@@ -55,7 +55,7 @@
#
# ----------------------------------------------------------------------- */
-from util.ioctl import *
+from kaa.ioctl import *
#struct input_event {
Modified: trunk/ui/src/menu/__init__.py
==============================================================================
--- trunk/ui/src/menu/__init__.py (original)
+++ trunk/ui/src/menu/__init__.py Fri Oct 27 18:12:35 2006
@@ -39,9 +39,6 @@
from menu import Menu
from stack import MenuStack
-# plugin interface to the menu
-from plugin import ItemPlugin
-
class ActionItem(Item, Action):
"""
A simple item with one action. The first parameter of the function
Modified: trunk/ui/src/menu/item.py
==============================================================================
--- trunk/ui/src/menu/item.py (original)
+++ trunk/ui/src/menu/item.py Fri Oct 27 18:12:35 2006
@@ -46,9 +46,6 @@
# freevo imports
import plugin
-# events covered by item
-from event import EJECT
-
# get logging object
log = logging.getLogger()
Modified: trunk/ui/src/menu/mediaitem.py
==============================================================================
--- trunk/ui/src/menu/mediaitem.py (original)
+++ trunk/ui/src/menu/mediaitem.py Fri Oct 27 18:12:35 2006
@@ -38,10 +38,10 @@
# kaa imports
import kaa.beacon
+from kaa.strutils import str_to_unicode
# freevo imports
-from event import *
-from sysconfig import Unicode
+from event import PLAY_START
# menu imports
from item import Item
@@ -107,7 +107,7 @@
self.parent['config:use_mediadb_names'] in (None, True):
self.name = self.info.get('title')
if not self.name:
- self.name = Unicode(self.info.get('name'))
+ self.name = str_to_unicode(self.info.get('name'))
else:
# Mode is not file, it has to be a network url. Other
@@ -118,7 +118,7 @@
if not self.name:
self.name = self.info.get('title')
if not self.name:
- self.name = Unicode(self.url)
+ self.name = str_to_unicode(self.url)
def __getitem__(self, attr):
Modified: trunk/ui/src/menu/menu.py
==============================================================================
--- trunk/ui/src/menu/menu.py (original)
+++ trunk/ui/src/menu/menu.py Fri Oct 27 18:12:35 2006
@@ -40,10 +40,10 @@
# freevo imports
import config
+from event import *
# menu imports
from item import Item
-from event import *
# get logging object
log = logging.getLogger()
Modified: trunk/ui/src/menu/stack.py
==============================================================================
--- trunk/ui/src/menu/stack.py (original)
+++ trunk/ui/src/menu/stack.py Fri Oct 27 18:12:35 2006
@@ -42,7 +42,6 @@
from kaa.weakref import weakref
# freevo imports
-import config
from event import *
# menu imports
Modified: trunk/ui/src/playlist.py
==============================================================================
--- trunk/ui/src/playlist.py (original)
+++ trunk/ui/src/playlist.py Fri Oct 27 18:12:35 2006
@@ -113,7 +113,9 @@
Returns: The list of interesting lines in the playlist
"""
try:
- lines = util.readfile(plsname)
+ fd = open(plsname)
+ lines = fd.readlines()
+ fd.close()
except IOError:
log.error('Cannot open file "%s"' % plsname)
return 0
@@ -141,7 +143,9 @@
Returns: The list of interesting lines in the playlist
"""
try:
- lines = util.readfile(plsname)
+ fd = open(plsname)
+ lines = fd.readlines()
+ fd.close()
except IOError:
log.error('Cannot open file "%s"' % list)
return 0
@@ -181,7 +185,9 @@
(curdir, playlistname) = os.path.split(ssrname)
out_lines = []
try:
- lines = util.readfile(ssrname)
+ fd = open(ssrname)
+ lines = fd.readlines()
+ fd.close()
except IOError:
log.error( 'Cannot open file "%s"' % list)
return 0
Modified: trunk/ui/src/plugin_loader.py
==============================================================================
--- trunk/ui/src/plugin_loader.py (original)
+++ trunk/ui/src/plugin_loader.py Fri Oct 27 18:12:35 2006
@@ -162,7 +162,7 @@
return False
- def init(self, plugin_path, callback = None, plugins=[]):
+ def init(self, plugin_path, callback = None):
"""
Load and init all the plugins. The function takes the path were the
plugins are searched in. Optional is a callback, called after a
@@ -180,20 +180,7 @@
# plugin already an object
self.__load_plugin(name, type, level, args)
continue
-
- if plugins:
- # load only plugins from exclusive list
- for p in plugins:
- if name.startswith('%s.' % p):
- self.__load_plugin(name, type, level, args)
- else:
- parent = name[:name.rfind('.')]
- if name.find('.') > 0 and not self.is_active(parent):
- # Parent plugin is not active. So this plugin is
- # deactivated by default.
- log.info('skip plugin %s' % name)
- continue
- self.__load_plugin(name, type, level, args)
+ self.__load_plugin(name, type, level, args)
# sort plugins
cmp_func = lambda l, o: cmp(l.plugin_level, o.plugin_level)
Modified: trunk/ui/src/plugins/mixer.py
==============================================================================
--- trunk/ui/src/plugins/mixer.py (original)
+++ trunk/ui/src/plugins/mixer.py Fri Oct 27 18:12:35 2006
@@ -73,7 +73,7 @@
import config
import plugin
from event import *
-from util.ioctl import ioctl
+from kaa.ioctl import *
import logging
log = logging.getLogger()
Modified: trunk/ui/src/util/__init__.py
==============================================================================
--- trunk/ui/src/util/__init__.py (original)
+++ trunk/ui/src/util/__init__.py Fri Oct 27 18:12:35 2006
@@ -28,13 +28,5 @@
#
# -----------------------------------------------------------------------------
-import sys
-
-if sys.argv[0] != 'setup.py':
- import __builtin__
-
- from misc import *
- from fileops import *
- import objectcache
- import fxdparser
- import cache
+from misc import *
+import cache
Modified: trunk/ui/src/util/misc.py
==============================================================================
--- trunk/ui/src/util/misc.py (original)
+++ trunk/ui/src/util/misc.py Fri Oct 27 18:12:35 2006
@@ -38,7 +38,21 @@
#
# -----------------------------------------------------------------------------
+
+
+# python imports
import os
+import statvfs
+import stat
+import logging
+
+# kaa imports
+import kaa.notifier
+from kaa.strutils import str_to_unicode
+
+# get logging object
+log = logging.getLogger()
+
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
def unique(s):
@@ -122,3 +136,164 @@
return default
+
+class ObjectCache(object):
+ """
+ Provides a cache for objects indexed by a string. It should
+ be slow for a large number of objects, since searching takes
+ O(n) time. The cachesize given in the constructor is the
+ maximum number of objects in the cache. Objects that have not
+ been accessed for the longest time get deleted first.
+ """
+
+ def __init__(self, cachesize = 30, desc='noname'):
+ self.cache = {}
+ self.lru = [] # Least recently used (lru) list, index 0 is lru
+ self.cachesize = cachesize
+ self.desc = desc
+
+
+ def __getitem__(self, key):
+ if isinstance(key, str):
+ key = str_to_unicode(key)
+
+ try:
+ del self.lru[self.lru.index(key)]
+ self.lru.append(key)
+ return self.cache[key]
+ except:
+ return None
+
+
+ def __setitem__(self, key, object):
+ if isinstance(key, str):
+ key = str_to_unicode(key)
+
+ try:
+ # remove old one if key is already in cache
+ del self.lru[self.lru.index(key)]
+ except:
+ pass
+
+ # Do we need to delete the oldest item?
+ if len(self.cache) > self.cachesize:
+ # Yes
+ lru_key = self.lru[0]
+ del self.cache[lru_key]
+ del self.lru[0]
+
+ self.cache[key] = object
+ self.lru.append(key)
+
+
+ def __delitem__(self, key):
+ if isinstance(key, str):
+ key = str_to_unicode(key)
+
+ if not key in self.cache:
+ return
+
+ del self.cache[key]
+ del self.lru[self.lru.index(key)]
+
+#
+# misc file ops
+#
+
+def freespace(path):
+ """
+ freespace(path) -> integer
+ Return the number of bytes available to the user on the file system
+ pointed to by path.
+ """
+ s = os.statvfs(path)
+ return s[statvfs.F_BAVAIL] * long(s[statvfs.F_BSIZE])
+
+
+def totalspace(path):
+ """
+ totalspace(path) -> integer
+ Return the number of total bytes available on the file system
+ pointed to by path.
+ """
+
+ s = os.statvfs(path)
+ return s[statvfs.F_BLOCKS] * long(s[statvfs.F_BSIZE])
+
+
+def unlink(filename):
+ try:
+ if os.path.isdir(filename) or \
+ os.stat(filename)[stat.ST_SIZE] > 1000000:
+ base = '.' + os.path.basename(filename) + '.freevo~'
+ name = os.path.join(os.path.dirname(filename), base)
+ os.rename(filename, name)
+ kaa.notifier.Process(['rm', '-rf', name]).start()
+ else:
+ os.unlink(filename)
+ except (OSError, IOError), e:
+ log.error('can\'t delete %s: %s' % (filename, e))
+
+
+#
+# find files by pattern or suffix
+#
+
+def match_suffix(filename, suffixlist):
+ """
+ Check if a filename ends in a given suffix, case is ignored.
+ """
+ fsuffix = os.path.splitext(filename)[1].lower()[1:]
+ for suffix in suffixlist:
+ if fsuffix == suffix:
+ return 1
+ return 0
+
+
+def match_files(dirname, suffix_list, recursive = False):
+ """
+ Find all files in a directory that has matches a list of suffixes.
+ Returns a list that is case insensitive sorted.
+ """
+ if recursive:
+ return match_files_recursively(dirname, suffix_list)
+
+ try:
+ files = [ os.path.join(dirname, fname) \
+ for fname in os.listdir(dirname) if
+ os.path.isfile(os.path.join(dirname, fname)) ]
+ except OSError, e:
+ print 'fileops:match_files: %s' % e
+ return []
+ matches = [ fname for fname in files if match_suffix(fname, suffix_list) ]
+ matches.sort(lambda l, o: cmp(l.upper(), o.upper()))
+ return matches
+
+
+def _match_files_recursively_helper(result, dirname, names):
+ """
+ help function for match_files_recursively
+ """
+ if dirname.find('/') != -1 and dirname[dirname.rfind('/'):][1] == '.':
+ # ignore directories starting with a dot
+ # Note: subdirectories of that dir will still be searched
+ return result
+ for name in names:
+ if not name in ('CVS', '.xvpics', '.thumbnails', '.pics',
+ 'folder.fxd', 'lost+found'):
+ fullpath = os.path.abspath(os.path.join(dirname, name))
+ result.append(fullpath)
+ return result
+
+
+def match_files_recursively(dir, suffix_list):
+ """
+ get all files matching suffix_list in the dir and in it's subdirectories
+ """
+ all_files = []
+ if dir.endswith('/'):
+ dir = dir[:-1]
+ os.path.walk(dir, _match_files_recursively_helper, all_files)
+ matches = unique([f for f in all_files if match_suffix(f, suffix_list) ])
+ matches.sort(lambda l, o: cmp(l.upper(), o.upper()))
+ return matches
Modified: trunk/ui/src/video/plugins/bookmarker.py
==============================================================================
--- trunk/ui/src/video/plugins/bookmarker.py (original)
+++ trunk/ui/src/video/plugins/bookmarker.py Fri Oct 27 18:12:35 2006
@@ -48,9 +48,9 @@
# freevo imports
import sysconfig
-import util
-from menu import Action, Menu, ItemPlugin
+from menu import Action, Menu
+from plugin import ItemPlugin
from event import *
# the logging object
@@ -118,7 +118,8 @@
item.get_menustack().delete_submenu(False)
items = []
- for line in util.readfile(bookmarkfile):
+ fd = open(bookmarkfile, 'r')
+ for line in fd.readline():
copy = item.copy()
sec = int(line)
@@ -133,7 +134,8 @@
copy.mplayer_options = ''
copy.mplayer_options += ' -ss %s' % time
items.append(copy)
-
+ fd.close()
+
if items:
moviemenu = Menu(item.name, items)
item.pushmenu(moviemenu)
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog