def run_command(self): """Run command line.""" cmd = self.getCmd() directory = os.path.dirname(self._document) subenviron = None if os.name == "nt": # Python 2.7 subprocess on Windows chokes on unicode in env subenviron = util.bytes_environ() else: subenviron = dict(os.environ) if sys.platform.startswith('darwin'): try: del subenviron['PYTHONHOME'] except KeyError: pass try: del subenviron['PYTHONPATH'] except KeyError: pass proc = subprocess.Popen(cmd, cwd=directory, env = subenviron, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE) stdouterr = proc.communicate() return stdouterr
def run_command(self): """ABC import (at least for now) needs a specific solution here.""" cmd = self.getCmd('document.ly') directory = util.tempdir() subenviron = None if os.name == "nt": # Python 2.7 subprocess on Windows chokes on unicode in env subenviron = util.bytes_environ() else: subenviron = dict(os.environ) if sys.platform.startswith('darwin'): try: del subenviron['PYTHONHOME'] except KeyError: pass try: del subenviron['PYTHONPATH'] except KeyError: pass proc = subprocess.Popen(cmd, cwd=directory, env = subenviron, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE) stdouterr = proc.communicate() if not stdouterr[0]: try: with open(os.path.join(directory, cmd[-1])) as abc: stdouterr = (abc.read(), stdouterr[1]) except IOError: pass return stdouterr
def run_command(self): """Run command line.""" cmd = self.getCmd() directory = os.path.dirname(self._document) subenviron = None if os.name == "nt": # Python 2.7 subprocess on Windows chokes on unicode in env subenviron = util.bytes_environ() else: subenviron = dict(os.environ) if sys.platform.startswith('darwin'): try: del subenviron['PYTHONHOME'] except KeyError: pass try: del subenviron['PYTHONPATH'] except KeyError: pass proc = subprocess.Popen(cmd, cwd=directory, env=subenviron, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdouterr = proc.communicate() return stdouterr
def run(self): """Runs convert-ly (again).""" fromVersion = self.fromVersion.text() toVersion = self.toVersion.text() if not fromVersion or not toVersion: self.messages.setPlainText( _("Both 'from' and 'to' versions need to be set.")) return info = self._info command = info.toolcommand(info.ly_tool('convert-ly')) command += ['-f', fromVersion, '-t', toVersion, '-'] # if the user wants english messages, do it also here: LANGUAGE=C env = None if os.name == "nt": # Python 2.7 subprocess on Windows chokes on unicode in env env = util.bytes_environ() else: env = dict(os.environ) if sys.platform.startswith('darwin'): try: del env['PYTHONHOME'] except KeyError: pass try: del env['PYTHONPATH'] except KeyError: pass if QSettings().value("lilypond_settings/no_translation", False, bool): if os.name == "nt": # Python 2.7 subprocess on Windows chokes on unicode in env env[b'LANGUAGE'] = b'C' else: env['LANGUAGE'] = 'C' with qutil.busyCursor(): try: proc = subprocess.Popen(command, env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate( util.platform_newlines(self._text).encode(self._encoding)) except OSError as e: self.messages.setPlainText( _("Could not start {convert_ly}:\n\n" "{message}\n").format(convert_ly=command[0], message=e)) return out = util.universal_newlines(out.decode('UTF-8')) err = util.universal_newlines(err.decode('UTF-8')) self.messages.setPlainText(err) self.setConvertedText(out) self.setDiffText(out) if not out or self._convertedtext == self._text: self.messages.append('\n' + _("The document has not been changed."))
def run(self): """Runs convert-ly (again).""" fromVersion = self.fromVersion.text() toVersion = self.toVersion.text() if not fromVersion or not toVersion: self.messages.setPlainText(_( "Both 'from' and 'to' versions need to be set.")) return info = self._info command = info.toolcommand(info.ly_tool('convert-ly')) command += ['-f', fromVersion, '-t', toVersion, '-'] # if the user wants english messages, do it also here: LANGUAGE=C env = None if os.name == "nt": # Python 2.7 subprocess on Windows chokes on unicode in env env = util.bytes_environ() else: env = dict(os.environ) if sys.platform.startswith('darwin'): try: del env['PYTHONHOME'] except KeyError: pass try: del env['PYTHONPATH'] except KeyError: pass if QSettings().value("lilypond_settings/no_translation", False, bool): if os.name == "nt": # Python 2.7 subprocess on Windows chokes on unicode in env env[b'LANGUAGE'] = b'C' else: env['LANGUAGE'] = 'C' with qutil.busyCursor(): try: proc = subprocess.Popen(command, env = env, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE) out, err = proc.communicate(util.platform_newlines(self._text).encode(self._encoding)) except OSError as e: self.messages.setPlainText(_( "Could not start {convert_ly}:\n\n" "{message}\n").format(convert_ly = command[0], message = e)) return out = util.universal_newlines(out.decode('UTF-8')) err = util.universal_newlines(err.decode('UTF-8')) self.messages.setPlainText(err) self.setConvertedText(out) self.setDiffText(out) if not out or self._convertedtext == self._text: self.messages.append('\n' + _("The document has not been changed."))
def run(self): """Runs convert-ly (again).""" fromVersion = self.fromVersion.text() toVersion = self.toVersion.text() if not fromVersion or not toVersion: self.messages.setPlainText(_( "Both 'from' and 'to' versions need to be set.")) return info = self._info convert_ly = os.path.join(info.bindir(), info.convert_ly) # on Windows the convert-ly command is not directly executable, but # must be started using the LilyPond-provided Python interpreter if os.name == "nt": if not os.access(convert_ly, os.R_OK) and not convert_ly.endswith('.py'): convert_ly += '.py' command = [info.python(), convert_ly] else: command = [convert_ly] command += ['-f', fromVersion, '-t', toVersion, '-'] # if the user wants english messages, do it also here: LANGUAGE=C env = None if QSettings().value("lilypond_settings/no_translation", False) in (True, "true"): if os.name == "nt": # Python 2.7 subprocess on Windows chokes on unicode in env env = util.bytes_environ() env[b'LANGUAGE'] = b'C' else: env = dict(os.environ) env['LANGUAGE'] = 'C' with qutil.busyCursor(): try: proc = subprocess.Popen(command, universal_newlines = True, env = env, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE) out, err = proc.communicate(self._text.encode(self._encoding)) except OSError as e: self.messages.setPlainText(_( "Could not start {convert_ly}:\n\n" "{message}\n").format(convert_ly = convert_ly, message = e)) return self.messages.setPlainText(err.decode('UTF-8')) self.setConvertedText(out.decode('UTF-8')) if not out or self._convertedtext == self._text: self.messages.append('\n' + _("The document has not been changed."))