Beispiel #1
0
 def _find_text(self, start_offset=1, backwards=False, wrap=True):
     match_case = self.match_case.get_active()
     whole_word = self.whole_word.get_active()
     regex = self.regex.get_active()
     assert self.textview
     buf = self.textview.get_buffer()
     insert = buf.get_iter_at_mark(buf.get_insert())
     tofind_utf8 = self.find_entry.get_text()
     tofind = tofind_utf8.decode("utf-8")  # tofind is utf-8 encoded
     start, end = buf.get_bounds()
     text = buf.get_text(start, end, False).decode("utf-8")  # as is buffer
     if not regex:
         tofind = re.escape(tofind)
     if whole_word:
         tofind = r'\b' + tofind + r'\b'
     try:
         pattern = re.compile(tofind,
                              (match_case and re.M or (re.M | re.I)))
     except re.error as e:
         misc.run_dialog(_("Regular expression error\n'%s'") % e,
                         self,
                         messagetype=gtk.MESSAGE_ERROR)
     else:
         self.wrap_box.set_visible(False)
         if backwards == False:
             match = pattern.search(text,
                                    insert.get_offset() + start_offset)
             if match is None and wrap:
                 self.wrap_box.set_visible(True)
                 match = pattern.search(text, 0)
         else:
             match = None
             for m in pattern.finditer(text, 0, insert.get_offset()):
                 match = m
             if match is None and wrap:
                 self.wrap_box.set_visible(True)
                 for m in pattern.finditer(text, insert.get_offset()):
                     match = m
         if match:
             it = buf.get_iter_at_offset(match.start())
             buf.place_cursor(it)
             it.forward_chars(match.end() - match.start())
             buf.move_mark(buf.get_selection_bound(), it)
             self.textview.scroll_to_mark(buf.get_insert(), 0.25)
             return True
         else:
             buf.place_cursor(buf.get_iter_at_mark(buf.get_insert()))
             self.find_entry.modify_base(gtk.STATE_NORMAL,
                                         gtk.gdk.color_parse("#ffdddd"))
             self.wrap_box.set_visible(False)
Beispiel #2
0
 def _find_text(self, start_offset=1, backwards=False, wrap=True):
     match_case = self.match_case.get_active()
     whole_word = self.whole_word.get_active()
     regex = self.regex.get_active()
     assert self.textview
     buf = self.textview.get_buffer()
     insert = buf.get_iter_at_mark( buf.get_insert() )
     tofind_utf8 = self.find_entry.get_text()
     tofind = tofind_utf8.decode("utf-8") # tofind is utf-8 encoded
     start, end = buf.get_bounds()
     text = buf.get_text(start, end, False).decode("utf-8") # as is buffer
     if not regex:
         tofind = re.escape(tofind)
     if whole_word:
         tofind = r'\b' + tofind + r'\b'
     try:
         pattern = re.compile( tofind, (match_case and re.M or (re.M|re.I)) )
     except re.error as e:
         misc.run_dialog( _("Regular expression error\n'%s'") % e, self, messagetype=gtk.MESSAGE_ERROR)
     else:
         self.wrap_box.hide()
         if backwards == False:
             match = pattern.search(text, insert.get_offset() + start_offset)
             if match is None and wrap:
                 self.wrap_box.show()
                 match = pattern.search(text, 0)
         else:
             match = None
             for m in pattern.finditer(text, 0, insert.get_offset()):
                 match = m
             if match is None and wrap:
                 self.wrap_box.show()
                 for m in pattern.finditer(text, insert.get_offset()):
                     match = m
         if match:
             it = buf.get_iter_at_offset( match.start() )
             buf.place_cursor( it )
             it.forward_chars( match.end() - match.start() )
             buf.move_mark( buf.get_selection_bound(), it )
             self.textview.scroll_to_mark(buf.get_insert(), 0.25)
             return True
         else:
             buf.place_cursor( buf.get_iter_at_mark(buf.get_insert()) )
             self.find_entry.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffdddd"))
             self.wrap_box.hide()
