File: rerun.py

package info (click to toggle)
obitools 1.2.13%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,652 kB
  • sloc: python: 18,199; ansic: 1,542; makefile: 98
file content (60 lines) | stat: -rw-r--r-- 1,444 bytes parent folder | download | duplicates (2)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'''
Created on 2 oct. 2014

@author: coissac
'''

import sys
import os

from distutils import log
from distutils.errors import DistutilsError


from obidistutils.serenity.globals import saved_args
from obidistutils.serenity.checkpython import is_good_python27, \
                                              lookfor_good_python27


def rerun_with_anothe_python(path, fork=False):
        
    if saved_args:
        args = saved_args
    else:
        args = list(sys.argv)
        
          
    assert is_good_python27(path), \
           'the selected python is not adapted to the installation of this package'
                   
    args.insert(0, path)
        
    sys.stderr.flush()
    sys.stdout.flush()
    
    if fork:
        log.info('Forking a new install process')
        os.system(' '.join(list(args)))
        log.info('External process ended')
        sys.exit(0)
    else:
        os.execv(path,list(args))

def enforce_good_python():
    if is_good_python27():
        return True
    
    goodpython = lookfor_good_python27()
    
    if not goodpython:
        raise DistutilsError('No good python identified on your system')

    goodpython=goodpython[0]
    
    log.warn("========================================")    
    log.warn("")
    log.warn("    Switching to python : %s" % goodpython)
    log.warn("")
    log.warn("========================================")    

    rerun_with_anothe_python(goodpython)