perfect solution imho too :)

I wasn't knowing a lot personnaly (yet) about the imp module. otherwise I'd
have already proposed the solution ofcourse ;)

rgds,

greg.


2011/3/2 Hartmut Goebel <h.goe...@goebel-consult.de>

> 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?
>
> --
> Schönen Gruß - Regards
> Hartmut Goebel
> Dipl.-Informatiker (univ.), CISSP, CSSLP
>
> Goebel Consult
> Spezialist für IT-Sicherheit in komplexen Umgebungen
> http://www.goebel-consult.de
>
> Monatliche Kolumne: http://www.cissp-gefluester.de/
> Goebel Consult mit Mitglied bei http://www.7-it.de
>
>
>
>
> ------------------------------------------------------------------------------
> 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
>
>
------------------------------------------------------------------------------
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

Reply via email to