Created
October 3, 2009 12:05
-
-
Save xhan/200611 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImagecommitController < ApplicationController | |
before_filter :find_svn_modify | |
def index | |
@result = "SVN仓库没有改变!" and return unless @is_modify | |
end | |
def commit | |
unless @is_modify | |
render :update do |page| | |
page.alert "SVN 没有改变,非法提交!" | |
end | |
return | |
end | |
comment = params[:comment].empty? ? "none comments" : params[:comment] | |
comment = "commited by " + User.current.login + ' : ' + comment | |
unless comment.unpack("U*").select{ |p| (0x4e00..0x9fa5).member? p }.pack("U*").empty? | |
render :update do |page| | |
page.alert "SVN 暂时不支持中文 :)" | |
end | |
return | |
end | |
a = `#{@params_add}` unless @params_add.empty? | |
b = `#{@params_del}` unless @params_del.empty? | |
# puts @params_add | |
# puts @params_del | |
# puts a | |
# puts b | |
result = `svn ci -m "#{comment}" /data/fileserver/proj/Mee_proj/Design/images/` | |
# puts result | |
respond_to do |wants| | |
wants.html { render :text => "<pre>success #{result}</pre>" } | |
wants.js do | |
render :update do |page| | |
# page.alert "success" | |
page.replace_html 'result',"<h2>Update Success!!</h2><p><pre>#{result}</pre></p>" | |
page.visual_effect :highlight , 'result' | |
page.hide 'commit_form' | |
end | |
end | |
end | |
end | |
private | |
def find_svn_modify | |
@params_add = "" | |
@params_del = "" | |
@array_add = [] | |
@array_del = [] | |
@array_mod = [] | |
svn_path = "/data/fileserver/proj/Mee_proj/Design/images/" | |
@svn_result = `svn status /data/fileserver/proj/Mee_proj/Design/images` | |
@svn_result.each_line do |line| | |
pre_sym ,path = line.split ' ' | |
# path.sub!(svn_path,'') | |
case pre_sym | |
when "?" | |
@params_add += path + " " | |
@array_add << path.sub(svn_path,'') | |
when "!" | |
@params_del += path + " " | |
@array_del << path.sub(svn_path,'') | |
when "M" | |
@array_mod << path.sub(svn_path,'') | |
when "D" | |
@array_del << "(已有状态)#{path.sub(svn_path,'')}" | |
when "A" | |
@array_add << "(已有状态)#{path.sub(svn_path,'')}" | |
end | |
end | |
@params_add = "svn add " + @params_add unless @params_add.empty? | |
@params_del = "svn delete " + @params_del unless @params_del.empty? | |
@is_modify = !@array_add.empty? || !@array_del.empty? || !@array_mod.empty? | |
# puts "is_modify :#{@is_modify}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment