Author: dmeyer
Date: Sat Oct 15 18:48:13 2005
New Revision: 7704
Added:
trunk/freevo-core/
trunk/freevo-core/setup.py
trunk/freevo-core/share/
trunk/freevo-core/share/mbus.conf
- copied unchanged from r7699, /trunk/freevo/share/mbus.conf
trunk/freevo-core/src/
trunk/freevo-core/src/__init__.py
trunk/freevo-core/src/conf.py
- copied, changed from r7699, /trunk/freevo/src/sysconfig.py
trunk/freevo-core/src/mcomm.py
- copied, changed from r7699, /trunk/freevo/src/mcomm.py
Log:
create freevo-core package
Added: trunk/freevo-core/setup.py
==============================================================================
--- (empty file)
+++ trunk/freevo-core/setup.py Sat Oct 15 18:48:13 2005
@@ -0,0 +1,20 @@
+# Python distutils stuff
+import os
+import sys
+from distutils.core import setup, Extension
+
+share_files = ['share/mbus.conf']
+
+# now start the python magic
+setup (name = "freevo",
+ version = "2.0",
+ description = "Freevo",
+ author = "Krister Lagerstrom, et al.",
+ author_email = "[email protected]",
+ url = "http://www.freevo.org",
+ license = "GPL",
+
+ package_dir = { 'freevo': 'src' },
+ packages = [ 'freevo', 'freevo' ],
+ data_files = [('share/freevo', share_files)]
+ )
Added: trunk/freevo-core/src/__init__.py
==============================================================================
Copied: trunk/freevo-core/src/conf.py (from r7699,
/trunk/freevo/src/sysconfig.py)
==============================================================================
--- /trunk/freevo/src/sysconfig.py (original)
+++ trunk/freevo-core/src/conf.py Sat Oct 15 18:48:13 2005
@@ -53,14 +53,10 @@
# cachedir are added to the resulting struct to have all needed informations.
application = 'freevo'
-# Should the sysconfig module prepare the application for the use of the
-# vfs util?
-use_vfs = True
-
# That's it, you shouldn't need to make changes after this point
-__all__ = [ 'CONF', 'Unicode', 'String', 'getvar', 'cachefile', 'datafile' ]
+__all__ = [ 'Unicode', 'String', 'cachefile', 'datafile' ]
# Python imports
import os
@@ -68,29 +64,66 @@
import locale
import __builtin__
import logging
+import ConfigParser
-# Directories were to search the config file
-_cfgfilepath = [ '.', os.path.expanduser('~/.' + application),
- '/etc/' + application, '/usr/local/etc/' + application]
-# Dummy class for the CONF
-class struct(object):
- pass
+class Section(object):
+ def __init__(self, section, config):
+ self.section = section
+ self.config = config
+
+ def getint(self, option, default=0):
+ try:
+ return self.config.getint(self.section, option)
+ except ConfigParser.NoOptionError:
+ return default
+
+ def get(self, option, default=''):
+ try:
+ return self.config.get(self.section, option)
+ except ConfigParser.NoOptionError:
+ return default
+
+ def getboolean(self, option, default=True):
+ try:
+ return self.config.getboolean(self.section, option)
+ except ConfigParser.NoOptionError:
+ return default
+
+ def set(self, option, value):
+ self.config.set(self.section, option, value)
+
+
+class Config(object):
+ def __init__(self, filename):
+ self.data = ConfigParser.ConfigParser()
+ self.data.read(filename)
+ self.filename = filename
+
+ def save(self):
+ f = open(self.filename, 'w')
+ self.data.write(f)
+ f.close()
+
+ def __getitem__(self, section):
+ if not self.data.has_section(section):
+ self.data.add_section(section)
+ return Section(section, self)
+
+ def __getattr__(self, attr):
+ return getattr(self.data, attr)
-CONF = struct()
+
+# Directories were to search the config file
+cfgfilepath = [ '.', os.path.expanduser('~/.' + application),
+ '/etc/' + application, '/usr/local/etc/' + application]
# find the currect encoding
try:
- CONF.default_encoding = locale.getdefaultlocale()[1]
- ''.encode(CONF.default_encoding)
+ ENCODING = locale.getdefaultlocale()[1]
+ ''.encode(ENCODING)
except:
- CONF.default_encoding = 'latin-1'
-
-CONF.encoding = CONF.default_encoding
-
-# set default vfs dir
-if use_vfs:
- CONF.vfs_dir = os.path.expanduser('~/.' + application + '/vfs')
+ ENCODING = 'latin-1'
# set default cachedir
if os.uname()[0] == 'FreeBSD':
@@ -98,94 +131,55 @@
else:
OS_CACHEDIR = '/var/cache'
-CONF.cachedir = OS_CACHEDIR + '/' + application
-CONF.datadir = '/var/lib/' + application
-CONF.logdir = '/var/log/' + application
+CACHEDIR = OS_CACHEDIR + '/' + application
+DATADIR = '/var/lib/' + application
+LOGDIR = '/var/log/' + application
-CONFIGFILE = ''
+# Directories were to search the config file
+_cfgfilepath = [ '.', os.path.expanduser('~/.' + application),
+ '/etc/' + application, '/usr/local/etc/' + application]
# read the config file, if no file is found, the default values
-# are used.
+# are used. FIXME: update the freevo.conf file
for dirname in _cfgfilepath:
- conf = os.path.join(dirname, application + '.conf')
+ conf = os.path.join(dirname, application + '.conf.new')
if os.path.isfile(conf):
- c = open(conf)
- for line in c.readlines():
- if line.startswith('#'):
- continue
- if line.find('=') == -1:
- continue
- vals = line.strip().split('=')
- if not len(vals) == 2:
- print 'invalid config entry: %s' % line
- continue
- name, val = vals[0].strip(), vals[1].strip()
- CONF.__dict__[name] = val
-
- c.close()
- CONFIGFILE = conf
+ c = Config(conf)
break
+# directory for 'share' files
+base = os.path.normpath(os.path.join(os.path.dirname(__file__), '../../../..'))
+SHAREDIR = os.path.join(base, 'share', application)
-# create the vfs
-if use_vfs:
- if not CONF.vfs_dir or CONF.vfs_dir == '/':
- print
- print 'ERROR: bad vfs dir.'
- print 'Set vfs dir it to a directory on the local filesystem.'
- print 'Make sure this partition has about 100 MB free space'
- sys.exit(0)
-
- # Make sure CONF.vfs_dir doesn't ends with a slash
- # With that, we don't need to use os.path.join, normal string
- # concat is much faster
- if CONF.vfs_dir.endswith('/'):
- CONF.vfs_dir = CONF.vfs_dir[:-1]
-
- if not os.path.isdir(CONF.vfs_dir):
- os.makedirs(CONF.vfs_dir)
-
- if not os.path.isdir(CONF.vfs_dir + '/disc'):
- os.makedirs(CONF.vfs_dir + '/disc')
-
- if not os.path.isdir(CONF.vfs_dir + '/disc/metadata'):
- os.makedirs(CONF.vfs_dir + '/disc/metadata')
-
- if not os.path.isdir(CONF.vfs_dir + '/disc-set'):
- os.makedirs(CONF.vfs_dir + '/disc-set')
+# create needed directories.
+# FIXME: make sure we can write to them
# create cachedir
-if not os.path.isdir(CONF.cachedir):
+if not os.path.isdir(CACHEDIR):
try:
- os.makedirs(CONF.cachedir)
+ os.makedirs(CACHEDIR)
except OSError:
- CONF.cachedir = os.path.expanduser('~/.' + application + '/cache')
- if not os.path.isdir(CONF.cachedir):
- os.makedirs(CONF.cachedir)
+ CACHEDIR = os.path.expanduser('~/.' + application + '/cache')
+ if not os.path.isdir(CACHEDIR):
+ os.makedirs(CACHEDIR)
# create datadir
-if not os.path.isdir(CONF.datadir):
+if not os.path.isdir(DATADIR):
try:
- os.makedirs(CONF.datadir)
+ os.makedirs(DATADIR)
except OSError:
- CONF.datadir = os.path.expanduser('~/.' + application + '/lib')
- if not os.path.isdir(CONF.datadir):
- os.makedirs(CONF.datadir)
+ DATADIR = os.path.expanduser('~/.' + application + '/lib')
+ if not os.path.isdir(DATADIR):
+ os.makedirs(DATADIR)
# create logdir
-if not os.path.isdir(CONF.logdir):
+if not os.path.isdir(LOGDIR):
try:
- os.makedirs(CONF.logdir)
+ os.makedirs(LOGDIR)
except OSError:
- CONF.logdir = os.path.expanduser('~/.' + application + '/log')
- if not os.path.isdir(CONF.logdir):
- os.makedirs(CONF.logdir)
-
-# add everything in CONF to the module variable list (but in upper
-# case, so CONF.vfs_dir is VFS_DIR, too
-for key in CONF.__dict__:
- exec('%s = CONF.%s' % (key.upper(), key))
-
+ LOGDIR = os.path.expanduser('~/.' + application + '/log')
+ if not os.path.isdir(LOGDIR):
+ os.makedirs(LOGDIR)
# create and setup the root logger object.
# using logging.getLogger() gives the root logger, calling
@@ -212,7 +206,7 @@
'%(filename)s %(lineno)s: '+\
'%(message)s')
syslogfile = os.path.splitext(os.path.basename(sys.argv[0]))[0]
-syslogfile = '%s/%s-%s' % (CONF.logdir, syslogfile, os.getuid())
+syslogfile = '%s/%s-%s' % (LOGDIR, syslogfile, os.getuid())
handler = logging.FileHandler(syslogfile)
handler.setFormatter(formatter)
logger.addHandler(handler)
@@ -229,17 +223,13 @@
fallback instead of ascii
"""
if not encoding:
- encoding = CONF.encoding
+ encoding = ENCODING
if string.__class__ == str:
try:
return unicode(string, encoding)
except UnicodeDecodeError:
pass
try:
- return unicode(string, CONF.default_encoding)
- except UnicodeDecodeError:
- pass
- try:
return unicode(string, 'UTF-8')
except UnicodeDecodeError:
pass
@@ -256,7 +246,7 @@
fallback instead of ascii
"""
if not encoding:
- encoding = CONF.encoding
+ encoding = ENCODING
if string.__class__ == unicode:
return string.encode(encoding, 'replace')
if string.__class__ == str:
@@ -272,35 +262,26 @@
__builtin__.__dict__['String'] = String
-def getvar(variable):
- """
- Get a variable from CONF, return None if not found
- """
- if hasattr(CONF, variable):
- return CONF.variable
- return None
-
-
def cachefile(name, uid=False):
"""
Return a cachefile based on the name. The result is an absolute path.
If uid is True, the uid will be added to the name.
"""
if uid:
- return os.path.join(CONF.cachedir, name + '-' + str(os.getuid()))
+ return os.path.join(CACHEDIR, name + '-' + str(os.getuid()))
else:
- return os.path.join(CONF.cachedir, name)
+ return os.path.join(CACHEDIR, name)
def datafile(name):
"""
Return a datafile based on the name. The result is an absolute path.
"""
- return os.path.join(CONF.datadir, name)
+ return os.path.join(DATADIR, name)
def logfile(name):
"""
Return a datafile based on the name. The result is an absolute path.
"""
- return os.path.join(CONF.logdir, name)
+ return os.path.join(LOGDIR, name)
Copied: trunk/freevo-core/src/mcomm.py (from r7699, /trunk/freevo/src/mcomm.py)
==============================================================================
--- /trunk/freevo/src/mcomm.py (original)
+++ trunk/freevo-core/src/mcomm.py Sat Oct 15 18:48:13 2005
@@ -59,13 +59,12 @@
import kaa.notifier
import mbus
-# freevo imports
-import sysconfig
-import config
+# freevo.core imports
+import conf
# fix encoding in mbus
import mbus.types
-mbus.types.encoding = sysconfig.ENCODING
+mbus.types.encoding = conf.ENCODING
# get logging object
log = logging.getLogger()
@@ -247,7 +246,7 @@
for i in range(len(val)):
if pattern[i] == str:
ret.append(unicode(val[i], 'UTF8').\
- encode(sysconfig.ENCODING, 'replace'))
+ encode(conf.ENCODING, 'replace'))
elif pattern[i] == unicode:
ret.append(unicode(val[i], 'UTF8'))
elif pattern[i] == bool:
@@ -449,7 +448,7 @@
# If the file does not exist, generate one with a random hash key
# and a user defined port. For security reasons it is not allowed
# to have read access to this file for 'others'
- tmp = open(os.path.join(config.SHARE_DIR, 'mbus.conf'))
+ tmp = open(os.path.join(conf.SHAREDIR, 'mbus.conf'))
cfg = open(mbus_config, 'w')
for line in tmp.readlines():
if line.startswith('PORT='):
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog