638251f00cb08336a47c47fc6e31a9be280fc5ad
[portpeek.git] / portpeek
1 #!/usr/bin/python
2 #
3 # Copyright 2006 Mike Pagano
4 # Distributed under the terms of the GNU General Public License v2
5 #
6 # $Header$
7 # Author: Mike Pagano <mpagano@gentoo.org>
8 #
9 # Portions written ripped from 
10 # - equery, by Karl Trygve Kalleberg <karltk@gentoo.org>
11 # - gentoolkit.py, by Karl Trygve Kalleberg <karltk@gentoo.org>
12 # - portage.py
13 # - emerge
14 #
15 #
16
17 __author__ = "Michael Pagano"
18 __email__ = "mpagano@gentoo.org"
19 __version__ = "2.1.1"
20 __productname__ = "portpeek"
21 __description__ = "Displays user unmasked ebuilds and installable options from the portage tree"
22
23 import sys, os, portage.output, fileinput, re, gentoolkit
24 from gentoolkit.versionmatch import VersionMatch,errors
25 from portage.const import USER_CONFIG_PATH
26 from portage.versions import catpkgsplit,pkgcmp,pkgsplit
27 from portage.exception import InvalidAtom
28 from gentoolkit.cpv import CPV
29 from gentoolkit.query import Query
30 from gentoolkit.flag import get_iuse
31
32 # support python 2
33 try:
34     input = raw_input
35 except NameError:
36     pass
37
38 porttree = portage.db[portage.root]["porttree"]
39 settings = portage.config(clone=portage.settings)
40
41 show_changes_only_flag = False
42 checking_package_unmask = False
43 checking_package_mask = False
44 print_overlay_flag = False
45 info = 0
46 debug = 1
47 logLevel = info
48 show_removable_only_flag = False
49 stable_list = []
50 stable_listNg = [] # handle package.accept_keywords
51 unmask_list = []
52 tilde = 0
53 processing_package_use = False
54 using_gentoo_as_overlay = False
55 overlay_list = []
56 fix_confirm = True
57 fix_asked = False
58 use_flag_dict = {}
59 useremove_display = ""
60 invalid_flag_found = False
61
62 try:
63     PORTAGE_CONFIGROOT
64 except NameError:
65     PORTAGE_CONFIGROOT="/"
66
67 USER_CONFIG_PATH=PORTAGE_CONFIGROOT + USER_CONFIG_PATH
68
69 #parameters
70 options = [
71 "--keyword",
72 "--unmask",
73 "--mask",
74 "--all",
75 "--changes-only",
76 "--version",
77 "--version",
78 "--help",
79 "--removable-only",
80 "--debug",
81 "--fix", 
82 "--tilde-check",
83 "--no-color",
84 "--package-use",
85 "--fix-confirm"
86 ]
87
88 mappings = {
89 "k":"--keyword",
90 "u":"--unmask",
91 "m":"--mask",
92 "a":"--all",
93 "c":"--changes-only",
94 "V":"--version",
95 "v":"--version",
96 "h":"--help",
97 "r":"--removable-only",
98 "d":"--debug",
99 "f":"--fix", 
100 "t":"--tilde-check",
101 "n":"--no-color",
102 "s":"--package-use",
103 "q":"--fix-confirm"
104 }
105
106 cmdline = []
107 overlays = [settings["PORTDIR_OVERLAY"]]
108
109 def print_usage():
110     # Print full usage information for this tool to the console.
111     print ("\nUsage: " + portage.output.turquoise(__productname__) +  portage.output.yellow(" command "))
112     print ("       " + portage.output.turquoise(__productname__) + portage.output.green(" [ options ]") +  portage.output.yellow(" command "))
113     print ("       " + portage.output.turquoise(__productname__) + portage.output.green(" [-c]") + portage.output.yellow(" [akmu]"))
114     print ("       " + portage.output.turquoise(__productname__) + portage.output.green(" [-r]") + portage.output.yellow(" [akmu]"))
115     print ("       " + portage.output.turquoise(__productname__) + portage.output.green(" [-f]") + portage.output.yellow(" [akmu]"))
116     print ("       " + portage.output.turquoise(__productname__) + portage.output.green(" [-F]") + portage.output.yellow(" [akmu]"))
117     print (portage.output.yellow(" command ") + " can be ")
118     print (portage.output.yellow(" -a, --all") + "       - show all matches")
119     print (portage.output.yellow(" -k, --keyword") + "       - show matches from package.keywords and package.accept_keywords only")
120     print (portage.output.yellow(" -m, --mask") + "      - show matches from package.mask only")
121     print (portage.output.yellow(" -u, --unmask") + "        - show matched from package.unmask only")
122     print (portage.output.yellow(" -s, --package.use") + "   - show matches from package.use only")
123     
124     print (portage.output.yellow(" -f, --fix") + "       - will remove the stabled and invalid packages without asking for confirmation")
125     print (portage.output.yellow(" -q, --confirm-fix") +"    - will remove the stabled and invalid packages asking for confirmation before doing so")
126     print (portage.output.yellow(" -h, --help") + "      - display this message")
127     print (portage.output.yellow(" -d, --debug") + "         - display more verbose output for debugging")
128     print (portage.output.yellow(" -V, --version") + "       - display version info")
129     print (portage.output.green("options") + " are ")
130     print (portage.output.green(" -c, --changes-only") + \
131         "   - show all matches that have upgrade option, use with " + \
132         "<" + portage.output.yellow(" k ") + "|" + portage.output.yellow(" u ") + \
133         "|" + portage.output.yellow(" m ") + "|" + \
134         portage.output.yellow(" a ") + ">")
135     print (portage.output.green(" -n, --no-color") + \
136         "   - suppress color output")
137     print (portage.output.green(" -r, --removable-only") + \
138         "   - show all matches that can be removed from package files, use with " + \
139         "<" + portage.output.yellow(" k ") + "|" + portage.output.yellow(" u ") + \
140         "|" + portage.output.yellow(" m ") + "|" + \
141         portage.output.yellow(" a ") + ">\n")
142
143 def get_keywords(package, var):
144     mytree = porttree
145     filtered_keywords = ""
146     try:
147         keywords = package.environment("KEYWORDS").split()
148     except KeyError as error:
149         print ("!!! Portpeek caught Exception:" + format(error))
150         print ("!!! This package/version seems to be no longer available, " + \
151         "please check and update/unmerge it") 
152         return "Not Available/Deprecated"
153     
154     #filtered_keywords = filter_keywords(keywords[0])
155     filtered_keywords = filter_keywords(keywords)
156     return filtered_keywords
157
158
159
160 # this is the main function for portpeek
161 # TODO comment this code!
162 def parse_line(line, filename):     
163     global info,debug,using_gentoo_as_overlay
164
165     using_gentoo_as_overlay = False
166     pkgs = None
167     ebuild_output = ""
168     check_pkg = ""
169     not_installed_pkgs = 0
170     pkg_length = 0
171     atom_check="<>="
172     original_line = line
173
174     # if the line has special characters, we need to make sure the original line is used for matching
175     special_line = False
176
177     if ( (re.match('[><:\*]',line) != None) ):
178         special_line = True
179
180     print_output(debug,portage.output.blue("Analyzing line: " + line))
181         # determine if we are also check ~ prefixed code
182     if  (tilde == 1): 
183         atom_check="<>=~"
184
185     diffs_found = False
186     display_done = False
187
188     fields = line.replace("\t", " ").split(" ")
189
190     if len(fields) > 0:
191         #if the line does not start with an atom such as (= or >), do not validate 
192         #status as this tool is for check specific versions and not entire packages 
193         # a ~cpv should be handled like an =cpv if requested bythe parameter -t
194         check_pkg = fields[0] # this should be one of <>=~
195         overlay_index = check_pkg.find("::")
196         if ( overlay_index >= 0):
197             overlay_list = check_pkg.rsplit("::")
198             if (len(overlay_list) > 0):
199                 overlay_name = overlay_list[1]
200                 if (overlay_name == "gentoo"):
201                     using_gentoo_as_overlay = True
202             check_pkg = check_pkg[0:check_pkg.find("::")]
203
204         if check_pkg[0] not in atom_check:
205
206             # if this is package_unmask, then check the non-atom containing package to see if any version is masked
207
208             if (checking_package_unmask == True):
209                 
210                 print_output(debug,portage.output.blue("check_pkg is " + check_pkg + " found"))
211                 if (is_any_cpv_masked(check_pkg) == False):
212                     print_output(info,portage.output.red("No masked versions of " + check_pkg + " found. Tagged for removal."))
213                     unmask_list.append(str(check_pkg))
214             return
215         if (tilde == 1):
216             if check_pkg[0] in "~":
217                 check_tilde_masked_pkg(check_pkg, filename)
218                 return
219
220         # determine if the package exists
221         try:
222             package_exists = portage.portdb.xmatch("match-all", fields[0])
223         except InvalidAtom:
224             package_exists = False
225
226         if package_exists:
227             # return a Package List based on the cpv
228             query = Query(check_pkg)
229             #query = Query(fields[0])
230             pkgs = []
231
232             try:
233                 pkgs = query.smart_find(True,True,True,True,False,True)
234             except errors.GentoolkitException as err:
235                 pass
236
237             if (pkgs != None):
238                 pkg_length = len(pkgs)
239                 not_installed_pkgs = 0
240                 display_done = False
241
242                                 # go through each package version for a specific version found above
243                 for current_package in pkgs:
244                     if not current_package.is_installed():
245
246                                                 # we have found a package that is in our file, but not installed
247                         not_installed_pkgs = not_installed_pkgs + 1
248
249                         # check to see if specific version of pkg is not installed 
250                         # and display if true
251                         check_pkg = fields[0]
252                         if check_pkg[0] in atom_check:
253                             check_pkg = check_pkg[1:]
254
255                         if (check_pkg == str(current_package.cpv)):
256                             if (not checking_package_mask):
257                                                                 # package is not instaleld
258                                 print_output(info,portage.output.yellow("\n" + str(current_package.cpv) + ": ") + portage.output.red("Not Installed") , current_package, filename)
259                                 if "package.keywords" in filename:
260                                     stable_list.append(str(current_package.cpv))
261                                 if "package.accept_keywords" in filename:
262                                     stable_listNg.append(str(current_package.cpv))
263                                 unmask_list.append(str(current_package.cpv))
264                             else:
265                                                                 # package is masked, and not installed, this is normal use of package.mask
266                                 print_output(info,portage.output.green("" + str(current_package.cpv) + ": ") + portage.output.yellow("Package Masked"),current_package, filename)
267                             display_done = True
268                         continue
269
270                                         # package is installed
271                                         # retrieve the keywords for a file
272                     keywords = "%s" % (get_keywords(current_package,"KEYWORDS").split())
273                     if (keywords.find("Available/Deprecated") >= 0):
274                         continue
275
276                                         #retrieve the mask status of a specific package
277                     pkgmask = _get_mask_status(current_package, False)
278
279                     #determine if installed package is unmasked, if so, display keywords as green
280                     stable = check_for_stable_release(current_package)
281
282                     # do not display if keywords don't exist
283                     if keywords == "[]":
284                         continue
285
286                     if stable:
287                         ebuild_output = portage.output.green("Installed: ") + \
288                             portage.output.turquoise(str(current_package.cpv)) + \
289                             portage.output.green("  Keywords " + keywords)
290                         if "package.unmask" in filename:
291                             unmask_list.append(str(current_package.cpv))
292                         if "package.keywords" in filename:
293                             stable_list.append(str(current_package.cpv))
294                         if "package.accept_keywords" in filename:
295                             stable_listNg.append(str(current_package.cpv))
296                     else:
297                         if (not show_removable_only_flag):
298                             if (not checking_package_unmask):
299                                 ebuild_output = portage.output.green("Installed: ") + \
300                                 portage.output.turquoise(str(current_package.cpv)) + \
301                                 portage.output.yellow("  Keywords " + keywords) 
302                         else:
303                             ebuild_output = portage.output.yellow(str(current_package.cpv))
304
305                                         # check package.unmask
306                     if (checking_package_unmask):
307                         if (not is_pkg_package_masked(str(current_package.cpv))):
308
309                                                         # package is in package.unmask unnecessarily
310                             ebuild_output = ebuild_output + ": " + portage.output.yellow("Not package masked")
311                             if "package.unmask" in filename:
312                                 unmask_list.append(str(current_package.cpv))
313                                 print_output (info, "" +  ebuild_output,None, filename)
314                                 continue
315
316                                         # print once
317                     ebuild_search_key_printed = False
318                     if stable:
319                         diffs_found = False
320                         ebuild_search_key_printed = True
321                         print_output(info,"\n" + ebuild_output,current_package, filename)
322                     elif not show_changes_only_flag and not show_removable_only_flag:
323                         diffs_found = False
324                         ebuild_search_key_printed = True
325                         print_output(info,"\n" + ebuild_output,current_package)
326
327                                         # go through all versions of a package
328                     query = Query(current_package.category + "/" + current_package.name)
329
330                     all_pkgs = []
331
332                     try:
333                         all_pkgs = query.smart_find(True,True,True,True,False,True)
334                     except errors.GentoolkitException as err:
335                         print_output(debug,portage.output.blue("Package " + current_package.category + "/" + current_package.name + " not found."))
336
337                     for a_package in all_pkgs:
338                         if not a_package.is_installed():
339                                                         # a_package is not installed
340                             pkgmask = _get_mask_status(a_package, False)
341                                                         # print status line of package we are now checking
342                             print_output(debug,portage.output.blue("Checking package: " + str(a_package.cpv) +".pkgmask is " + str(pkgmask)))
343                                                         # if package versions are different
344                             if (VersionMatch(CPV(current_package.cpv)).match(CPV(a_package.cpv))):
345                                 diffs_found = True
346                                 keylist = a_package.environment("KEYWORDS")
347                                 keywords = "%s" % (filter_keywords(keylist)).split()
348                                 #if a_package is masked
349                                 if pkgmask > 0 and not show_removable_only_flag:
350                                     if show_changes_only_flag and not ebuild_search_key_printed:
351                                         print_output (info, "\n" +  ebuild_output, current_package)
352                                         ebuild_search_key_printed = True
353                                         check_for_stable_release(current_package)
354                                     if (pkgmask >= 3):
355                                         print_output (info,portage.output.red("Available: " + str(a_package.cpv) + " [M] Keywords: " + keywords),a_package)
356                                     else:
357                                         print_output (info,portage.output.brown("Available: " + str(a_package.cpv) + " Keywords: " + keywords),a_package)
358                                 else:
359                                     if show_changes_only_flag and not ebuild_search_key_printed:
360                                         print_output (info,"\n" + ebuild_output,current_package)
361                                         ebuild_search_key_printed = True
362                                         print_output(info,portage.output.green("Available: " + str(a_package.cpv) + " Keywords: " + keywords),a_package)
363                 #else:
364                     #print (portage.output.red ("\nCannot find package: " + check_pkg))
365
366                 # if package does not exist, and current_package is None
367                 # then make package using fields[0]
368
369                 # display if pkg/cat is not installed (missing version)
370                 if not_installed_pkgs ==  pkg_length:
371                     if not display_done:
372                         if (not checking_package_mask):
373                             print_output(info,portage.output.yellow("\n" + fields[0] + ": ") + portage.output.red("Not Installed"),current_package)
374                             if "package.keywords" in filename:
375                                 if (special_line == False):
376                                     stable_list.append(str(current_package.cpv))
377                                 else:
378                                     stable_list.append(original_line)
379                             if "package.accept_keywords" in filename:
380                                 if (special_line == False):
381                                     stable_listNg.append(str(current_package.cpv))
382                                 else:
383                                     stable_listNg.append(original_line)
384                             if (special_line == False):
385                                 unmask_list.append(str(current_package.cpv))
386                             else:
387                                 unmask_list.append(original_line)
388                         else:
389                             print_output (info,portage.output.green("\n" + str(current_package.cpv) + ": ") + portage.output.yellow("Package Masked"),current_package)
390         else:
391             diffs_found = True
392             print (portage.output.red ("\nPackage: " + fields[0] + " not found. Please check " + filename + " to validate entry"))
393             if "package.keywords" in filename:
394                 stable_list.append(fields[0])
395             if "package.accept_keywords" in filename:
396                 stable_listNg.append(fields[0])
397             unmask_list.append(fields[0])
398             show_all_versions(fields[0], filename)
399     current_package = ""
400
401     return diffs_found
402
403 # adding support for etc/portage/package.keywords/<whatever>/package.keywords
404 def get_recursive_info(filename):
405
406     # determine if filename is a directory
407     if os.path.isdir(filename):
408         # get listing of directory
409         filenames = os.listdir(filename)
410         for file_name in filenames:
411             get_recursive_info(filename+os.path.sep+file_name)
412     else:   
413         get_info(filename)
414
415 def get_info(filename):
416
417     diffs_found = False
418     no_file = False
419     filedescriptor = None
420
421     try:
422         filedescriptor = open(filename)
423         for line in filedescriptor.readlines():
424             line = line.strip()
425             if len(line) <= 0:
426                 continue
427             elif line.find("#") >= 0:
428                 # found '#' remove comment
429                 if (skipFile(line,filename)):
430                     return
431                 line = line[0:line.find("#")]
432                 line = line.strip()
433                 if len(line) <= 0:
434                     continue
435             if (processing_package_use == False):
436                 diffs_found = parse_line(line, filename)
437             else:
438                 # process package.use
439                 diffs_found = parse_package_use(line,filename)
440     except IOError:
441         print (portage.output.red("Could not find file " + filename))
442         no_file = True
443
444     if not diffs_found and no_file:
445         print (portage.output.brown("No ebuild options found."))
446
447     # close file
448     if (filedescriptor != None):
449         filedescriptor.close()
450
451 # parse the package.use file and look for packages
452 # not installed
453 def parse_package_use(line, filename):
454
455     global info,debug
456     print_output(debug,portage.output.blue("parse_package_use: Line: " + line))
457     pkgs = None
458     check_pkg = ""
459     pkg_length = 0
460     atom_check="<>="
461     any_version = False
462     has_atom = True
463
464     diffs_found = False
465     package_installed = False
466     fields = line.replace("\t", " ").split(" ")
467
468     if len(fields) > 0:
469         check_pkg = fields[0] # this could be one of <>=
470         if check_pkg[0] not in atom_check:
471             has_atom = False
472         else:
473             check_pkg = check_pkg[1:]
474
475
476         # if there is a wildcard, check to make sure at least one
477         # of the packages is installed
478         if check_pkg.find("/*") >= 0:
479             query = Query(check_pkg)
480             pkgs = []
481             try:
482                 pkgs = query.smart_find(True,True,True,True,False,True)
483             except errors.GentoolkitException as err:
484                 print_output(debug,portage.output.blue("parse_package_use: Package " + check_pkg + " not found."))
485                 return False
486
487             if (pkgs != None):
488                 pkg_length = len(pkgs)
489             for current_package in pkgs:
490                 # on wildcard scenario, return False if one package is installed
491                 if current_package.is_installed():
492                     check_useflags(current_package,line)
493                     return False
494         else:
495             # look for any version of check_pkg installed as there is 
496             # no version specified in package.use
497             package_exists = portage.portdb.xmatch("match-all", check_pkg)
498             if package_exists:
499                 # get all package versions
500                 query = Query(check_pkg)
501                 pkgs = []
502                 try:
503                     pkgs = query.smart_find(True,True,True,True,False,True)
504                 except errors.GentoolkitException as err:
505                     print_output(debug,portage.output.blue("Package " + check_pkg + " not found."))
506     
507                 if (pkgs != None):
508                     pkg_length = len(pkgs)
509     
510                     # go through each package version for a specific 
511                     # version found above
512                     # if one line check returns all ok, we don't need 
513                     #to check the rest. One slot could have different 
514                     #use flags than another
515                     if (has_atom == False):
516                         check_useflags_all_versions(pkgs, line, check_pkg)
517                         package_installed = check_for_any_installed_version(pkgs)
518                         current_package = None
519
520                         #for current_package in pkgs:
521                         #    if current_package.is_installed():
522                         #        check_useflags(current_package,line)
523                         #        package_installed = True
524                         #        if (invalid_flag_found == False):
525                         #            break;
526                     else: 
527                         # go through each package version for a specific version found above
528                         for current_package in pkgs:
529                             if (str(current_package.cpv) == check_pkg):
530                                 if not current_package.is_installed():
531                                     print_output(info,portage.output.yellow("\n" + check_pkg + ": ") + portage.output.red("Not Installed"),current_package)
532                                     if "package.keywords" in filename:
533                                         stable_list.append(check_pkg)
534                                     if "package.accept_keywords" in filename:
535                                         stable_listNg.append(check_pkg)
536                                     unmask_list.append(check_pkg)
537                                     if "package.use" in filename:
538                                         valid_flag_list = []
539                                         valid_flag_list.insert(0,current_package);
540                                         use_flag_dict[line] = valid_flag_list
541                                         check_for_change = use_flag_dict[line]
542                                     return True
543                                 else:
544                                     check_useflags(current_package,line)
545                                     return False
546             else:
547                 print (portage.output.red ("\nPackage: " + fields[0] + " not found. Please check " + filename + " to validate entry"))
548                 if "package.keywords" in filename:
549                     stable_list.append(check_pkg)
550                 if "package.accept_keywords" in filename:
551                     stable_listNg.append(check_pkg)
552                 unmask_list.append(check_pkg)
553                 if "package.use" in filename:
554                     valid_flag_list = []
555                     #valid_flag_list.insert(0,current_package);
556                     valid_flag_list.insert(0,fields[0]);
557                     use_flag_dict[line] = valid_flag_list
558                     check_for_change = use_flag_dict[line]
559                 return True
560
561     if (package_installed == False):
562         # package does not exists
563         print_output(info,portage.output.yellow("\n" + check_pkg + ": ") + portage.output.red("Not Installed"),current_package)
564         if "package.keywords" in filename:
565             stable_list.append(check_pkg)
566         if "package.accept_keywords" in filename:
567             stable_listNg.append(check_pkg)
568         if "package.use" in filename:
569             valid_flag_list = []
570             valid_flag_list.insert(0,current_package);
571             use_flag_dict[line] = valid_flag_list
572             check_for_change = use_flag_dict[line]
573
574         unmask_list.append(check_pkg)
575         return True
576
577     return False
578
579
580
581
582 # skip the file if portpeek-skip found in a comment
583 # you can put this in the middle of a file and it will
584 #skip all entrie below it, this is useful to speed things
585 #up by not checking ~kde versions, for example
586 def skipFile (line, filename):
587     if ( (line == None) or (filename == None)):
588         return False
589
590     if line.find("portpeek-skip") >= 0:
591         return True
592
593     return False
594
595 # parts blatantly stolen from equery
596 # if pure is true, then get "true" mask status that is
597 # not affected by entries in /etc/portage/package.*
598 def _get_mask_status(pkg, pure):
599     pkgmask = 0
600
601     if (pkg == None):
602         return 0
603
604     if pkg.is_masked():
605         pkgmask = pkgmask + 3
606
607     if pure:
608         try:
609             keywords = portage.portdb.aux_get(str(pkg.cpv), ["KEYWORDS"])
610             keywords = keywords[0].split()
611         except KeyError:
612             # cpv does not exist
613             return 0
614     else:
615         keywords = pkg.environment("KEYWORDS").split()
616
617     # first check for stable arch, stop there if it is found
618     if settings["ARCH"] in keywords:
619         return 0
620
621     if "~" + settings["ARCH"] in keywords:
622         pkgmask = pkgmask + 1
623     elif "-*" in keywords or "-" + settings["ARCH"] in keywords:
624         pkgmask = pkgmask + 2
625     
626     return pkgmask
627
628 def is_pkg_package_masked(cpv):
629
630     print_output(debug,portage.output.blue("is_pkg_package_masked called"))
631     mysplit = catpkgsplit(cpv)
632     if not mysplit:
633         raise ValueError("invalid CPV: %s" % cpv)
634     if not portage.portdb.cpv_exists(cpv):
635         return False
636
637     mycp = mysplit[0] + "/" + mysplit[1]
638
639     pmaskdict = settings._mask_manager._pmaskdict
640     if mycp in pmaskdict:
641         for package in pmaskdict[mycp]:
642             if cpv in portage.portdb.xmatch("match-all", package):
643                 return True
644                 
645     return False    
646
647 # filter out keywords for archs other than the current one
648 def filter_keywords(keywords):
649     filtered_keywords = ""
650
651     #for key in key_list:
652     for key in keywords:
653         key = key.replace("[", '')
654         key = key.replace("]", "")
655         key = key.replace(",", "")
656         arch=settings["ARCH"]
657
658         # remove '~' from key for comparison
659         key_comparison = key.lstrip('~')
660         if key_comparison == arch:
661             if len(filtered_keywords) != 0:
662                 filtered_keywords = filtered_keywords + " "
663             filtered_keywords = filtered_keywords + key
664         elif "-*" in key:
665             if len(filtered_keywords) != 0:
666                 filtered_keywords = filtered_keywords + " "
667             filtered_keywords = filtered_keywords + key
668
669
670     return filtered_keywords
671
672
673 # this function takes in a package with no cpv
674 # and returns True if any version is masked
675 def is_any_cpv_masked(package_name):
676     print_output(debug,portage.output.blue("inside is_any_cpv_masked: " + package_name))
677
678     query = Query(package_name, True)
679
680     packages = []
681     try:
682         packages = query.smart_find(True,True,True,True,False,True)
683     except errors.GentoolkitException as err:
684         print_output(debug,portage.output.blue("Package " + package_name + " not found."))
685
686     for package in packages:
687         if is_pkg_package_masked(package.cpv):
688             print_output(debug,portage.output.blue("Package " + package.cpv + " is masked."))
689             return True
690
691     print_output(debug,portage.output.blue("Package " + package_name + ". No masked versions."))
692     return False
693
694
695 # check to see if we have a stable release
696 # in our package.* files that we can remove
697 def check_for_stable_release(pkg):
698     if not is_pkg_package_masked(str(pkg.cpv)):
699         status = _get_mask_status(pkg, True)
700         if status == 0:
701             return True
702     return False
703
704 #print version info
705 def print_version():
706     # Print the version of this tool to the console.
707     print (__productname__ + "(" + __version__ + ") - " + \
708         __description__)
709     print ("Author(s): " + __author__)
710
711 # function to go through a ~cp without a version
712 # and set for removal from file if no masked package version exists
713 def check_tilde_masked_pkg(package_name, filename):
714     ebuild_output=""
715     variable_version = ""
716
717     orig_package_name = package_name
718     package_name = package_name.replace('~','')
719
720     print_output(debug,portage.output.blue("check_tilde_maskd_pkg: orig_package-name is " + orig_package_name))
721     print_output(debug,portage.output.blue("check_tilde_maskd_pkg: package_name is " + package_name))
722
723     query = Query(package_name, True)
724
725     packages = []
726     try:
727         packages = query.smart_find(True,True,True,True,False,True)
728     except errors.GentoolkitException as err:
729         print_output(debug,portage.output.blue("Package " + package_name + " not found."))
730
731     no_versions_installed = True
732     for package in packages:
733         if package.is_installed():
734             no_versions_installed = False
735
736     if (no_versions_installed == True):
737         ebuild_output = portage.output.yellow("\n" + package_name + ": ") + portage.output.red("Not Installed")
738         if "package.unmask" in filename:
739             unmask_list.append(orig_package_name)
740         if "package.keywords" in filename:
741             stable_list.append(orig_package_name)
742         if "package.accept_keywords" in filename:
743             stable_listNg.append(orig_package_name)
744         print (ebuild_output + portage.output.brown(" : " + filename))
745
746         return
747
748     # get all packages matching cat/package
749     if (packages != None):
750         for current_package in packages:
751             print_output(debug,portage.output.blue("check_tilde_maskd_pkg: current_package is " + str(current_package.cpv)))
752             print_output(debug,portage.output.blue("comparing " + package_name + " to " + str(current_package.cpv)))
753             if (pkgcmp(pkgsplit(package_name),pkgsplit(str(current_package.cpv))) <=0 ):
754             #if (pkgcmp(package_name, str(current_package.cpv)) <= 0):
755                 packageObj = gentoolkit.package.Package(str(current_package.cpv))
756                 if (packageObj == None):
757                     # we could not create a package object
758                     return
759                 pkgmask = _get_mask_status(packageObj, True)
760
761                 print_output(debug,portage.output.blue("check_tilde_maskd_pkg: current_package is " + str(current_package.cpv) + " and pkgmask is " + str(pkgmask)))
762
763                 if "package.unmask" in filename:
764                     if (is_pkg_package_masked(str(current_package.cpv))):
765                         # package was found as masked
766                         return
767                     else:
768                         # package is not masked
769                         unmask_list.append(str(current_package.cpv))
770                         ebuild_output = portage.output.yellow(str(current_package.cpv)) + ": " + portage.output.yellow("Not package masked")
771                         print_output(info,ebuild_output, package, filename)
772                         return
773                 else:
774                     if (pkgmask >= 1):
775                         # package was found as masked
776                         return 
777         else:
778             # at this point we have no packages >= ~cpv that are masked, present for removal
779             # package does not have any masked versions
780             ebuild_output = portage.output.green(package_name + " has no masked versions")
781             
782             if "package.unmask" in filename:
783                 unmask_list.append(orig_package_name)
784             if "package.keywords" in filename:
785                 stable_list.append(orig_package_name)
786             if "package.accept_keywords" in filename:
787                 stable_listNg.append(orig_package_name)
788             print_output(info,ebuild_output, package, filename)
789
790 #helper function to print avail pks when version does not exist
791 def show_all_versions(pkg, filename):
792
793     # is package masked
794     is_package_masked = False
795     pkgArr = portage.pkgsplit(pkg)
796
797     if pkgArr is None or len(pkgArr) == 0:
798         return
799
800     # determine if category/package is masked 
801     package = pkgArr[0]
802
803     operator = portage.dep.Atom(pkg).operator
804     if operator is not None:
805         package = package[len(operator):]
806
807     # package is category/package and pkg is category/package-version
808     # is category/package-version we are checking package masked?
809     #if portage.settings.pmaskdict.has_key(package):
810     pmaskdict = settings._mask_manager._pmaskdict
811     if package in pmaskdict:
812         pkg_list = pmaskdict.get(package)
813         # iterate through list array looking for pkg
814         for pkg_check in pkg_list:
815             operator = portage.get_operator(pkg_check)
816             if operator is None:
817                 if pkg_check == package:
818                     is_package_masked = True
819
820     query = Query(package)
821
822     all_pkgs = []
823
824     try:
825         all_pkgs = query.smart_find(True,True,True,True,False,True)
826     except errors.GentoolkitException as err:
827         print_output(debug,portage.output.blue("Package " + package + " not found."))
828
829     for current_package in all_pkgs:
830         keywords = "%s" % (current_package.environment("KEYWORDS").split())
831         keywords = filter_keywords(keywords)
832         keywords = "[%s]" % (keywords)
833         ebuild = current_package.ebuild_path()
834         if ebuild:
835             pkgmask = _get_mask_status(current_package, True)
836             if is_package_masked:
837                 print (portage.output.red("Available: " + str(current_package.cpv) + " [M] Keywords: " + keywords))
838             elif pkgmask > 4:
839                 print (portage.output.red("Available: " + str(current_package.cpv) + " [M] Keywords: " + keywords))
840             elif pkgmask == 4 or pkgmask == 1:
841                 print (portage.output.brown("Available: " + str(current_package.cpv) + " Keywords: " + keywords))
842             else:
843                 print (portage.output.green("Available: " + str(current_package.cpv) + " Keywords: " + keywords))
844                 if "package.keywords" in filename:
845                     stable_list.append(str(current_package.cpv))
846                 if "package.accept_keywords" in filename:
847                     stable_listNg.append(str(current_package.cpv))
848
849
850 def get_useflags(package):
851     iuse = get_iuse(package.cpv)
852     return iuse
853
854 def check_useflags_all_versions(pkgs, line, check_pkgs):
855
856     global useremove_display, invalid_flag_found 
857     invalid_flag_found = False
858    
859     print_output(debug,portage.output.blue("ENTERED check_useflags_all_versions: " + check_pkgs))
860
861     potential_invalid_flag = []
862     valid_flag_list = []
863     for package in pkgs:
864
865         # if package not installed, move on
866         if (not package.is_installed()):
867             continue;
868
869         print_output(debug,portage.output.blue("check_useflags_all_versions: package: " + package.cpv))
870         if ((package is None) or (package == "")):
871             return
872
873         useflag_removal_display=""
874
875         if (len(line) <= 0):
876             return
877
878         iuse = get_useflags(package)
879
880         #for iuse_item in iuse:
881         #    print_output(debug,portage.output.blue(("iuse_item is " + iuse_item)))
882     
883         useflags_fromfile = line.replace("\t", " ").split(" ")
884
885         #for useflags_fromfile_item in useflags_fromfile:
886         #    print_output(debug,portage.output.blue(("useflags_fromfile_item is " + useflags_fromfile_item)))
887
888         package_string = useflags_fromfile.pop(0)
889         print_output(debug,portage.output.blue(("package_string is " + package_string)))
890     
891         clean_useflags_list = []
892         # remove + or -
893         atom = "-+"
894     
895         #clean list from portage of + or -
896         clean_iuse = []
897         for item in iuse:
898             if item[0] in atom:
899                 clean_iuse.append(item[1:])
900             else:
901                 clean_iuse.append(item)
902     
903         for original_flag in useflags_fromfile:
904             if (original_flag is None or original_flag == ""):
905                 continue
906             flag = original_flag
907             if original_flag[0] in atom:
908                 flag = original_flag[1:]
909             if flag not in clean_iuse:
910                 print_output(debug,portage.output.blue(("found invalid flag: " + flag)))
911
912                 # only add to invalid list if it's not in valid list
913                 try:
914                     index = valid_flag_list.index(original_flag)
915                 except ValueError as error:
916
917                     try:
918                        index = potential_invalid_flag.index(original_flag)
919                     except ValueError:
920                        print_output(debug,portage.output.blue(original_flag + " not found for " + package.cpv))
921                        potential_invalid_flag.append(original_flag)
922
923             else:
924                 print_output(debug,portage.output.blue(("found valid flag: " + flag)))
925                 try:
926                     index = valid_flag_list.index(original_flag)
927                 except ValueError as error:
928                     valid_flag_list.append(original_flag)
929
930                 try:
931                     index = potential_invalid_flag.index(original_flag)
932                     potential_invalid_flag.remove(original_flag)
933                 except ValueError as error:
934                     continue
935
936
937     # if potential_invalid_flag list is empty, we are done
938     if (len(potential_invalid_flag) <= 0):
939         return
940
941     invalid_flag_found = True
942
943     # build sentence
944     invalid_flags = ""
945     verb = "is"
946     for inv_flag in potential_invalid_flag:
947         if (len(invalid_flags) > 0):
948             invalid_flags += ","
949             verb = "are"
950         invalid_flags += inv_flag
951
952     # if there are no valid flags at all, we remove the line
953     if ( len(valid_flag_list) == 0):
954         print_output (info,portage.output.red("No valid use flags found for package: " + str(package.category) + "/" + str(package.name) + ". Invalid flag(s) found: " + invalid_flags +  "\n"))
955         useremove_display += "Removing line: " + line + "\n"
956         use_flag_dict[line] = ""
957         return
958
959     # if there are values in potential_invalid_flag, we need to remove them
960
961     if (len(potential_invalid_flag) > 0):
962         removal_text = "use flags: "
963     else:
964         removal_text = "use flag: "
965
966     if ( (len(valid_flag_list) > 0)):
967         useremove_display += "Removing " + removal_text + invalid_flags + " for package " + check_pkgs + "\n"
968         print (portage.output.yellow(removal_text) +  portage.output.red(invalid_flags) + portage.output.yellow(" " + verb + " invalid for " + str(package.cpv)))
969
970     valid_flag_list.insert(0,package_string);
971
972     if (len(potential_invalid_flag) > 0):
973         use_flag_dict[line] = valid_flag_list
974         
975     return valid_flag_list
976
977 def check_useflags(package,line):
978
979     global useremove_display, invalid_flag_found 
980     invalid_flag_found = False
981
982     print_output(debug,portage.output.blue("check_useflags: package: " + package.cpv))
983     if ((package is None) or (package == "")):
984         return
985
986     useflag_removal_display=""
987
988     if (len(line) <= 0):
989         return
990
991     iuse = get_useflags(package)
992
993     #for iuse_item in iuse:
994     #    print_output(debug,portage.output.blue(("iuse_item is " + iuse_item)))
995
996     useflags_fromfile = line.replace("\t", " ").split(" ")
997     #for useflags_fromfile_item in useflags_fromfile:
998     #    print_output(debug,portage.output.blue(("useflags_fromfile_item is " + useflags_fromfile_item)))
999
1000     package_string = useflags_fromfile.pop(0)
1001     print_output(debug,portage.output.blue(("package_string is " + package_string)))
1002
1003     clean_useflags_list = []
1004     # remove + or -
1005     atom = "-+"
1006
1007     #clean list from portage of + or -
1008     clean_iuse = []
1009     for item in iuse:
1010         if item[0] in atom:
1011             clean_iuse.append(item[1:])
1012         else:
1013             clean_iuse.append(item)
1014
1015     valid_flag_list = []
1016     for original_flag in useflags_fromfile:
1017         if (original_flag is None or original_flag == ""):
1018             continue
1019         flag = original_flag
1020         if original_flag[0] in atom:
1021             flag = original_flag[1:]
1022         if flag not in clean_iuse:
1023             print_output (info,portage.output.red("use flag: " + flag + " is invalid for : " + str(package.cpv)))
1024             useflag_removal_display += "Removing use flag: " + flag + " for package " + str(package.cpv)
1025             invalid_flag_found = True
1026         else:
1027             valid_flag_list.append(original_flag)
1028
1029     # if valid_flag_list is empty, there are no valid flags
1030     if ( (len(valid_flag_list) > 0) and (len(useflag_removal_display) >0)):
1031         useremove_display += useflag_removal_display + "\n"
1032     elif ( len(valid_flag_list) == 0):
1033         useremove_display += "No valid use flags found for package " + str(package.cpv) + ". Removing line: " + line + "\n"
1034         if ( invalid_flag_found != True):
1035             print_output (info,portage.output.red("No valid use flags found for package " + str(package.cpv)))
1036         invalid_flag_found = True
1037
1038     valid_flag_list.insert(0,package_string);
1039     if (invalid_flag_found == True):
1040         use_flag_dict[line] = valid_flag_list
1041
1042     return valid_flag_list
1043
1044
1045 def clean_useflagsFile(filename):
1046
1047     if "--fix-confirm" in cmdline:
1048         if (confirmFix() == False):
1049             return
1050     
1051     display_line = ""
1052     removed_list = []
1053
1054     try:
1055         # determine if filename is a directory
1056         if os.path.isdir(filename):
1057             # get listing of directory
1058             filenames = os.listdir(filename)
1059             for file_name in filenames:
1060                 clean_useflagsFile(filename+os.path.sep+file_name)
1061             return
1062         else:
1063             #go through stable array and remove line if found
1064             for line in fileinput.input(filename,inplace =1):
1065                 itemFound = False
1066                 line = line.strip()
1067
1068                 # make sure line is not empty and do not remove commented out lines
1069                 if len(line) <= 0:
1070                     continue
1071                 elif line.find("#") == 0:
1072                     print (line)
1073                     continue
1074
1075                 check_for_change = ""
1076                 use_flag_dict.get(line,"")
1077                 try:
1078                     check_for_change = use_flag_dict[line]
1079                     removed_list.append(line)
1080                     if ( len(check_for_change) > 1):
1081                         print (" ".join(check_for_change))
1082                 except KeyError as error:
1083                     print (line)
1084
1085             fileinput.close()
1086     except OSError as error:
1087         print (portage.output.red("Modify/Read access to file: " + filename + " failed: " + format(error)))
1088
1089     if (len(removed_list) > 0):
1090         print ("\n")
1091         for package in removed_list:
1092             print (portage.output.red("Removing from: ") + portage.output.yellow(filename) + ": " + portage.output.green(package) + "\n")
1093     return
1094
1095 def handle_if_overlay(package):
1096     overlay_text = ""
1097     global print_overlay_flag,using_gentoo_as_overlay
1098
1099     if (using_gentoo_as_overlay):
1100         return overlay_text
1101
1102     print_overlay_flag = True
1103
1104     ebuild_path,overlay_path = porttree.dbapi.findname2(str(package.cpv))
1105     index = -1
1106     try:
1107         index = overlay_list.index(overlay_path)
1108     except ValueError as error:
1109         overlay_list.append(overlay_path)
1110         index = overlay_list.index(overlay_path)
1111
1112     overlay_text = " [%s]" % (str(index+1))
1113
1114     return overlay_text
1115
1116 # if the overlay_text was displayed to the user
1117 # we need to display the string at the end 
1118 # this array will store the overlays to be displayed
1119 def print_overlay_text():
1120    
1121     global print_overlay_flag
1122     
1123     if (not print_overlay_flag):
1124         return
1125     
1126     if (len(overlay_list) <= 0):
1127         return
1128
1129     index = 1
1130     for x in overlay_list:
1131         print (portage.output.turquoise("[" + str(index) + "] ") + x)
1132         index = index + 1
1133     
1134     print ("\n")
1135
1136 #helper function to print output
1137 def print_output(log_level,output_string, package=None, filename=None):
1138     
1139     global logLevel
1140
1141     if package != None:
1142         if (package.is_overlay()):
1143             output_string = "%s%s" % (output_string,portage.output.turquoise(handle_if_overlay(package)))
1144             #output_string = output_string + portage.output.turquoise(handle_if_overlay(package))
1145         else:
1146             if filename != None:
1147                 output_string = "%s%s" % (output_string,portage.output.brown(" : " + filename))
1148                 #output_string = output_string + portage.output.brown(" : " + filename)
1149
1150     if (log_level <= logLevel):
1151         print (output_string)
1152
1153 # remove stabled files that are no longer needed from package.keywords
1154 # or package.mask
1155 # includes support for etc/portage/package.keywords/<whatever>/package.keywords
1156 def cleanFile (filename):
1157
1158     removeDups = []
1159     removed_list = []
1160
1161     if "--fix-confirm" in cmdline:
1162         if (confirmFix() == False):
1163             return
1164
1165     # if the file or directory does not exist
1166     # exit out
1167     if (os.path.exists(filename) == False):
1168         return
1169     
1170     if "package.keywords" in filename:
1171         if ( len(stable_list) == 0):
1172             return
1173         removeDups = stable_list
1174     elif "package.accept_keywords" in filename:
1175         if ( len(stable_listNg) == 0):
1176             return
1177         removeDups = stable_listNg
1178     else:
1179         if ( len(unmask_list) == 0):
1180             return
1181         removeDups = unmask_list
1182
1183     removedDict = {}
1184
1185     try:
1186         # determine if filename is a directory
1187         if os.path.isdir(filename):
1188             # get listing of directory
1189             filenames = os.listdir(filename)
1190             for file_name in filenames:
1191                 cleanFile(filename+os.path.sep+file_name)
1192             return
1193         else:   
1194             #go through stable array and remove line if found
1195             for line in fileinput.input(filename,inplace =1):
1196                 itemFound = False
1197                 line = line.strip()
1198
1199                 # make sure line is not empty and do not remove commented out lines
1200                 if len(line) <= 0:
1201                     continue
1202                 elif line.find("#") == 0:
1203                     print (line)
1204                     continue
1205
1206                 for item in removeDups:
1207                     if item in line:
1208                         removed_list.append(item)
1209                         removedDict[filename] = item
1210                         itemFound = True
1211                         removeDups.pop(removeDups.index(item))
1212                         break
1213                 if (itemFound == False):
1214                     print (line)
1215             fileinput.close()
1216     except OSError as error:
1217         print (portage.output.red("Modify/Read access to file: " + filename + " failed: " + format(error)))
1218     
1219     if (len(removed_list) > 0):
1220         print ("\n")
1221         for package in removed_list:
1222             print (portage.output.red("Removing from: ") + portage.output.yellow(filename) + ": " + portage.output.green(package) + "\n")
1223
1224 # ask the user if they want to fix their files
1225 # and remove unneeded entries
1226 # Return true if they say yes and False if they say no
1227 def confirmFix():
1228     
1229     global fix_asked,fix_confirm
1230
1231     if (fix_asked == True):
1232         return fix_confirm
1233
1234     # only ask if we actually have anything to check
1235     if ( (len(stable_list) == 0) and 
1236           (len(stable_listNg) == 0) and
1237           (len(unmask_list) == 0) and
1238           (invalid_flag_found == False) and 
1239           (len(use_flag_dict) == 0)):
1240         fix_confirm = True
1241         return fix_confirm
1242
1243     fix_asked = True 
1244
1245     valid = {"yes":"yes",   "y":"yes", 
1246              "no":"no",     "n":"no"}
1247    
1248     prompt = portage.output.bold("Remove entries from files [") + portage.output.green("y") + "/" + portage.output.red("n") + portage.output.bold("]") + " "
1249
1250     while 1:
1251         sys.stdout.write('\n' + prompt)
1252         choice = input().lower()
1253         if choice == '':
1254             fix_confirm = False
1255             break
1256         elif choice in valid.keys():
1257             if (choice == 'y' or choice == 'yes'):
1258                 fix_confirm = True
1259                 break
1260             else:
1261                 fix_confirm = False
1262                 break 
1263         else:
1264             sys.stdout.write("Please respond with 'yes' or 'no' "\
1265                              "(or 'y' or 'n').\n")
1266
1267     return fix_confirm
1268
1269
1270 def check_for_any_installed_version(pkgs):
1271     
1272     for package in pkgs:
1273         if (package.is_installed()):
1274             return True
1275
1276     return False
1277
1278 # main
1279 if __name__ == "__main__":
1280
1281     if len(sys.argv) == 1:
1282         print_usage()
1283         sys.exit(1)
1284
1285     # soooooo stolen from emerge
1286     tmpcmdline = sys.argv[1:]
1287
1288     for cmd in tmpcmdline:
1289         if cmd[0:1] == "-" and cmd[1:2] != "-":
1290             for cmd_item in cmd[1:]:
1291                 if cmd_item in mappings:
1292                     if mappings[cmd_item] in cmdline:
1293                         print ()
1294                         print ("*** Warning: Redundant use of ", mappings[cmd_item])
1295                     else:
1296                         cmdline.append(mappings[cmd_item])
1297                 else:
1298                     print ("!!! Error: -"+cmd_item+" is an invalid option.")
1299                     sys.exit(-1)
1300         else:
1301             cmdline.append(cmd)
1302
1303     #parse long options
1304     for cmd in cmdline:
1305         if len(cmd)>=2 and cmd[0:2]=="--":
1306             try:
1307                 i = options.index(cmd)
1308                 continue
1309             except ValueError:
1310                 print ("!!! Error: -"+cmd+" is an invalid option.")
1311                 sys.exit(-1)
1312
1313     if "--changes-only" in cmdline:
1314         cmdline.remove("--changes-only")
1315         show_changes_only_flag = True
1316
1317     if "--removable-only" in cmdline:
1318         cmdline.remove("--removable-only")
1319         show_removable_only_flag = True
1320
1321     if "--debug" in cmdline:
1322         logLevel = debug
1323
1324     if "--no-color" in cmdline:
1325         portage.output.nocolor()
1326
1327     if "--tilde-check" in cmdline:
1328         tilde=1
1329
1330     if "--version" in cmdline:
1331         print_version()
1332         sys.exit(0)
1333
1334     if "--fix-confirm" in cmdline:
1335         if '--fix' not in cmdline:
1336             cmdline.append("--fix")
1337     
1338     if "--all" in cmdline:
1339         tmpcmdline = ["--all"]
1340         if "--fix" in cmdline:
1341             tmpcmdline.append("--fix")
1342             if "--fix-confirm" in cmdline:
1343                 tmpcmdline.append("--fix-confirm")
1344                 fix_confirm = False
1345         cmdline=tmpcmdline      
1346
1347     if "--help" in cmdline:
1348         print_usage()
1349         sys.exit(0)
1350     
1351     if (show_changes_only_flag and show_removable_only_flag):
1352         print ("Please select only one of --show-removable (-r) or --changes-only")
1353         print ("Use --help for more info.")
1354         sys.exit(0)
1355         
1356     for cmd in cmdline:
1357         if cmd == "--keyword":
1358             print (portage.output.bold("\npackage.keywords:"))
1359             get_recursive_info(USER_CONFIG_PATH + "/package.keywords")
1360             if "--fix" in cmdline:
1361                 cleanFile(USER_CONFIG_PATH + "/package.keywords")
1362             print (portage.output.bold("Done\n"))
1363             print (portage.output.bold("\npackage.accept_keywords:"))
1364             get_recursive_info(USER_CONFIG_PATH + "/package.accept_keywords")
1365             if "--fix" in cmdline:
1366                 cleanFile(USER_CONFIG_PATH + "/package.accept_keywords")
1367             print (portage.output.bold("Done\n"))
1368         elif cmd == "--unmask": 
1369             print (portage.output.bold("\npackage.unmask:"))
1370             checking_package_unmask = True
1371             get_recursive_info(USER_CONFIG_PATH + "/package.unmask")
1372             checking_package_unmask = False
1373             if "--fix" in cmdline:
1374                 cleanFile(USER_CONFIG_PATH + "/package.unmask")
1375         elif cmd == "--mask":
1376             checking_package_mask = True
1377             print (portage.output.bold("\npackage.mask:"))
1378             get_recursive_info(USER_CONFIG_PATH + "/package.mask")
1379             print (portage.output.bold("Done\n"))
1380             checking_package_mask = False
1381             if "--fix" in cmdline:
1382                 cleanFile(USER_CONFIG_PATH + "/package.mask")
1383         elif cmd == "--package-use":
1384             print (portage.output.bold("\npackage.use:"))
1385             processing_package_use = True
1386             get_recursive_info(USER_CONFIG_PATH + "/package.use")
1387             if "--fix" in cmdline:
1388                 cleanFile(USER_CONFIG_PATH + "/package.use")
1389                 clean_useflagsFile(USER_CONFIG_PATH + "/package.use")
1390             print (portage.output.bold("Done\n"))
1391         elif cmd == "--all":
1392             print (portage.output.bold("\npackage.keywords:"))
1393             get_recursive_info(USER_CONFIG_PATH + "/package.keywords")
1394             print (portage.output.bold("\npackage.accept_keywords:"))
1395             get_recursive_info(USER_CONFIG_PATH + "/package.accept_keywords")
1396             print (portage.output.bold("\npackage.unmask:"))
1397             checking_package_unmask = True
1398             get_recursive_info(USER_CONFIG_PATH + "/package.unmask")
1399             checking_package_unmask = False
1400             checking_package_mask = True
1401             print (portage.output.bold("\npackage.mask:"))
1402             get_recursive_info(USER_CONFIG_PATH + "/package.mask")
1403             print (portage.output.bold("\npackage.use:"))
1404             processing_package_use = True
1405             get_recursive_info(USER_CONFIG_PATH + "/package.use")
1406             if "--fix" in cmdline:
1407                 cleanFile(USER_CONFIG_PATH + "/package.keywords")
1408                 cleanFile(USER_CONFIG_PATH + "/package.accept_keywords")
1409                 cleanFile(USER_CONFIG_PATH + "/package.unmask")
1410                 cleanFile(USER_CONFIG_PATH + "/package.use")
1411                 cleanFile(USER_CONFIG_PATH + "/package.mask")
1412                 clean_useflagsFile(USER_CONFIG_PATH + "/package.use")
1413             print (portage.output.bold("\nDone\n"))
1414
1415     print_overlay_text()
1416
1417     if len(cmdline) == 0:
1418         if show_changes_only_flag or show_removable_only_flag:
1419             if (show_changes_only_flag):
1420                 print (portage.output.green("-c") + " or " + portage.output.green("--changes-only") + " must be accompanied by one of the following:")
1421             else:
1422                 print (portage.output.green("-r") + " or " + portage.output.green("--removable-only") + " must be accompanied by one of the following:")
1423
1424             print ("     " + portage.output.yellow("-k") + " or " + portage.output.yellow("--keyword"))
1425             print ("     " + portage.output.yellow("-u") + " or " + portage.output.yellow("--unmask"))
1426             print ("     " + portage.output.yellow("-m") + " or " + portage.output.yellow("--mask"))
1427             print ("     " + portage.output.yellow("-a") + " or " + portage.output.yellow("--all"))
1428
1429             print_usage()
1430