Menu

[r7]: / python_path.py  Maximize  Restore  History

Download this file

38 lines (32 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-
## CLIG v. 1.2.0
## Dieter Hilfer 30.10.2009
## Licensed under GPLv2
## http://clig.sourceforge.net/
"""
walk recursive tru subdirs, serach for py files, add dirs to sys.path
"""
import os, sys
allready_run=False
def updatePythonPath(dirpath):
## start=time.clock()
global allready_run
if allready_run:
return
allready_run=True
## print "Expand Python path in ",os.path.realpath(dirpath)
directories={}
#search for relevant directories
for root, dirs, files in os.walk(dirpath):
for name in files:
filename,extension=os.path.splitext(name)
dir_path=unicode(os.path.realpath(os.path.normpath(root)))
if (extension==".py" or extension==".pyc"):
# this dir has a py file -> take it
if directories.get(dir_path) is None:
# dir is not known yet
directories[dir_path]=0
break
for dir in directories.keys():
sys.path.append(dir)
## print "Run done in ", str(time.clock()-start), "s"