def get_path_for_repo_file(self, path, commit=None): if commit is not None: raise NotImplementedError if not path.startswith(self.root + os.path.sep): raise _vc.InvalidVCPath(self, path, "Path not in repository") path = path[len(self.root) + 1:] diffiter = misc.read_pipe_iter([self.CMD, "diff", "-u", path], FakeErrorStream(), workdir=self.root) patch = None while patch is None: patch = next(diffiter) tmpdir = tempfile.mkdtemp("-meld") destfile = os.path.join(tmpdir, os.path.basename(path)) try: shutil.copyfile(os.path.join(self.root, path), destfile) except IOError: # For missing files, create a new empty file open(destfile, "w").close() patchcmd = ["patch", "-R", "-d", tmpdir] try: with open(os.devnull, "w") as NULL: result = misc.write_pipe(patchcmd, patch, error=NULL) assert result == 0 with open(destfile) as patched_file: with tempfile.NamedTemporaryFile(prefix='meld-tmp', delete=False) as temp_file: shutil.copyfileobj(patched_file, temp_file) return temp_file.name except (OSError, AssertionError): return finally: if os.path.exists(destfile): os.remove(destfile) if os.path.exists(destfile): os.rmdir(tmpdir)
def get_path_for_repo_file(self, path, commit=None): if commit is not None: raise NotImplementedError if not path.startswith(self.root + os.path.sep): raise _vc.InvalidVCPath(self, path, "Path not in repository") path = path[len(self.root) + 1:] diffiter = misc.read_pipe_iter([self.CMD, "diff", "-u", path], FakeErrorStream(), workdir=self.root) patch = None while patch is None: patch = next(diffiter) status = next(diffiter) tmpdir = tempfile.mkdtemp("-meld") destfile = os.path.join(tmpdir, os.path.basename(path)) try: shutil.copyfile(os.path.join(self.root, path), destfile) except IOError: # For missing files, create a new empty file open(destfile, "w").close() patchcmd = ["patch", "-R", "-d", tmpdir] try: with open(os.devnull, "w") as NULL: result = misc.write_pipe(patchcmd, patch, error=NULL) assert result == 0 with open(destfile) as patched_file: with tempfile.NamedTemporaryFile(prefix='meld-tmp', delete=False) as temp_file: shutil.copyfileobj(patched_file, temp_file) return temp_file.name except (OSError, AssertionError): return finally: if os.path.exists(destfile): os.remove(destfile) if os.path.exists(destfile): os.rmdir(tmpdir)
def _command_iter(self, command, files, refresh, working_dir): """An iterable that runs a VC command on a set of files This method is intended to be used as a scheduled task, with standard out and error output displayed in this view's consolestream. """ def shelljoin(command): def quote(s): return '"%s"' % s if len(s.split()) > 1 else s return " ".join(quote(tok) for tok in command) files = [os.path.relpath(f, working_dir) for f in files] msg = shelljoin(command + files) + " (in %s)\n" % working_dir self.consolestream.command(msg) readiter = misc.read_pipe_iter( command + files, workdir=working_dir, errorstream=self.consolestream) try: result = next(readiter) while not result: yield 1 result = next(readiter) except IOError as err: misc.error_dialog( "Error running command", "While running '%s'\nError: %s" % (msg, err)) result = (1, "") returncode, output = result self.consolestream.output(output + "\n") if returncode: self.console_vbox.show() if refresh: refresh = functools.partial(self.refresh_partial, working_dir) GLib.idle_add(refresh)
def _command_iter(self, command, files, refresh, working_dir): """An iterable that runs a VC command on a set of files This method is intended to be used as a scheduled task, with standard out and error output displayed in this view's consolestream. """ def shelljoin(command): def quote(s): return '"%s"' % s if len(s.split()) > 1 else s return " ".join(quote(tok) for tok in command) files = [os.path.relpath(f, working_dir) for f in files] msg = shelljoin(command + files) + " (in %s)\n" % working_dir self.consolestream.command(msg) readiter = read_pipe_iter( command + files, workdir=working_dir, errorstream=self.consolestream) try: result = next(readiter) while not result: yield 1 result = next(readiter) except IOError as err: error_dialog( "Error running command", "While running '%s'\nError: %s" % (msg, err)) result = (1, "") returncode, output = result self.consolestream.output(output + "\n") if returncode: self.console_vbox.show() if refresh: refresh = functools.partial(self.refresh_partial, working_dir) GLib.idle_add(refresh)