Beispiel #3
0
 def _find_text(self, start_offset=1, backwards=False, wrap=True):
     match_case = self.match_case.get_active()
     whole_word = self.whole_word.get_active()
     regex = self.regex.get_active()
     assert self.textview
     buf = self.textview.get_buffer()
     insert = buf.get_iter_at_mark( buf.get_insert() )
     tofind_utf8 = self.find_entry.get_text()
     tofind = tofind_utf8.decode("utf-8") # tofind is utf-8 encoded
     start, end = buf.get_bounds()
     text = buf.get_text(start, end, False).decode("utf-8") # as is buffer
     if not regex:
         tofind = re.escape(tofind)
     if whole_word:
         tofind = r'\b' + tofind + r'\b'
     try:
         pattern = re.compile( tofind, (match_case and re.M or (re.M|re.I)) )
     except re.error, e:
         misc.run_dialog( _("Regular expression error\n'%s'") % e, self, messagetype=gtk.MESSAGE_ERROR)
Beispiel #4
0
 def _find_text(self, start_offset=1, backwards=False, wrap=True):
     match_case = self.match_case.get_active()
     whole_word = self.whole_word.get_active()
     regex = self.regex.get_active()
     assert self.textview
     buf = self.textview.get_buffer()
     insert = buf.get_iter_at_mark(buf.get_insert())
     tofind_utf8 = self.find_entry.get_text()
     tofind = tofind_utf8.decode("utf-8")  # tofind is utf-8 encoded
     start, end = buf.get_bounds()
     text = buf.get_text(start, end, False).decode("utf-8")  # as is buffer
     if not regex:
         tofind = re.escape(tofind)
     if whole_word:
         tofind = r'\b' + tofind + r'\b'
     try:
         pattern = re.compile(tofind,
                              (match_case and re.M or (re.M | re.I)))
     except re.error, e:
         misc.run_dialog(_("Regular expression error\n'%s'") % e,
                         self,
                         messagetype=gtk.MESSAGE_ERROR)
