def run_command(command, stderr=False, shell=None, dont_parse_command=False): if not dont_parse_command: if type(command) not in [list, tuple, set]: command = string_split(command) else: command = list(command) if shell in (True, False): process = common.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell) else: process = common.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) return process
def __get_branch(branch=None, quiet=True, only_use_regedit=False): if only_use_regedit == False: debug("Using cache/file to read registry.") branch_file_name, branch_root = __get_branch_file(branch) if branch_file_name != None: with codecs.open(branch_file_name, 'r', encoding=get_codepage()) as registry_file: registry = registry_file.read() #CACHE[branch_root] = registry return (branch_root, registry) debug("Using regedit to read registry.") _initWine() process_args = [common.ENV['WINE'], "regedit", "/E", "-"] if branch != None: process_args.append(branch) else: branch = '' registry = '' process = common.Popen(process_args, env=common.ENV_NO_DISPLAY(common.ENV_NO_GECKO())) buffer = process.stdout.readline() while buffer != '': registry += buffer buffer = process.stdout.readline() #if process.returncode and not quiet: if registry == '' or registry.strip() == 'Success': if not quiet: error("Warning: Registry branch '%s' doesn't exist." % branch) return '' try: registry = registry.decode(get_codepage()) except UnicodeDecodeError: pass return registry
def _initWine(): _wineprocess = common.Popen("%s -p10" % common.ENV['WINESERVER'], shell=True, stdin='null', stdout='null', stderr='null', env=common.ENV_NO_DISPLAY( common.ENV_NO_GECKO()))
def _writeRegistry(registrycontent): _initWine() regfilename = util.tempname('setregistry-', '.reg') with codecs.open(regfilename, 'w', encoding=get_codepage()) as regfile: regfile.write(registrycontent) #print("Running regedit with no display output") process = common.Popen([common.ENV['WINE'], "regedit", regfilename], stdout='null', stderr='null', env=common.ENV_NO_DISPLAY(common.ENV_NO_GECKO())) process.communicate() return process.returncode
def run(command, run_in_dir=True, dont_run=False, monitor=True, shell_output=False, name=None, use_terminal=False, disable_pulseaudio=False, cpu_limit=None): """Intelligently runs a Windows program. This function also handles start.exe arguments (like web links), .msi installers and provides the alias "cmd" for launching the wineconsole and "winetricks" for running, and optionally downloading winetricks, with arguments. Note that disable_pulseaudio only works when use_terminal is True.""" command = parse_command(command) if 'VINEYARD_NO_MONITORING' in command['env']: monitor = False if monitor and shell_output: error("monitor and shell_output can't both be True, disabling shell_output") shell_output = False # Override any WINEPREFIX defined by command command['env']['WINEPREFIX'] = common.ENV['WINEPREFIX'] # Create a new environment dict from our internal one env = common.copy(common.ENV) # Update it with the command's environment env.update(command['env']) if name is not None: command['name'] = name kwargs = { 'env': env, } if command['command'] is None: command['command'] = common.ENV['WINE'] if run_in_dir and command['path'] is not None: kwargs['cwd'] = command['path'] if cpu_limit is not None: if type(cpu_limit) is int: kwargs['cpu_limit'] = cpu_limit elif cpu_limit is True: kwargs['cpu_limit'] = 1 if monitor: kwargs['output_to_shell'] = False kwargs['use_log'] = True kwargs['name'] = command['name'] kwargs['executable'] = command['command'] if dont_run: return ('Monitor', command['arguments'], kwargs) else: if use_terminal: return util.open_terminal( cwd = kwargs.get('cwd', None), configuration_name = name, cmd = command['command'], arguments = command['arguments'], disable_pulseaudio = disable_pulseaudio, keep_open = True ) else: return sys.modules['wine.monitor'].Program( command['arguments'], **kwargs ) else: command_list = [command['command']] + command['arguments'] if shell_output: kwargs['stdout'] = sys.stdout kwargs['stderr'] = sys.stderr if dont_run: return ('Run', command_list, kwargs) else: if use_terminal: return util.open_terminal( cwd = kwargs.get('cwd', None), configuration_name = name, cmd = command['command'], arguments = command_list, disable_pulseaudio = disable_pulseaudio, keep_open = True ) else: return common.Popen( command_list, **kwargs )