def install_header(name, dir_name=None): # Make sure the extension is valid Helpers.require_file_extension(name, '.h') # Get the location headers are stored in prog_root = None if Config.os_type in OSType.Windows: prog_root = os.environ.get('programfiles', 'C:\Program Files') else: prog_root = '/usr/include/' # Get the native install source and dest source = to_native(name) install_dir = os.path.join(prog_root, dir_name or '') dest = os.path.join(install_dir, source) # Install def fn(): # Make the dir if needed if dir_name and not os.path.isdir(install_dir): os.mkdir(install_dir) # Copy the file shutil.copy2(source, dest) Process.do_on_fail_exit("Installing the header '{0}'".format(name), "Failed to install the header '{0}'.".format(name), lambda: fn())
def uninstall_header(name, dir_name=None): # Make sure the extension is valid Helpers.require_file_extension(name, '.h') # Get the location header are stored in prog_root = None if Config.os_type in OSType.Windows: prog_root = os.environ.get('programfiles', 'C:\Program Files') else: prog_root = '/usr/include/' # Get the native install source and dest source = to_native(name) install_dir = os.path.join(prog_root, dir_name or '') dest = os.path.join(install_dir, source) # Remove def fn(): # Remove the file if os.path.isfile(dest): os.remove(dest) # Remove the dir if empty if dir_name and os.path.isdir( install_dir) and not os.listdir(install_dir): shutil.rmtree(install_dir) Process.do_on_fail_exit( "Uninstalling the header '{0}'".format(name), "Failed to uninstall the header '{0}'.".format(name), lambda: fn())
def make_dir(source, ignore_failure = False): if ignore_failure: Process.do_on_fail_pass("Making the dir '{0}'".format(source), lambda: os.mkdir(source)) else: Process.do_on_fail_exit("Making the dir '{0}'".format(source), "Failed to make the dir '{0}'.".format(source), lambda: os.mkdir(source))
def install_program(name, dir_name): # Make sure the extension is valid Helpers.require_file_extension(name, '.exe') # Get the location programs are stored in prog_root = None if Config.os_type in OSType.Windows: prog_root = os.environ.get('programfiles', 'C:\Program Files') else: prog_root = '/usr/lib/' # Get the native install source and dest source = to_native(name) install_dir = os.path.join(prog_root, dir_name or '') dest = os.path.join(install_dir, source) # Install def fn(): # Make the dir if needed if dir_name and not os.path.isdir(install_dir): os.mkdir(install_dir) # Copy the file shutil.copy2(source, dest) if not Config.os_type in OSType.Windows: script_name = Helpers.before(name, '.') script_path = os.path.join('/usr/bin/', script_name) with open(script_path, 'w') as f: f.write("#!/usr/bin/env bash\n") f.write("\n") f.write( "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/{0}\n". format(dir_name)) f.write("THIS_EXE=\"/usr/lib/{0}/{1}.exe\"\n".format( dir_name, script_name)) f.write("exec mono $THIS_EXE \"$@\"\n") f.write("\n") st = os.stat(script_path) os.chmod(script_path, st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) Process.do_on_fail_exit( "Installing the program '{0}'".format(name), "Failed to install the program '{0}'.".format(name), lambda: fn())
def require_python_modules(mod_names): for mod_name in mod_names: Process.do_on_fail_exit( "Checking for python module '{0}'".format(mod_name), "Install the python module '{0}' and try again.".format(mod_name), '{0} -c "import {1}"'.format(Config.python, mod_name))
def copy_dir(source, dest, symlinks = False): Process.do_on_fail_exit("Copying the dir '{0}' to '{1}'".format(source, dest), "Failed to copy the dir '{0}' to '{1}'.".format(source, dest), lambda: shutil.copytree(source, dest, symlinks = symlinks))
def copy_file(source, dest): Process.do_on_fail_exit("Copying the file '{0}' to '{1}'".format(source, dest), "Failed to copy the file '{0}' to '{1}'.".format(source, dest), lambda: shutil.copy2(source, dest))
def move_file(source, dest): Process.do_on_fail_exit("Moving the file '{0}' to '{1}'".format(source, dest), "Failed to move the file' {0}'.".format(source), lambda: shutil.move(source, dest))
def change_dir(name): Process.do_on_fail_exit("Changing to dir '{0}'".format(name), "Failed to change to the dir '{0}'.".format(name), lambda: os.chdir(name))
def symlink(source, link_name): Process.do_on_fail_exit("Symlinking '{0}' to '{1}'".format(source, link_name), "Failed linking '{0}' to '{1}'.".format(source, link_name), lambda: os.symlink(source, link_name))