def install(): check_dependencies() if not os.path.exists(IS_BUILD): build() install_folder = getinput( '\nEnter custom installation directory or press enter', default_install_folder) install_folder = os.path.abspath(install_folder) if os.path.exists(install_folder) and os.path.exists( os.path.join(install_folder, IS_LABSCRIPT_SUITE)): if not yn_choice( '\nReplace existing installation? in %s? ' % install_folder + 'userlib and configuration ' + 'will be kept, but backing them up is recommended.', default='n'): print('Cancelled') sys.exit(1) uninstall(confirm=False) os.chdir(this_folder) # Add libs to python's search path: site_packages_dir = site.getsitepackages()[0] pth_file = os.path.join(site_packages_dir, 'labscript_suite.pth') print('Adding to Python search path (%s)' % pth_file) # temporarily escalate privileges so we can create the .pth file: with escalated_privileges(): with open(pth_file, 'w') as f: f.write(install_folder + '\n') f.write(os.path.join(install_folder, 'userlib') + '\n') f.write( os.path.join(install_folder, 'userlib', 'pythonlib') + '\n') print('Copying files') if not os.path.exists(install_folder): try: os.mkdir(install_folder) except OSError as e: sys.stderr.write('Could not create to install directory:\n %s' % str(e)) sys.exit(1) try: # Add file that marks this as a labscript suite install dir: with open(os.path.join(install_folder, IS_LABSCRIPT_SUITE), 'w'): pass for entry in os.listdir('.'): if not exclude_from_copying(entry): if os.path.isdir(entry): dest = os.path.join(install_folder, entry) copy = shutil.copytree else: dest = install_folder copy = shutil.copy if entry in do_not_delete: if os.path.exists(dest): continue copy(entry, dest) except OSError as e: sys.stderr.write('Could not write to install directory:\n %s' % str(e)) sys.exit(1) # Rename setup.py to uninstall.py, as it will function only as an uninstaller from within the # labscript install directory: shutil.move(os.path.join(install_folder, 'setup.py'), os.path.join(install_folder, 'uninstall.py')) # Replace the readme file with one with instructions for uninstalling only os.unlink(os.path.join(install_folder, README)) with open(os.path.join(install_folder, 'README_uninstall.txt'), 'w') as f: f.write('To uninstall, run: \n\n' + ' python uninstall.py\n\n' + 'in this directory.\n' + 'userlib and configuration ' + 'will be kept, but backing them up is recommended.\n') # Remove the dependencies.txt file: os.unlink(os.path.join(install_folder, DEPENDENCIES)) # Reload the site module so later code sees these paths: reload(site) make_labconfig_file(install_folder) mkdir_p(os.path.join(install_folder, 'userlib', 'app_saved_configs')) if os.name == 'nt': print('adding application shortcuts') # TODO make this work on linux! if os.name == 'nt': from labscript_utils.winshell import appids, app_descriptions, make_shortcut, add_to_start_menu for program in gui_programs: path = os.path.join(install_folder, launcher_name(program)) executable = sys.executable.lower() if not executable.endswith('w.exe'): executable = executable.replace('.exe', 'w.exe') # Executable to run is the current Python interpreter, but # the graphical version of it (pythonw.exe) target = executable # Args is a single arg to the path to the __main__ script of the app: arguments = [os.path.join(install_folder, program, '__main__.py')] def condify(target, arguments): # format is ROOT_PYTHONW ROOT_CWP_SCRIPT ENV_BASE ENV_PYTHONW # Followed by our actual program and args root_pythonw = os.getenv('CONDA_PYTHON_EXE').replace( '.exe', 'w.exe') root_cwp_script = root_pythonw.replace('pythonw.exe', 'cwp.py') env_base = os.getenv('CONDA_PREFIX') env_pythonw = target args = [root_cwp_script, env_base, env_pythonw] + arguments return root_pythonw, args # If we are in a conda environment, the shortcuts will need to use conda's # 'cpw' wrapper script in order to correctly configure the conda # environment, otherwise dll loading will fail and that sort of thing: if os.getenv('CONDA_PREFIX', None) is not None: target, arguments = condify(target, arguments) # Quote for spaces etc in the target and args list: target = '"%s"' % target arglist = ' '.join(['"%s"' % arg for arg in arguments]) working_directory = os.path.join(install_folder, program) working_directory = '"%s"' % working_directory icon_path = os.path.join(install_folder, program, '%s.ico' % program) description = app_descriptions[program] appid = appids[program] make_shortcut(path, target, arglist, working_directory, icon_path, description, appid) add_to_start_menu(path) # Clear the icon cache so Windows gets the shortcut icons right even if they were previously broken: if not (struct.calcsize("P") == 8) and (platform.machine().endswith('64')): # 64-bit windows auto-redirects 32-bit python calls away from system32 # have to use full path with emulator re-direct exe = os.path.join(os.environ['WINDIR'], 'sysnative', 'ie4uinit.exe') else: exe = 'ie4uinit.exe' try: subprocess.Popen([exe, '-ClearIconCache']) except Exception: sys.stderr.write( 'failed to clear icon cache, icons might be blank\n') print('done')
def install(): check_dependencies() if not os.path.exists(IS_BUILD): build() install_folder = getinput( '\nEnter custom installation directory or press enter', default_install_folder) install_folder = os.path.abspath(install_folder) if os.path.exists(install_folder) and os.path.exists( os.path.join(install_folder, IS_LABSCRIPT_SUITE)): if not yn_choice( '\nReplace existing installation? in %s? ' % install_folder + 'userlib and configuration ' + 'will be kept, but backing them up is recommended.', default='n'): print('Cancelled') sys.exit(1) uninstall(confirm=False) os.chdir(this_folder) # Add libs to python's search path: site_packages_dir = site.getsitepackages()[0] pth_file = os.path.join(site_packages_dir, 'labscript_suite.pth') print('Adding to Python search path (%s)' % pth_file) # temporarily escalate privileges so we can create the .pth file: with escalated_privileges(): with open(pth_file, 'w') as f: f.write(install_folder + '\n') f.write(os.path.join(install_folder, 'userlib') + '\n') f.write( os.path.join(install_folder, 'userlib', 'pythonlib') + '\n') print('Copying files') if not os.path.exists(install_folder): try: os.mkdir(install_folder) except OSError as e: sys.stderr.write('Could not create to install directory:\n %s' % str(e)) sys.exit(1) try: # Add file that marks this as a labscript suite install dir: with open(os.path.join(install_folder, IS_LABSCRIPT_SUITE), 'w'): pass for entry in os.listdir('.'): if not exclude_from_copying(entry): if os.path.isdir(entry): dest = os.path.join(install_folder, entry) copy = shutil.copytree else: dest = install_folder copy = shutil.copy if entry in do_not_delete: if os.path.exists(dest): continue copy(entry, dest) except OSError as e: sys.stderr.write('Could not write to install directory:\n %s' % str(e)) sys.exit(1) # Rename setup.py to uninstall.py, as it will function only as an uninstaller from within the # labscript install directory: shutil.move(os.path.join(install_folder, 'setup.py'), os.path.join(install_folder, 'uninstall.py')) # Replace the readme file with one with instructions for uninstalling only os.unlink(os.path.join(install_folder, README)) with open(os.path.join(install_folder, 'README_uninstall.txt'), 'w') as f: f.write('To uninstall, run: \n\n' + ' python uninstall.py\n\n' + 'in this directory.\n' + 'userlib and configuration ' + 'will be kept, but backing them up is recommended.\n') # Remove the dependencies.txt file: os.unlink(os.path.join(install_folder, DEPENDENCIES)) # Reload the site module so later code sees these paths: reload(site) make_labconfig_file(install_folder) mkdir_p(os.path.join(install_folder, 'userlib', 'app_saved_configs')) if os.name == 'nt': print('adding application shortcuts') # TODO make this work on linux! if os.name == 'nt': from labscript_utils.winshell import appids, app_descriptions, make_shortcut, add_to_start_menu for program in gui_programs: path = os.path.join(install_folder, shortcut_format % program) executable = sys.executable.lower() if not executable.endswith('w.exe'): executable = executable.replace('.exe', 'w.exe') target = executable arguments = os.path.join(install_folder, program, '__main__.py') working_directory = os.path.join(install_folder, program) icon_path = os.path.join(install_folder, program, '%s.ico' % program) description = app_descriptions[program] appid = appids[program] make_shortcut(path, target, arguments, working_directory, icon_path, description, appid) add_to_start_menu(path) # Clear the icon cache so Windows gets the shortcut icons right even if they were previously broken: if not (struct.calcsize("P") == 8) and (platform.machine().endswith('64')): # 64-bit windows auto-redirects 32-bit python calls away from system32 # have to use full path with emulator re-direct exe = os.path.join(os.environ['WINDIR'], 'sysnative', 'ie4uinit.exe') else: exe = 'ie4uinit.exe' try: subprocess.Popen([exe, '-ClearIconCache']) except Exception: sys.stderr.write( 'failed to clear icon cache, icons might be blank\n') print('done')
def install(): check_dependencies() if not os.path.exists(IS_BUILD): build() install_folder = getinput('\nEnter custom installation directory or press enter', default_install_folder) install_folder = os.path.abspath(install_folder) if os.path.exists(install_folder) and os.path.exists(os.path.join(install_folder, IS_LABSCRIPT_SUITE)): if not yn_choice('\nReplace existing installation? in %s? ' % install_folder + 'userlib and configuration ' + 'will be kept, but backing them up is recommended.', default='n'): print('Cancelled') sys.exit(1) uninstall(confirm=False) os.chdir(this_folder) # Add libs to python's search path: site_packages_dir = site.getsitepackages()[0] pth_file = os.path.join(site_packages_dir, 'labscript_suite.pth') print('Adding to Python search path (%s)' % pth_file) # temporarily escalate privileges so we can create the .pth file: with escalated_privileges(): with open(pth_file, 'w') as f: f.write(install_folder + '\n') f.write(os.path.join(install_folder, 'userlib') + '\n') f.write(os.path.join(install_folder, 'userlib', 'pythonlib') + '\n') print('Copying files') if not os.path.exists(install_folder): try: os.mkdir(install_folder) except OSError as e: sys.stderr.write('Could not create to install directory:\n %s' % str(e)) sys.exit(1) try: # Add file that marks this as a labscript suite install dir: with open(os.path.join(install_folder, IS_LABSCRIPT_SUITE), 'w'): pass for entry in os.listdir('.'): if not exclude_from_copying(entry): if os.path.isdir(entry): dest = os.path.join(install_folder, entry) copy = shutil.copytree else: dest = install_folder copy = shutil.copy if entry in do_not_delete: if os.path.exists(dest): continue copy(entry, dest) except OSError as e: sys.stderr.write('Could not write to install directory:\n %s' % str(e)) sys.exit(1) # Rename setup.py to uninstall.py, as it will function only as an uninstaller from within the # labscript install directory: shutil.move(os.path.join(install_folder, 'setup.py'), os.path.join(install_folder, 'uninstall.py')) # Replace the readme file with one with instructions for uninstalling only os.unlink(os.path.join(install_folder, README)) with open(os.path.join(install_folder, 'README_uninstall.txt'), 'w') as f: f.write('To uninstall, run: \n\n' + ' python uninstall.py\n\n' + 'in this directory.\n' + 'userlib and configuration ' + 'will be kept, but backing them up is recommended.\n') # Remove the dependencies.txt file: os.unlink(os.path.join(install_folder, DEPENDENCIES)) # Reload the site module so later code sees these paths: reload(site) make_labconfig_file(install_folder) if os.name == 'nt': print('adding application shortcuts') # TODO make this work on linux! if os.name == 'nt': from labscript_utils.winshell import appids, app_descriptions, make_shortcut, add_to_start_menu for program in gui_programs: path = os.path.join(install_folder, shortcut_format % program) executable = sys.executable.lower() if not executable.endswith('w.exe'): executable = executable.replace('.exe', 'w.exe') target = executable arguments = os.path.join(install_folder, program, '__main__.py') working_directory = os.path.join(install_folder, program) icon_path = os.path.join(install_folder, program, '%s.ico' % program) description = app_descriptions[program] appid = appids[program] make_shortcut(path, target, arguments, working_directory, icon_path, description, appid) add_to_start_menu(path) # Clear the icon cache so Windows gets the shortcut icons right even if they were previously broken: try: subprocess.Popen(['ie4uinit.exe', '-ClearIconCache']) except Exception: sys.stderr.write('failed to clear icon cache, icons might be blank\n') print('done')