Class: Autoproj::InstallationManifest
- Inherits:
-
Object
- Object
- Autoproj::InstallationManifest
- Defined in:
- lib/autoproj/installation_manifest.rb
Overview
Manifest of installed packages imported from another autoproj installation
Defined Under Namespace
Classes: ContactInfo, Dependency, Manifest, Package, PackageSet
Instance Attribute Summary collapse
-
#package_sets ⇒ Object
readonly
Returns the value of attribute package_sets.
-
#packages ⇒ Object
readonly
Returns the value of attribute packages.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
- .from_workspace_root(root_dir) ⇒ Object
-
.path_for_workspace_root(root_dir) ⇒ String
Returns the default Autoproj installation manifest path for a given autoproj workspace root.
Instance Method Summary collapse
-
#add_package(pkg) ⇒ Package
Add a PackageDefinition to this manifest.
-
#add_package_set(pkg_set) ⇒ PackageSet
Add a PackageSet to this manifest.
- #convert_manifest(manifest) ⇒ Object
-
#each_package {|| ... } ⇒ Object
Enumerate this InstallationManifest‘s packages.
-
#each_package_set {|| ... } ⇒ Object
Enumerate this InstallationManifest‘s package sets.
- #exist? ⇒ Boolean
-
#find_package_by_name(name) ⇒ Package
Resolve a package by name.
-
#find_package_set_by_name(name) ⇒ Package
Resolve a package set by name.
- #hash_to_yaml(obj) ⇒ Object
-
#initialize(path = nil) ⇒ InstallationManifest
constructor
A new instance of InstallationManifest.
- #load(path = @path) ⇒ Object
- #load_contact_list(list) ⇒ Object
- #load_manifest(entry) ⇒ Object
- #load_manifest_dependencies(list) ⇒ Object
- #object_to_yaml(obj) ⇒ Object
-
#save(path = @path) ⇒ Object
Save the installation manifest.
- #struct_to_yaml(obj) ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ InstallationManifest
Returns a new instance of InstallationManifest.
24 25 26 27 28 |
# File 'lib/autoproj/installation_manifest.rb', line 24 def initialize(path = nil) @path = path @packages = Hash.new @package_sets = Hash.new end |
Instance Attribute Details
#package_sets ⇒ Object (readonly)
Returns the value of attribute package_sets.
22 23 24 |
# File 'lib/autoproj/installation_manifest.rb', line 22 def package_sets @package_sets end |
#packages ⇒ Object (readonly)
Returns the value of attribute packages.
21 22 23 |
# File 'lib/autoproj/installation_manifest.rb', line 21 def packages @packages end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
20 21 22 |
# File 'lib/autoproj/installation_manifest.rb', line 20 def path @path end |
Class Method Details
.from_workspace_root(root_dir) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/autoproj/installation_manifest.rb', line 196 def self.from_workspace_root(root_dir) path = path_for_workspace_root(root_dir) manifest = InstallationManifest.new(path) unless manifest.exist? raise ConfigError.new, "no #{path} file found. You should probably rerun " \ "autoproj envsh in that folder first" end manifest.load manifest end |
.path_for_workspace_root(root_dir) ⇒ String
Returns the default Autoproj installation manifest path for a given autoproj workspace root
192 193 194 |
# File 'lib/autoproj/installation_manifest.rb', line 192 def self.path_for_workspace_root(root_dir) File.join(root_dir, ".autoproj", "installation-manifest") end |
Instance Method Details
#add_package(pkg) ⇒ Package
Add a PackageDefinition to this manifest
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/autoproj/installation_manifest.rb', line 37 def add_package(pkg) packages[pkg.name] = case pkg when PackageDefinition v = pkg.autobuild manifest = convert_manifest(v.description) Package.new( v.name, v.class.name, pkg.vcs.to_hash, v.srcdir, (v.importdir if v.respond_to?(:importdir)), v.prefix, (v.builddir if v.respond_to?(:builddir)), v.logdir, v.dependencies, manifest ) else pkg end end |
#add_package_set(pkg_set) ⇒ PackageSet
Add a PackageSet to this manifest
66 67 68 69 70 71 |
# File 'lib/autoproj/installation_manifest.rb', line 66 def add_package_set(pkg_set) package_sets[pkg_set.name] = PackageSet.new( pkg_set.name, pkg_set.vcs.to_hash, pkg_set.raw_local_dir, pkg_set.user_local_dir ) end |
#convert_manifest(manifest) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/autoproj/installation_manifest.rb', line 56 def convert_manifest(manifest) fields = Manifest.members.each_with_object({}) do |k, h| h[k] = manifest.send(k) end Manifest.new(**fields) end |
#each_package {|| ... } ⇒ Object
Enumerate this Autoproj::InstallationManifest‘s packages
83 84 85 |
# File 'lib/autoproj/installation_manifest.rb', line 83 def each_package(&block) packages.each_value(&block) end |
#each_package_set {|| ... } ⇒ Object
Enumerate this Autoproj::InstallationManifest‘s package sets
76 77 78 |
# File 'lib/autoproj/installation_manifest.rb', line 76 def each_package_set(&block) package_sets.each_value(&block) end |
#exist? ⇒ Boolean
30 31 32 |
# File 'lib/autoproj/installation_manifest.rb', line 30 def exist? File.exist?(path) if path end |
#find_package_by_name(name) ⇒ Package
Resolve a package by name
97 98 99 |
# File 'lib/autoproj/installation_manifest.rb', line 97 def find_package_by_name(name) @packages[name] end |
#find_package_set_by_name(name) ⇒ Package
Resolve a package set by name
90 91 92 |
# File 'lib/autoproj/installation_manifest.rb', line 90 def find_package_set_by_name(name) @package_sets[name] end |
#hash_to_yaml(obj) ⇒ Object
183 184 185 |
# File 'lib/autoproj/installation_manifest.rb', line 183 def hash_to_yaml(obj) obj.transform_values { |el| object_to_yaml(el) } end |
#load(path = @path) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/autoproj/installation_manifest.rb', line 101 def load(path = @path) @packages = Hash.new raw = YAML.load(File.open(path)) if raw.respond_to?(:to_str) # old CSV-based format CSV.read(path).map do |row| name, srcdir, prefix, builddir = *row builddir = nil if builddir && builddir.empty? packages[name] = Package.new(name, srcdir, prefix, builddir, []) end save(path) else raw.each do |entry| if entry["package_set"] pkg_set = PackageSet.new( entry["package_set"], entry["vcs"], entry["raw_local_dir"], entry["user_local_dir"] ) package_sets[pkg_set.name] = pkg_set else manifest = load_manifest(entry["manifest"]) pkg = Package.new( entry["name"], entry["type"], entry["vcs"], entry["srcdir"], entry["importdir"], entry["prefix"], entry["builddir"], entry["logdir"], entry["dependencies"], manifest ) packages[pkg.name] = pkg end end end end |
#load_contact_list(list) ⇒ Object
141 142 143 |
# File 'lib/autoproj/installation_manifest.rb', line 141 def load_contact_list(list) list.map { |fields| ContactInfo.new(**fields.transform_keys(&:to_sym)) } end |
#load_manifest(entry) ⇒ Object
131 132 133 134 135 136 137 138 139 |
# File 'lib/autoproj/installation_manifest.rb', line 131 def load_manifest(entry) entry = entry.dup %w[authors maintainers rock_maintainers].each do |field| entry[field] = load_contact_list(entry[field]) end entry["dependencies"] = load_manifest_dependencies(entry["dependencies"]) Manifest.new(**entry.transform_keys(&:to_sym)) end |
#load_manifest_dependencies(list) ⇒ Object
145 146 147 |
# File 'lib/autoproj/installation_manifest.rb', line 145 def load_manifest_dependencies(list) list.map { |fields| Dependency.new(**fields.transform_keys(&:to_sym)) } end |
#object_to_yaml(obj) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/autoproj/installation_manifest.rb', line 164 def object_to_yaml(obj) case obj when Struct struct_to_yaml(obj) when Array obj.map { |el| object_to_yaml(el) } when Hash hash_to_yaml(obj) else obj end end |
#save(path = @path) ⇒ Object
Save the installation manifest
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/autoproj/installation_manifest.rb', line 150 def save(path = @path) Ops.atomic_write(path) do |io| marshalled_package_sets = each_package_set.map do |pkg_set| set = struct_to_yaml(pkg_set) set["package_set"] = set["name"] set end marshalled_packages = each_package.map do |pkg| struct_to_yaml(pkg) end io.write YAML.dump(marshalled_package_sets + marshalled_packages) end end |
#struct_to_yaml(obj) ⇒ Object
177 178 179 180 181 |
# File 'lib/autoproj/installation_manifest.rb', line 177 def struct_to_yaml(obj) obj.to_h .transform_keys(&:to_s) .transform_values { |el| object_to_yaml(el) } end |