Class: Hive::FileSystem
- Inherits:
-
Object
- Object
- Hive::FileSystem
- Defined in:
- lib/hive/file_system.rb
Instance Method Summary collapse
- #check_build_integrity(destination_path) ⇒ Object
- #executed_script_path ⇒ Object
- #fetch_build(build_url, destination_path) ⇒ Object
-
#finalise_results_directory ⇒ Object
Copy useful stuff into the results directory.
- #home_path ⇒ Object
-
#initialize(job_id, home_directory, log) ⇒ FileSystem
constructor
A new instance of FileSystem.
- #logs_path ⇒ Object
- #results_path ⇒ Object
- #script_errors_file ⇒ Object
- #testbed_path ⇒ Object
Constructor Details
#initialize(job_id, home_directory, log) ⇒ FileSystem
Returns a new instance of FileSystem.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/hive/file_system.rb', line 5 def initialize(job_id, home_directory, log) @job_id = job_id @home_directory = home_directory @log = log @log.debug "Creating job paths with id=#{@job_id} and home=#{@home_directory}" make_directory(home_path) make_directory(results_path) make_directory(logs_path) make_directory(testbed_path) FileUtils.touch(script_errors_file) end |
Instance Method Details
#check_build_integrity(destination_path) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/hive/file_system.rb', line 62 def check_build_integrity( destination_path ) output = `file #{destination_path}` if output =~ /\s[Zz]ip\s/ result = `zip -T #{destination_path}` @log.info(result) $? == 0 elsif output =~ /\sgzip\s/ result = `tar -tzf #{destination_path} > /dev/null` @log.info(result) $? == 0 else true end end |
#executed_script_path ⇒ Object
37 38 39 |
# File 'lib/hive/file_system.rb', line 37 def executed_script_path @bash_script_path ||= "#{testbed_path}/executed_script.sh" end |
#fetch_build(build_url, destination_path) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/hive/file_system.rb', line 46 def fetch_build(build_url, destination_path) base_url = Hive.config.network['scheduler'] apk_url = base_url + '/' + build_url job = Hive::Messages::Job.new response = job.fetch(apk_url) tempfile = Tempfile.new('build.apk') File.open(tempfile.path,'w') do |f| f.write response.body end copy_file(tempfile.path, destination_path) check_build_integrity( destination_path ) end |
#finalise_results_directory ⇒ Object
Copy useful stuff into the results directory
42 43 44 |
# File 'lib/hive/file_system.rb', line 42 def finalise_results_directory copy_file(executed_script_path, "#{results_path}/executed_script.sh") end |
#home_path ⇒ Object
17 18 19 |
# File 'lib/hive/file_system.rb', line 17 def home_path @home_path ||= "#{@home_directory}/#{@job_id.to_s}" end |
#logs_path ⇒ Object
25 26 27 |
# File 'lib/hive/file_system.rb', line 25 def logs_path @logs_path ||= "#{home_path}/logs" end |
#results_path ⇒ Object
21 22 23 |
# File 'lib/hive/file_system.rb', line 21 def results_path @results_path ||= "#{home_path}/results" end |
#script_errors_file ⇒ Object
29 30 31 |
# File 'lib/hive/file_system.rb', line 29 def script_errors_file @script_errors_file ||= File.('script_errors.txt', logs_path) end |
#testbed_path ⇒ Object
33 34 35 |
# File 'lib/hive/file_system.rb', line 33 def testbed_path @testbed_path ||= "#{home_path}/test_code" end |