def get_coin_features(self): "set the global variable SWIG_COND_SYMBOLS needed for conditional " + \ "wrapping" if sys.platform == "win32": return print blue("Checking for Coin features..."), if not os.system("coin-config --have-feature 3ds_import"): self.SWIG_COND_SYMBOLS.append("-DHAVE_FEATURE_3DS_IMPORT") print green("3ds import "), if not os.system("coin-config --have-feature vrml97"): self.SWIG_COND_SYMBOLS.append("-DHAVE_FEATURE_VRML97") print green("vrml97 "), if not os.system("coin-config --have-feature sound"): self.SWIG_COND_SYMBOLS.append("-DHAVE_FEATURE_SOUND") print green("sound "), if not os.system("coin-config --have-feature superglu"): self.SWIG_COND_SYMBOLS.append("-DHAVE_FEATURE_SUPERGLUE") print green("superglu "), if not os.system("coin-config --have-feature threads"): self.SWIG_COND_SYMBOLS.append("-DHAVE_FEATURE_THREADS") print green("threads "), if not os.system("coin-config --have-feature threadsafe"): self.SWIG_COND_SYMBOLS.append("-DHAVE_FEATURE_THREADSAFE") print green("threadsafe "), print
def check_cmd_exists(self, cmd): "return the path of the specified command if it exists" print blue("Checking for %s..." % cmd), for path in os.environ['PATH'].split(os.path.pathsep): if os.path.exists(os.path.join(path, cmd)): print blue("'%s'" % os.path.join(path, cmd)) return 1 print red("not found.") return 0
def check_coin_version(self): "check the Coin version" if sys.platform == "win32": return if not self.check_cmd_exists("coin-config"): sys.exit(1) print blue("Coin version..."), version = self.do_os_popen("coin-config --version") print blue("%s" % version) if not version.startswith('2.4'): print yellow("** Warning: Pivy has only been tested with Coin " "versions 2.4.x.")
def check_swig_version(self, swig): "check for the swig version" global SWIG_VERSION if not self.check_cmd_exists(swig): sys.exit(1) print blue("Checking for SWIG version..."), fd = os.popen4("%s -version" % swig)[1] version = fd.readlines()[1].strip().split(" ")[2] fd.close() print blue("%s" % version) SWIG_VERSION = version if not version in self.SUPPORTED_SWIG_VERSIONS: print yellow("Warning: Pivy has only been tested with the following " + \ "SWIG versions: %s." % " ".join(self.SUPPORTED_SWIG_VERSIONS))
def swig_generate(self): "build all available modules" for module in self.MODULES: module_name = self.MODULES[module][0] config_cmd = self.MODULES[module][1] module_pkg_name = self.MODULES[module][2] mod_out_prefix = module_pkg_name.replace('.', os.sep) + module if sys.platform == "win32": INCLUDE_DIR = os.getenv("COIN3DDIR") + "\\include" CPP_FLAGS = "-I" + INCLUDE_DIR + " " + \ "-I" + os.getenv("COIN3DDIR") + "\\include\\Inventor\\annex" + \ " /DSOWIN_DLL /DCOIN_DLL /wd4244 /wd4049" LDFLAGS_LIBS = os.getenv("COIN3DDIR") + "\\lib\\coin2.lib " + \ os.getenv("COIN3DDIR") + "\\lib\\sowin1.lib" else: INCLUDE_DIR = self.do_os_popen("coin-config --includedir") CPP_FLAGS = self.do_os_popen("%s --cppflags" % config_cmd) LDFLAGS_LIBS = self.do_os_popen("%s --ldflags --libs" % config_cmd) self.CXX_INCS = self.CXX_INCS + ' ' + CPP_FLAGS #G.Barrand if not os.path.isfile(mod_out_prefix + "_wrap.cpp"): print red("\n=== Generating %s_wrap.cpp for %s ===\n" % (mod_out_prefix, module)) print blue( self.SWIG + " " + self.SWIG_SUPPRESS_WARNINGS + " " + self.SWIG_PARAMS % (INCLUDE_DIR, self.CXX_INCS, mod_out_prefix, module)) if os.system( self.SWIG + " " + self.SWIG_SUPPRESS_WARNINGS + " " + self.SWIG_PARAMS % (INCLUDE_DIR, self.CXX_INCS, mod_out_prefix, module)): print red( "SWIG did not generate wrappers successfully! ** Aborting **" ) sys.exit(1) else: print red("=== %s_wrap.cpp for %s already exists! ===" % (mod_out_prefix, module_pkg_name + module)) self.ext_modules.append( Extension( module_name, [mod_out_prefix + "_wrap.cpp"], extra_compile_args=(self.CXX_INCS + CPP_FLAGS).split(), extra_link_args=(self.CXX_LIBS + LDFLAGS_LIBS).split())) self.py_modules.append(module_pkg_name + module)
def copy_and_swigify_headers(self, includedir, dirname, files): """Copy the header files to the local include directories. Add an #include line at the beginning for the SWIG interface files...""" for file in files: if not os.path.isfile(os.path.join(dirname, file)): continue if file[-2:] == ".i": file_i = os.path.join(dirname, file) file_h = os.path.join(dirname, file)[:-2] + ".h" if (not os.path.exists(file_h) and os.path.exists(os.path.join(includedir, file_h))): shutil.copyfile(os.path.join(includedir, file_h), file_h) sys.stdout.write(' ' + turquoise(file_h)) fd = open(file_h, 'r+') contents = fd.readlines() ins_line_nr = -1 for line in contents: ins_line_nr += 1 if line.find("#include ") != -1: break if ins_line_nr != -1: contents.insert(ins_line_nr, self.pivy_header_include % (file_i)) fd.seek(0) fd.writelines(contents) else: print blue("[") + red("failed") + blue("]") sys.exit(1) fd.close # fixes for SWIG 1.3.21 and upwards # (mostly workarounding swig's preprocessor "function like macros" # preprocessor bug when no parameters are provided which then results # in no constructors being created in the wrapper) elif file[-4:] == ".fix": sys.stdout.write(' ' + red(os.path.join(dirname, file)[:-4])) shutil.copyfile(os.path.join(dirname, file), os.path.join(dirname, file)[:-4]) # had to introduce this because windows is a piece of crap elif sys.platform == "win32" and file[-6:] == ".win32": sys.stdout.write(' ' + red(os.path.join(dirname, file)[:-6])) shutil.copyfile(os.path.join(dirname, file), os.path.join(dirname, file)[:-6])
def check_gui_bindings(self): "check for availability of SoGui bindings and removes the not available ones" if sys.platform == "win32": print "Using SoWin by default for Windows builds!" self.MODULES = { 'coin': ('_coin', 'coin-config', 'pivy.'), 'sowin': ('gui._sowin', 'sowin-config', 'pivy.gui.') } return for gui in self.SOGUI: gui_config_cmd = self.MODULES[gui][1] if not self.check_cmd_exists(gui_config_cmd): del self.MODULES[gui] else: print blue("Checking for %s version..." % gui), version = self.do_os_popen("%s --version" % gui_config_cmd) print blue("%s" % version)
def git_merge_all(self, from_branch, to_branch, working_path='/var/release'): """ Merge all Git Repositories from one branch into another. :param from_branch: What branch to merge from :param to_branch: What branch to merge into :param working_path: :return: """ if not os.path.exists(working_path): # if path doesn't exist, create it: os.mkdir(working_path) os.chdir(working_path) for repo in self.config.repositories: os.chdir(working_path) out(1, blue("\n------- REPO: " + repo + " -------")) # see if the repo exists path = working_path + '/' + repo output = '' try: if not os.path.exists(path): output += self.exec_shell('git clone ' + self.git_server + '/' + repo + '.git ' + path) if 'Access denied.' in output: out(2, yellow('skipped')) continue os.chdir(path) output += self.exec_shell('git reset --hard HEAD') output += self.exec_shell( 'git checkout --force {}'.format(from_branch)) output += self.exec_shell('git pull') output += self.exec_shell( 'git checkout --force {}'.format(to_branch)) output += self.exec_shell('git pull') output += self.exec_shell('git merge {}'.format(from_branch)) output += self.exec_shell( 'git push origin {}'.format(to_branch)) for line in output.splitlines(True): if line.startswith('error') or line.startswith('CONFLICT'): out(2, red(line)) else: out(2, green(line)) except Exception as e: out(2, red('Error: ')) out(2, red(output)) out(2, red(e)) return False return output
def invokeCmd(self, cmd, path=None): if path == None: path = self.workdir cmd = "cd " + self.getAbsPath(path) + "; " + cmd # print every command before executing if debug flag set if (self.flag_debug): print output.blue("running: ") + cmd # command returns error if (os.system(cmd)): self.printStatus(0) # sys.exit(1) # command completes without error else: self.printStatus(1)
def pivy_configure(self): "configure Pivy" print turquoise(self.PIVY_SNAKES) print blue("Platform...%s" % sys.platform) self.check_python_version() self.check_swig_version(self.SWIG) self.check_coin_version() self.get_coin_features() if self.SOGUI: self.check_gui_bindings() if sys.platform == "win32": INCLUDE_DIR = os.getenv("COIN3DDIR") + "\\include" else: INCLUDE_DIR = self.do_os_popen("coin-config --includedir") sys.stdout.write( blue("Preparing") + green(" Inventor ") + blue("headers:")) os.path.walk("Inventor", self.copy_and_swigify_headers, INCLUDE_DIR) print green(".")
def run(self): "the entry point for the distutils clean class" sys.stdout.write(blue("Cleaning headers:")) os.path.walk("Inventor", self.remove_headers, None) # remove the SWIG generated wrappers for wrapper_file in self.REMOVE_FILES: if os.path.isfile(wrapper_file): sys.stdout.write(' ' + turquoise(wrapper_file)) os.remove(wrapper_file) print green(".") clean.run(self)
def git_merge_all(self, from_branch, to_branch, working_path='/var/release'): """ Merge all Git Repositories from one branch into another. :param from_branch: What branch to merge from :param to_branch: What branch to merge into :param working_path: :return: """ if not os.path.exists(working_path): # if path doesn't exist, create it: os.mkdir(working_path) os.chdir(working_path) for repo in self.config.repositories: os.chdir(working_path) out(1, blue("\n------- REPO: " + repo + " -------")) # see if the repo exists path = working_path+'/'+repo output = '' try: if not os.path.exists(path): output += self.exec_shell('git clone '+self.git_server+'/'+repo+'.git ' + path) if 'Access denied.' in output: out(2, yellow('skipped')) continue os.chdir(path) output += self.exec_shell('git reset --hard HEAD') output += self.exec_shell('git checkout --force {}'.format(from_branch)) output += self.exec_shell('git pull') output += self.exec_shell('git checkout --force {}'.format(to_branch)) output += self.exec_shell('git pull') output += self.exec_shell('git merge {}'.format(from_branch)) output += self.exec_shell('git push origin {}'.format(to_branch)) for line in output.splitlines(True): if line.startswith('error') or line.startswith('CONFLICT'): out(2, red(line)) else: out(2, green(line)) except Exception as e: out(2, red('Error: ')) out(2, red(output)) out(2, red(e)) return False return output
def check_python_version(self): "check the Python version" print blue("Python version...%s" % sys.version.split(" ")[0]) if int(sys.version[0]) < 2: print red("Pivy only works with Python versions >= 2.0.") sys.exit(1)