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
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
retfiles.append( _vc.File(path, name, state, rev, tag, options) ) # known cvsfiles = map(lambda x: x[1], matches) # ignored 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: