Author: duncan
Date: Sun Nov 11 00:01:56 2007
New Revision: 10095

Log:
Fixed a debug message encode option
Done some housekeeping on the code


Modified:
   branches/rel-1-7/freevo/src/config.py
   branches/rel-1/freevo/src/config.py

Modified: branches/rel-1-7/freevo/src/config.py
==============================================================================
--- branches/rel-1-7/freevo/src/config.py       (original)
+++ branches/rel-1-7/freevo/src/config.py       Sun Nov 11 00:01:56 2007
@@ -61,7 +61,7 @@
 DERROR = -2
 DCRITICAL = -3
 
-locale.setlocale(locale.LC_TIME,'')
+locale.setlocale(locale.LC_TIME, '')
 
 if float(sys.version[0:3]) >= 2.3:
     import warnings
@@ -75,7 +75,7 @@
     gettext.install('freevo', os.environ['FREEVO_LOCALE'], 1)
 except: # unavailable, define '_' for all modules
     import __builtin__
-    __builtin__.__dict__['_']= lambda m: m
+    __builtin__.__dict__['_'] = lambda m: m
 
 
 # temp solution until this is fixed to True and False
@@ -94,8 +94,8 @@
 
 class Logger:
     """
-    Class to create a logger object which will send messages to stdout
-    and log them into a logfile
+    Class to create a logger object which will send messages to stdout and log 
them
+    into a logfile
     """
     def __init__(self, logtype='(unknown)'):
         self.lineno = 1
@@ -124,7 +124,7 @@
         lock.acquire()
         try:
             if isinstance(msg, unicode):
-                msg = msg.encode(LOCALE)
+                msg = msg.encode(LOCALE, 'replace')
             sys.__stdout__.write(msg)
             sys.__stdout__.flush()
             self.fp.write(msg)
@@ -183,7 +183,7 @@
         self.vdev = vdev
         self.vvbi = vvbi
         self.adev = adev
-        self.input_type = input_type
+        self.input_type = string.lower(input_type)
         self.input_num  = int(input_num)
         self.tuner_type = tuner_type
         self.tuner_norm = string.upper(tuner_norm)
@@ -195,7 +195,7 @@
         self.in_use = FALSE
         self.tuner = None
         self.cmd = None
-        if cmd != None and isinstance(cmd,str) and cmd.strip() != '':
+        if cmd != None and isinstance(cmd, str) and cmd.strip() != '':
             self.cmd = cmd.strip()
 
     def __str__(self):
@@ -291,8 +291,9 @@
 
 
 def make_freevodir(envvar, linux_dir, bsd_dir, private_dir):
-    '''Make the freevo specific directory and return it's name
-    '''
+    """
+    Make the freevo specific directory and return it's name
+    """
     if os.environ.has_key('OS_' + envvar):
         os_dirname = os.environ['OS_' + envvar]
     elif os.uname()[0] == 'FreeBSD':
@@ -386,11 +387,11 @@
 
 
 def _debug_function_(s, level=1):
-    '''The debug function that is mapped to the _debug_ builtin
-    There are different levels of debugging and logging. Debug messages
-    range from 1 (default) to 9 (most verbose), logging messages range
-    from NOTSET to DCRITICAL
-    '''
+    """
+    The debug function that is mapped to the _debug_ builtin There are 
different
+    levels of debugging and logging. Debug messages range from 1 (default) to 9
+    (most verbose), logging messages range from NOTSET to DCRITICAL
+    """
     if DEBUG < level:
         return
     if not s:
@@ -401,7 +402,7 @@
     try:
         try:
             # add the current trace to the string
-            if isinstance( s, unicode ):
+            if isinstance(s, unicode):
                 s = s.encode(encoding, 'replace')
             where =  traceback.extract_stack(limit = 2)[0]
             msg = '%s (%s): %s' % (where[0][where[0].rfind('/')+1:], where[1], 
s)
@@ -439,8 +440,8 @@
 #
 # Config file handling
 #
-cfgfilepath = [ '.', os.path.expanduser('~/.freevo'), '/etc/freevo',
-                '/usr/local/etc/freevo' ]
+cfgfilepath = ['.', os.path.expanduser('~/.freevo'), '/etc/freevo',
+                '/usr/local/etc/freevo']
 
 
 #
@@ -467,6 +468,7 @@
 FONT_DIR  = os.path.join(SHARE_DIR, 'fonts')
 
 RUNAPP = os.environ['RUNAPP']
