source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/gluon/tests/fix_path.py

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 884 bytes
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3import os
4import sys
5
6def fix_sys_path(current_path):
7    """
8    logic to have always the correct sys.path
9     '', web2py/gluon, web2py/site-packages, web2py/ ...
10    """
11
12    def add_path_first(path):
13        sys.path = [path] + [p for p in sys.path if (
14            not p == path and not p == (path + '/'))]
15
16    path = os.path.dirname(os.path.abspath(current_path))
17
18    if not os.path.isfile(os.path.join(path,'web2py.py')):
19        i = 0
20        while i<10:
21            i += 1
22            if os.path.exists(os.path.join(path,'web2py.py')):
23                break
24            path = os.path.abspath(os.path.join(path, '..'))
25
26    paths = [path,
27             os.path.abspath(os.path.join(path, 'site-packages')),
28             os.path.abspath(os.path.join(path, 'gluon')),
29             '']
30    [add_path_first(path) for path in paths]
Note: See TracBrowser for help on using the repository browser.