Class: Bosh::Gen::Generators::ExtractJobGenerator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/bosh/gen/generators/extract_job_generator.rb

Instance Method Summary collapse

Instance Method Details

#check_job_path_is_a_jobObject



23
24
25
26
27
28
# File 'lib/bosh/gen/generators/extract_job_generator.rb', line 23

def check_job_path_is_a_job
  parent_dir = File.basename(File.dirname(source_job_path))
  unless parent_dir == "jobs"
    raise Thor::Error.new("source jobs path is not a BOSH job")
  end
end

#check_job_path_is_validObject



17
18
19
20
21
# File 'lib/bosh/gen/generators/extract_job_generator.rb', line 17

def check_job_path_is_valid
  unless File.exist?(source_job_path)
    raise Thor::Error.new("source job path does not exist")
  end
end

#check_job_path_within_releaseObject



30
31
32
33
34
35
36
# File 'lib/bosh/gen/generators/extract_job_generator.rb', line 30

def check_job_path_within_release
  FileUtils.chdir(source_release_path) do
    unless File.exist?("jobs") && File.exist?("packages")
      raise Thor::Error.new("source job path is not within a BOSH release project")
    end
  end
end

#check_root_is_releaseObject



11
12
13
14
15
# File 'lib/bosh/gen/generators/extract_job_generator.rb', line 11

def check_root_is_release
  unless File.exist?("jobs") && File.exist?("packages")
    raise Thor::Error.new("run inside a BOSH release project")
  end
end

#copy_dependent_packagesObject



50
51
52
# File 'lib/bosh/gen/generators/extract_job_generator.rb', line 50

def copy_dependent_packages
  @packages.each {|package| directory "packages/#{package}"}
end

#copy_job_dirObject



42
43
44
# File 'lib/bosh/gen/generators/extract_job_generator.rb', line 42

def copy_job_dir
  directory "jobs/#{source_job_name}", "jobs/#{target_job_name}", mode: :preserve
end

#copy_package_spec_filesObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/bosh/gen/generators/extract_job_generator.rb', line 54

def copy_package_spec_files
  @blobs = false
  @packages.each do |package|
    spec = source_file("packages", package, "spec")
    file_globs = YAML.load_file(spec)["files"]

    file_globs.each do |file_glob|
      source_files = Dir.glob(File.join(source_release_path, "src", file_glob))
      source_files.each do |source_path|
        if target_path = source_path.scan(%r{/blobs/(.*)}).flatten.first
          copy_file(File.join("src", target_path))
        else
          puts("Failed to copy file: #{source_path}")
        end
      end
    end

    file_globs.each do |file_glob|
      source_files = Dir.glob(File.join(source_release_path, "blobs", file_glob))
      source_files.each do |source_path|
        target_path = source_path.scan(%r{/blobs/(.*)}).flatten.first
        BoshCli.run "add-blob #{source_path} #{target_path}"
        say_status "add-blob", target_path
        @blobs = true
      end
    end
  end
end

#detect_dependent_packagesObject



46
47
48
# File 'lib/bosh/gen/generators/extract_job_generator.rb', line 46

def detect_dependent_packages
  @packages = YAML.load_file(job_dir("spec"))["packages"]
end

#readmeObject



83
84
85
86
87
# File 'lib/bosh/gen/generators/extract_job_generator.rb', line 83

def readme
  if @blobs
    say_status "readme", "Upload blobs with 'bosh upload-blobs'"
  end
end

#using_source_release_for_templatesObject



38
39
40
# File 'lib/bosh/gen/generators/extract_job_generator.rb', line 38

def using_source_release_for_templates
  source_paths << File.join(source_release_path)
end