예제 #1
0
파일: cvs.py 프로젝트: bytearchive/meld
    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)
예제 #2
0
파일: cvs.py 프로젝트: Psykar/meld
    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)
예제 #3
0
파일: vcview.py 프로젝트: thics/meld
    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)
예제 #4
0
파일: vcview.py 프로젝트: skluchan/meld
    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)