📄 enforcer
字号:
Here we verify file copies which may not meet our requirements. """ if debug: print "Copied %r to %r" % (source_filename, destination_filename) if configuration.has_key("verify_file_copied"): configuration["verify_file_copied"](destination_filename, source_filename)def verify_file_modified(filename): """ Here we verify files which may not meet our requirements. Any failure, even if not due to the specific changes in the commit will raise an error. """ if debug: print "Modified file %r" % filename if configuration.has_key("verify_file_modified"): configuration["verify_file_modified"](filename)def verify_line_added(filename, line): """ Here we verify new lines of code which may not meet our requirements. Code not changed as part of this commit is not verified. """ if configuration.has_key("verify_line_added"): configuration["verify_line_added"](filename, line)def verify_line_removed(filename, line): """ Here we verify removed lines of code which may not meet our requirements. Code not changed as part of this commit is not verified. """ if configuration.has_key("verify_line_removed"): configuration["verify_line_removed"](filename, line)def verify_property_line_added(filename, property, line): """ Here we verify added property lines which may not meet our requirements. Code not changed as part of this commit is not verified. """ if debug: print "Add %s::%s: %s" % (filename, property, line) if configuration.has_key("verify_property_line_added"): configuration["verify_property_line_added"](filename, property, line)def verify_property_line_removed(filename, property, line): """ Here we verify removed property lines which may not meet our requirements. Code not changed as part of this commit is not verified. """ if debug: print "Del %s::%s: %s" % (filename, property, line) if configuration.has_key("verify_property_line_removed"): configuration["verify_property_line_removed"](filename, property, line)### Do the Right Thing##configuration = {"open_file": open_file}execfile(configuration_filename, configuration, configuration)diff_cmd = [ "svnlook", "diff", None, repository ]if transaction: diff_cmd[2] = "--transaction=" + transactionelif revision: diff_cmd[2] = "--revision=" + revisionelse: raise ValueError("No transaction or revision")diff_out, diff_in = popen2.popen2(diff_cmd)diff_in.close()try: state = 0 # # This is the svnlook output parser # for line in diff_out: if line[-1] == "\n": line = line[:-1] # Zap trailing newline # Test cases: # r2266: Added text files, property changes # r18923: Added, deleted, modified text files # r25692: Copied files # r7758: Added binary files if debug > 1: print "%4d: %s" % (state, line) # Useful for testing parser problems if state is -1: # Used for testing new states: print whatever is left print line continue if state in (0, 100, 300): # Initial state or in a state that may return to initial state if state is 0 and not line: continue colon = line.find(":") if colon != -1 and len(line) > colon + 2: action = line[:colon] filename = line[colon+2:] if action in ( "Modified", "Added", "Deleted", "Copied", "Property changes on", ): if action == "Modified": verify_file_modified(filename) elif action == "Added" : verify_file_added (filename) elif action == "Deleted" : verify_file_removed (filename) elif action == "Copied": i = filename.find(" (from rev ") destination_filename = filename[:i] filename = filename[i:] i = filename.find(", ") assert filename[-1] == ")" source_filename = filename[i+2:-1] verify_file_copied(destination_filename, source_filename) filename = destination_filename if action == "Modified" : state = 10 elif action == "Added" : state = 10 elif action == "Deleted" : state = 10 elif action == "Copied" : state = 20 elif action == "Property changes on": state = 30 else: raise AssertionError("Unknown action") current_filename = filename current_property = None continue assert state in (100, 300) if state is 10: # Expecting a bar (follows "Modified:" line) assert line == "=" * 67 state = 11 continue if state is 11: # Expecting left file info (follows bar) if line == "": state = 0 elif line == "(Binary files differ)": state = 0 elif line.startswith("--- "): state = 12 else: raise AssertionError("Expected left file info, got: %r" % line) continue if state is 12: # Expecting right file info (follows left file info) assert line.startswith("+++ " + current_filename) state = 100 continue if state is 20: # Expecting a bar or blank (follows "Copied:" line) # Test cases: # r25692: Copied and not modified (blank) # r26613: Copied and modified (bar) if not line: state = 0 elif line == "=" * 67: state = 11 else: raise AssertionError("After Copied: line, neither bar nor blank: %r" % line) continue if state is 100: # Expecting diff data for c, verify in (("-", verify_line_removed), ("+", verify_line_added)): if len(line) >= 1 and line[0] == c: try: verify(current_filename, line[1:]) except Exception, e: sys.stderr.write(str(e)) sys.stderr.write("\n") sys.exit(1) break else: if ( not line or (len(line) >= 4 and line[:2] == "@@" == line[-2:]) or (len(line) >= 1 and line[0] == " ") or line == "\\ No newline at end of file" ): continue raise AssertionError("Expected diff data, got: %r" % line) continue if state is 30: # Expecting a bar (follows "Property changes on:" line) assert line == "_" * 67 state = 31 continue if state is 31: # Expecting property name (follows bar) assert line.startswith("Name: ") state = 300 # Fall through to state 300 if state is 300: if line.startswith("Name: "): current_property = line[6:] continue for prefix, verify in ( (" - ", verify_property_line_removed), (" + ", verify_property_line_added) ): if line.startswith(prefix): try: verify(current_filename, current_property, line[5:]) except Exception, e: sys.stderr.write(str(e)) sys.stderr.write("\n") sys.exit(1) break else: if not line: continue raise AssertionError("Expected property diff data, got: %r" % line) continue raise AssertionError("Unparsed line: %r" % line) if debug: print "Commit is OK"finally: while diff_out.read(1024 * 1024 * 64): pass diff_out.close()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -