Author: dmeyer
Date: Thu Oct 27 17:57:21 2005
New Revision: 7768

Removed:
   trunk/ui/src/util/dbutil.py
Modified:
   trunk/ui/src/directory.py
   trunk/ui/src/util/misc.py
   trunk/ui/src/video/plugins/imdb.py

Log:
more cleanups / code move

Modified: trunk/ui/src/directory.py
==============================================================================
--- trunk/ui/src/directory.py   (original)
+++ trunk/ui/src/directory.py   Thu Oct 27 17:57:21 2005
@@ -106,6 +106,56 @@
 
 
 
+def smartsort(x,y):
+    """
+    Compares strings after stripping off 'The' and 'A' to be 'smarter'
+    Also obviously ignores the full path when looking for 'The' and 'A'
+    """
+    m = os.path.basename(x)
+    n = os.path.basename(y)
+
+    for word in ('The', 'A'):
+        word += ' '
+        if m.find(word) == 0:
+            m = m.replace(word, '', 1)
+        if n.find(word) == 0:
+            n = n.replace(word, '', 1)
+
+    return cmp(m.upper(),n.upper()) # be case insensitive
+
+
+def find_start_string(s1, s2):
+    """
+    Find similar start in both strings
+    """
+    ret = ''
+    tmp = ''
+    while True:
+        if len(s1) < 2 or len(s2) < 2:
+            return ret
+        if s1[0] == s2[0]:
+            tmp += s2[0]
+            if s1[1] in (u' ', u'-', u'_', u',', u':', '.') and \
+               s2[1] in (u' ', u'-', u'_', u',', u':', '.'):
+                ret += tmp + u' '
+                tmp = ''
+            s1 = s1[1:].lstrip(u' -_,:.')
+            s2 = s2[1:].lstrip(u' -_,:.')
+        else:
+            return ret
+
+
+def remove_start_string(string, start):
+    """
+    remove start from the beginning of string.
+    """
+    start = start.replace(u' ', '')
+    for i in range(len(start)):
+        string = string[1:].lstrip(' -_,:.')
+
+    return string[0].upper() + string[1:]
+
+
 class DirItem(Playlist):
     """
     class for handling directories
@@ -634,14 +684,14 @@
             substr = play_items[0].name[:-5].lower()
             for i in play_items[1:]:
                 if len(i.name) > 5:
-                    substr = util.find_start_string(i.name.lower(), substr)
+                    substr = find_start_string(i.name.lower(), substr)
                     if not substr or len(substr) < 10:
                         break
                 else:
                     break
             else:
                 for i in play_items:
-                    i.name = util.remove_start_string(i.name, substr)
+                    i.name = remove_start_string(i.name, substr)
 
         t5 = time.time()
 
@@ -651,7 +701,7 @@
 
         # sort directories
         if self.DIRECTORY_SMART_SORT:
-            dir_items.sort(lambda l, o: util.smartsort(l.dir,o.dir))
+            dir_items.sort(lambda l, o: smartsort(l.dir,o.dir))
         else:
             dir_items.sort(lambda l, o: cmp(l.dir.upper(), o.dir.upper()))
 

Modified: trunk/ui/src/util/misc.py
==============================================================================
--- trunk/ui/src/util/misc.py   (original)
+++ trunk/ui/src/util/misc.py   Thu Oct 27 17:57:21 2005
@@ -38,18 +38,7 @@
 #
 # -----------------------------------------------------------------------------
 
-# python imports
-import os
-import string
-import re
-import copy
-import htmlentitydefs
-
-# freevo imports
-import sysconfig
-
 # util imports
-import vfs
 from vfs import abspath as vfs_abspath
 
 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
@@ -123,19 +112,6 @@
     return u
 
 
-def escape(sql):
-    """
-    Escape a SQL query in a manner suitable for sqlite. Also convert
-    Unicode to normal string object.
-    """
-    if sql:
-        sql = sql.replace('\'','\'\'')
-        return String(sql)
-    else:
-        return 'null'
-
-
-
 def getimage(base, default=None):
     """
     return the image base+'.png' or base+'.jpg' if one of them exists.
@@ -148,88 +124,3 @@
     return default
 
 
-def smartsort(x,y):
-    """
-    Compares strings after stripping off 'The' and 'A' to be 'smarter'
-    Also obviously ignores the full path when looking for 'The' and 'A'
-    """
-    m = os.path.basename(x)
-    n = os.path.basename(y)
-
-    for word in ('The', 'A'):
-        word += ' '
-        if m.find(word) == 0:
-            m = m.replace(word, '', 1)
-        if n.find(word) == 0:
-            n = n.replace(word, '', 1)
-
-    return cmp(m.upper(),n.upper()) # be case insensitive
-
-
-def find_start_string(s1, s2):
-    """
-    Find similar start in both strings
-    """
-    ret = ''
-    tmp = ''
-    while True:
-        if len(s1) < 2 or len(s2) < 2:
-            return ret
-        if s1[0] == s2[0]:
-            tmp += s2[0]
-            if s1[1] in (u' ', u'-', u'_', u',', u':', '.') and \
-               s2[1] in (u' ', u'-', u'_', u',', u':', '.'):
-                ret += tmp + u' '
-                tmp = ''
-            s1 = s1[1:].lstrip(u' -_,:.')
-            s2 = s2[1:].lstrip(u' -_,:.')
-        else:
-            return ret
-
-def remove_start_string(string, start):
-    """
-    remove start from the beginning of string.
-    """
-    start = start.replace(u' ', '')
-    for i in range(len(start)):
-        string = string[1:].lstrip(' -_,:.')
-
-    return string[0].upper() + string[1:]
-
-
-def htmlenties2txt(string):
-    """
-    Converts a string to a string with all html entities resolved.
-    Returns the result as Unicode object (that may conatin chars outside 256.
-    """
-    e = copy.deepcopy(htmlentitydefs.entitydefs)
-    e['ndash'] = "-";
-    e['bull'] = "-";
-    e['rsquo'] = "'";
-    e['lsquo'] = "`";
-    e['hellip'] = '...'
-
-    string = Unicode(string).replace("&#039", "'").replace("&#146;", "'")
-
-    i = 0
-    while i < len(string):
-        amp = string.find("&", i) # find & as start of entity
-        if amp == -1: # not found
-            break
-        i = amp + 1
-
-        semicolon = string.find(";", amp) # find ; as end of entity
-        if string[amp + 1] == "#": # numerical entity like "&#039;"
-            entity = string[amp:semicolon+1]
-            replacement = Unicode(unichr(int(entity[2:-1])))
-        else:
-            entity = string[amp:semicolon + 1]
-            if semicolon - amp > 7:
-                continue
-            try:
-                # the array has mappings like "Uuml" -> "�"
-                replacement = e[entity[1:-1]]
-            except KeyError:
-                continue
-        string = string.replace(entity, replacement)
-    return string

Modified: trunk/ui/src/video/plugins/imdb.py
==============================================================================
--- trunk/ui/src/video/plugins/imdb.py  (original)
+++ trunk/ui/src/video/plugins/imdb.py  Thu Oct 27 17:57:21 2005
@@ -39,6 +39,8 @@
 import os
 import re
 import time
+import copy
+import htmlentitydefs
 
 # kaa imports
 import kaa.notifier
@@ -49,7 +51,6 @@
 from menu import Action, ActionItem, Menu, ItemPlugin
 from util.fxdimdb import FxdImdb, makeVideo, makePart, point_maker
 from gui.windows import WaitBox, MessageBox
-from util import htmlenties2txt
 
 # shortcut for the actions
 SHORTCUT = 'imdb_search_or_cover_search'
@@ -128,6 +129,44 @@
         return []
 
             
+    def htmlenties2txt(self, string):
+        """
+        Converts a string to a string with all html entities resolved.
+        Returns the result as Unicode object (that may conatin chars outside 
256.
+        """
+        e = copy.deepcopy(htmlentitydefs.entitydefs)
+        e['ndash'] = "-";
+        e['bull'] = "-";
+        e['rsquo'] = "'";
+        e['lsquo'] = "`";
+        e['hellip'] = '...'
+
+        string = Unicode(string).replace("&#039", "'").replace("&#146;", "'")
+
+        i = 0
+        while i < len(string):
+            amp = string.find("&", i) # find & as start of entity
+            if amp == -1: # not found
+                break
+            i = amp + 1
+
+            semicolon = string.find(";", amp) # find ; as end of entity
+            if string[amp + 1] == "#": # numerical entity like "&#039;"
+                entity = string[amp:semicolon+1]
+                replacement = Unicode(unichr(int(entity[2:-1])))
+            else:
+                entity = string[amp:semicolon + 1]
+                if semicolon - amp > 7:
+                    continue
+                try:
+                    # the array has mappings like "Uuml" -> "�"
+                    replacement = e[entity[1:-1]]
+                except KeyError:
+                    continue
+            string = string.replace(entity, replacement)
+        return string
+
+
     def imdb_search(self, item, disc_set):
         """
         Search imdb for the item
@@ -170,7 +209,7 @@
         """
         items = []
         for id, name, year, type in results:
-            name = '%s (%s, %s)' % (htmlenties2txt(name), year, type)
+            name = '%s (%s, %s)' % (self.htmlenties2txt(name), year, type)
             a = ActionItem(name, item, self.download)
             a.parameter(id, disc_set)
             items.append(a)


-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to