<commit_before>#!/usr/bin/env python
#
# Geant4Post5, Geant4Pre5
#
# Geant4 installers, big difference after geant4.9.5
#
# Author <NAME> - 15/05/2012 <<EMAIL>> : First revision
# Author <NAME> - 21/05/2012 <<EMAIL>> : Add Post 4.9.5 version
# Author <NAME> - 22/09/2012 <<EMAIL>> : Major refactor of snoing.
####################################################################################################
import localpackage
import installmode
import os
import shutil

class Geant4Post5(localpackage.LocalPackage):
    """ Base geant4 installer for post 4.9.5 geant versions. This is sooooo much nicer"""
    def __init__(self, name, system, tar_name, clhep_dep, xerces_dep):
        """ Initialise the geant4 package."""
        super(Geant4Post5, self).__init__(name, system)
        self._tar_name = tar_name
        self._xerces_dep = xerces_dep
        self._clhep_dep = clhep_dep
    def get_dependencies(self):
        """ Return the dependency names as a list of names."""
        dependencies = ["make", "g++", "gcc", "cmake", self._xerces_dep, self._clhep_dep]
        if self._system.get_install_mode() == installmode.Graphical:
            dependencies.extend(["Xm", "Xt", "opengl", "Xmu", "Xi"])
        return dependencies
    def _is_downloaded(self):
        """ Check if the tar file has been downloaded."""
        return self._system.file_exists(self._tar_name)
    def _is_installed(self):
        """ Check if the package has been installed."""
        installed = self._system.library_exists("libG4event", os.path.join(self.get_install_path(), "lib")) or \
            self._system.library_exists("libG4event", os.path.join(self.get_install_path(), "lib64"))
        if self._system.get_install_mode() == installmode.Graphical:
            installed = installed and \
                self._system.library_exists("libG4OpenGL", os.path.join(self.get_install_path(), "lib")) or \
                self._system.library_exists("libG4OpenGL", os.path.join(self.get_install_path(), "lib64"))
        return installed
    def _download(self):
        """ Derived classes should override this to download the package."""
        self._system.download_file(
            "http://geant4.web.cern.ch/geant4/support/source/" + self._tar_name)
    def _install(self):
        """ Install geant4, using cmake."""
        source_path = os.path.join(self._system.get_install_path(), "%s-source" % self._name)
        self._system.untar_file(self._tar_name, source_path, 1)
        self._patch_timeout()
        if not os.path.exists(self.get_install_path()):
            os.makedirs(self.get_install_path())
        cmake_opts = ["-DCMAKE_INSTALL_PREFIX=%s" % self.get_install_path(), 
                      "-DCLHEP_ROOT_DIR=%s" % self._dependency_paths[self._clhep_dep], 
                      "-DXERCESC_ROOT_DIR=%s" % self._dependency_paths[self._xerces_dep], 
                      "-DGEANT4_INSTALL_DATA=ON", 
                      "-DCLHEP_CONFIG_EXECUTABLE=%s" % \
                          os.path.join(self._dependency_paths[self._clhep_dep], "bin/clhep-config")]
        # Now set the environment, if needed
        env = {}
        if self._system.get_install_mode() == installmode.Graphical:
            cmake_opts.extend(["-DGEANT4_USE_XM=ON", "-DGEANT4_USE_OPENGL_X11=ON", 
                               "-DGEANT4_USE_RAYTRACER_X11=ON" ])
            env = {'G4VIS_BUILD_VRML_DRIVER' : "1", 'G4VIS_BUILD_OPENGLX_DRIVER' : "1", 
                   'G4VIS_BUILD_OPENGLXM_DRIVER' : "1", 'G4VIS_BUILD_DAWN_DRIVER' : "1" }
        cmake_opts.extend([source_path])
        cmake_command = "cmake"
        if self._dependency_paths["cmake"] is not None: # Special cmake installed
            cmake_command = "%s/bin/cmake" % self._dependency_paths["cmake"]
        self._system.configure_command(cmake_command, cmake_opts, self.get_install_path(), env)
        self._system.execute_command("make", [], self.get_install_path(), env)
        self._system.execute_command("make", ['install'], self.get_install_path(), env)
    def _patch_timeout(self):
        """ Patch the cmake scripts to increase the timeout limit, geant4.9.5.p01 fix."""
        file_path = os.path.join(self._system.get_install_path(), 
                                 "%s-source/cmake/Modules/Geant4InstallData.cmake" % self._name)
        cmake_file = open(file_path, "r")
        text = cmake_file.read()
        cmake_file.close()
        text = text.replace("PREFIX", "TIMEOUT 1800\n        PREFIX")
        cmake_file = open(file_path, "w")
        cmake_file.write(text)
        cmake_file.close()
        
class Geant4Pre5(localpackage.LocalPackage):
    """ Base geant4 installer for pre 4.9.5 geant versions."""
    def __init__(self, name, system, tar_name, data_tars, clhep_dep, xerces_dep):
        """ Initialise the geant4 package."""
        super(Geant4Pre5, self).__init__(name, system)
        self._clhep_dep = clhep_dep
        self._data_tars = data_tars
        self._tar_name = tar_name
        self._xerces_dep = xerces_dep
    def get_dependencies(self):
        """ Return the dependency names as a list of names."""
        dependencies = ["make", "g++", "gcc", self._xerces_dep, self._clhep_dep]
        if self._system.get_install_mode() == installmode.Graphical:
            dependencies.extend(["Xm", "Xt", "opengl", "Xmu", "Xi"])
        return dependencies
    def _is_downloaded(self):
        """ Check tar files have been downloaded."""<commit_msg>Up download timeout for very slow internet connections.<commit_after>#!/usr/bin/env python
