root/infra/tracx/tracx/loader.py @ 156

Revision 156, 2.5 KB (checked in by lazaridis_com, 4 years ago)

closes #82, re #50: implemented mechanism which allows automated loading of plugins from 2nd-level directories.

Line 
1#------------------------------------------------------------------------------
2# $Id$
3# $URL$
4# Copyright (c) 2006, Ilias Lazaridis - All Rights Reserved
5#------------------------------------------------------------------------------
6
7from trac.core import *
8from trac.env import IEnvironmentSetupParticipant
9
10import os.path
11import os
12       
13#------------------------------------------------------------------------------
14
15class PluginLoader(Component):
16    """ (draft) Loads further plugins from the plugin/ directory
17   
18    the plugins don't need to have a egg-info, it will be generated from this
19    component.
20   
21    The plugins are loaded and enabled without manual intervention.
22   
23    This way it is possible to check-out and activate multiple plugins via
24    svn-externals directly from svn repositories.
25   
26    """
27
28    def __init__(self):
29        # retrieve directory of tracx and tracx/plugins
30        from tracx import __file__ as tracx_file
31        tracxdir = os.path.split(os.path.dirname(tracx_file)) [0]
32        self.log.debug("tracx, loading plugins form: %s", tracxdir)
33       
34        plugindir =  os.path.join(tracxdir, 'plugins') 
35        files = os.listdir(plugindir)
36       
37        # create a list of subdirectories
38        subdirs = []
39        for file in files:
40            fullname = os.path.join(plugindir,file)
41            if os.path.isdir( fullname ):
42                subdirs.append(fullname)
43       
44        # create the egg-info for each subdir
45        curdir = os.getcwd()
46        for dir in subdirs:
47            os.chdir(dir)
48            if os.path.exists( os.path.join(dir,'setup.py')):
49                import sys               
50                #TODO: pass argv in the global dict of the execfile function
51                sys.argv = ["setup.py", "egg_info"]
52                execfile( os.path.join(dir,'setup.py'))
53                self.log.debug(dir)
54
55        os.chdir(curdir)
56       
57        # call plugin loader     
58#TODO: trac:#4317 - replace next line with below after fixing
59        from tracx.modified.loader import load_components
60        #trac.loader import load_components
61#       
62        load_components(self.env, subdirs)
63       
64#TODO trac:$4190 - replace dummies to force component initialization
65    implements(IEnvironmentSetupParticipant)
66    # IEnvironmentSetupParticipant
67    def environment_created(self): pass
68    def environment_needs_upgrade(self, db): return False
69    def upgrade_environment(self, db): pass
70#
Note: See TracBrowser for help on using the browser.