Class: Idb::RsyncGitManager
- Inherits:
-
Object
- Object
- Idb::RsyncGitManager
- Defined in:
- lib/lib/rsync_git_manager.rb
Instance Method Summary collapse
- #commit_new_revision ⇒ Object
-
#initialize(local_path) ⇒ RsyncGitManager
constructor
A new instance of RsyncGitManager.
- #start_new_revision ⇒ Object
- #sync_dir(remote, local_relative) ⇒ Object
Constructor Details
#initialize(local_path) ⇒ RsyncGitManager
Returns a new instance of RsyncGitManager.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lib/rsync_git_manager.rb', line 7 def initialize local_path @local_path = local_path FileUtils.mkdir_p @local_path unless Dir.exist? @local_path begin @g = Git.open(local_path, :log => $log) rescue $log.debug "Repository could not be opened. This is likely the first clone. Creating empty repo." Git.init(local_path) @g = Git.open(local_path, :log => $log) FileUtils.touch "#{local_path}/idb_dummy.placeholder" @g.add(:all=>true) $log.debug "Committing placeholder to initialize the repo." begin @g.commit_all("Initial commit. Initializing the repo.") rescue $log.error "Initial commit failed." end end end |
Instance Method Details
#commit_new_revision ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/lib/rsync_git_manager.rb', line 66 def commit_new_revision $log.info "Rsync Done. committing to git." @g.add(:all=>true) begin @g.commit_all("Snapshot from #{Time.now.to_s}") rescue end end |
#start_new_revision ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/lib/rsync_git_manager.rb', line 75 def start_new_revision $log.info "Hard resetting work dir #{@local_path}..." begin @g.reset_hard rescue $log.error "Reset of repo failed. If this is the first time you run rsync+git for this app this may be okay." end end |
#sync_dir(remote, local_relative) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/lib/rsync_git_manager.rb', line 30 def sync_dir remote, local_relative local = @local_path + "/" + local_relative if $settings['device_connection_mode'] == "ssh" cmd = "rsync -avz -e 'ssh -oStrictHostKeyChecking=no -p #{$settings.ssh_port}' #{$settings.ssh_username}@#{$settings.ssh_host}:#{Shellwords.escape(remote)}/ #{Shellwords.escape(local)}/" else cmd = "rsync -avz -e 'ssh -oStrictHostKeyChecking=no -p #{$device.tool_port}' root@localhost:#{Shellwords.escape(remote)}/ #{Shellwords.escape(local)}/" end $log.info "Executing rsync command #{cmd}" begin PTY.spawn(cmd) { |rsync_out, rsync_in, pid | STDOUT.flush rsync_out.sync = true rsync_in.sync = true $expect_verbose = true rsync_out.expect(/assword: /) { |x| begin $log.info "Supplying password for rsync if required..." rsync_in.printf("#{$settings.ssh_password}\n") rescue $log.info "No password required for rsync...." end } rsync_out.each { |x| $log.info x } PTY.check } rescue end end |