#
# Geant4Post5, Geant4Pre5
#
# Geant4 installers, big difference after geant4.9.5
#
# Author <NAME> - 15/05/2012 <<EMAIL>> : First revision
# Author <NAME> - 21/05/2012 <<EMAIL>> : Add Post 4.9.5 version
# Author <NAME> - 22/09/2012 <<EMAIL>> : Major refactor of snoing.
####################################################################################################
import localpackage
import installmode
import os
import shutil

class Geant4Post5(localpackage.LocalPackage):
    """ Base geant4 installer for post 4.9.5 geant versions. This is sooooo much nicer"""
    def __init__(self, name, system, tar_name, clhep_dep, xerces_dep):
        """ Initialise the geant4 package."""
        super(Geant4Post5, self).__init__(name, system)
        self._tar_name = tar_name
        self._xerces_dep = xerces_dep
        self._clhep_dep = clhep_dep
    def get_dependencies(self):
        """ Return the dependency names as a list of names."""
        dependencies = ["make", "g++", "gcc", "cmake", self._xerces_dep, self._clhep_dep]
        if self._system.get_install_mode() == installmode.Graphical:
            dependencies.extend(["Xm", "Xt", "opengl", "Xmu", "Xi"])
        return dependencies
    def _is_downloaded(self):
        """ Check if the tar file has been downloaded."""
        return self._system.file_exists(self._tar_name)
    def _is_installed(self):
        """ Check if the package has been installed."""
        installed = self._system.library_exists("libG4event", os.path.join(self.get_install_path(), "lib")) or \
            self._system.library_exists("libG4event", os.path.join(self.get_install_path(), "lib64"))
        if self._system.get_install_mode() == installmode.Graphical:
            installed = installed and \
                self._system.library_exists("libG4OpenGL", os.path.join(self.get_install_path(), "lib")) or \
                self._system.library_exists("libG4OpenGL", os.path.join(self.get_install_path(), "lib64"))
        return installed
    def _download(self):
        """ Derived classes should override this to download the package."""
        self._system.download_file(
            "http://geant4.web.cern.ch/geant4/support/source/" + self._tar_name)
    def _install(self):
        """ Install geant4, using cmake."""
        source_path = os.path.join(self._system.get_install_path(), "%s-source" % self._name)
        self._system.untar_file(self._tar_name, source_path, 1)
        self._patch_timeout()
        if not os.path.exists(self.get_install_path()):
            os.makedirs(self.get_install_path())
        cmake_opts = ["-DCMAKE_INSTALL_PREFIX=%s" % self.get_install_path(), 
                      "-DCLHEP_ROOT_DIR=%s" % self._dependency_paths[self._clhep_dep], 
                      "-DXERCESC_ROOT_DIR=%s" % self._dependency_paths[self._xerces_dep], 
                      "-DGEANT4_INSTALL_DATA=ON", 
                      "-DCLHEP_CONFIG_EXECUTABLE=%s" % \
                          os.path.join(self._dependency_paths[self._clhep_dep], "bin/clhep-config")]
        # Now set the environment, if needed
        env = {}
        if self._system.get_install_mode() == installmode.Graphical:
            cmake_opts.extend(["-DGEANT4_USE_XM=ON", "-DGEANT4_USE_OPENGL_X11=ON", 
                               "-DGEANT4_USE_RAYTRACER_X11=ON" ])
            env = {'G4VIS_BUILD_VRML_DRIVER' : "1", 'G4VIS_BUILD_OPENGLX_DRIVER' : "1", 
                   'G4VIS_BUILD_OPENGLXM_DRIVER' : "1", 'G4VIS_BUILD_DAWN_DRIVER' : "1" }
        cmake_opts.extend([source_path])
        cmake_command = "cmake"
        if self._dependency_paths["cmake"] is not None: # Special cmake installed
            cmake_command = "%s/bin/cmake" % self._dependency_paths["cmake"]
        self._system.configure_command(cmake_command, cmake_opts, self.get_install_path(), env)
        self._system.execute_command("make", [], self.get_install_path(), env)
        self._system.execute_command("make", ['install'], self.get_install_path(), env)
    def _patch_timeout(self):
        """ Patch the cmake scripts to increase the timeout limit, geant4.9.5.p01 fix."""
        file_path = os.path.join(self._system.get_install_path(), 
                                 "%s-source/cmake/Modules/Geant4InstallData.cmake" % self._name)
        cmake_file = open(file_path, "r")
        text = cmake_file.read()
        cmake_file.close()
        text = text.replace("PREFIX", "TIMEOUT 10000\n        PREFIX")
        cmake_file = open(file_path, "w")
        cmake_file.write(text)
        cmake_file.close()
        
class Geant4Pre5(localpackage.LocalPackage):
    """ Base geant4 installer for pre 4.9.5 geant versions."""
    def __init__(self, name, system, tar_name, data_tars, clhep_dep, xerces_dep):
        """ Initialise the geant4 package."""
        super(Geant4Pre5, self).__init__(name, system)
        self._clhep_dep = clhep_dep
        self._data_tars = data_tars
        self._tar_name = tar_name
        self._xerces_dep = xerces_dep
    def get_dependencies(self):
        """ Return the dependency names as a list of names."""
        dependencies = ["make", "g++", "gcc", self._xerces_dep, self._clhep_dep]
        if self._system.get_install_mode() == installmode.Graphical:
            dependencies.extend(["Xm", "Xt", "opengl", "Xmu", "Xi"])
        return dependencies
    def _is_downloaded(self):
        """ Check tar files have been downloaded."""
{'fraction_non_alphanumeric': 0.14530070057319625, 'fraction_numerical': 0.016649986352470204, 'mean_word_length': 2.8964906061680256, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4395909', 'n_tokens_mistral': 3599, 'n_tokens_neox': 3417, 'n_words': 682}