From 2b42c6a3ead7c2bd35bbea1c6d704a4f89a4c8a2 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 26 May 2013 20:07:12 +0200 Subject: Update setup.py to use distutils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (use new default directory, install the plugins as a separate python moduleā€¦) --- src/__init__.py | 1 + src/config.py | 7 ++++++- src/plugin_manager.py | 37 +++++++++++++++++++++++++++---------- src/poezio.py | 6 ++++-- 4 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 src/__init__.py (limited to 'src') diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 00000000..9fdbcc02 --- /dev/null +++ b/src/__init__.py @@ -0,0 +1 @@ +from poezio.poezio import main diff --git a/src/config.py b/src/config.py index 2134513f..47262e28 100644 --- a/src/config.py +++ b/src/config.py @@ -251,7 +251,12 @@ options = parse_args(CONFIG_PATH) # Copy a default file if none exists if not path.isfile(options.filename): - copy2(path.join(path.dirname(__file__), '../data/default_config.cfg'), options.filename) + default = path.join(path.dirname(__file__), '../data/default_config.cfg') + other = '/etc/poezio/default_config.cfg' + if path.isfile(default): + copy2(default, options.filename) + elif path.isfile(other): + copy2(other, options.filename) firstrun = True config = Config(options.filename) diff --git a/src/plugin_manager.py b/src/plugin_manager.py index f494fefc..9e253f97 100644 --- a/src/plugin_manager.py +++ b/src/plugin_manager.py @@ -20,6 +20,8 @@ from config import config log = logging.getLogger(__name__) +load_path = [] + plugins_dir = config.get('plugins_dir', '') plugins_dir = plugins_dir or\ os.path.join(os.environ.get('XDG_DATA_HOME') or\ @@ -39,6 +41,8 @@ try: os.makedirs(plugins_dir) except OSError: pass +else: + load_path.append(plugins_dir) try: os.makedirs(plugins_conf_dir) @@ -47,14 +51,23 @@ except OSError: default_plugin_path = path.join(path.dirname(path.dirname(__file__)), 'plugins') -sys.path.append(plugins_dir) -sys.path.append(default_plugin_path) +if os.path.exists(default_plugin_path): + load_path.append(default_plugin_path) + +try: + import poezio_plugins +except: + pass +else: + if poezio_plugins.__path__: + load_path.append(poezio_plugins.__path__[0]) + +sys.path.extend(load_path) if version_info[1] >= 3: # 3.3 & > from importlib import machinery finder = machinery.PathFinder() - class PluginManager(object): """ Plugin Manager @@ -94,7 +107,7 @@ class PluginManager(object): imp.acquire_lock() module = imp.reload(self.modules[name]) else: - file, filename, info = imp.find_module(name, [plugins_dir, default_plugin_path]) + file, filename, info = imp.find_module(name, load_path) imp.acquire_lock() module = imp.load_module(name, file, filename, info) else: # 3.3 & > @@ -288,15 +301,19 @@ class PluginManager(object): all .py files in plugins_dir """ try: - try: - names = set(os.listdir(default_plugin_path)) - except: - names = set() - names |= set(os.listdir(plugins_dir)) + names = set() + for path in load_path: + try: + add = set(os.listdir(path)) + names |= add + except: + pass except OSError as e: self.core.information(_('Completion failed: %s' % e), 'Error') return - plugins_files = [name[:-3] for name in names if name.endswith('.py')] + plugins_files = [name[:-3] for name in names if name.endswith('.py') + and name != '__init__.py' and not name.startswith('.')] + plugins_files.sort() return the_input.auto_completion(plugins_files, '', quotify=False) def completion_unload(self, the_input): diff --git a/src/poezio.py b/src/poezio.py index 161446da..c0863416 100644 --- a/src/poezio.py +++ b/src/poezio.py @@ -12,11 +12,13 @@ Starting point of poezio. Launches both the Connection and Gui import sys import os -sys.path.append(os.path.dirname(os.path.abspath(__file__))) + import signal import logging -from logger import logger +sys.path.append(os.path.dirname(os.path.abspath(__file__))) + +from logger import logger from config import options import singleton import core -- cgit v1.2.3