5bc8515dd02a67d7b45dcc46e2baa25830630962
[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.9"
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         list2 = get_useflags(package)
875
876         for uf in list2:
877             print_output(debug,portage.output.blue(("use found " + uf)))
878  
879         iuse_string = package.use()
880         iuse = iuse_string.split(" ")
881
882         for uflag in list2:
883             iuse.append(uflag)
884
885         for iuse_item in iuse:
886             print_output(debug,portage.output.blue(("iuse_item is " + iuse_item)))
887
888         useflags_fromfile = line.replace("\t", " ").split(" ")
889
890         #for useflags_fromfile_item in useflags_fromfile:
891         #    print_output(debug,portage.output.blue(("useflags_fromfile_item is " + useflags_fromfile_item)))
892
893         package_string = useflags_fromfile.pop(0)
894         print_output(debug,portage.output.blue(("package_string is " + package_string)))
895     
896         clean_useflags_list = []
897         # remove + or -
898         atom = "-+"
899     
900         #clean list from portage of + or -
901         clean_iuse = []
902         for item in iuse:
903             if item[0] in atom:
904                 clean_iuse.append(item[1:])
905             else:
906                 clean_iuse.append(item)
907     
908         for original_flag in useflags_fromfile:
909             if (original_flag is None or original_flag == ""):
910                 continue
911             flag = original_flag
912             if original_flag[0] in atom:
913                 flag = original_flag[1:]
914             if flag not in clean_iuse:
915                 print_output(debug,portage.output.blue(("found invalid flag: " + flag)))
916
917                 # only add to invalid list if it's not in valid list
918                 try:
919                     index = valid_flag_list.index(original_flag)
920                 except ValueError as error:
921
922                     try:
923                        index = potential_invalid_flag.index(original_flag)
924                     except ValueError:
925                        print_output(debug,portage.output.blue(original_flag + " not found for " + package.cpv))
926                        potential_invalid_flag.append(original_flag)
927
928             else:
929                 print_output(debug,portage.output.blue(("found valid flag: " + flag)))
930                 try:
931                     index = valid_flag_list.index(original_flag)
932                 except ValueError as error:
933                     valid_flag_list.append(original_flag)
934
935                 try:
936                     index = potential_invalid_flag.index(original_flag)
937                     potential_invalid_flag.remove(original_flag)
938                 except ValueError as error:
939                     continue
940
941
942     # if potential_invalid_flag list is empty, we are done
943     if (len(potential_invalid_flag) <= 0):
944         return
945
946     invalid_flag_found = True
947
948     # build sentence
949     invalid_flags = ""
950     verb = "is"
951     for inv_flag in potential_invalid_flag:
952         if (len(invalid_flags) > 0):
953             invalid_flags += ","
954             verb = "are"
955         invalid_flags += inv_flag
956
957     # if there are no valid flags at all, we remove the line
958     if ( len(valid_flag_list) == 0):
959         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"))
960         useremove_display += "Removing line: " + line + "\n"
961         use_flag_dict[line] = ""
962         return
963
964     # if there are values in potential_invalid_flag, we need to remove them
965
966     if (len(potential_invalid_flag) > 0):
967         removal_text = "use flags: "
968     else:
969         removal_text = "use flag: "
970
971     if ( (len(valid_flag_list) > 0)):
972         useremove_display += "Removing " + removal_text + invalid_flags + " for package " + check_pkgs + "\n"
973         print (portage.output.yellow(removal_text) +  portage.output.red(invalid_flags) + portage.output.yellow(" " + verb + " invalid for " + str(package.cpv)))
974
975     valid_flag_list.insert(0,package_string);
976
977     if (len(potential_invalid_flag) > 0):
978         use_flag_dict[line] = valid_flag_list
979         
980     return valid_flag_list
981
982 def check_useflags(package,line):
983
984     global useremove_display, invalid_flag_found 
985     invalid_flag_found = False
986
987     print_output(debug,portage.output.blue("check_useflags: package: " + package.cpv))
988     if ((package is None) or (package == "")):
989         return
990
991     useflag_removal_display=""
992
993     if (len(line) <= 0):
994         return
995
996     iuse = get_useflags(package)
997
998     #for iuse_item in iuse:
999     #    print_output(debug,portage.output.blue(("iuse_item is " + iuse_item)))
1000
1001     useflags_fromfile = line.replace("\t", " ").split(" ")
1002     #for useflags_fromfile_item in useflags_fromfile:
1003     #    print_output(debug,portage.output.blue(("useflags_fromfile_item is " + useflags_fromfile_item)))
1004
1005     package_string = useflags_fromfile.pop(0)
1006     print_output(debug,portage.output.blue(("package_string is " + package_string)))
1007
1008     clean_useflags_list = []
1009     # remove + or -
1010     atom = "-+"
1011
1012     #clean list from portage of + or -
1013     clean_iuse = []
1014     for item in iuse:
1015         if item[0] in atom:
1016             clean_iuse.append(item[1:])
1017         else:
1018             clean_iuse.append(item)
1019
1020     valid_flag_list = []
1021     for original_flag in useflags_fromfile:
1022         if (original_flag is None or original_flag == ""):
1023             continue
1024         flag = original_flag
1025         if original_flag[0] in atom:
1026             flag = original_flag[1:]
1027         if flag not in clean_iuse:
1028             print_output (info,portage.output.red("use flag: " + flag + " is invalid for : " + str(package.cpv)))
1029             useflag_removal_display += "Removing use flag: " + flag + " for package " + str(package.cpv)
1030             invalid_flag_found = True
1031         else:
1032             valid_flag_list.append(original_flag)
1033
1034     # if valid_flag_list is empty, there are no valid flags
1035     if ( (len(valid_flag_list) > 0) and (len(useflag_removal_display) >0)):
1036         useremove_display += useflag_removal_display + "\n"
1037     elif ( len(valid_flag_list) == 0):
1038         useremove_display += "No valid use flags found for package " + str(package.cpv) + ". Removing line: " + line + "\n"
1039         if ( invalid_flag_found != True):
1040             print_output (info,portage.output.red("No valid use flags found for package " + str(package.cpv)))
1041         invalid_flag_found = True
1042
1043     valid_flag_list.insert(0,package_string);
1044     if (invalid_flag_found == True):
1045         use_flag_dict[line] = valid_flag_list
1046
1047     return valid_flag_list
1048
1049
1050 def clean_useflagsFile(filename):
1051
1052     if "--fix-confirm" in cmdline:
1053         if (confirmFix() == False):
1054             return
1055     
1056     display_line = ""
1057     removed_list = []
1058
1059     try:
1060         # determine if filename is a directory
1061         if os.path.isdir(filename):
1062             # get listing of directory
1063             filenames = os.listdir(filename)
1064             for file_name in filenames:
1065                 clean_useflagsFile(filename+os.path.sep+file_name)
1066             return
1067         else:
1068             #go through stable array and remove line if found
1069             for line in fileinput.input(filename,inplace =1):
1070                 itemFound = False
1071                 line = line.strip()
1072
1073                 # make sure line is not empty and do not remove commented out lines
1074                 if len(line) <= 0:
1075                     continue
1076                 elif line.find("#") == 0:
1077                     print (line)
1078                     continue
1079
1080                 check_for_change = ""
1081                 use_flag_dict.get(line,"")
1082                 try:
1083                     check_for_change = use_flag_dict[line]
1084                     removed_list.append(line)
1085                     if ( len(check_for_change) > 1):
1086                         print (" ".join(check_for_change))
1087                 except KeyError as error:
1088                     print (line)
1089
1090             fileinput.close()
1091     except OSError as error:
1092         print (portage.output.red("Modify/Read access to file: " + filename + " failed: " + format(error)))
1093
1094     if (len(removed_list) > 0):
1095         print ("\n")
1096         for package in removed_list:
1097             print (portage.output.red("Removing from: ") + portage.output.yellow(filename + ": Invalid use flag(s) from ")  + portage.output.green(package) + "\n")
1098
1099     return
1100
1101 def handle_if_overlay(package):
1102     overlay_text = ""
1103     global print_overlay_flag,using_gentoo_as_overlay
1104
1105     if (using_gentoo_as_overlay):
1106         return overlay_text
1107
1108     print_overlay_flag = True
1109
1110     ebuild_path,overlay_path = porttree.dbapi.findname2(str(package.cpv))
1111     index = -1
1112     try:
1113         index = overlay_list.index(overlay_path)
1114     except ValueError as error:
1115         overlay_list.append(overlay_path)
1116         index = overlay_list.index(overlay_path)
1117
1118     overlay_text = " [%s]" % (str(index+1))
1119
1120     return overlay_text
1121
1122 # if the overlay_text was displayed to the user
1123 # we need to display the string at the end 
1124 # this array will store the overlays to be displayed
1125 def print_overlay_text():
1126    
1127     global print_overlay_flag
1128     
1129     if (not print_overlay_flag):
1130         return
1131     
1132     if (len(overlay_list) <= 0):
1133         return
1134
1135     index = 1
1136     for x in overlay_list:
1137         print (portage.output.turquoise("[" + str(index) + "] ") + x)
1138         index = index + 1
1139     
1140     print ("\n")
1141
1142 #helper function to print output
1143 def print_output(log_level,output_string, package=None, filename=None):
1144     
1145     global logLevel
1146
1147     if package != None:
1148         if (package.is_overlay()):
1149             output_string = "%s%s" % (output_string,portage.output.turquoise(handle_if_overlay(package)))
1150             #output_string = output_string + portage.output.turquoise(handle_if_overlay(package))
1151         else:
1152             if filename != None:
1153                 output_string = "%s%s" % (output_string,portage.output.brown(" : " + filename))
1154                 #output_string = output_string + portage.output.brown(" : " + filename)
1155
1156     if (log_level <= logLevel):
1157         print (output_string)
1158
1159 # remove stabled files that are no longer needed from package.keywords
1160 # or package.mask
1161 # includes support for etc/portage/package.keywords/<whatever>/package.keywords
1162 def cleanFile (filename):
1163
1164     removeDups = []
1165     removed_list = []
1166
1167     if "--fix-confirm" in cmdline:
1168         if (confirmFix() == False):
1169             return
1170
1171     # if the file or directory does not exist
1172     # exit out
1173     if (os.path.exists(filename) == False):
1174         return
1175     
1176     if "package.keywords" in filename:
1177         if ( len(stable_list) == 0):
1178             return
1179         removeDups = stable_list
1180     elif "package.accept_keywords" in filename:
1181         if ( len(stable_listNg) == 0):
1182             return
1183         removeDups = stable_listNg
1184     else:
1185         if ( len(unmask_list) == 0):
1186             return
1187         removeDups = unmask_list
1188
1189     removedDict = {}
1190
1191     try:
1192         # determine if filename is a directory
1193         if os.path.isdir(filename):
1194             # get listing of directory
1195             filenames = os.listdir(filename)
1196             for file_name in filenames:
1197                 cleanFile(filename+os.path.sep+file_name)
1198             return
1199         else:   
1200             #go through stable array and remove line if found
1201             for line in fileinput.input(filename,inplace =1):
1202                 itemFound = False
1203                 line = line.strip()
1204
1205                 # make sure line is not empty and do not remove commented out lines
1206                 if len(line) <= 0:
1207                     continue
1208                 elif line.find("#") == 0:
1209                     print (line)
1210                     continue
1211
1212                 for item in removeDups:
1213                     if item in line:
1214                         removed_list.append(item)
1215                         removedDict[filename] = item
1216                         itemFound = True
1217                         removeDups.pop(removeDups.index(item))
1218                         break
1219                 if (itemFound == False):
1220                     print (line)
1221             fileinput.close()
1222     except OSError as error:
1223         print (portage.output.red("Modify/Read access to file: " + filename + " failed: " + format(error)))
1224     
1225     if (len(removed_list) > 0):
1226         print ("\n")
1227         for package in removed_list:
1228             print (portage.output.red("Removing from: ") + portage.output.yellow(filename) + ": " + portage.output.green(package) + "\n")
1229
1230 # ask the user if they want to fix their files
1231 # and remove unneeded entries
1232 # Return true if they say yes and False if they say no
1233 def confirmFix():
1234     
1235     global fix_asked,fix_confirm
1236
1237     if (fix_asked == True):
1238         return fix_confirm
1239
1240     # only ask if we actually have anything to check
1241     if ( (len(stable_list) == 0) and 
1242           (len(stable_listNg) == 0) and
1243           (len(unmask_list) == 0) and
1244           (invalid_flag_found == False) and 
1245           (len(use_flag_dict) == 0)):
1246         fix_confirm = True
1247         return fix_confirm
1248
1249     fix_asked = True 
1250
1251     valid = {"yes":"yes",   "y":"yes", 
1252              "no":"no",     "n":"no"}
1253    
1254     prompt = portage.output.bold("Remove entries from files [") + portage.output.green("y") + "/" + portage.output.red("n") + portage.output.bold("]") + " "
1255
1256     while 1:
1257         sys.stdout.write('\n' + prompt)
1258         choice = input().lower()
1259         if choice == '':
1260             fix_confirm = False
1261             break
1262         elif choice in valid.keys():
1263             if (choice == 'y' or choice == 'yes'):
1264                 fix_confirm = True
1265                 break
1266             else:
1267                 fix_confirm = False
1268                 break 
1269         else:
1270             sys.stdout.write("Please respond with 'yes' or 'no' "\
1271                              "(or 'y' or 'n').\n")
1272
1273     return fix_confirm
1274
1275
1276 def check_for_any_installed_version(pkgs):
1277     
1278     for package in pkgs:
1279         if (package.is_installed()):
1280             return True
1281
1282     return False
1283
1284 # main
1285 if __name__ == "__main__":
1286
1287     if len(sys.argv) == 1:
1288         print_usage()
1289         sys.exit(1)
1290
1291     # soooooo stolen from emerge
1292     tmpcmdline = sys.argv[1:]
1293
1294     for cmd in tmpcmdline:
1295         if cmd[0:1] == "-" and cmd[1:2] != "-":
1296             for cmd_item in cmd[1:]:
1297                 if cmd_item in mappings:
1298                     if mappings[cmd_item] in cmdline:
1299                         print ()
1300                         print ("*** Warning: Redundant use of ", mappings[cmd_item])
1301                     else:
1302                         cmdline.append(mappings[cmd_item])
1303                 else:
1304                     print ("!!! Error: -"+cmd_item+" is an invalid option.")
1305                     sys.exit(-1)
1306         else:
1307             cmdline.append(cmd)
1308
1309     #parse long options
1310     for cmd in cmdline:
1311         if len(cmd)>=2 and cmd[0:2]=="--":
1312             try:
1313                 i = options.index(cmd)
1314                 continue
1315             except ValueError:
1316                 print ("!!! Error: -"+cmd+" is an invalid option.")
1317                 sys.exit(-1)
1318
1319     if "--changes-only" in cmdline:
1320         cmdline.remove("--changes-only")
1321         show_changes_only_flag = True
1322
1323     if "--removable-only" in cmdline:
1324         cmdline.remove("--removable-only")
1325         show_removable_only_flag = True
1326
1327     if "--debug" in cmdline:
1328         logLevel = debug
1329
1330     if "--no-color" in cmdline:
1331         portage.output.nocolor()
1332
1333     if "--tilde-check" in cmdline:
1334         tilde=1
1335
1336     if "--version" in cmdline:
1337         print_version()
1338         sys.exit(0)
1339
1340     if "--fix-confirm" in cmdline:
1341         if '--fix' not in cmdline:
1342             cmdline.append("--fix")
1343     
1344     if "--all" in cmdline:
1345         tmpcmdline = ["--all"]
1346         if "--fix" in cmdline:
1347             tmpcmdline.append("--fix")
1348             if "--fix-confirm" in cmdline:
1349                 tmpcmdline.append("--fix-confirm")
1350                 fix_confirm = False
1351         cmdline=tmpcmdline      
1352
1353     if "--help" in cmdline:
1354         print_usage()
1355         sys.exit(0)
1356     
1357     if (show_changes_only_flag and show_removable_only_flag):
1358         print ("Please select only one of --show-removable (-r) or --changes-only")
1359         print ("Use --help for more info.")
1360         sys.exit(0)
1361         
1362     for cmd in cmdline:
1363         if cmd == "--keyword":
1364             print (portage.output.bold("\npackage.keywords:"))
1365             get_recursive_info(USER_CONFIG_PATH + "/package.keywords")
1366             if "--fix" in cmdline:
1367                 cleanFile(USER_CONFIG_PATH + "/package.keywords")
1368             print (portage.output.bold("Done\n"))
1369             print (portage.output.bold("\npackage.accept_keywords:"))
1370             get_recursive_info(USER_CONFIG_PATH + "/package.accept_keywords")
1371             if "--fix" in cmdline:
1372                 cleanFile(USER_CONFIG_PATH + "/package.accept_keywords")
1373             print (portage.output.bold("Done\n"))
1374         elif cmd == "--unmask": 
1375             print (portage.output.bold("\npackage.unmask:"))
1376             checking_package_unmask = True
1377             get_recursive_info(USER_CONFIG_PATH + "/package.unmask")
1378             checking_package_unmask = False
1379             if "--fix" in cmdline:
1380                 cleanFile(USER_CONFIG_PATH + "/package.unmask")
1381         elif cmd == "--mask":
1382             checking_package_mask = True
1383             print (portage.output.bold("\npackage.mask:"))
1384             get_recursive_info(USER_CONFIG_PATH + "/package.mask")
1385             print (portage.output.bold("Done\n"))
1386             checking_package_mask = False
1387             if "--fix" in cmdline:
1388                 cleanFile(USER_CONFIG_PATH + "/package.mask")
1389         elif cmd == "--package-use":
1390             print (portage.output.bold("\npackage.use:"))
1391             processing_package_use = True
1392             get_recursive_info(USER_CONFIG_PATH + "/package.use")
1393             if "--fix" in cmdline:
1394                 cleanFile(USER_CONFIG_PATH + "/package.use")
1395                 clean_useflagsFile(USER_CONFIG_PATH + "/package.use")
1396             print (portage.output.bold("Done\n"))
1397         elif cmd == "--all":
1398             print (portage.output.bold("\npackage.keywords:"))
1399             get_recursive_info(USER_CONFIG_PATH + "/package.keywords")
1400             print (portage.output.bold("\npackage.accept_keywords:"))
1401             get_recursive_info(USER_CONFIG_PATH + "/package.accept_keywords")
1402             print (portage.output.bold("\npackage.unmask:"))
1403             checking_package_unmask = True
1404             get_recursive_info(USER_CONFIG_PATH + "/package.unmask")
1405             checking_package_unmask = False
1406             checking_package_mask = True
1407             print (portage.output.bold("\npackage.mask:"))
1408             get_recursive_info(USER_CONFIG_PATH + "/package.mask")
1409             print (portage.output.bold("\npackage.use:"))
1410             processing_package_use = True
1411             get_recursive_info(USER_CONFIG_PATH + "/package.use")
1412             if "--fix" in cmdline:
1413                 cleanFile(USER_CONFIG_PATH + "/package.keywords")
1414                 cleanFile(USER_CONFIG_PATH + "/package.accept_keywords")
1415                 cleanFile(USER_CONFIG_PATH + "/package.unmask")
1416                 cleanFile(USER_CONFIG_PATH + "/package.use")
1417                 cleanFile(USER_CONFIG_PATH + "/package.mask")
1418                 clean_useflagsFile(USER_CONFIG_PATH + "/package.use")
1419             print (portage.output.bold("\nDone\n"))
1420
1421     print_overlay_text()
1422
1423     if len(cmdline) == 0:
1424         if show_changes_only_flag or show_removable_only_flag:
1425             if (show_changes_only_flag):
1426                 print (portage.output.green("-c") + " or " + portage.output.green("--changes-only") + " must be accompanied by one of the following:")
1427             else:
1428                 print (portage.output.green("-r") + " or " + portage.output.green("--removable-only") + " must be accompanied by one of the following:")
1429
1430             print ("     " + portage.output.yellow("-k") + " or " + portage.output.yellow("--keyword"))
1431             print ("     " + portage.output.yellow("-u") + " or " + portage.output.yellow("--unmask"))
1432             print ("     " + portage.output.yellow("-m") + " or " + portage.output.yellow("--mask"))
1433             print ("     " + portage.output.yellow("-a") + " or " + portage.output.yellow("--all"))
1434
1435             print_usage()
1436