On Wed, Mar 2, 2011 at 12:05 PM, Hartmut Goebel <h.goe...@goebel-consult.de>wrote:
> Hi, > Hi > > we discussed about sys.path hacks (see below) a few weeks ago. > > # Try to load shinken lib. > # Maybe it's not in our python path, so we detect it > # If so (it's an untar install) we add .. in the path > try: > import shinken > except ImportError, e: > if hasattr(sys.modules['__main__'], '__file__'): > my_path = os.path.abspath(sys.modules['__main__'].__file__) > parent_path = os.path.dirname(os.path.dirname(my_path)) > sys.path.append(parent_path) > sys.path.append(os.path.join(parent_path, 'shinken')) > > IMHO this has the big drawback of changing sys.path (and being a hack). > Today I found another solution: > > try: > import shinken > except ImportError: > import imp, os > imp.load_module('shinken', *imp.find_module('shinken', [".", ".."])) > > This doe not change sys.path, but tries to import shinken from the > current directory and the parent directory. This is what we want at > last, isn't it? > > What do you think about this? > So to to the trick for the main satellites, but how modules like the broker ones will have to do? After the "daemonization", they will be in the current directory /var/lib/shinken or something similar. If we do not set the sys.path, they won't be able to load the shinken lib isn't it? I think the sys.path is not a so bad thing. After this, we know that we can import shinken.whatwewant from every place of the daemon and it do not change if we do a direct launch or a daemon one. It's like a sort "cleaning" of path before starting. If we comment it quite good, it's not a howful hack after all, and it's quite even clear what we do (just set in the path so we can just import shinken/ after all), we should add such a comment for imp too after all. Jean
------------------------------------------------------------------------------ Free Software Download: Index, Search & Analyze Logs and other IT data in Real-Time with Splunk. Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________ Shinken-devel mailing list Shinken-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/shinken-devel