+_debug_('RUNAPP: %s' % (RUNAPP))
 
 _debug_('logdir: %s %s' % (OS_LOGDIR, FREEVO_LOGDIR), DINFO)
 _debug_('staticdir: %s %s' % (OS_STATICDIR, FREEVO_STATICDIR), DINFO)
@@ -734,13 +736,13 @@
 if ROM_DRIVES == None:
     ROM_DRIVES = []
     if os.path.isfile('/etc/fstab'):
-        re_cd        = re.compile( 
'^(/dev/cdrom[0-9]*|/dev/[am]?cd[0-9]+[a-z]?)[ \t]+([^ \t]+)[ \t]+', re.I )
-        re_cdrec     = re.compile( '^(/dev/cdrecorder[0-9]*)[ \t]+([^ \t]+)[ 
\t]+', re.I )
-        re_dvd       = re.compile( '^(/dev/dvd[0-9]*)[ \t]+([^ \t]+)[ \t]+', 
re.I )
-        re_iso       = re.compile( '^([^ \t]+)[ \t]+([^ \t]+)[ 
\t]+(iso|cd)9660', re.I )
-        re_automount = re.compile( '^none[ \t]+([^ 
\t]+).*supermount.*dev=([^,]+).*', re.I )
-        re_bymountcd = re.compile( '^(/dev/[^ \t]+)[ \t]+([^ ]*cdrom[0-9]*)[ 
\t]+', re.I )
-        re_bymountdvd= re.compile( '^(/dev/[^ \t]+)[ \t]+([^ ]*dvd[0-9]*)[ 
\t]+', re.I )
+        re_cd        = 
re.compile('^(/dev/cdrom[0-9]*|/dev/[am]?cd[0-9]+[a-z]?)[ \t]+([^ \t]+)[ \t]+', 
re.I)
+        re_cdrec     = re.compile('^(/dev/cdrecorder[0-9]*)[ \t]+([^ \t]+)[ 
\t]+', re.I)
+        re_dvd       = re.compile('^(/dev/dvd[0-9]*)[ \t]+([^ \t]+)[ \t]+', 
re.I)
+        re_iso       = re.compile('^([^ \t]+)[ \t]+([^ \t]+)[ 
\t]+(iso|cd)9660', re.I)
+        re_automount = re.compile('^none[ \t]+([^ 
\t]+).*supermount.*dev=([^,]+).*', re.I)
+        re_bymountcd = re.compile('^(/dev/[^ \t]+)[ \t]+([^ ]*cdrom[0-9]*)[ 
\t]+', re.I)
+        re_bymountdvd= re.compile('^(/dev/[^ \t]+)[ \t]+([^ ]*dvd[0-9]*)[ 
\t]+', re.I)
         fd_fstab = open('/etc/fstab')
         for line in fd_fstab:
             # Match on the devices /dev/cdrom, /dev/dvd, and fstype iso9660
@@ -782,7 +784,7 @@
                     print 'Trying to autodetect type of %s' % devname
                     if os.path.exists('/proc/ide/' + re.sub(r'^(/dev/)', '', 
devname) + '/media'):
                         if open('/proc/ide/'+  re.sub(r'^(/dev/)', '', 
devname) +\
-                             '/media','r').read().lower().find('cdrom') !=1:
+                             '/media', 'r').read().lower().find('cdrom') !=1:
                             dispname = 'CD-%s' % (len(ROM_DRIVES)+1)
                             print ("%s is a cdrom drive" %devname)
                     else:
@@ -809,7 +811,7 @@
             else:
                 # This was not a duplicate of another device
                 if mntdir and devname and dispname:
-                    ROM_DRIVES += [ (mntdir, devname, dispname) ]
+                    ROM_DRIVES += [(mntdir, devname, dispname)]
                     if not HELPER:
                         print 'ROM_DRIVES: Auto-detected and added "%s"' % 
(ROM_DRIVES[-1], )
         fd_fstab.close()
@@ -832,7 +834,7 @@
     # index for the tunerid and forcing 'int'
     for l in list:
         if len(l[key]) == 1:
-            l[key].append(('0',))
+            l[key].append(('0', ))
     nlist = map(lambda x, key=key: (string.split(x[key][1][0])[0], x), list)
     nlist.sort()
     return map(lambda (key, x): x, nlist)
@@ -852,7 +854,7 @@
     path = FREEVO_CACHEDIR
     pfile = 'xmltv_channels.pickle'
 
