Class: Bosh::Gen::Generators::ExtractPackageGenerator

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

Instance Method Summary collapse

Instance Method Details

#check_package_path_is_a_packageObject



25
26
27
28
29
30
# File 'lib/bosh/gen/generators/extract_package_generator.rb', line 25

def check_package_path_is_a_package
  parent_dir = File.basename(File.dirname(source_package_path))
  unless parent_dir == "packages"
    raise Thor::Error.new("source package path is not a BOSH package")
  end
end

#check_package_path_within_releaseObject



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

def check_package_path_within_release
  FileUtils.chdir(source_release_path) do
    unless File.exist?("jobs") && File.exist?("packages")
      raise Thor::Error.new("source package 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_package_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



43
44
45
46
47
# File 'lib/bosh/gen/generators/extract_package_generator.rb', line 43

def copy_dependent_packages
  @packages.each do |package|
    directory "packages/#{package}", mode: :preserve
  end
end

#copy_package_spec_filesObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/bosh/gen/generators/extract_package_generator.rb', line 49

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|
        target_path = source_path.scan(%r{/src/(.*)}).flatten.first
        copy_file(File.join("src", target_path))
      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

Extract target package and all its dependencies



37
38
39
40
41
# File 'lib/bosh/gen/generators/extract_package_generator.rb', line 37

def detect_dependent_packages
  spec = YAML.load_file(source_package_dir("spec"))
  @packages = [source_package_name]
  @packages << spec["packages"] if spec["packages"]
end

#readmeObject



75
76
77
78
79
# File 'lib/bosh/gen/generators/extract_package_generator.rb', line 75

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

#using_source_release_for_templatesObject



32
33
34
# File 'lib/bosh/gen/generators/extract_package_generator.rb', line 32

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