Beispiel #5
0
    def _get_dirsandfiles(self, directory, dirs, files):
        log = logging.getLogger(__name__)

        vc_path = os.path.join(directory, self.VC_DIR)

        try:
            with open(os.path.join(vc_path, "Entries")) as f:
                entries = f.read()
            # poor mans universal newline
            entries = entries.replace("\r", "\n").replace("\n\n", "\n")
         # No CVS directory
        except IOError as e:
            d = [_vc.Dir(x[1], x[0], _vc.STATE_NONE) for x in dirs]
            f = [_vc.File(x[1], x[0], _vc.STATE_NONE) for x in files]
            return d, f

        try:
            with open(os.path.join(vc_path, "Entries.Log")) as f:
                logentries = f.read()
        except IOError as e:
            pass
        else:
            matches = re.findall("^([AR])\s*(.+)$(?m)", logentries)
            toadd = []
            for match in matches:
                if match[0] == "A":
                    toadd.append(match[1])
                elif match[0] == "R":
                    try:
                        toadd.remove(match[1])
                    except ValueError:
                        pass
                else:
                    log.warning("Unknown Entries.Log line '%s'", match[0])
            entries += "\n".join(toadd)

        retfiles = []
        retdirs = []
        matches = re.findall("^(D?)/([^/]+)/(.+)$(?m)", entries)
        matches.sort()

        for match in matches:
            isdir = match[0]
            name = match[1]
            path = os.path.join(directory, name)
            rev, date, options, tag = match[2].split("/")
            if tag:
                tag = tag[1:]
            if isdir:
                if os.path.exists(path):
                    state = _vc.STATE_NORMAL
                else:
                    state = _vc.STATE_MISSING
                retdirs.append(_vc.Dir(path, name, state))
            else:
                if rev.startswith("-"):
                    state = _vc.STATE_REMOVED
                elif date == "dummy timestamp":
                    if rev[0] == "0":
                        state = _vc.STATE_NEW
                    else:
                        state = _vc.STATE_ERROR
                elif date == "dummy timestamp from new-entry":
                    state = _vc.STATE_MODIFIED
                else:
                    date_sub = lambda x: "%3i" % int(x.group())
                    date = re.sub(r"\s*\d+", date_sub, date, 1)
                    plus = date.find("+")
                    if plus >= 0:
                        state = _vc.STATE_CONFLICT
                        try:
                            txt = open(path, "U").read()
                        except IOError:
                            pass
                        else:
                            if txt.find("\n=======\n") == -1:
                                state = _vc.STATE_MODIFIED
                    else:
                        try:
                            mtime = os.stat(path).st_mtime
                        except OSError:
                            state = _vc.STATE_MISSING
                        else:
                            if time.asctime(time.gmtime(mtime)) == date:
                                state = _vc.STATE_NORMAL
                            else:
                                state = _vc.STATE_MODIFIED
                retfiles.append(_vc.File(path, name, state, rev, tag, options))
        # known
        cvsfiles = [x[1] for x in matches]
        # ignored
        try:
            with open(os.path.join(os.environ["HOME"], ".cvsignore")) as f:
                ignored = f.read().split()
        except (IOError, KeyError):
            ignored = []
        try:
            with open(os.path.join(directory, ".cvsignore")) as f:
                ignored += f.read().split()
        except IOError:
            pass

        if len(ignored):
            try:
                regexes = [misc.shell_to_regex(i)[:-1] for i in ignored]
                ignore_re = re.compile("(" + "|".join(regexes) + ")")
            except re.error as e:
                misc.run_dialog(_("Error converting to a regular expression\n"
                                  "The pattern was '%s'\nThe error was '%s'") %
                                (",".join(ignored), e))
        else:
            class dummy(object):
                def match(self, *args):
                    return None
            ignore_re = dummy()

        for f, path in files:
            if f not in cvsfiles:
                state = (ignore_re.match(f) is None and _vc.STATE_NONE or
                         _vc.STATE_IGNORED)
                retfiles.append(_vc.File(path, f, state))
        for d, path in dirs:
            if d not in cvsfiles:
                state = (ignore_re.match(d) is None and _vc.STATE_NONE or
                         _vc.STATE_IGNORED)
                retdirs.append(_vc.Dir(path, d, state))

        return retdirs, retfiles
