Class: Larrow::Runner::Vcs::FileSystem
- Defined in:
- lib/larrow/runner/vcs/file_system.rb
Instance Attribute Summary collapse
-
#project_folder ⇒ Object
path: absulute path of LarrowFile.
Attributes inherited from Base
Instance Method Summary collapse
- #formatted_url ⇒ Object
- #get(filename) ⇒ Object
-
#initialize(path) ⇒ FileSystem
constructor
A new instance of FileSystem.
- #invoke(command) ⇒ Object
- #rsync_command(user, host, target_dir) ⇒ Object
- #ssh_options ⇒ Object
- #update_source(node, target_dir) ⇒ Object
Constructor Details
#initialize(path) ⇒ FileSystem
Returns a new instance of FileSystem.
6 7 8 9 10 11 12 13 14 |
# File 'lib/larrow/runner/vcs/file_system.rb', line 6 def initialize path if File.file? path path = File.absolute_path path self.larrow_file = File.basename path self.project_folder = File.dirname path else # directory self.project_folder = File.absolute_path path end end |
Instance Attribute Details
#project_folder ⇒ Object
path: absulute path of LarrowFile
5 6 7 |
# File 'lib/larrow/runner/vcs/file_system.rb', line 5 def project_folder @project_folder end |
Instance Method Details
#formatted_url ⇒ Object
16 17 18 |
# File 'lib/larrow/runner/vcs/file_system.rb', line 16 def formatted_url self.project_folder end |
#get(filename) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/larrow/runner/vcs/file_system.rb', line 20 def get filename file_path = "#{project_folder}/#{filename}" return nil unless File.exist? file_path File.read(file_path) end |
#invoke(command) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/larrow/runner/vcs/file_system.rb', line 49 def invoke command RunLogger.level(1).info command time = Time.new `#{command} 2>&1`.split(/\r?\n/).each do |msg| RunLogger.level(2).detail msg end RunLogger.level(1).detail "invoke time: #{Time.new - time}" end |
#rsync_command(user, host, target_dir) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/larrow/runner/vcs/file_system.rb', line 33 def rsync_command user, host, target_dir ssh_path = '%s@%s:%s' % [user, host, target_dir] excludes = (get('.gitignore')||''). # rsync exclude according .gitignore split(/[\r\n]/). # select{|s| s =~ /^[^#]/}. # not commented compact. # not blank unshift('.git'). # .git itself is ignored map{|s| "--exclude '#{s}'" } # build rsync exclude arguments = "-az -e 'ssh #{}' #{excludes.join ' '}" += ' -v' if RunOption.key? :debug "rsync #{} #{project_folder}/ '#{ssh_path}'" end |
#ssh_options ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/larrow/runner/vcs/file_system.rb', line 58 def { 'GSSAPIAuthentication' => 'no', 'StrictHostKeyChecking' => 'no', 'LogLevel' => 'ERROR' }.map do |k,v| "-o #{k}=#{v}" end.join(' ') end |
#update_source(node, target_dir) ⇒ Object
27 28 29 30 31 |
# File 'lib/larrow/runner/vcs/file_system.rb', line 27 def update_source node, target_dir command = rsync_command node.user, node.host,target_dir invoke command `ssh-keygen -R #{node.host} 2>&1 >/dev/null` end |