37
38
39
40
41
42
43
44
45
46
47
48
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/repo_manager/tasks/add/asset.rb', line 37
def process_discovered_assets(discovered_assets=[])
say_status "configuring", "setting discovered asset attributes"
discovered_assets.each do |discovered_asset|
folder = File.dirname(asset_name_to_config_file(discovered_asset.name))
discovered_asset.configuration.folder = folder
end
if options[:refresh]
if existing_assets.any? && discovered_assets.any?
say_status "merging", "merging existing asset attributes"
discovered_assets.each do |discovered_asset|
existing_asset = existing_assets.detect do |existing_asset|
existing_asset.name == discovered_asset.name
end
discovered_asset.attributes.merge!(existing_asset.attributes) if existing_asset
end
end
else
say_status "comparing", "looking at existing asset names"
discovered_assets.delete_if do |asset|
result = false
if File.exists?(asset.configuration.folder)
logger.debug "#{asset.name} asset name already exists, skipping"
result = true
end
result
end
say_status "comparing", "looking at existing asset paths"
discovered_assets.delete_if do |asset|
result = false
existing_asset = existing_assets.detect do |existing_asset|
existing_asset.path && asset.path && (File.expand_path(existing_asset.path) == File.expand_path(asset.path))
end
if (existing_asset)
logger.debug "#{asset.name} path matches existing asset #{existing_asset.name}, skipping"
result = true
end
result
end
end
unless discovered_assets.any?
say "no assets found for updating"
exit 0
end
say "Discovered assets"
discovered_assets.each do |asset|
say_status :found, "%-40s path => '%s'" % [asset.name, relative_path(asset.path)] , :green
end
say
unless options[:force]
exit 0 unless (ask("Found #{discovered_assets.size} asset(s), write the configuration file(s) (y/n)?") == 'y')
end
say
discovered_assets.each do |asset|
say_status :creating, "repo_manager configuration file for #{asset.name}", :green
logger.debug "writing asset #{asset.name} to #{asset.configuration.folder}"
asset.attributes.merge!(:parent => "../global/default")
save_writable_attributes(asset, asset.attributes)
end
end
|