Changeset 92
- Timestamp:
- 2009年08月23日 12时15分25秒 (2 years ago)
- Location:
- trunk/pysvnmanager/hooks
- Files:
-
- 5 modified
-
init/hook1.4/pre-commit (modified) (1 diff)
-
init/hook1.4/scripts/check-mime-type.py (modified) (3 diffs)
-
init/hook1.5/pre-commit (modified) (1 diff)
-
init/hook1.5/scripts/check-mime-type.py (modified) (3 diffs)
-
plugins/EolStyleCheck.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pysvnmanager/hooks/init/hook1.4/pre-commit
r47 r92 73 73 if [ "$eol_style_check" = "yes" ]; then 74 74 # New file must set svn:mime-type and svn:eol-style 75 $TOOLS_DIR/check-mime-type.py "$REPOS" "$TXN" || exit 175 $TOOLS_DIR/check-mime-type.py "$REPOS" "$TXN" $eol_style_check_force || exit 1 76 76 fi 77 77 -
trunk/pysvnmanager/hooks/init/hook1.4/scripts/check-mime-type.py
r90 r92 27 27 MIN_LENGTH = 5 28 28 29 def main(repos, txn ):29 def main(repos, txn, force=""): 30 30 """main entry point""" 31 32 if force == "no": 33 force = False 34 else: 35 force = True 31 36 32 37 files_added = [] … … 62 67 63 68 if check_mime: 64 if mime_type == "" and eol_style == '': 65 errmsg.append( "%s : 属性 svn:mime-type 或者 svn:eol-style 没有设置" % path.decode('utf-8','replace').encode('utf-8','replace') ) 66 elif ptext.match(mime_type) and eol_style == '': 67 errmsg.append( "%s : svn:mime-type=%s 但是 svn:eol-style 没有设置" % (path.decode('utf-8','replace').encode('utf-8','replace'), mime_type) ) 69 if mime_type == "" or ptext.match(mime_type): 70 if eol_style == '': 71 ## check if crlf in file contents 72 if not force: 73 if crlf_in_file(txn, repos, path): 74 errmsg.append( "CRLF (DOS style EOL) in file: %s" % path.decode('utf-8','replace').encode('utf-8','replace') ) 75 else: 76 continue 77 if mime_type == "": 78 errmsg.append( "%s : 属性 svn:mime-type 或者 svn:eol-style 没有设置" % path.decode('utf-8','replace').encode('utf-8','replace') ) 79 else: 80 errmsg.append( "%s : svn:mime-type=%s 但是 svn:eol-style 没有设置" % (path.decode('utf-8','replace').encode('utf-8','replace'), mime_type) ) 68 81 69 82 if len( errmsg ) > 0: 70 83 die( errmsg ) 71 84 72 85 def crlf_in_file(txn, repos, path): 86 cmd = '%s cat -t "%s" "%s" "%s"' % (SVNLOOK, txn, repos, path) 87 buff = os.popen(cmd, 'r').read(1024) 88 if '\r' in buff: 89 return True 90 else: 91 return False 92 73 93 def die(msg): 74 94 """ … … 106 126 sys.stderr.write("Usage: %s REPOS TXN\n" % (sys.argv[0])) 107 127 else: 108 main(sys.argv[1], sys.argv[2] )128 main(sys.argv[1], sys.argv[2], sys.argv[3:] and sys.argv[3] or '') -
trunk/pysvnmanager/hooks/init/hook1.5/pre-commit
r47 r92 73 73 if [ "$eol_style_check" = "yes" ]; then 74 74 # New file must set svn:mime-type and svn:eol-style 75 $TOOLS_DIR/check-mime-type.py "$REPOS" "$TXN" || exit 175 $TOOLS_DIR/check-mime-type.py "$REPOS" "$TXN" $eol_style_check_force || exit 1 76 76 fi 77 77 -
trunk/pysvnmanager/hooks/init/hook1.5/scripts/check-mime-type.py
r90 r92 27 27 MIN_LENGTH = 5 28 28 29 def main(repos, txn ):29 def main(repos, txn, force=""): 30 30 """main entry point""" 31 32 if force == "no": 33 force = False 34 else: 35 force = True 31 36 32 37 files_added = [] … … 62 67 63 68 if check_mime: 64 if mime_type == "" and eol_style == '': 65 errmsg.append( "%s : 属性 svn:mime-type 或者 svn:eol-style 没有设置" % path.decode('utf-8','replace').encode('utf-8','replace') ) 66 elif ptext.match(mime_type) and eol_style == '': 67 errmsg.append( "%s : svn:mime-type=%s 但是 svn:eol-style 没有设置" % (path.decode('utf-8','replace').encode('utf-8','replace'), mime_type) ) 69 if mime_type == "" or ptext.match(mime_type): 70 if eol_style == '': 71 ## check if crlf in file contents 72 if not force: 73 if crlf_in_file(txn, repos, path): 74 errmsg.append( "CRLF (DOS style EOL) in file: %s" % path.decode('utf-8','replace').encode('utf-8','replace') ) 75 else: 76 continue 77 if mime_type == "": 78 errmsg.append( "%s : 属性 svn:mime-type 或者 svn:eol-style 没有设置" % path.decode('utf-8','replace').encode('utf-8','replace') ) 79 else: 80 errmsg.append( "%s : svn:mime-type=%s 但是 svn:eol-style 没有设置" % (path.decode('utf-8','replace').encode('utf-8','replace'), mime_type) ) 68 81 69 82 if len( errmsg ) > 0: 70 83 die( errmsg ) 71 84 72 85 def crlf_in_file(txn, repos, path): 86 cmd = '%s cat -t "%s" "%s" "%s"' % (SVNLOOK, txn, repos, path) 87 buff = os.popen(cmd, 'r').read(1024) 88 if '\r' in buff: 89 return True 90 else: 91 return False 92 73 93 def die(msg): 74 94 """ … … 106 126 sys.stderr.write("Usage: %s REPOS TXN\n" % (sys.argv[0])) 107 127 else: 108 main(sys.argv[1], sys.argv[2] )128 main(sys.argv[1], sys.argv[2], sys.argv[3:] and sys.argv[3] or '') -
trunk/pysvnmanager/hooks/plugins/EolStyleCheck.py
r50 r92 39 39 40 40 # Plugin config option/value in config ini file. 41 key = "eol_style_check"42 value = "yes"41 key_switch = "eol_style_check" 42 key_force = "eol_style_check_force" 43 43 44 44 section = 'pre_commit' … … 49 49 Simply call 'has_config()'. 50 50 """ 51 return self.has_config( )51 return self.has_config(self.key_switch) 52 52 53 53 def install_info(self): … … 58 58 reST reference: http://docutils.sourceforge.net/docs/user/rst/quickref.html 59 59 """ 60 return self.description 60 result = self.description 61 if self.enabled(): 62 result += "\n\n" 63 result += "**" + _("Current configuration") + "**\n\n" 64 force = self.get_config(self.key_force) 65 if force == "no": 66 result += "- " + _("Loose mode: permit checkin without svn:eol-style properity if no CRLF in text file.") 67 else: 68 result += "- " + _("Strict mode: must have svn:eol-style even if not CRLF in text file.") 69 70 return result 71 61 72 62 73 def install_config_form(self): … … 66 77 Any html and javascript are welcome. 67 78 """ 68 return "" 79 if self.get_config(self.key_force)=="no": 80 enable_checked = "" 81 disable_checked = "checked" 82 else: 83 enable_checked = "checked" 84 disable_checked = "" 85 86 result = "" 87 result += "<p><strong>%s</strong></p>" % _("Fill this form") 88 result += "<blockquote>" 89 result += "<dl>" 90 result += "\n<dt>" 91 result += "<input type='radio' name='force' value='yes' " + \ 92 enable_checked + ">" + _("Strict mode") + " " 93 result += "\n<dd>" 94 result += _("Must set svn:eol-style even if CRLF not in text file (in Unix format).") 95 result += "\n<dt>" 96 result += "<input type='radio' name='force' value='no' " + \ 97 disable_checked + ">" + _("Loose mode") + "<br>" 98 result += "\n<dd>" 99 result += _("Permit checkin without svn:eol-style properity if is in Unix file format (no crlf in text file).") 100 result += "\n</dl>" 101 result += "</blockquote>" 102 return result 69 103 70 104 def uninstall(self): … … 73 107 Simply call 'unset_config()' and 'save()'. 74 108 """ 75 self.unset_config() 109 self.unset_config(self.key_switch) 110 self.unset_config(self.key_force) 76 111 self.save() 77 112 … … 83 118 Form fields in setup_config() will pass as params. 84 119 """ 85 self.set_config() 120 force = params.get('force', 'no') 121 if force != 'no': 122 force = 'yes' 123 self.set_config(self.key_switch, 'yes') 124 self.set_config(self.key_force, force) 86 125 self.save() 87 126
![(please configure the [header_logo] section in trac.ini)](/trac/pysvnmanager/chrome/common/trac_banner.png)