-    pname = os.path.join(path,pfile)
+    pname = os.path.join(path, pfile)
 
     if not os.path.isfile(file):
         if not HELPER:
@@ -895,7 +897,7 @@
         xmltv_channels = xmltv.read_channels(tmp)
         tmp.close()
 
-        xmltv_channels = sortchannels(xmltv_channels,'display-name')
+        xmltv_channels = sortchannels(xmltv_channels, 'display-name')
         chanlist = []
 
         for a in xmltv_channels:
@@ -907,7 +909,7 @@
                 tunerid = string.split(a['display-name'][0][0].encode(LOCALE, 
'ignore'))[0]
             id = a['id'].encode(LOCALE, 'ignore')
 
-            chanlist += [(id,display_name,tunerid)]
+            chanlist += [(id, display_name, tunerid)]
 
         f = lambda a, b: cmp(int(a[2]), int(b[2]))
         chanlist.sort(f)
@@ -995,11 +997,11 @@
 
 encoding = None
 try:
-    encoding = os.environ[ 'LANG' ].split( '.' )[ 1 ]
+    encoding = os.environ['LANG'].split('.')[1]
     ''.encode(encoding)
 except:
     try:
-        encoding = os.environ[ 'LC_ALL' ].split( '.' )[ 1 ]
+        encoding = os.environ['LC_ALL'].split('.')[1]
         ''.encode(encoding)
     except:
         encoding = LOCALE
@@ -1008,9 +1010,9 @@
     encoding = LOCALE
 
 if not HELPER:
-    _debug_( "Using '%s' encoding" % encoding )
+    _debug_("Using '%s' encoding" % encoding)
 
-for k,v in CONF.__dict__.items():
+for k, v in CONF.__dict__.items():
     _debug_('%r: %r' % (k, v))
 
 # make sure USER and HOME are set

Modified: branches/rel-1/freevo/src/config.py
==============================================================================
--- branches/rel-1/freevo/src/config.py (original)
+++ branches/rel-1/freevo/src/config.py Sun Nov 11 00:01:56 2007
@@ -75,7 +75,7 @@
     gettext.install('freevo', os.environ['FREEVO_LOCALE'], 1)
 except: # unavailable, define '_' for all modules
     import __builtin__
-    __builtin__.__dict__['_']= lambda m: m
+    __builtin__.__dict__['_'] = lambda m: m
 
 
 # temp solution until this is fixed to True and False
@@ -94,8 +94,8 @@
 
 class Logger:
     """
-    Class to create a logger object which will send messages to stdout
-    and log them into a logfile
+    Class to create a logger object which will send messages to stdout and log 
them
+    into a logfile
     """
     def __init__(self, logtype='(unknown)'):
         self.lineno = 1
@@ -124,7 +124,7 @@
         lock.acquire()
         try:
             if isinstance(msg, unicode):
-                msg = msg.encode(LOCALE)
+                msg = msg.encode(LOCALE, 'replace')
             sys.__stdout__.write(msg)
             sys.__stdout__.flush()
             self.fp.write(msg)
@@ -325,8 +325,9 @@
 
 
 def make_freevodir(envvar, linux_dir, bsd_dir, private_dir):
-    '''Make the freevo specific directory and return it's name
-    '''
+    """
+    Make the freevo specific directory and return it's name
+    """
     if os.environ.has_key('OS_' + envvar):
         os_dirname = os.environ['OS_' + envvar]
     elif os.uname()[0] == 'FreeBSD':
@@ -420,11 +421,11 @@
 
 
 def _debug_function_(s, level=1):
-    '''The debug function that is mapped to the _debug_ builtin
-    There are different levels of debugging and logging. Debug messages
-    range from 1 (default) to 9 (most verbose), logging messages range
-    from NOTSET to DCRITICAL
-    '''
+    """
+    The debug function that is mapped to the _debug_ builtin There are 
different
+    levels of debugging and logging. Debug messages range from 1 (default) to 9
+    (most verbose), logging messages range from NOTSET to DCRITICAL
+    """
     if DEBUG < level:
         return
     if not s:
@@ -501,6 +502,7 @@
 FONT_DIR  = os.path.join(SHARE_DIR, 'fonts')
 
 RUNAPP = os.environ['RUNAPP']
+_debug_('RUNAPP: %s' % (RUNAPP))
 
 _debug_('logdir: %s %s' % (OS_LOGDIR, FREEVO_LOGDIR), DINFO)
 _debug_('staticdir: %s %s' % (OS_STATICDIR, FREEVO_STATICDIR), DINFO)

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to