Beispiel #6
0
    def _get_dirsandfiles(self, directory, dirs, files):
        log = logging.getLogger(__name__)

        vc_path = os.path.join(directory, self.VC_DIR)

        try:
            with open(os.path.join(vc_path, "Entries")) as f:
                entries = f.read()
            # poor mans universal newline
            entries = entries.replace("\r", "\n").replace("\n\n", "\n")
        # No CVS directory
        except IOError as e:
            d = [_vc.Dir(x[1], x[0], _vc.STATE_NONE) for x in dirs]
            f = [_vc.File(x[1], x[0], _vc.STATE_NONE) for x in files]
            return d, f

        try:
            with open(os.path.join(vc_path, "Entries.Log")) as f:
                logentries = f.read()
        except IOError as e:
            pass
        else:
            matches = re.findall("^([AR])\s*(.+)$(?m)", logentries)
            toadd = []
            for match in matches:
                if match[0] == "A":
                    toadd.append(match[1])
                elif match[0] == "R":
                    try:
                        toadd.remove(match[1])
                    except ValueError:
                        pass
                else:
                    log.warning("Unknown Entries.Log line '%s'", match[0])
            entries += "\n".join(toadd)

        retfiles = []
        retdirs = []
        matches = re.findall("^(D?)/([^/]+)/(.+)$(?m)", entries)
        matches.sort()

        for match in matches:
            isdir = match[0]
            name = match[1]
            path = os.path.join(directory, name)
            rev, date, options, tag = match[2].split("/")
            if isdir:
                if os.path.exists(path):
                    state = _vc.STATE_NORMAL
                else:
                    state = _vc.STATE_MISSING
                retdirs.append(_vc.Dir(path, name, state))
            else:
                if rev.startswith("-"):
                    state = _vc.STATE_REMOVED
                elif date == "dummy timestamp":
                    if rev[0] == "0":
                        state = _vc.STATE_NEW
                    else:
                        state = _vc.STATE_ERROR
                elif date == "dummy timestamp from new-entry":
                    state = _vc.STATE_MODIFIED
                else:
                    date_sub = lambda x: "%3i" % int(x.group())
                    date = re.sub(r"\s*\d+", date_sub, date, 1)
                    plus = date.find("+")
                    if plus >= 0:
                        state = _vc.STATE_CONFLICT
                        try:
                            txt = open(path, "U").read()
                        except IOError:
                            pass
                        else:
                            if txt.find("\n=======\n") == -1:
                                state = _vc.STATE_MODIFIED
                    else:
                        try:
                            mtime = os.stat(path).st_mtime
                        except OSError:
                            state = _vc.STATE_MISSING
                        else:
                            if time.asctime(time.gmtime(mtime)) == date:
                                state = _vc.STATE_NORMAL
                            else:
                                state = _vc.STATE_MODIFIED
                retfiles.append(_vc.File(path, name, state, rev, options))
        # known
        cvsfiles = [x[1] for x in matches]
        # ignored
        try:
            with open(os.path.join(os.environ["HOME"], ".cvsignore")) as f:
                ignored = f.read().split()
        except (IOError, KeyError):
            ignored = []
        try:
            with open(os.path.join(directory, ".cvsignore")) as f:
                ignored += f.read().split()
        except IOError:
            pass

        if len(ignored):
            try:
                regexes = [misc.shell_to_regex(i)[:-1] for i in ignored]
                ignore_re = re.compile("(" + "|".join(regexes) + ")")
            except re.error as e:
                misc.run_dialog(
                    _("Error converting to a regular expression\n"
                      "The pattern was '%s'\nThe error was '%s'") %
                    (",".join(ignored), e))
        else:

            class dummy(object):
                def match(self, *args):
                    return None

            ignore_re = dummy()

        for f, path in files:
            if f not in cvsfiles:
                state = (ignore_re.match(f) is None and _vc.STATE_NONE
                         or _vc.STATE_IGNORED)
                retfiles.append(_vc.File(path, f, state))
        for d, path in dirs:
            if d not in cvsfiles:
                state = (ignore_re.match(d) is None and _vc.STATE_NONE
                         or _vc.STATE_IGNORED)
                retdirs.append(_vc.Dir(path, d, state))

        return retdirs, retfiles
Beispiel #7
0
        try:
            ignored = open(os.path.join(os.environ["HOME"], ".cvsignore")).read().split()
        except (IOError, KeyError):
            ignored = []
        try:
            ignored += open( os.path.join(directory, ".cvsignore")).read().split()
        except IOError:
            pass

        if len(ignored):
            try:
                regexes = [ misc.shell_to_regex(i)[:-1] for i in ignored ]
                ignore_re = re.compile( "(" + "|".join(regexes) + ")" )
            except re.error, e:
                misc.run_dialog(_("Error converting to a regular expression\n"
                                  "The pattern was '%s'\n"
                                  "The error was '%s'") % (",".join(ignored), e))
        else:
            class dummy(object):
                def match(self, *args): return None
            ignore_re = dummy()

        for f,path in files:
            if f not in cvsfiles:
                state = ignore_re.match(f) is None and _vc.STATE_NONE or _vc.STATE_IGNORED
                retfiles.append( _vc.File(path, f, state, "") )
        for d,path in dirs:
            if d not in cvsfiles:
                state = ignore_re.match(d) is None and _vc.STATE_NONE or _vc.STATE_IGNORED
                retdirs.append( _vc.Dir(path, d, state) )