Example #1
0
    def _load_can_automerge(self, source, destination):
        """
        Determine if source file path equals destination file path,
        thus it can be automerged.
        """
        def _vanished():
            # file went away? not really needed, but...
            if not os.path.lexists(source):
                return True
            # broken symlink
            if os.path.islink(source) and not os.path.exists(source):
                return True
            return False

        if _vanished():
            return True

        source_unicode = self._unicode_path(source)
        destination_unicode = self._unicode_path(destination)

        # first diff test
        try:
            exit_st = getstatusoutput(
                'diff -Nua "%s" "%s" | grep '
                '"^[+-][^+-]" | grep -v \'# .Header:.*\'' % (
                    source_unicode,
                    destination_unicode,
                ))[1]
        except (OSError, IOError):
            exit_st = 1
        if exit_st == os.EX_OK:
            return True
        elif _vanished():
            return True

        # second diff test
        try:
            exit_st = subprocess.call(
                'diff -Bbua "%s" "%s" | '
                'egrep \'^[+-]\' | '
                'egrep -v \'^[+-][\t ]*#|^--- |^\+\+\+ \' | '
                'egrep -qv \'^[-+][\t ]*$\'' % (
                    source_unicode,
                    destination_unicode,
                ),
                shell=True)
        except (
                IOError,
                OSError,
        ):
            exit_st = 0
        if exit_st == 1:
            return True

        if _vanished():
            return True
        # requires manual merge
        return False
Example #2
0
    def _load_can_automerge(self, source, destination):
        """
        Determine if source file path equals destination file path,
        thus it can be automerged.
        """

        def _vanished():
            # file went away? not really needed, but...
            if not os.path.lexists(source):
                return True
            # broken symlink
            if os.path.islink(source) and not os.path.exists(source):
                return True
            return False

        if _vanished():
            return True

        # first diff test
        try:
            exit_st = getstatusoutput(
                'diff -Nua "%s" "%s" | grep ' "\"^[+-][^+-]\" | grep -v '# .Header:.*'" % (source, destination)
            )[1]
        except (OSError, IOError):
            exit_st = 1
        if exit_st == os.EX_OK:
            return True
        elif _vanished():
            return True

        # second diff test
        try:
            exit_st = subprocess.call(
                'diff -Bbua "%s" "%s" | '
                "egrep '^[+-]' | "
                "egrep -v '^[+-][\t ]*#|^--- |^\+\+\+ ' | "
                "egrep -qv '^[-+][\t ]*$'" % (source, destination),
                shell=True,
            )
        except (IOError, OSError):
            exit_st = 0
        if exit_st == 1:
            return True

        if _vanished():
            return True
        # requires manual merge
        return False
Example #3
0
def xterm_title_reset():
    """
    Reset xterm title to default.
    """
    global default_xterm_title
    if default_xterm_title is None:
        prompt_command = os.getenv('PROMPT_COMMAND')
        if not prompt_command:
            default_xterm_title = ""
        elif prompt_command is not None:
            from entropy.tools import getstatusoutput
            default_xterm_title = getstatusoutput(prompt_command)[1]
        else:
            pwd = os.getenv('PWD', '')
            home = os.getenv('HOME', '')
            if home != '' and pwd.startswith(home):
                pwd = '~' + pwd[len(home):]
            default_xterm_title = '\x1b]0;%s@%s:%s\x07' % (os.getenv(
                'LOGNAME', ''), os.getenv('HOSTNAME', '').split('.',
                                                                1)[0], pwd)
    xterm_title(default_xterm_title, raw=True)
Example #4
0
def xterm_title_reset():
    """
    Reset xterm title to default.
    """
    global default_xterm_title
    if default_xterm_title is None:
        prompt_command = os.getenv('PROMPT_COMMAND')
        if not prompt_command:
            default_xterm_title = ""
        elif prompt_command is not None:
            from entropy.tools import getstatusoutput
            default_xterm_title = getstatusoutput(prompt_command)[1]
        else:
            pwd = os.getenv('PWD', '')
            home = os.getenv('HOME', '')
            if home != '' and pwd.startswith(home):
                pwd = '~' + pwd[len(home):]
            default_xterm_title = '\x1b]0;%s@%s:%s\x07' % (
                os.getenv('LOGNAME', ''),
                os.getenv('HOSTNAME', '').split('.', 1)[0],
                pwd)
    xterm_title(default_xterm_title)