Module: S4tUtils::SvnFileTransfer
- Includes:
- FileUtils
- Defined in:
- lib/s4t-utils/svn-file-movement.rb
Overview
These are not particularly well tested. Use at your own risk.
Class Method Summary collapse
- .create_and_transfer(src, dest, new_name) ⇒ Object
- .interesting(basenames) ⇒ Object
- .svn_add(pathname) ⇒ Object
- .svn_cmd(cmd, pathname) ⇒ Object
- .svn_mkdir(pathname) ⇒ Object
- .svn_rm(pathname) ⇒ Object
- .transfer_dir(src, dest, leave_extras = false) ⇒ Object
- .under_svn_control?(pathname) ⇒ Boolean
- .update_existing_destination(src, dest, common_name) ⇒ Object
Class Method Details
.create_and_transfer(src, dest, new_name) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/s4t-utils/svn-file-movement.rb', line 54 def create_and_transfer(src, dest, new_name) src = src+new_name dest = dest+new_name if File.directory?(src) transfer_dir(src, dest) else cp(src, dest, :verbose=>true) svn_add(dest) end end |
.interesting(basenames) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/s4t-utils/svn-file-movement.rb', line 93 def interesting(basenames) basenames.reject do | basename | basename[0,1] == '.' or basename =~ /^\#.*\#$/ or basename =~ /.*~$/ or basename == 'third-party' end end |
.svn_add(pathname) ⇒ Object
81 82 83 |
# File 'lib/s4t-utils/svn-file-movement.rb', line 81 def svn_add(pathname) svn_cmd('add', pathname) if under_svn_control?(pathname) end |
.svn_cmd(cmd, pathname) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/s4t-utils/svn-file-movement.rb', line 69 def svn_cmd(cmd, pathname) cmd = "svn #{cmd} #{pathname}" puts cmd system(cmd) exit if $? != 0 end |
.svn_mkdir(pathname) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/s4t-utils/svn-file-movement.rb', line 85 def svn_mkdir(pathname) if under_svn_control?(pathname) svn_cmd('mkdir', pathname) else mkdir pathname end end |
.svn_rm(pathname) ⇒ Object
76 77 78 79 |
# File 'lib/s4t-utils/svn-file-movement.rb', line 76 def svn_rm(pathname) svn_cmd('rm --force', pathname) if under_svn_control?(pathname) rm_rf pathname end |
.transfer_dir(src, dest, leave_extras = false) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/s4t-utils/svn-file-movement.rb', line 18 def transfer_dir(src, dest, leave_extras=false) # puts "transfer dir #{src} to #{dest}." unless File.exist?(dest) svn_mkdir dest end src_files = interesting(Dir.chdir(src) { Dir.glob('*') }).sort dest_files = interesting(Dir.chdir(dest) { Dir.glob('*')}).sort # puts "src_files = #{src_files.inspect}" # puts "dest_files = #{dest_files.inspect}" src_files.each do | src_file | if dest_files.delete(src_file) update_existing_destination(src, dest, src_file) else create_and_transfer(src, dest, src_file) end end unless leave_extras dest_files.each do | dest_file | svn_rm(dest+dest_file) end end end |
.under_svn_control?(pathname) ⇒ Boolean
65 66 67 |
# File 'lib/s4t-utils/svn-file-movement.rb', line 65 def under_svn_control?(pathname) File.exist?(Pathname.new(pathname).parent + '.svn') end |
.update_existing_destination(src, dest, common_name) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/s4t-utils/svn-file-movement.rb', line 41 def update_existing_destination(src, dest, common_name) src = src+common_name dest = dest+common_name user_claims(File.directory?(src) == File.directory?(dest)) { "#{src} is a different type of file than #{dest}." } if File.directory?(src) transfer_dir(src, dest) elsif not uptodate?(dest, [src]) cp(src, dest, :verbose=>true) end end |