|
Revision 287, 434 bytes
(checked in by t, 4 years ago)
|
texttest path cleansing.
|
| Line | |
|---|
| 1 |
""" |
|---|
| 2 |
Insert the lib/ directory into the path. |
|---|
| 3 |
""" |
|---|
| 4 |
import sys, os.path |
|---|
| 5 |
|
|---|
| 6 |
this_dir = os.path.dirname(__file__) |
|---|
| 7 |
home_dir = os.path.realpath(os.path.join(this_dir, '../')) |
|---|
| 8 |
lib_dir = '../lib/' |
|---|
| 9 |
|
|---|
| 10 |
joined_dir = os.path.abspath(os.path.join(this_dir, lib_dir)) |
|---|
| 11 |
sys.path.insert(0, joined_dir) |
|---|
| 12 |
|
|---|
| 13 |
def remove_home(p): |
|---|
| 14 |
p = os.path.realpath(p) |
|---|
| 15 |
if p.startswith(home_dir): |
|---|
| 16 |
p = p[len(home_dir):] |
|---|
| 17 |
p = p.lstrip('/') |
|---|
| 18 |
|
|---|
| 19 |
return p |
|---|