# -*- mode: python; coding: utf-8 -*- import os, sys, logging import ConfigParser import util import ps BASE = os.path.dirname(sys.argv[0]) sys.path.append(BASE) USERDIR = os.environ['HOME'] TPBASE = os.path.join(USERDIR, '.twinpanel') ENABLED = os.path.join(TPBASE, 'enabled') DBFILE = os.path.join(TPBASE, 'factorymap') PLUGDIRS = [os.path.join(BASE, 'plugins'), ENABLED] for dname in PLUGDIRS: if dname not in sys.path: sys.path.append(dname) DEFAULT_METHOD = 'ice' def revision(): try: import commands retval = commands.getoutput(\ "cd %s; hg tip | awk -F':' '/changeset/ {print $2}'" % BASE).strip() if not retval.isdigit(): retval = '??' return retval except: return '??' def path(fname, user=None): paths = [ os.path.join(BASE, fname), os.path.join(BASE, 'plugins', fname), ] if user: paths.append(os.path.join(os.path.dirname(user), fname)) for p in paths: if os.path.exists(p): return p logging.error("File '%s' not found" % fname) return None # Aplicaciones predefinidas por tipo de fichero # FIXME: Gestión de MIME-types (GVFS) # FIXME: Utilizar la clase URI def open(uri): logging.debug('open(%s)' % uri) if os.path.splitext(uri)[1] == '.html' or\ uri.startswith('http'): ps.Subprocess('sensible-browser %s' % uri) class ConfigManager: __metaclass__ = util.Singleton def __init__(self): if not os.path.exists(TPBASE): self.gen_default_config() files = [ os.path.join(TPBASE, 'config'), 'config'] self.parser = ConfigParser.SafeConfigParser() self.parser.read(files) def get(self, option, cls=str): section, sep, option = option.partition('.') return cls(self.parser.get(section, option)) def gen_default_config(self): os.mkdir(TPBASE) os.mkdir(ENABLED) Config = ConfigManager()