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}" : ''
22 "=#{name}-#{version}:#{slot}#{repo}"
24 "~#{name}-#{version.remove_revision}:#{slot}#{repo}"
31 def write_file(arr, file, base)
33 arr.each {|x| output += "\n#{x}"}
36 file = "#{dir}/#{@spec.to_s.gsub('/','_')}.conf"
43 if (@subdir && !File.directory?("#{@config_dir}/#{dir}"))
44 puts "#{dir} is not a directory. Either specify \"--use-subdir no\" or create #{dir}"
47 File.open("#{@config_dir}/#{file}",'a') {|file| file.puts output}
52 def collect_highest_versions(dl)
55 next unless entry.kind == DepListEntryKind::Masked
56 pid = entry.package_id
58 seen[pid.name][:version] ||= VersionSpec.new('0')
59 if pid.version > seen[pid.name][:version]
60 seen[pid.name][:version] = pid.version
61 seen[pid.name][:dle] = entry
66 seen.each_value {|v| out << v[:dle]}
70 opts = GetoptLong.new(
71 [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
72 [ '--version', '-V', GetoptLong::NO_ARGUMENT ],
73 [ '--log-level', GetoptLong::REQUIRED_ARGUMENT ],
74 [ '--environment', '-E', GetoptLong::REQUIRED_ARGUMENT ],
75 [ '--match-type', '-m', GetoptLong::REQUIRED_ARGUMENT ],
76 [ '--pretend', '-p', GetoptLong::NO_ARGUMENT ],
77 [ '--override-masks', '-o', GetoptLong::REQUIRED_ARGUMENT ],
78 [ '--use-subdir', '-s', GetoptLong::REQUIRED_ARGUMENT ],
79 [ '--include-repository-name', GetoptLong::REQUIRED_ARGUMENT ])
88 dlomf = DepListOverrideMasksFunctions.new
90 opts.each do | opt, arg |
93 puts "Usage: " + $0 + " [options] target"
96 puts " --help Display a help message"
97 puts " --version Display libpaludis version"
99 puts " --pretend Display changes instead of changing files"
100 puts " --log-level level Set log level (debug, qa, warning, silent)"
101 puts " --environment env Environment specification (class:suffix, both parts optional, class must be 'paludis' if specified)" if @gt020
102 puts " --match-type type Set match type (equal, tilde (default), package)"
103 puts " --include-repository-name Include repository name in DepSpec (yes (default), no)"
104 puts " --override-masks list List of masks to override, seperated by \",\", default is all"
106 puts " tilde_keywords"
108 puts " repository_masks"
109 puts " --use-subdir Write files to conf.d dirs (yes, no (default))"
113 puts "#{$0} (libpaludis version: #{Paludis::Version})"
119 Log.instance.log_level = LogLevel::Debug
121 Log.instance.log_level = LogLevel::Qa
123 Log.instance.log_level = LogLevel::Warning
125 Log.instance.log_level = LogLevel::Silent
127 $stderr.puts "Bad --log-level value " + arg
137 @match_type = PACKAGE
143 $stderr.puts "Bad --match-type value #{arg}"
147 when '--include-repository-name'
154 $stderr.puts "Bad --include-repository-name value #{arg}"
158 when '--override-masks'
168 $stderr.puts "Bad --use-subdir value #{arg}"
179 puts "Please specify exactly 1 target"
185 if (envspec || "") =~ /^(?:paludis)?(?::(.*))?$/ then
186 env = Paludis::PaludisEnvironment.new($1 || "")
187 @config_dir = env.config_dir
189 $stderr.puts "#$0: --environment must specify class 'paludis'"
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
218 unless target.include? ?/
219 @spec = env.set(target)
220 @spec = parse_user_package_dep_spec(db.fetch_unique_qualified_package_name(target), []) if @spec.nil?
222 @spec = parse_user_package_dep_spec(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 = db.query(Query::Matches.new(parse_user_package_dep_spec(bad_spec,[])) & Query::SupportsInstallAction.new(), QueryOrder::OrderByVersion)
234 puts "No versions of #{bad_spec} are available."
236 puts "I'm not allowed to unmask #{bad_spec}: Masks are:"
238 print "#{pid}: Masked by: "
240 pid.masks.each do |reason|
241 if reason.instance_of? UnacceptedMask
242 if reason.unaccepted_key.instance_of? MetadataKeywordNameSetKey
245 elsif reason.instance_of? RepositoryMask
246 reasons << 'repository'
249 puts reasons.join(', ')
258 collect_highest_versions(dl).each do |entry|
259 reasons = entry.package_id.masks
260 repo = db.fetch_repository(entry.package_id.repository_name)
261 e_spec = entry.package_id.my_string(@match_type, @repository)
262 reasons.each do |reason|
263 if reason.instance_of? UnacceptedMask
264 key = reason.unaccepted_key
265 if key.instance_of? MetadataKeywordNameSetKey
266 my_arch = repo.profile_variable("ARCH")
267 kw = reason.unaccepted_key.value
270 elsif kw.include?("~#{my_arch}")
271 my_arch = "~#{my_arch}"
274 my_arch += (my_arch[0] == ?~ ? " #{my_arch[1..-1]}" : '')
276 keywords <<(e_spec + " #{my_arch}")
278 elsif reason.instance_of? RepositoryMask
284 output_base = "\n# Added by #{$0} for #{target}"
285 output_base += "\n" + ('#' * (output_base.length-1))
287 write_file(keywords, 'keywords.conf', output_base) unless keywords.empty?
288 write_file(unmask, 'package_unmask.conf', output_base) unless unmask.empty?
289 #write_file(license, 'license.conf', output_base) unless license.empty?