]> Creatis software - cpPlugins.git/blob - dependencies/dependencies.py
cc1d9172e1048c51b73e4e180ea678261b788293
[cpPlugins.git] / dependencies / dependencies.py
1 import os, platform, readline, glob, multiprocessing
2 from distutils import spawn
3
4 ## ------------------------
5 ## -- Filename completer --
6 ## ------------------------
7
8 def complete( text, state ):
9     return ( glob.glob( text + '*' ) + [ None ] )[ state ]
10 # fed
11
12 ## -----------------------
13 ## -- File decompressor --
14 ## -----------------------
15
16 def decompress( filename, outdir ):
17     real_ext = None
18     for ext in [ ".zip", ".tar", ".tar.gz", ".tar.bz2" ]:
19         if filename[ len( filename ) - len( ext ) : ] == ext:
20             real_ext = ext
21         # fi
22     # rof
23     command = None
24     if real_ext == ".zip":
25         command = "unzip " + filename + " -d " + outdir
26     elif real_ext == ".tar":
27         command = "tar xf " + filename + " -C " + outdir + " --strip-components=1"
28     elif real_ext == ".tar.gz":
29         command = "tar xzf " + filename + " -C " + outdir + " --strip-components=1"
30     elif real_ext == ".tar.bz2":
31         command = "tar xjf " + filename + " -C " + outdir + " --strip-components=1"
32     # fi
33     if command <> None:
34         print( "\tExtracting " + filename + "..." )
35         res = os.system( "mkdir -p " + outdir + " && " + command )
36         print( "\t\tdone." )
37         if res == 0:
38             return True
39         else:
40             return False
41     else:
42         return False
43     # fi
44 # fed
45
46 ## -------------------------
47 ## -- Find necessary data --
48 ## -------------------------
49
50 system_name = platform.system( )
51 process_count = multiprocessing.cpu_count( ) / 2
52 qmake_exec = spawn.find_executable( "qmake-qt4" )
53 cmake_exec = spawn.find_executable( "cmake" )
54 readline.set_completer_delims( ' \t\n;' )
55 readline.parse_and_bind( "tab: complete" )
56 readline.set_completer( complete )
57 install_prefix = os.path.abspath( raw_input( "Install prefix: " ) )
58
59 ## --------------------------------------------
60 ## -- Ask if new versions should be compiled --
61 ## --------------------------------------------
62
63 build_qmake = "y"
64 if qmake_exec <> None:
65     build_qmake = raw_input( "Qt4 was found in \"" + qmake_exec + "\", do you want to install a new Qt4 [y/n]? " )
66 # fi
67 build_qmake.lower( )
68
69 build_cmake = "y"
70 if cmake_exec <> None:
71     build_cmake = raw_input( "CMake was found in \"" + cmake_exec + "\", do you want to install a new CMake [y/n]? " )
72 # fi
73 build_cmake.lower( )
74
75 ## -----------------
76 ## -- Compile Qt4 --
77 ## -----------------
78
79 if build_qmake[ 0 ] == "y":
80     print( "Compiling Qt4..." )
81     readline.set_completer_delims( ' \t\n;' )
82     readline.parse_and_bind( "tab: complete" )
83     readline.set_completer( complete )
84     qt4_file = os.path.abspath(
85         raw_input( "\tCompressed file containing Qt4: " )
86         )
87     full = raw_input( "\tWould you like to perform a full build [y/n]? " )
88     full.lower( )
89     build_type = raw_input( "\tBuild type [release/debug]? " )
90     build_type.lower( )
91     if not decompress( qt4_file, "./qt4_source" ):
92         print( "Unable to decompress Qt4." )
93         exit( 1 )
94     # fi
95     qt4_source = os.path.abspath( "./qt4_source" )
96     os.system( "mkdir -p ./qt4_build" )
97     qt4_build = os.path.abspath( "./qt4_build" )
98
99     config_command = qt4_source + "/configure"
100     config_command += " -prefix " + install_prefix
101     config_command += " -" + build_type
102     config_command += " -opensource -shared -fast -no-webkit -optimized-qmake -confirm-license"
103     if full[ 0 ] == "n":
104         config_command += " -no-phonon -no-phonon-backend -no-openvg -nomake demos -nomake examples"
105     # fi
106     ## MACOS: -no-framework
107
108     ## Build and install
109     res = os.system( "cd " + qt4_build + " && " + config_command )
110     if res <> 0:
111         print( "Error configuring Qt4." )
112         exit( 1 )
113     # fi
114     res = os.system( "cd " + qt4_build + " && make -j" + str( process_count ) )
115     if res <> 0:
116         print( "Error compiling Qt4." )
117         exit( 1 )
118     # fi
119     res = os.system( "cd " + qt4_build + " && make -j install" )
120     if res <> 0:
121         print( "Error installing Qt4." )
122         exit( 1 )
123     # fi
124 # fi
125
126 ## eof - $RCSfile$