2 # vim: set sw=4 sts=4 et tw=80 :
5 %w{Paludis getoptlong}.each {|x| require x}
10 Log.instance.log_level = LogLevel::Warning
11 Log.instance.program_name = $0
18 def my_string(style, show_repo)
19 repo = show_repo ? "::#{repository_name}" : ''
20 slot = slot_key ? ":#{slot_key.value}" : ''
23 "=#{name}-#{version}#{slot}#{repo}"
25 "~#{name}-#{version.remove_revision}#{slot}#{repo}"
32 def write_file(arr, file, base)
34 arr.each {|x| output += "\n#{x}"}
37 file = "#{dir}/#{@spec.to_s.gsub('/','_')}.conf"
44 if (@subdir && !File.directory?("#{@config_dir}/#{dir}"))
45 puts "#{dir} is not a directory. Either specify \"--use-subdir no\" or create #{dir}"
48 File.open("#{@config_dir}/#{file}",'a') {|file| file.puts output}
53 def collect_highest_versions(dl)
56 next unless entry.kind == DepListEntryKind::Masked
57 pid = entry.package_id
59 seen[pid.name][:version] ||= VersionSpec.new('0')
60 if pid.version > seen[pid.name][:version]
61 seen[pid.name][:version] = pid.version
62 seen[pid.name][:dle] = entry
67 seen.each_value {|v| out << v[:dle]}
71 opts = GetoptLong.new(
72 [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
73 [ '--version', '-V', GetoptLong::NO_ARGUMENT ],
74 [ '--log-level', GetoptLong::REQUIRED_ARGUMENT ],
75 [ '--environment', '-E', GetoptLong::REQUIRED_ARGUMENT ],
76 [ '--match-type', '-m', GetoptLong::REQUIRED_ARGUMENT ],
77 [ '--pretend', '-p', GetoptLong::NO_ARGUMENT ],
78 [ '--override-masks', '-o', GetoptLong::REQUIRED_ARGUMENT ],
79 [ '--use-subdir', '-s', GetoptLong::REQUIRED_ARGUMENT ],
80 [ '--include-repository-name', GetoptLong::REQUIRED_ARGUMENT ])
89 dlomf = DepListOverrideMasksFunctions.new
91 opts.each do | opt, arg |
94 puts "Usage: " + $0 + " [options] target"
97 puts " --help Display a help message"
98 puts " --version Display libpaludis version"
100 puts " --pretend Display changes instead of changing files"
101 puts " --log-level level Set log level (debug, qa, warning, silent)"
102 puts " --environment env Environment specification (class:suffix, both parts optional, class must be 'paludis' if specified)" if @gt020
103 puts " --match-type type Set match type (equal, tilde (default), package)"
104 puts " --include-repository-name Include repository name in DepSpec (yes (default), no)"
105 puts " --override-masks list List of masks to override, seperated by \",\", default is all"
107 puts " tilde_keywords"
109 puts " repository_masks"
110 puts " --use-subdir Write files to conf.d dirs (yes, no (default))"
114 puts "#{$0} (libpaludis version: #{Paludis::Version})"
120 Log.instance.log_level = LogLevel::Debug
122 Log.instance.log_level = LogLevel::Qa
124 Log.instance.log_level = LogLevel::Warning
126 Log.instance.log_level = LogLevel::Silent
128 $stderr.puts "Bad --log-level value " + arg
138 @match_type = PACKAGE
144 $stderr.puts "Bad --match-type value #{arg}"
148 when '--include-repository-name'
155 $stderr.puts "Bad --include-repository-name value #{arg}"
159 when '--override-masks'
169 $stderr.puts "Bad --use-subdir value #{arg}"
180 puts "Please specify exactly 1 target"
186 env = Paludis::EnvironmentFactory.instance.create(envspec)
187 if env.format_key.value != "paludis" then
188 $stderr.puts "#$0: --environment must specify class 'paludis'"
191 @config_dir = env.config_location_key.value
194 dlomf.bind(:tilde_keywords, env)
195 dlomf.bind(:unkeyworded, env)
196 dlomf.bind(:repository_masks)
199 @masks.scan(/\w+/) do |mask|
200 mask_sym = mask.to_sym
202 when :tilde_keywords, :unkeyworded
203 dlomf.bind(mask_sym, env)
204 when :repository_masks, :license
207 $stderr.puts "Unrecognised --override-masks option: #{mask}"
214 db = env.package_database
219 @spec = parse_user_package_dep_spec(target, env, [:throw_if_set],
220 Filter::SupportsAction.new(InstallAction))
221 rescue GotASetNotAPackageDepSpec
222 @spec = env.set(target)
225 dl = DepList.new(env, DepListOptions.new)
226 dl.options.override_masks = dlomf
229 dl.add(@spec, env.default_destinations)
230 rescue AllMaskedError
232 pids = env[Selection::AllVersionsSorted.new(
233 Generator::Matches.new(parse_user_package_dep_spec(bad_spec, env, []),[]) |
234 Filter::SupportsAction.new(InstallAction))]
236 puts "No versions of #{bad_spec} are available."
238 puts "I'm not allowed to unmask #{bad_spec}: Masks are:"
240 print "#{pid}: Masked by: "
242 pid.masks.each do |reason|
243 if reason.instance_of? UnacceptedMask
244 if reason.unaccepted_key.instance_of? MetadataKeywordNameSetKey
247 elsif reason.instance_of? RepositoryMask
248 reasons << 'repository'
251 puts reasons.join(', ')
260 collect_highest_versions(dl).each do |entry|
261 reasons = entry.package_id.masks
262 repo = db.fetch_repository(entry.package_id.repository_name)
263 e_spec = entry.package_id.my_string(@match_type, @repository)
264 reasons.each do |reason|
265 if reason.instance_of? UnacceptedMask
266 key = reason.unaccepted_key
267 if key.instance_of? MetadataKeywordNameSetKey
268 my_arch = repo.profile_variable("ARCH")
269 kw = reason.unaccepted_key.value
272 elsif kw.include?("~#{my_arch}")
273 my_arch = "~#{my_arch}"
276 my_arch += (my_arch[0] == ?~ ? " #{my_arch[1..-1]}" : '')
278 keywords <<(e_spec + " #{my_arch}")
280 elsif reason.instance_of? RepositoryMask
286 output_base = "\n# Added by #{$0} for #{target}"
287 output_base += "\n" + ('#' * (output_base.length-1))
289 write_file(keywords, 'keywords.conf', output_base) unless keywords.empty?
290 write_file(unmask, 'package_unmask.conf', output_base) unless unmask.empty?
291 #write_file(license, 'license.conf', output_base) unless license.empty?