Fix pattern match. Bump version
[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.8"
20 __productname__ = "portpeek"
21 __description__ = "Displays user unmasked ebuilds and installable options from the portage tree"
22
23 import sys, os, portage, 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 #settings = portage.config(local_config=False)
41
42 show_changes_only_flag = False
43 checking_package_unmask = False
44 checking_package_mask = False
45 print_overlay_flag = False
46 info = 0
47 debug = 1
48 logLevel = info
49 show_removable_only_flag = False
50 stable_list = []
51 stable_listNg = [] # handle package.accept_keywords
52 unmask_list = []
53 tilde = 0
54 processing_package_use = False
55 using_gentoo_as_overlay = False
56 overlay_list = []
57 fix_confirm = True
58 fix_asked = False
59 use_flag_dict = {}
60 useremove_display = ""
61 invalid_flag_found = False
62
63 try:
64     PORTAGE_CONFIGROOT
65 except NameError:
66     PORTAGE_CONFIGROOT="/"
67
68 USER_CONFIG_PATH=PORTAGE_CONFIGROOT + USER_CONFIG_PATH
69
70 #parameters
71 options = [
72 "--keyword",
73 "--unmask",
74 "--mask",
75 "--all",
76 "--changes-only",
77 "--version",
78 "--version",
79 "--help",
80 "--removable-only",
81 "--debug",
82 "--fix", 
83 "--tilde-check",
84 "--no-color",
85 "--package-use",
86 "--fix-confirm"
87 ]
88
89 mappings = {
90 "k":"--keyword",
91 "u":"--unmask",
92 "m":"--mask",
93 "a":"--all",
94 "c":"--changes-only",
95 "V":"--version",
96 "v":"--version",
97 "h":"--help",
98 "r":"--removable-only",
99 "d":"--debug",
100 "f":"--fix", 
101 "t":"--tilde-check",
102 "n":"--no-color",
103 "s":"--package-use",
104 "q":"--fix-confirm"
105 }
106
107 cmdline = []
108 overlays = [settings["PORTDIR_OVERLAY"]]
109
110 def print_usage():
111     # Print full usage information for this tool to the console.
112     print ("\nUsage: " + portage.output.turquoise(__productname__) +  portage.output.yellow(" command "))
113     print ("       " + portage.output.turquoise(__productname__) + portage.output.green(" [ options ]") +  portage.output.yellow(" command "))
114     print ("       " + portage.output.turquoise(__productname__) + portage.output.green(" [-c]") + portage.output.yellow(" [akmu]"))
115     print ("       " + portage.output.turquoise(__productname__) + portage.output.green(" [-r]") + portage.output.yellow(" [akmu]"))
116     print ("       " + portage.output.turquoise(__productname__) + portage.output.green(" [-f]") + portage.output.yellow(" [akmu]"))
117     print ("       " + portage.output.turquoise(__productname__) + portage.output.green(" [-F]") + portage.output.yellow(" [akmu]"))
118     print (portage.output.yellow(" command ") + " can be ")
119     print (portage.output.yellow(" -a, --all") + "       - show all matches")
120     print (portage.output.yellow(" -k, --keyword") + "       - show matches from package.keywords and package.accept_keywords only")
121     print (portage.output.yellow(" -m, --mask") + "      - show matches from package.mask only")
122     print (portage.output.yellow(" -u, --unmask") + "        - show matched from package.unmask only")
123     print (portage.output.yellow(" -s, --package.use") + "   - show matches from package.use only")
124     
125     print (portage.output.yellow(" -f, --fix") + "       - will remove the stabled and invalid packages without asking for confirmation")
126     print (portage.output.yellow(" -q, --confirm-fix") +"    - will remove the stabled and invalid packages asking for confirmation before doing so")
127     print (portage.output.yellow(" -h, --help") + "      - display this message")
128     print (portage.output.yellow(" -d, --debug") + "         - display more verbose output for debugging")
129     print (portage.output.yellow(" -V, --version") + "       - display version info")
130     print (portage.output.green("options") + " are ")
131     print (portage.output.green(" -c, --changes-only") + \
132         "   - show all matches that have upgrade option, use with " + \
133         "<" + portage.output.yellow(" k ") + "|" + portage.output.yellow(" u ") + \
134         "|" + portage.output.yellow(" m ") + "|" + \
135         portage.output.yellow(" a ") + ">")
136     print (portage.output.green(" -n, --no-color") + \
137         "   - suppress color output")
138     print (portage.output.green(" -r, --removable-only") + \
139         "   - show all matches that can be removed from package files, use with " + \
140         "<" + portage.output.yellow(" k ") + "|" + portage.output.yellow(" u ") + \
141         "|" + portage.output.yellow(" m ") + "|" + \
142         portage.output.yellow(" a ") + ">\n")
143
144 def get_keywords(package, var):
145     mytree = porttree
146     filtered_keywords = ""
147     try:
148         keywords = package.environment("KEYWORDS").split()
149     except KeyError as error:
150         print ("!!! Portpeek caught Exception:" + format(error))
151         print ("!!! This package/version seems to be no longer available, " + \
152         "please check and update/unmerge it") 
153         return "Not Available/Deprecated"
154     
155     #filtered_keywords = filter_keywords(keywords[0])
156     filtered_keywords = filter_keywords(keywords)
157     return filtered_keywords
158
159
160
161 # this is the main function for portpeek
162 # TODO comment this code!
163 def parse_line(line, filename):     
164     global info,debug,using_gentoo_as_overlay
165
166     using_gentoo_as_overlay = False
167     pkgs = None
168     ebuild_output = ""
169     check_pkg = ""
170     not_installed_pkgs = 0
171     pkg_length = 0
172     atom_check="<>=~"
173     original_line = line
174
175     # if the line has special characters, we need to make sure the original line is used for matching
176     special_line = False
177
178     pattern=r'[<>:*]'
179
180     if ( (re.search(pattern,line) != None) ):
181         special_line = True
182
183     print_output(debug,portage.output.blue("Analyzing line: " + line))
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             if check_pkg[0] in atom_check:
475                 check_pkg = check_pkg[1:]
476
477
478         # if there is a wildcard, check to make sure at least one
479         # of the packages is installed
480         if check_pkg.find("/*") >= 0:
481             query = Query(check_pkg)
482             pkgs = []
483             try:
484                 pkgs = query.smart_find(True,True,True,True,False,True)
485             except errors.GentoolkitException as err:
486                 print_output(debug,portage.output.blue("parse_package_use: Package " + check_pkg + " not found."))
487                 return False
488
489             if (pkgs != None):
490                 pkg_length = len(pkgs)
491             for current_package in pkgs:
492                 # on wildcard scenario, return False if one package is installed
493                 if current_package.is_installed():
494                     check_useflags(current_package,line)
495                     return False
496         else:
497             # look for any version of check_pkg installed as there is 
498             # no version specified in package.use
499             package_exists = portage.portdb.xmatch("match-all", check_pkg)
500             if package_exists:
501                 # get all package versions
502                 query = Query(check_pkg)
503                 pkgs = []
504                 try:
505                     pkgs = query.smart_find(True,True,True,True,False,True)
506                 except errors.GentoolkitException as err:
507                     print_output(debug,portage.output.blue("Package " + check_pkg + " not found."))
508     
509                 if (pkgs != None):
510                     pkg_length = len(pkgs)
511     
512                     # go through each package version for a specific 
513                     # version found above
514                     # if one line check returns all ok, we don't need 
515                     #to check the rest. One slot could have different 
516                     #use flags than another
517                     if (has_atom == False):
518                         check_useflags_all_versions(pkgs, line, check_pkg)
519                         package_installed = check_for_any_installed_version(pkgs)
520                         current_package = None
521
522                         #for current_package in pkgs:
523                         #    if current_package.is_installed():
524                         #        check_useflags(current_package,line)
525                         #        package_installed = True
526                         #        if (invalid_flag_found == False):
527                         #            break;
528                     else: 
529                         # go through each package version for a specific version found above
530                         for current_package in pkgs:
531                             if (str(current_package.cpv) == check_pkg):
532                                 if not current_package.is_installed():
533                                     print_output(info,portage.output.yellow("\n" + check_pkg + ": ") + portage.output.red("Not Installed"),current_package)
534                                     if "package.keywords" in filename:
535                                         stable_list.append(check_pkg)
536                                     if "package.accept_keywords" in filename:
537                                         stable_listNg.append(check_pkg)
538                                     unmask_list.append(check_pkg)
539                                     if "package.use" in filename:
540                                         valid_flag_list = []
541                                         valid_flag_list.insert(0,current_package);
542                                         use_flag_dict[line] = valid_flag_list
543                                         check_for_change = use_flag_dict[line]
544                                     return True
545                                 else:
546                                     check_useflags(current_package,line)
547                                     return False
548             else:
549                 print (portage.output.red ("\nPackage: " + fields[0] + " not found. Please check " + filename + " to validate entry"))
550                 if "package.keywords" in filename:
551                     stable_list.append(check_pkg)
552                 if "package.accept_keywords" in filename:
553                     stable_listNg.append(check_pkg)
554                 unmask_list.append(check_pkg)
555                 if "package.use" in filename:
556                     valid_flag_list = []
557                     #valid_flag_list.insert(0,current_package);
558                     valid_flag_list.insert(0,fields[0]);
559                     use_flag_dict[line] = valid_flag_list
560                     check_for_change = use_flag_dict[line]
561                 return True
562
563     if (package_installed == False):
564         # package does not exists
565         print_output(info,portage.output.yellow("\n" + check_pkg + ": ") + portage.output.red("Not Installed"),current_package)
566         if "package.keywords" in filename:
567             stable_list.append(check_pkg)
568         if "package.accept_keywords" in filename:
569             stable_listNg.append(check_pkg)
570         if "package.use" in filename:
571             valid_flag_list = []
572             valid_flag_list.insert(0,current_package);
573             use_flag_dict[line] = valid_flag_list
574             check_for_change = use_flag_dict[line]
575
576         unmask_list.append(check_pkg)
577         return True
578
579     return False
580
581
582
583
584 # skip the file if portpeek-skip found in a comment
585 # you can put this in the middle of a file and it will
586 #skip all entrie below it, this is useful to speed things
587 #up by not checking ~kde versions, for example
588 def skipFile (line, filename):
589     if ( (line == None) or (filename == None)):
590         return False
591
592     if line.find("portpeek-skip") >= 0:
593         return True
594
595     return False
596
597 # parts blatantly stolen from equery
598 # if pure is true, then get "true" mask status that is
599 # not affected by entries in /etc/portage/package.*
600 def _get_mask_status(pkg, pure):
601     pkgmask = 0
602
603     if (pkg == None):
604         return 0
605
606     if pkg.is_masked():
607         pkgmask = pkgmask + 3
608
609     if pure:
610         try:
611             keywords = portage.portdb.aux_get(str(pkg.cpv), ["KEYWORDS"])
612             keywords = keywords[0].split()
613         except KeyError:
614             # cpv does not exist
615             return 0
616     else:
617         keywords = pkg.environment("KEYWORDS").split()
618
619     # first check for stable arch, stop there if it is found
620     if settings["ARCH"] in keywords:
621         return 0
622
623     if "~" + settings["ARCH"] in keywords:
624         pkgmask = pkgmask + 1
625     elif "-*" in keywords or "-" + settings["ARCH"] in keywords:
626         pkgmask = pkgmask + 2
627     
628     return pkgmask
629
630 def is_pkg_package_masked(cpv):
631
632     print_output(debug,portage.output.blue("is_pkg_package_masked called: " + cpv))
633     settings2 = portage.config(local_config=False)
634     portdb2 = portage.portdbapi(None, settings)
635
636     mask_reason_list = None
637     
638     try:
639         for mask_reason_list in portage.getmaskingstatus(cpv, settings2, portdb=portdb2):
640             return True
641     except:
642         return False
643
644     return False
645
646 # filter out keywords for archs other than the current one
647 def filter_keywords(keywords):
648     filtered_keywords = ""
649
650     #for key in key_list:
651     for key in keywords:
652         key = key.replace("[", '')
653         key = key.replace("]", "")
654         key = key.replace(",", "")
655         arch=settings["ARCH"]
656
657         # remove '~' from key for comparison
658         key_comparison = key.lstrip('~')
659         if key_comparison == arch:
660             if len(filtered_keywords) != 0:
661                 filtered_keywords = filtered_keywords + " "
662             filtered_keywords = filtered_keywords + key
663         elif "-*" in key:
664             if len(filtered_keywords) != 0:
665                 filtered_keywords = filtered_keywords + " "
666             filtered_keywords = filtered_keywords + key
667
668
669     return filtered_keywords
670
671
672 # this function takes in a package with no cpv
673 # and returns True if any version is masked
674 def is_any_cpv_masked(package_name):
675     print_output(debug,portage.output.blue("inside is_any_cpv_masked: " + package_name))
676
677     query = Query(package_name, True)
678
679     packages = []
680     try:
681         packages = query.smart_find(True,True,True,True,False,True)
682     except errors.GentoolkitException as err:
683         print_output(debug,portage.output.blue("Package " + package_name + " not found."))
684
685     for package in packages:
686         if is_pkg_package_masked(package.cpv):
687             print_output(debug,portage.output.blue("Package " + package.cpv + " is masked."))
688             return True
689
690     print_output(debug,portage.output.blue("Package " + package_name + ". No masked versions."))
691     return False
692
693
694 # check to see if we have a stable release
695 # in our package.* files that we can remove
696 def check_for_stable_release(pkg):
697     if not is_pkg_package_masked(str(pkg.cpv)):
698         status = _get_mask_status(pkg, True)
699         if status == 0:
700             return True
701     return False
702
703 #print version info
704 def print_version():
705     # Print the version of this tool to the console.
706     print (__productname__ + "(" + __version__ + ") - " + \
707         __description__)
708     print ("Author(s): " + __author__)
709
710 # function to go through a ~cp without a version
711 # and set for removal from file if no masked package version exists
712 def check_tilde_masked_pkg(package_name, filename):
713     ebuild_output=""
714     variable_version = ""
715
716     orig_package_name = package_name
717     package_name = package_name.replace('~','')
718
719     print_output(debug,portage.output.blue("check_tilde_maskd_pkg: orig_package-name is " + orig_package_name))
720     print_output(debug,portage.output.blue("check_tilde_maskd_pkg: package_name is " + package_name))
721
722     query = Query(package_name, True)
723
724     packages = []
725     try:
726         packages = query.smart_find(True,True,True,True,False,True)
727     except errors.GentoolkitException as err:
728         print_output(debug,portage.output.blue("Package " + package_name + " not found."))
729
730     no_versions_installed = True
731     for package in packages:
732         if package.is_installed():
733             no_versions_installed = False
734
735     if (no_versions_installed == True):
736         ebuild_output = portage.output.yellow("\n" + package_name + ": ") + portage.output.red("Not Installed")
737         if "package.unmask" in filename:
738             unmask_list.append(orig_package_name)
739         if "package.keywords" in filename:
740             stable_list.append(orig_package_name)
741         if "package.accept_keywords" in filename:
742             stable_listNg.append(orig_package_name)
743         print (ebuild_output + portage.output.brown(" : " + filename))
744
745         return
746
747     # get all packages matching cat/package
748     if (packages != None):
749         for current_package in packages:
750             print_output(debug,portage.output.blue("check_tilde_maskd_pkg: current_package is " + str(current_package.cpv)))
751             print_output(debug,portage.output.blue("comparing " + package_name + " to " + str(current_package.cpv)))
752             if (pkgcmp(pkgsplit(package_name),pkgsplit(str(current_package.cpv))) <=0 ):
753             #if (pkgcmp(package_name, str(current_package.cpv)) <= 0):
754                 packageObj = gentoolkit.package.Package(str(current_package.cpv))
755                 if (packageObj == None):
756                     # we could not create a package object
757                     return
758
759                 if "package.unmask" in filename:
760                     if (is_pkg_package_masked(str(current_package.cpv))):
761                         # package was found as masked
762                         return
763                     else:
764                         # package is not masked
765                         unmask_list.append(str(current_package.cpv))
766                         ebuild_output = portage.output.yellow(str(current_package.cpv)) + ": " + portage.output.yellow("Not package masked")
767                         print_output(info,ebuild_output, package, filename)
768                         return
769                 else:
770                     if (is_pkg_package_masked(str(current_package.cpv))):
771                         # package was found as masked
772                         return 
773         else:
774             # at this point we have no packages >= ~cpv that are masked, present for removal
775             # package does not have any masked versions
776             ebuild_output = portage.output.green(package_name + " has no masked versions")
777             
778             if "package.unmask" in filename:
779                 unmask_list.append(orig_package_name)
780             if "package.keywords" in filename:
781                 stable_list.append(orig_package_name)
782             if "package.accept_keywords" in filename:
783                 stable_listNg.append(orig_package_name)
784             print_output(info,ebuild_output, package, filename)
785
786 #helper function to print avail pks when version does not exist
787 def show_all_versions(pkg, filename):
788
789     # is package masked
790     is_package_masked = False
791     pkgArr = portage.pkgsplit(pkg)
792
793     if pkgArr is None or len(pkgArr) == 0:
794         return
795
796     # determine if category/package is masked 
797     package = pkgArr[0]
798
799     operator = portage.dep.Atom(pkg).operator
800     if operator is not None:
801         package = package[len(operator):]
802
803     # package is category/package and pkg is category/package-version
804     # is category/package-version we are checking package masked?
805     #if portage.settings.pmaskdict.has_key(package):
806     pmaskdict = settings._mask_manager._pmaskdict
807     if package in pmaskdict:
808         pkg_list = pmaskdict.get(package)
809         # iterate through list array looking for pkg
810         for pkg_check in pkg_list:
811             operator = portage.get_operator(pkg_check)
812             if operator is None:
813                 if pkg_check == package:
814                     is_package_masked = True
815
816     query = Query(package)
817
818     all_pkgs = []
819
820     try:
821         all_pkgs = query.smart_find(True,True,True,True,False,True)
822     except errors.GentoolkitException as err:
823         print_output(debug,portage.output.blue("Package " + package + " not found."))
824
825     for current_package in all_pkgs:
826         keywords = "%s" % (current_package.environment("KEYWORDS").split())
827         keywords = filter_keywords(keywords)
828         keywords = "[%s]" % (keywords)
829         ebuild = current_package.ebuild_path()
830         if ebuild:
831             pkgmask = _get_mask_status(current_package, True)
832             if is_package_masked:
833                 print (portage.output.red("Available: " + str(current_package.cpv) + " [M] Keywords: " + keywords))
834             elif pkgmask > 4:
835                 print (portage.output.red("Available: " + str(current_package.cpv) + " [M] Keywords: " + keywords))
836             elif pkgmask == 4 or pkgmask == 1:
837                 print (portage.output.brown("Available: " + str(current_package.cpv) + " Keywords: " + keywords))
838             else:
839                 print (portage.output.green("Available: " + str(current_package.cpv) + " Keywords: " + keywords))
840                 if "package.keywords" in filename:
841                     stable_list.append(str(current_package.cpv))
842                 if "package.accept_keywords" in filename:
843                     stable_listNg.append(str(current_package.cpv))
844
845
846 def get_useflags(package):
847     iuse = get_iuse(package.cpv)
848     return iuse
849
850 def check_useflags_all_versions(pkgs, line, check_pkgs):
851
852     global useremove_display, invalid_flag_found 
853     invalid_flag_found = False
854    
855     print_output(debug,portage.output.blue("ENTERED check_useflags_all_versions: " + check_pkgs))
856
857     potential_invalid_flag = []
858     valid_flag_list = []
859     for package in pkgs:
860
861         # if package not installed, move on
862         if (not package.is_installed()):
863             continue;
864
865         print_output(debug,portage.output.blue("check_useflags_all_versions: package: " + package.cpv))
866         if ((package is None) or (package == "")):
867             return
868
869         useflag_removal_display=""
870
871         if (len(line) <= 0):
872             return
873
874         iuse = get_useflags(package)
875
876         #for iuse_item in iuse:
877         #    print_output(debug,portage.output.blue(("iuse_item is " + iuse_item)))
878     
879         useflags_fromfile = line.replace("\t", " ").split(" ")
880
881         #for useflags_fromfile_item in useflags_fromfile:
882         #    print_output(debug,portage.output.blue(("useflags_fromfile_item is " + useflags_fromfile_item)))
883
884         package_string = useflags_fromfile.pop(0)
885         print_output(debug,portage.output.blue(("package_string is " + package_string)))
886     
887         clean_useflags_list = []
888         # remove + or -
889         atom = "-+"
890     
891         #clean list from portage of + or -
892         clean_iuse = []
893         for item in iuse:
894             if item[0] in atom:
895                 clean_iuse.append(item[1:])
896             else:
897                 clean_iuse.append(item)
898     
899         for original_flag in useflags_fromfile:
900             if (original_flag is None or original_flag == ""):
901                 continue
902             flag = original_flag
903             if original_flag[0] in atom:
904                 flag = original_flag[1:]
905             if flag not in clean_iuse:
906                 print_output(debug,portage.output.blue(("found invalid flag: " + flag)))
907
908                 # only add to invalid list if it's not in valid list
909                 try:
910                     index = valid_flag_list.index(original_flag)
911                 except ValueError as error:
912
913                     try:
914                        index = potential_invalid_flag.index(original_flag)
915                     except ValueError:
916                        print_output(debug,portage.output.blue(original_flag + " not found for " + package.cpv))
917                        potential_invalid_flag.append(original_flag)
918
919             else:
920                 print_output(debug,portage.output.blue(("found valid flag: " + flag)))
921                 try:
922                     index = valid_flag_list.index(original_flag)
923                 except ValueError as error:
924                     valid_flag_list.append(original_flag)
925
926                 try:
927                     index = potential_invalid_flag.index(original_flag)
928                     potential_invalid_flag.remove(original_flag)
929                 except ValueError as error:
930                     continue
931
932
933     # if potential_invalid_flag list is empty, we are done
934     if (len(potential_invalid_flag) <= 0):
935         return
936
937     invalid_flag_found = True
938
939     # build sentence
940     invalid_flags = ""
941     verb = "is"
942     for inv_flag in potential_invalid_flag:
943         if (len(invalid_flags) > 0):
944             invalid_flags += ","
945             verb = "are"
946         invalid_flags += inv_flag
947
948     # if there are no valid flags at all, we remove the line
949     if ( len(valid_flag_list) == 0):
950         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"))
951         useremove_display += "Removing line: " + line + "\n"
952         use_flag_dict[line] = ""
953         return
954
955     # if there are values in potential_invalid_flag, we need to remove them
956
957     if (len(potential_invalid_flag) > 0):
958         removal_text = "use flags: "
959     else:
960         removal_text = "use flag: "
961
962     if ( (len(valid_flag_list) > 0)):
963         useremove_display += "Removing " + removal_text + invalid_flags + " for package " + check_pkgs + "\n"
964         print (portage.output.yellow(removal_text) +  portage.output.red(invalid_flags) + portage.output.yellow(" " + verb + " invalid for " + str(package.cpv)))
965
966     valid_flag_list.insert(0,package_string);
967
968     if (len(potential_invalid_flag) > 0):
969         use_flag_dict[line] = valid_flag_list
970         
971     return valid_flag_list
972
973 def check_useflags(package,line):
974
975     global useremove_display, invalid_flag_found 
976     invalid_flag_found = False
977
978     print_output(debug,portage.output.blue("check_useflags: package: " + package.cpv))
979     if ((package is None) or (package == "")):
980         return
981
982     useflag_removal_display=""
983
984     if (len(line) <= 0):
985         return
986
987     iuse = get_useflags(package)
988
989     #for iuse_item in iuse:
990     #    print_output(debug,portage.output.blue(("iuse_item is " + iuse_item)))
991
992     useflags_fromfile = line.replace("\t", " ").split(" ")
993     #for useflags_fromfile_item in useflags_fromfile:
994     #    print_output(debug,portage.output.blue(("useflags_fromfile_item is " + useflags_fromfile_item)))
995
996     package_string = useflags_fromfile.pop(0)
997     print_output(debug,portage.output.blue(("package_string is " + package_string)))
998
999     clean_useflags_list = []
1000     # remove + or -
1001     atom = "-+"
1002
1003     #clean list from portage of + or -
1004     clean_iuse = []
1005     for item in iuse:
1006         if item[0] in atom:
1007             clean_iuse.append(item[1:])
1008         else:
1009             clean_iuse.append(item)
1010
1011     valid_flag_list = []
1012     for original_flag in useflags_fromfile:
1013         if (original_flag is None or original_flag == ""):
1014             continue
1015         flag = original_flag
1016         if original_flag[0] in atom:
1017             flag = original_flag[1:]
1018         if flag not in clean_iuse:
1019             print_output (info,portage.output.red("use flag: " + flag + " is invalid for : " + str(package.cpv)))
1020             useflag_removal_display += "Removing use flag: " + flag + " for package " + str(package.cpv)
1021             invalid_flag_found = True
1022         else:
1023             valid_flag_list.append(original_flag)
1024
1025     # if valid_flag_list is empty, there are no valid flags
1026     if ( (len(valid_flag_list) > 0) and (len(useflag_removal_display) >0)):
1027         useremove_display += useflag_removal_display + "\n"
1028     elif ( len(valid_flag_list) == 0):
1029         useremove_display += "No valid use flags found for package " + str(package.cpv) + ". Removing line: " + line + "\n"
1030         if ( invalid_flag_found != True):
1031             print_output (info,portage.output.red("No valid use flags found for package " + str(package.cpv)))
1032         invalid_flag_found = True
1033
1034     valid_flag_list.insert(0,package_string);
1035     if (invalid_flag_found == True):
1036         use_flag_dict[line] = valid_flag_list
1037
1038     return valid_flag_list
1039
1040
1041 def clean_useflagsFile(filename):
1042
1043     if "--fix-confirm" in cmdline:
1044         if (confirmFix() == False):
1045             return
1046     
1047     display_line = ""
1048     removed_list = []
1049
1050     try:
1051         # determine if filename is a directory
1052         if os.path.isdir(filename):
1053             # get listing of directory
1054             filenames = os.listdir(filename)
1055             for file_name in filenames:
1056                 clean_useflagsFile(filename+os.path.sep+file_name)
1057             return
1058         else:
1059             #go through stable array and remove line if found
1060             for line in fileinput.input(filename,inplace =1):
1061                 itemFound = False
1062                 line = line.strip()
1063
1064                 # make sure line is not empty and do not remove commented out lines
1065                 if len(line) <= 0:
1066                     continue
1067                 elif line.find("#") == 0:
1068                     print (line)
1069                     continue
1070
1071                 check_for_change = ""
1072                 use_flag_dict.get(line,"")
1073                 try:
1074                     check_for_change = use_flag_dict[line]
1075                     removed_list.append(line)
1076                     if ( len(check_for_change) > 1):
1077                         print (" ".join(check_for_change))
1078                 except KeyError as error:
1079                     print (line)
1080
1081             fileinput.close()
1082     except OSError as error:
1083         print (portage.output.red("Modify/Read access to file: " + filename + " failed: " + format(error)))
1084
1085     if (len(removed_list) > 0):
1086         print ("\n")
1087         for package in removed_list:
1088             print (portage.output.red("Removing from: ") + portage.output.yellow(filename + ": Invalid use flag(s) from ")  + portage.output.green(package) + "\n")
1089
1090     return
1091
1092 def handle_if_overlay(package):
1093     overlay_text = ""
1094     global print_overlay_flag,using_gentoo_as_overlay
1095
1096     if (using_gentoo_as_overlay):
1097         return overlay_text
1098
1099     print_overlay_flag = True
1100
1101     ebuild_path,overlay_path = porttree.dbapi.findname2(str(package.cpv))
1102     index = -1
1103     try:
1104         index = overlay_list.index(overlay_path)
1105     except ValueError as error:
1106         overlay_list.append(overlay_path)
1107         index = overlay_list.index(overlay_path)
1108
1109     overlay_text = " [%s]" % (str(index+1))
1110
1111     return overlay_text
1112
1113 # if the overlay_text was displayed to the user
1114 # we need to display the string at the end 
1115 # this array will store the overlays to be displayed
1116 def print_overlay_text():
1117    
1118     global print_overlay_flag
1119     
1120     if (not print_overlay_flag):
1121         return
1122     
1123     if (len(overlay_list) <= 0):
1124         return
1125
1126     index = 1
1127     for x in overlay_list:
1128         print (portage.output.turquoise("[" + str(index) + "] ") + x)
1129         index = index + 1
1130     
1131     print ("\n")
1132
1133 #helper function to print output
1134 def print_output(log_level,output_string, package=None, filename=None):
1135     
1136     global logLevel
1137
1138     if package != None:
1139         if (package.is_overlay()):
1140             output_string = "%s%s" % (output_string,portage.output.turquoise(handle_if_overlay(package)))
1141             #output_string = output_string + portage.output.turquoise(handle_if_overlay(package))
1142         else:
1143             if filename != None:
1144                 output_string = "%s%s" % (output_string,portage.output.brown(" : " + filename))
1145                 #output_string = output_string + portage.output.brown(" : " + filename)
1146
1147     if (log_level <= logLevel):
1148         print (output_string)
1149
1150 # remove stabled files that are no longer needed from package.keywords
1151 # or package.mask
1152 # includes support for etc/portage/package.keywords/<whatever>/package.keywords
1153 def cleanFile (filename):
1154
1155     removeDups = []
1156     removed_list = []
1157
1158     if "--fix-confirm" in cmdline:
1159         if (confirmFix() == False):
1160             return
1161
1162     # if the file or directory does not exist
1163     # exit out
1164     if (os.path.exists(filename) == False):
1165         return
1166     
1167     if "package.keywords" in filename:
1168         if ( len(stable_list) == 0):
1169             return
1170         removeDups = stable_list
1171     elif "package.accept_keywords" in filename:
1172         if ( len(stable_listNg) == 0):
1173             return
1174         removeDups = stable_listNg
1175     else:
1176         if ( len(unmask_list) == 0):
1177             return
1178         removeDups = unmask_list
1179
1180     removedDict = {}
1181
1182     try:
1183         # determine if filename is a directory
1184         if os.path.isdir(filename):
1185             # get listing of directory
1186             filenames = os.listdir(filename)
1187             for file_name in filenames:
1188                 cleanFile(filename+os.path.sep+file_name)
1189             return
1190         else:   
1191             #go through stable array and remove line if found
1192             for line in fileinput.input(filename,inplace =1):
1193                 itemFound = False
1194                 line = line.strip()
1195
1196                 # make sure line is not empty and do not remove commented out lines
1197                 if len(line) <= 0:
1198                     continue
1199                 elif line.find("#") == 0:
1200                     print (line)
1201                     continue
1202
1203                 for item in removeDups:
1204                     if item in line:
1205                         removed_list.append(item)
1206                         removedDict[filename] = item
1207                         itemFound = True
1208                         removeDups.pop(removeDups.index(item))
1209                         break
1210                 if (itemFound == False):
1211                     print (line)
1212             fileinput.close()
1213     except OSError as error:
1214         print (portage.output.red("Modify/Read access to file: " + filename + " failed: " + format(error)))
1215     
1216     if (len(removed_list) > 0):
1217         print ("\n")
1218         for package in removed_list:
1219             print (portage.output.red("Removing from: ") + portage.output.yellow(filename) + ": " + portage.output.green(package) + "\n")
1220
1221 # ask the user if they want to fix their files
1222 # and remove unneeded entries
1223 # Return true if they say yes and False if they say no
1224 def confirmFix():
1225     
1226     global fix_asked,fix_confirm
1227
1228     if (fix_asked == True):
1229         return fix_confirm
1230
1231     # only ask if we actually have anything to check
1232     if ( (len(stable_list) == 0) and 
1233           (len(stable_listNg) == 0) and
1234           (len(unmask_list) == 0) and
1235           (invalid_flag_found == False) and 
1236           (len(use_flag_dict) == 0)):
1237         fix_confirm = True
1238         return fix_confirm
1239
1240     fix_asked = True 
1241
1242     valid = {"yes":"yes",   "y":"yes", 
1243              "no":"no",     "n":"no"}
1244    
1245     prompt = portage.output.bold("Remove entries from files [") + portage.output.green("y") + "/" + portage.output.red("n") + portage.output.bold("]") + " "
1246
1247     while 1:
1248         sys.stdout.write('\n' + prompt)
1249         choice = input().lower()
1250         if choice == '':
1251             fix_confirm = False
1252             break
1253         elif choice in valid.keys():
1254             if (choice == 'y' or choice == 'yes'):
1255                 fix_confirm = True
1256                 break
1257             else:
1258                 fix_confirm = False
1259                 break 
1260         else:
1261             sys.stdout.write("Please respond with 'yes' or 'no' "\
1262                              "(or 'y' or 'n').\n")
1263
1264     return fix_confirm
1265
1266
1267 def check_for_any_installed_version(pkgs):
1268     
1269     for package in pkgs:
1270         if (package.is_installed()):
1271             return True
1272
1273     return False
1274
1275 # main
1276 if __name__ == "__main__":
1277
1278     if len(sys.argv) == 1:
1279         print_usage()
1280         sys.exit(1)
1281
1282     # soooooo stolen from emerge
1283     tmpcmdline = sys.argv[1:]
1284
1285     for cmd in tmpcmdline:
1286         if cmd[0:1] == "-" and cmd[1:2] != "-":
1287             for cmd_item in cmd[1:]:
1288                 if cmd_item in mappings:
1289                     if mappings[cmd_item] in cmdline:
1290                         print ()
1291                         print ("*** Warning: Redundant use of ", mappings[cmd_item])
1292                     else:
1293                         cmdline.append(mappings[cmd_item])
1294                 else:
1295                     print ("!!! Error: -"+cmd_item+" is an invalid option.")
1296                     sys.exit(-1)
1297         else:
1298             cmdline.append(cmd)
1299
1300     #parse long options
1301     for cmd in cmdline:
1302         if len(cmd)>=2 and cmd[0:2]=="--":
1303             try:
1304                 i = options.index(cmd)
1305                 continue
1306             except ValueError:
1307                 print ("!!! Error: -"+cmd+" is an invalid option.")
1308                 sys.exit(-1)
1309
1310     if "--changes-only" in cmdline:
1311         cmdline.remove("--changes-only")
1312         show_changes_only_flag = True
1313
1314     if "--removable-only" in cmdline:
1315         cmdline.remove("--removable-only")
1316         show_removable_only_flag = True
1317
1318     if "--debug" in cmdline:
1319         logLevel = debug
1320
1321     if "--no-color" in cmdline:
1322         portage.output.nocolor()
1323
1324     if "--tilde-check" in cmdline:
1325         tilde=1
1326
1327     if "--version" in cmdline:
1328         print_version()
1329         sys.exit(0)
1330
1331     if "--fix-confirm" in cmdline:
1332         if '--fix' not in cmdline:
1333             cmdline.append("--fix")
1334     
1335     if "--all" in cmdline:
1336         tmpcmdline = ["--all"]
1337         if "--fix" in cmdline:
1338             tmpcmdline.append("--fix")
1339             if "--fix-confirm" in cmdline:
1340                 tmpcmdline.append("--fix-confirm")
1341                 fix_confirm = False
1342         cmdline=tmpcmdline      
1343
1344     if "--help" in cmdline:
1345         print_usage()
1346         sys.exit(0)
1347     
1348     if (show_changes_only_flag and show_removable_only_flag):
1349         print ("Please select only one of --show-removable (-r) or --changes-only")
1350         print ("Use --help for more info.")
1351         sys.exit(0)
1352         
1353     for cmd in cmdline:
1354         if cmd == "--keyword":
1355             print (portage.output.bold("\npackage.keywords:"))
1356             get_recursive_info(USER_CONFIG_PATH + "/package.keywords")
1357             if "--fix" in cmdline:
1358                 cleanFile(USER_CONFIG_PATH + "/package.keywords")
1359             print (portage.output.bold("Done\n"))
1360             print (portage.output.bold("\npackage.accept_keywords:"))
1361             get_recursive_info(USER_CONFIG_PATH + "/package.accept_keywords")
1362             if "--fix" in cmdline:
1363                 cleanFile(USER_CONFIG_PATH + "/package.accept_keywords")
1364             print (portage.output.bold("Done\n"))
1365         elif cmd == "--unmask": 
1366             print (portage.output.bold("\npackage.unmask:"))
1367             checking_package_unmask = True
1368             get_recursive_info(USER_CONFIG_PATH + "/package.unmask")
1369             checking_package_unmask = False
1370             if "--fix" in cmdline:
1371                 cleanFile(USER_CONFIG_PATH + "/package.unmask")
1372         elif cmd == "--mask":
1373             checking_package_mask = True
1374             print (portage.output.bold("\npackage.mask:"))
1375             get_recursive_info(USER_CONFIG_PATH + "/package.mask")
1376             print (portage.output.bold("Done\n"))
1377             checking_package_mask = False
1378             if "--fix" in cmdline:
1379                 cleanFile(USER_CONFIG_PATH + "/package.mask")
1380         elif cmd == "--package-use":
1381             print (portage.output.bold("\npackage.use:"))
1382             processing_package_use = True
1383             get_recursive_info(USER_CONFIG_PATH + "/package.use")
1384             if "--fix" in cmdline:
1385                 cleanFile(USER_CONFIG_PATH + "/package.use")
1386                 clean_useflagsFile(USER_CONFIG_PATH + "/package.use")
1387             print (portage.output.bold("Done\n"))
1388         elif cmd == "--all":
1389             print (portage.output.bold("\npackage.keywords:"))
1390             get_recursive_info(USER_CONFIG_PATH + "/package.keywords")
1391             print (portage.output.bold("\npackage.accept_keywords:"))
1392             get_recursive_info(USER_CONFIG_PATH + "/package.accept_keywords")
1393             print (portage.output.bold("\npackage.unmask:"))
1394             checking_package_unmask = True
1395             get_recursive_info(USER_CONFIG_PATH + "/package.unmask")
1396             checking_package_unmask = False
1397             checking_package_mask = True
1398             print (portage.output.bold("\npackage.mask:"))
1399             get_recursive_info(USER_CONFIG_PATH + "/package.mask")
1400             print (portage.output.bold("\npackage.use:"))
1401             processing_package_use = True
1402             get_recursive_info(USER_CONFIG_PATH + "/package.use")
1403             if "--fix" in cmdline:
1404                 cleanFile(USER_CONFIG_PATH + "/package.keywords")
1405                 cleanFile(USER_CONFIG_PATH + "/package.accept_keywords")
1406                 cleanFile(USER_CONFIG_PATH + "/package.unmask")
1407                 cleanFile(USER_CONFIG_PATH + "/package.use")
1408                 cleanFile(USER_CONFIG_PATH + "/package.mask")
1409                 clean_useflagsFile(USER_CONFIG_PATH + "/package.use")
1410             print (portage.output.bold("\nDone\n"))
1411
1412     print_overlay_text()
1413
1414     if len(cmdline) == 0:
1415         if show_changes_only_flag or show_removable_only_flag:
1416             if (show_changes_only_flag):
1417                 print (portage.output.green("-c") + " or " + portage.output.green("--changes-only") + " must be accompanied by one of the following:")
1418             else:
1419                 print (portage.output.green("-r") + " or " + portage.output.green("--removable-only") + " must be accompanied by one of the following:")
1420
1421             print ("     " + portage.output.yellow("-k") + " or " + portage.output.yellow("--keyword"))
1422             print ("     " + portage.output.yellow("-u") + " or " + portage.output.yellow("--unmask"))
1423             print ("     " + portage.output.yellow("-m") + " or " + portage.output.yellow("--mask"))
1424             print ("     " + portage.output.yellow("-a") + " or " + portage.output.yellow("--all"))
1425
1426             print_usage()
1427