From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1SkS7n-0005q2-KW for garchives@archives.gentoo.org; Fri, 29 Jun 2012 03:44:04 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id ABFCDE0160; Fri, 29 Jun 2012 03:43:55 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 2D565E0160 for ; Fri, 29 Jun 2012 03:43:55 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 48F9E1B404D for ; Fri, 29 Jun 2012 03:43:54 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 17C44E5432 for ; Fri, 29 Jun 2012 03:43:53 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1340941409.a880f62d652ae59de80d430ce0331b6b71af11c4.dol-sen@gentoo> Subject: [gentoo-commits] proj/gentoolkit:gentoolkit commit in: pym/gentoolkit/enalyze/ X-VCS-Repository: proj/gentoolkit X-VCS-Files: pym/gentoolkit/enalyze/analyze.py pym/gentoolkit/enalyze/rebuild.py X-VCS-Directories: pym/gentoolkit/enalyze/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: a880f62d652ae59de80d430ce0331b6b71af11c4 X-VCS-Branch: gentoolkit Date: Fri, 29 Jun 2012 03:43:53 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 336ec987-0cb4-4838-8fe3-9c9016662646 X-Archives-Hash: 0ab32e8bc08e2151d4232886d9aaec9b commit: a880f62d652ae59de80d430ce0331b6b71af11c4 Author: Brian Dolbec gentoo org> AuthorDate: Fri Jun 29 03:43:29 2012 +0000 Commit: Brian Dolbec gmail com> CommitDate: Fri Jun 29 03:43:29 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoolkit.gi= t;a=3Dcommit;h=3Da880f62d reverse an accidental indentation change from tabs to spaces. --- pym/gentoolkit/enalyze/analyze.py | 784 ++++++++++++++++++-------------= ----- pym/gentoolkit/enalyze/rebuild.py | 648 +++++++++++++++--------------- 2 files changed, 716 insertions(+), 716 deletions(-) diff --git a/pym/gentoolkit/enalyze/analyze.py b/pym/gentoolkit/enalyze/a= nalyze.py index 33d1651..2ba028f 100644 --- a/pym/gentoolkit/enalyze/analyze.py +++ b/pym/gentoolkit/enalyze/analyze.py @@ -26,423 +26,423 @@ import portage =20 =20 def gather_flags_info( - cpvs=3DNone, - system_flags=3DNone, - include_unset=3DFalse, - target=3D"USE", - use_portage=3DFalse, - # override-able for testing - _get_flags=3Dget_flags, - _get_used=3Dget_installed_use - ): - """Analyze the installed pkgs USE flags for frequency of use + cpvs=3DNone, + system_flags=3DNone, + include_unset=3DFalse, + target=3D"USE", + use_portage=3DFalse, + # override-able for testing + _get_flags=3Dget_flags, + _get_used=3Dget_installed_use + ): + """Analyze the installed pkgs USE flags for frequency of use =20 - @type cpvs: list - @param cpvs: optional list of [cat/pkg-ver,...] to analyze or - defaults to entire installed pkg db - @type: system_flags: list - @param system_flags: the current default USE flags as defined - by portage.settings["USE"].split() - @type include_unset: bool - @param include_unset: controls the inclusion of unset USE flags in t= he report. - @type target: string - @param target: the environment variable being analyzed - one of ["USE", "PKGUSE"] - @type _get_flags: function - @param _get_flags: ovride-able for testing, - defaults to gentoolkit.enalyze.lib.get_flags - @param _get_used: ovride-able for testing, - defaults to gentoolkit.enalyze.lib.get_installed_use - @rtype dict. {flag:{"+":[cat/pkg-ver,...], "-":[cat/pkg-ver,...], "u= nset":[]} - """ - if cpvs is None: - cpvs =3D VARDB.cpv_all() - # pass them in to override for tests - flags =3D FlagAnalyzer(system_flags, - filter_defaults=3DFalse, - target=3Dtarget, - _get_flags=3D_get_flags, - _get_used=3Dget_installed_use - ) - flag_users =3D {} - for cpv in cpvs: - if cpv.startswith("virtual"): - continue - if use_portage: - plus, minus, unset =3D flags.analyse_cpv(cpv) - else: - pkg =3D Package(cpv) - plus, minus, unset =3D flags.analyse_pkg(pkg) - for flag in plus: - if flag in flag_users: - flag_users[flag]["+"].append(cpv) - else: - flag_users[flag] =3D {"+": [cpv], "-": []} - for flag in minus: - if flag in flag_users: - flag_users[flag]["-"].append(cpv) - else: - flag_users[flag] =3D {"+":[], "-": [cpv]} - if include_unset: - for flag in unset: - if flag in flag_users: - if "unset" in flag_users[flag]: - flag_users[flag]["unset"].append(cpv) - else: - flag_users[flag]["unset"] =3D [cpv] - else: - flag_users[flag] =3D {"+": [], "-": [], "unset": [cp= v]} - return flag_users + @type cpvs: list + @param cpvs: optional list of [cat/pkg-ver,...] to analyze or + defaults to entire installed pkg db + @type: system_flags: list + @param system_flags: the current default USE flags as defined + by portage.settings["USE"].split() + @type include_unset: bool + @param include_unset: controls the inclusion of unset USE flags in the = report. + @type target: string + @param target: the environment variable being analyzed + one of ["USE", "PKGUSE"] + @type _get_flags: function + @param _get_flags: ovride-able for testing, + defaults to gentoolkit.enalyze.lib.get_flags + @param _get_used: ovride-able for testing, + defaults to gentoolkit.enalyze.lib.get_installed_use + @rtype dict. {flag:{"+":[cat/pkg-ver,...], "-":[cat/pkg-ver,...], "unse= t":[]} + """ + if cpvs is None: + cpvs =3D VARDB.cpv_all() + # pass them in to override for tests + flags =3D FlagAnalyzer(system_flags, + filter_defaults=3DFalse, + target=3Dtarget, + _get_flags=3D_get_flags, + _get_used=3Dget_installed_use + ) + flag_users =3D {} + for cpv in cpvs: + if cpv.startswith("virtual"): + continue + if use_portage: + plus, minus, unset =3D flags.analyse_cpv(cpv) + else: + pkg =3D Package(cpv) + plus, minus, unset =3D flags.analyse_pkg(pkg) + for flag in plus: + if flag in flag_users: + flag_users[flag]["+"].append(cpv) + else: + flag_users[flag] =3D {"+": [cpv], "-": []} + for flag in minus: + if flag in flag_users: + flag_users[flag]["-"].append(cpv) + else: + flag_users[flag] =3D {"+":[], "-": [cpv]} + if include_unset: + for flag in unset: + if flag in flag_users: + if "unset" in flag_users[flag]: + flag_users[flag]["unset"].append(cpv) + else: + flag_users[flag]["unset"] =3D [cpv] + else: + flag_users[flag] =3D {"+": [], "-": [], "unset": [cpv]} + return flag_users =20 =20 def gather_keywords_info( - cpvs=3DNone, - system_keywords=3DNone, - use_portage=3DFalse, - # override-able for testing - keywords=3Dportage.settings["ACCEPT_KEYWORDS"], - analyser =3D None - ): - """Analyze the installed pkgs 'keywords' for frequency of use + cpvs=3DNone, + system_keywords=3DNone, + use_portage=3DFalse, + # override-able for testing + keywords=3Dportage.settings["ACCEPT_KEYWORDS"], + analyser =3D None + ): + """Analyze the installed pkgs 'keywords' for frequency of use =20 - @param cpvs: optional list of [cat/pkg-ver,...] to analyze or - defaults to entire installed pkg db - @param system_keywords: list of the system keywords - @param keywords: user defined list of keywords to check and report o= n - or reports on all relevant keywords found to have been used. - @param _get_kwds: overridable function for testing - @param _get_used: overridable function for testing - @rtype dict. {keyword:{"stable":[cat/pkg-ver,...], "testing":[cat/pk= g-ver,...]} - """ - if cpvs is None: - cpvs =3D VARDB.cpv_all() - keyword_users =3D {} - for cpv in cpvs: - if cpv.startswith("virtual"): - continue - if use_portage: - keyword =3D analyser.get_inst_keyword_cpv(cpv) - else: - pkg =3D Package(cpv) - keyword =3D analyser.get_inst_keyword_pkg(pkg) - #print "returned keyword =3D", cpv, keyword, keyword[0] - key =3D keyword[0] - if key in ["~", "-"]: - _kwd =3D keyword[1:] - if _kwd in keyword_users: - if key in ["~"]: - keyword_users[_kwd]["testing"].append(cpv) - elif key in ["-"]: - #print "adding cpv to missing:", cpv - keyword_users[_kwd]["missing"].append(cpv) - else: - if key in ["~"]: - keyword_users[_kwd] =3D {"stable": [], - "testing": [cpv], "missing": []} - elif key in ["-"]: - keyword_users[_kwd] =3D {"stable": [], - "testing": [], "missing": [cpv]} - else: - keyword_users[_kwd] =3D {"stable": [cpv], - "testing": [], "missing": []} - elif keyword in keyword_users: - keyword_users[keyword]["stable"].append(cpv) - else: - keyword_users[keyword] =3D { - "stable": [cpv], - "testing": [], - "missing": [] - } - return keyword_users + @param cpvs: optional list of [cat/pkg-ver,...] to analyze or + defaults to entire installed pkg db + @param system_keywords: list of the system keywords + @param keywords: user defined list of keywords to check and report on + or reports on all relevant keywords found to have been used. + @param _get_kwds: overridable function for testing + @param _get_used: overridable function for testing + @rtype dict. {keyword:{"stable":[cat/pkg-ver,...], "testing":[cat/pkg-v= er,...]} + """ + if cpvs is None: + cpvs =3D VARDB.cpv_all() + keyword_users =3D {} + for cpv in cpvs: + if cpv.startswith("virtual"): + continue + if use_portage: + keyword =3D analyser.get_inst_keyword_cpv(cpv) + else: + pkg =3D Package(cpv) + keyword =3D analyser.get_inst_keyword_pkg(pkg) + #print "returned keyword =3D", cpv, keyword, keyword[0] + key =3D keyword[0] + if key in ["~", "-"]: + _kwd =3D keyword[1:] + if _kwd in keyword_users: + if key in ["~"]: + keyword_users[_kwd]["testing"].append(cpv) + elif key in ["-"]: + #print "adding cpv to missing:", cpv + keyword_users[_kwd]["missing"].append(cpv) + else: + if key in ["~"]: + keyword_users[_kwd] =3D {"stable": [], + "testing": [cpv], "missing": []} + elif key in ["-"]: + keyword_users[_kwd] =3D {"stable": [], + "testing": [], "missing": [cpv]} + else: + keyword_users[_kwd] =3D {"stable": [cpv], + "testing": [], "missing": []} + elif keyword in keyword_users: + keyword_users[keyword]["stable"].append(cpv) + else: + keyword_users[keyword] =3D { + "stable": [cpv], + "testing": [], + "missing": [] + } + return keyword_users =20 =20 class Analyse(ModuleBase): - """Installed db analysis tool to query the installed databse - and produce/output stats for USE flags or keywords/mask. - The 'rebuild' action output is in the form suitable for file type ou= tput - to create a new package.use, package.keywords, package.unmask - type files in the event of needing to rebuild the - /etc/portage/* user configs - """ - def __init__(self): - ModuleBase.__init__(self) - self.module_name =3D "enalyze" - self.options =3D { - "flags": False, - "keywords": False, - "packages": False, - "unset": False, - "verbose": False, - "quiet": False, - 'prefix': False, - 'portage': True - } - self.module_opts =3D { - "-f": ("flags", "boolean", True), - "--flags": ("flags", "boolean", True), - "-k": ("keywords", "boolean", True), - "--keywords": ("keywords", "boolean", True), - "-u": ("unset", "boolean", True), - "--unset": ("unset", "boolean", True), - "-v": ("verbose", "boolean", True), - "--verbose": ("verbose", "boolean", True), - "-p": ("prefix", "boolean", True), - "--prefix": ("prefix", "boolean", True), - "-G": ("portage", "boolean", False), - "--portage": ("portage", "boolean", False), - } - self.formatted_options =3D [ - (" -h, --help", "Outputs this useage message"), - (" -a, --analyze", - "Action, sets the module to gather data and output the"), - ("", "formatted stats/information to the screen"), - (" -u, --unset", - "Additionally include any unset USE flags and the packages")= , - ("", "that could use them"), - (" -v, --verbose", - "Used in the analyze action to output more detailed informat= ion"), - (" -p, --prefix", - "Used for testing purposes only, runs report using " + - "a prefix keyword and 'prefix' USE flag"), - #(" -G, --portage", - #"Use portage directly instead of gentoolkit's Package " + - #"object for some operations. Usually a little faster."), - ] - self.formatted_args =3D [ - (" use", - "Causes the action to analyze the installed packages USE fla= gs"), - (" pkguse", - "Causes the action to analyze the installed packages PKGUSE = flags"), - (" ", - "These are flags that have been set in /etc/portage/package.= use"), - (" keywords", - "Causes the action to analyze the installed packages keyword= s"), - (" packages", - "Causes the action to analyze the installed packages and the= "), - (" ", - "USE flags they were installed with"), - ] - self.short_opts =3D "huvpG" - self.long_opts =3D ("help", "unset", "verbose", "prefix") #, "po= rtage") - self.need_queries =3D True - self.arg_spec =3D "Target" - self.arg_options =3D ['use', 'pkguse','keywords', 'packages'] - self.arg_option =3D False - self.warning =3D ( - " CAUTION", - "This is beta software and some features/options are incompl= ete,", - "some features may change in future releases includig its na= me.", - "Feedback will be appreciated, http://bugs.gentoo.org") + """Installed db analysis tool to query the installed databse + and produce/output stats for USE flags or keywords/mask. + The 'rebuild' action output is in the form suitable for file type outpu= t + to create a new package.use, package.keywords, package.unmask + type files in the event of needing to rebuild the + /etc/portage/* user configs + """ + def __init__(self): + ModuleBase.__init__(self) + self.module_name =3D "enalyze" + self.options =3D { + "flags": False, + "keywords": False, + "packages": False, + "unset": False, + "verbose": False, + "quiet": False, + 'prefix': False, + 'portage': True + } + self.module_opts =3D { + "-f": ("flags", "boolean", True), + "--flags": ("flags", "boolean", True), + "-k": ("keywords", "boolean", True), + "--keywords": ("keywords", "boolean", True), + "-u": ("unset", "boolean", True), + "--unset": ("unset", "boolean", True), + "-v": ("verbose", "boolean", True), + "--verbose": ("verbose", "boolean", True), + "-p": ("prefix", "boolean", True), + "--prefix": ("prefix", "boolean", True), + "-G": ("portage", "boolean", False), + "--portage": ("portage", "boolean", False), + } + self.formatted_options =3D [ + (" -h, --help", "Outputs this useage message"), + (" -a, --analyze", + "Action, sets the module to gather data and output the"), + ("", "formatted stats/information to the screen"), + (" -u, --unset", + "Additionally include any unset USE flags and the packages"), + ("", "that could use them"), + (" -v, --verbose", + "Used in the analyze action to output more detailed information"), + (" -p, --prefix", + "Used for testing purposes only, runs report using " + + "a prefix keyword and 'prefix' USE flag"), + #(" -G, --portage", + #"Use portage directly instead of gentoolkit's Package " + + #"object for some operations. Usually a little faster."), + ] + self.formatted_args =3D [ + (" use", + "Causes the action to analyze the installed packages USE flags"), + (" pkguse", + "Causes the action to analyze the installed packages PKGUSE flags"), + (" ", + "These are flags that have been set in /etc/portage/package.use"), + (" keywords", + "Causes the action to analyze the installed packages keywords"), + (" packages", + "Causes the action to analyze the installed packages and the"), + (" ", + "USE flags they were installed with"), + ] + self.short_opts =3D "huvpG" + self.long_opts =3D ("help", "unset", "verbose", "prefix") #, "portage"= ) + self.need_queries =3D True + self.arg_spec =3D "Target" + self.arg_options =3D ['use', 'pkguse','keywords', 'packages'] + self.arg_option =3D False + self.warning =3D ( + " CAUTION", + "This is beta software and some features/options are incomplete,", + "some features may change in future releases includig its name.", + "Feedback will be appreciated, http://bugs.gentoo.org") =20 =20 - def run(self, input_args, quiet=3DFalse): - """runs the module + def run(self, input_args, quiet=3DFalse): + """runs the module =20 - @param input_args: input arguments to be parsed - """ - query =3D self.main_setup(input_args) - query =3D self.validate_query(query) - self.set_quiet(quiet) - if query in ["use", "pkguse"]: - self.analyse_flags(query) - elif query in ["keywords"]: - self.analyse_keywords() - elif query in ["packages"]: - self.analyse_packages() + @param input_args: input arguments to be parsed + """ + query =3D self.main_setup(input_args) + query =3D self.validate_query(query) + self.set_quiet(quiet) + if query in ["use", "pkguse"]: + self.analyse_flags(query) + elif query in ["keywords"]: + self.analyse_keywords() + elif query in ["packages"]: + self.analyse_packages() =20 - def analyse_flags(self, target): - """This will scan the installed packages db and analyze the - USE flags used for installation and produce a report on how - they were used. + def analyse_flags(self, target): + """This will scan the installed packages db and analyze the + USE flags used for installation and produce a report on how + they were used. =20 - @type target: string - @param target: the target to be analyzed, one of ["use", "pkguse= "] - """ - system_use =3D portage.settings["USE"].split() - self.printer =3D AnalysisPrinter( - "use", - self.options["verbose"], - system_use) - if self.options["verbose"]: - cpvs =3D VARDB.cpv_all() - #cpvs =3D get_installed_cpvs() - #print "Total number of installed ebuilds =3D", len(cpvs) - flag_users =3D gather_flags_info(cpvs, system_use, - self.options["unset"], target=3Dtarget.upper(), - use_portage=3Dself.options['portage']) - else: - cpvs =3D get_installed_cpvs() - flag_users =3D gather_flags_info(cpvs, system_flags=3Dsystem= _use, - include_unset=3Dself.options["unset"], target=3Dtarget.u= pper(), - use_portage=3Dself.options['portage']) - #print flag_users - flag_keys =3D sorted(flag_users) - if self.options["verbose"]: - print(" Flag System #pkgs = cat/pkg-ver") - blankline =3D nl - elif not self.options['quiet']: - print(" Flag System #pkgs") - blankline =3D lambda: None - for flag in flag_keys: - flag_pos =3D flag_users[flag]["+"] - if len(flag_pos): - self.printer(flag, "+", flag_pos) - #blankline() - flag_neg =3D flag_users[flag]["-"] - if len(flag_neg): - self.printer(flag, "-", flag_neg) - #blankline() - if "unset" in flag_users[flag] and flag_users[flag]["unset"]= : - flag_unset =3D flag_users[flag]["unset"] - self.printer(flag, "unset", flag_unset) - #blankline() - if not self.options['quiet']: - print("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D") - print("Total number of flags in report =3D", - pp.output.red(str(len(flag_keys)))) - if self.options["verbose"]: - print("Total number of installed ebuilds =3D", - pp.output.red(str(len([x for x in cpvs])))) - print() + @type target: string + @param target: the target to be analyzed, one of ["use", "pkguse"] + """ + system_use =3D portage.settings["USE"].split() + self.printer =3D AnalysisPrinter( + "use", + self.options["verbose"], + system_use) + if self.options["verbose"]: + cpvs =3D VARDB.cpv_all() + #cpvs =3D get_installed_cpvs() + #print "Total number of installed ebuilds =3D", len(cpvs) + flag_users =3D gather_flags_info(cpvs, system_use, + self.options["unset"], target=3Dtarget.upper(), + use_portage=3Dself.options['portage']) + else: + cpvs =3D get_installed_cpvs() + flag_users =3D gather_flags_info(cpvs, system_flags=3Dsystem_use, + include_unset=3Dself.options["unset"], target=3Dtarget.upper(), + use_portage=3Dself.options['portage']) + #print flag_users + flag_keys =3D sorted(flag_users) + if self.options["verbose"]: + print(" Flag System #pkgs cat/pkg-= ver") + blankline =3D nl + elif not self.options['quiet']: + print(" Flag System #pkgs") + blankline =3D lambda: None + for flag in flag_keys: + flag_pos =3D flag_users[flag]["+"] + if len(flag_pos): + self.printer(flag, "+", flag_pos) + #blankline() + flag_neg =3D flag_users[flag]["-"] + if len(flag_neg): + self.printer(flag, "-", flag_neg) + #blankline() + if "unset" in flag_users[flag] and flag_users[flag]["unset"]: + flag_unset =3D flag_users[flag]["unset"] + self.printer(flag, "unset", flag_unset) + #blankline() + if not self.options['quiet']: + print("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D") + print("Total number of flags in report =3D", + pp.output.red(str(len(flag_keys)))) + if self.options["verbose"]: + print("Total number of installed ebuilds =3D", + pp.output.red(str(len([x for x in cpvs])))) + print() =20 =20 - def analyse_keywords(self, keywords=3DNone): - """This will scan the installed packages db and analyze the - keywords used for installation and produce a report on them. - """ - print() - system_keywords =3D portage.settings["ACCEPT_KEYWORDS"] - arch =3D portage.settings["ARCH"] - if self.options["prefix"]: - # build a new keyword for testing - system_keywords =3D "~" + arch + "-linux" - if self.options["verbose"] or self.options["prefix"]: - print("Current system ARCH =3D", arch) - print("Current system ACCEPT_KEYWORDS =3D", system_keywords) - system_keywords =3D system_keywords.split() - self.printer =3D AnalysisPrinter( - "keywords", - self.options["verbose"], - system_keywords) - self.analyser =3D KeywordAnalyser( arch, system_keywords, VARDB) - #self.analyser.set_order(portage.settings["USE"].split()) - # only for testing - test_use =3D portage.settings["USE"].split() - if self.options['prefix'] and 'prefix' not in test_use: - print("ANALYSE_KEYWORDS() 'prefix' flag not found in system"= , - "USE flags!!! appending for testing") - print() - test_use.append('prefix') - self.analyser.set_order(test_use) - # /end testing + def analyse_keywords(self, keywords=3DNone): + """This will scan the installed packages db and analyze the + keywords used for installation and produce a report on them. + """ + print() + system_keywords =3D portage.settings["ACCEPT_KEYWORDS"] + arch =3D portage.settings["ARCH"] + if self.options["prefix"]: + # build a new keyword for testing + system_keywords =3D "~" + arch + "-linux" + if self.options["verbose"] or self.options["prefix"]: + print("Current system ARCH =3D", arch) + print("Current system ACCEPT_KEYWORDS =3D", system_keywords) + system_keywords =3D system_keywords.split() + self.printer =3D AnalysisPrinter( + "keywords", + self.options["verbose"], + system_keywords) + self.analyser =3D KeywordAnalyser( arch, system_keywords, VARDB) + #self.analyser.set_order(portage.settings["USE"].split()) + # only for testing + test_use =3D portage.settings["USE"].split() + if self.options['prefix'] and 'prefix' not in test_use: + print("ANALYSE_KEYWORDS() 'prefix' flag not found in system", + "USE flags!!! appending for testing") + print() + test_use.append('prefix') + self.analyser.set_order(test_use) + # /end testing =20 - if self.options["verbose"]: - cpvs =3D VARDB.cpv_all() - #print "Total number of installed ebuilds =3D", len(cpvs) - keyword_users =3D gather_keywords_info( - cpvs=3Dcpvs, - system_keywords=3Dsystem_keywords, - use_portage=3Dself.options['portage'], - keywords=3Dkeywords, analyser =3D self.analyser - ) - blankline =3D nl - else: - keyword_users =3D gather_keywords_info( - system_keywords=3Dsystem_keywords, - use_portage=3Dself.options['portage'], - keywords=3Dkeywords, - analyser =3D self.analyser - ) - blankline =3D lambda: None - #print keyword_users - keyword_keys =3D sorted(keyword_users) - if self.options["verbose"]: - print(" Keyword System #pkgs cat/pkg-ver") - elif not self.options['quiet']: - print(" Keyword System #pkgs") - for keyword in keyword_keys: - kwd_stable =3D keyword_users[keyword]["stable"] - if len(kwd_stable): - self.printer(keyword, " ", kwd_stable) - blankline() - kwd_testing =3D keyword_users[keyword]["testing"] - if len(kwd_testing): - self.printer(keyword, "~", kwd_testing) - blankline() - kwd_missing =3D keyword_users[keyword]["missing"] - if len(kwd_missing): - self.printer(keyword, "-", kwd_missing) - blankline - if not self.options['quiet']: - if self.analyser.mismatched: - print("_________________________________________________= ") - print(("The following packages were found to have a \n" = + - "different recorded ARCH than the current system ARC= H")) - for cpv in self.analyser.mismatched: - print("\t", pp.cpv(cpv)) - print("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D") - print("Total number of keywords in report =3D", - pp.output.red(str(len(keyword_keys)))) - if self.options["verbose"]: - print("Total number of installed ebuilds =3D", - pp.output.red(str(len(cpvs)))) - print() + if self.options["verbose"]: + cpvs =3D VARDB.cpv_all() + #print "Total number of installed ebuilds =3D", len(cpvs) + keyword_users =3D gather_keywords_info( + cpvs=3Dcpvs, + system_keywords=3Dsystem_keywords, + use_portage=3Dself.options['portage'], + keywords=3Dkeywords, analyser =3D self.analyser + ) + blankline =3D nl + else: + keyword_users =3D gather_keywords_info( + system_keywords=3Dsystem_keywords, + use_portage=3Dself.options['portage'], + keywords=3Dkeywords, + analyser =3D self.analyser + ) + blankline =3D lambda: None + #print keyword_users + keyword_keys =3D sorted(keyword_users) + if self.options["verbose"]: + print(" Keyword System #pkgs cat/pkg-ver") + elif not self.options['quiet']: + print(" Keyword System #pkgs") + for keyword in keyword_keys: + kwd_stable =3D keyword_users[keyword]["stable"] + if len(kwd_stable): + self.printer(keyword, " ", kwd_stable) + blankline() + kwd_testing =3D keyword_users[keyword]["testing"] + if len(kwd_testing): + self.printer(keyword, "~", kwd_testing) + blankline() + kwd_missing =3D keyword_users[keyword]["missing"] + if len(kwd_missing): + self.printer(keyword, "-", kwd_missing) + blankline + if not self.options['quiet']: + if self.analyser.mismatched: + print("_________________________________________________") + print(("The following packages were found to have a \n" + + "different recorded ARCH than the current system ARCH")) + for cpv in self.analyser.mismatched: + print("\t", pp.cpv(cpv)) + print("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D") + print("Total number of keywords in report =3D", + pp.output.red(str(len(keyword_keys)))) + if self.options["verbose"]: + print("Total number of installed ebuilds =3D", + pp.output.red(str(len(cpvs)))) + print() =20 =20 - def analyse_packages(self): - """This will scan the installed packages db and analyze the - USE flags used for installation and produce a report. + def analyse_packages(self): + """This will scan the installed packages db and analyze the + USE flags used for installation and produce a report. =20 - @type target: string - @param target: the target to be analyzed, one of ["use", "pkguse= "] - """ - system_use =3D portage.settings["USE"].split() - if self.options["verbose"]: - cpvs =3D VARDB.cpv_all() - key_width =3D 45 - else: - cpvs =3D get_installed_cpvs() - key_width =3D 1 + @type target: string + @param target: the target to be analyzed, one of ["use", "pkguse"] + """ + system_use =3D portage.settings["USE"].split() + if self.options["verbose"]: + cpvs =3D VARDB.cpv_all() + key_width =3D 45 + else: + cpvs =3D get_installed_cpvs() + key_width =3D 1 =20 - self.printer =3D AnalysisPrinter( - "packages", - self.options["verbose"], - key_width=3Dkey_width) + self.printer =3D AnalysisPrinter( + "packages", + self.options["verbose"], + key_width=3Dkey_width) =20 - cpvs =3D sorted(cpvs) - flags =3D FlagAnalyzer( - system=3Dsystem_use, - filter_defaults=3DFalse, - target=3D"USE" - ) + cpvs =3D sorted(cpvs) + flags =3D FlagAnalyzer( + system=3Dsystem_use, + filter_defaults=3DFalse, + target=3D"USE" + ) =20 - if self.options["verbose"]: - print(" cat/pkg-ver USE Flags"= ) - # "app-emulation/emul-linux-x86-sdl-20100915 ...." - blankline =3D nl - elif not self.options['quiet']: - print(" cat/pkg-ver USE Flags"= ) - blankline =3D lambda: None - for cpv in cpvs: - (flag_plus, flag_neg, unset) =3D flags.analyse_cpv(cpv) - if self.options["unset"]: - self.printer(cpv, "", (flag_plus, flag_neg, unset)) - else: - self.printer(cpv, "", (flag_plus, flag_neg, [])) - if not self.options['quiet']: - print("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D") - print("Total number of installed ebuilds =3D", - pp.output.red(str(len([x for x in cpvs])))) - print() + if self.options["verbose"]: + print(" cat/pkg-ver USE Flags") + # "app-emulation/emul-linux-x86-sdl-20100915 ...." + blankline =3D nl + elif not self.options['quiet']: + print(" cat/pkg-ver USE Flags") + blankline =3D lambda: None + for cpv in cpvs: + (flag_plus, flag_neg, unset) =3D flags.analyse_cpv(cpv) + if self.options["unset"]: + self.printer(cpv, "", (flag_plus, flag_neg, unset)) + else: + self.printer(cpv, "", (flag_plus, flag_neg, [])) + if not self.options['quiet']: + print("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D") + print("Total number of installed ebuilds =3D", + pp.output.red(str(len([x for x in cpvs])))) + print() =20 =20 def main(input_args): - """Common starting method by the analyze master - unless all modules are converted to this class method. + """Common starting method by the analyze master + unless all modules are converted to this class method. =20 - @param input_args: input args as supplied by equery master module. - """ - query_module =3D Analyse() - query_module.run(input_args, gentoolkit.CONFIG['quiet']) + @param input_args: input args as supplied by equery master module. + """ + query_module =3D Analyse() + query_module.run(input_args, gentoolkit.CONFIG['quiet']) =20 # vim: set ts=3D4 sw=3D4 tw=3D79: diff --git a/pym/gentoolkit/enalyze/rebuild.py b/pym/gentoolkit/enalyze/r= ebuild.py index 0db001e..d0e1813 100644 --- a/pym/gentoolkit/enalyze/rebuild.py +++ b/pym/gentoolkit/enalyze/rebuild.py @@ -21,7 +21,7 @@ from gentoolkit.dbapi import PORTDB, VARDB from gentoolkit.module_base import ModuleBase from gentoolkit import pprinter as pp from gentoolkit.enalyze.lib import (get_installed_use, get_flags, FlagAn= alyzer, - KeywordAnalyser) + KeywordAnalyser) from gentoolkit.flag import reduce_flags from gentoolkit.enalyze.output import RebuildPrinter from gentoolkit.atom import Atom @@ -31,339 +31,339 @@ import portage =20 =20 def cpv_all_diff_use( - cpvs=3DNone, - system_flags=3DNone, - # override-able for testing - _get_flags=3Dget_flags, - _get_used=3Dget_installed_use - ): - """Data gathering and analysis function determines - the difference between the current default USE flag settings - and the currently installed pkgs recorded USE flag settings - - @type cpvs: list - @param cpvs: optional list of [cat/pkg-ver,...] to analyze or - defaults to entire installed pkg db - @type: system_flags: list - @param system_flags: the current default USE flags as defined - by portage.settings["USE"].split() - @type _get_flags: function - @param _get_flags: ovride-able for testing, - defaults to gentoolkit.enalyze.lib.get_flags - @param _get_used: ovride-able for testing, - defaults to gentoolkit.enalyze.lib.get_installed_use - @rtype dict. {cpv:['flag1', '-flag2',...]} - """ - if cpvs is None: - cpvs =3D VARDB.cpv_all() - cpvs.sort() - data =3D {} - cp_counts =3D {} - # pass them in to override for tests - flags =3D FlagAnalyzer(system_flags, - filter_defaults=3DTrue, - target=3D"USE", - _get_flags=3D_get_flags, - _get_used=3Dget_installed_use - ) - for cpv in cpvs: - plus, minus, unset =3D flags.analyse_cpv(cpv) - atom =3D Atom("=3D"+cpv) - atom.slot =3D VARDB.aux_get(atom.cpv, ["SLOT"])[0] - for flag in minus: - plus.add("-"+flag) - if len(plus): - if atom.cp not in data: - data[atom.cp] =3D [] - if atom.cp not in cp_counts: - cp_counts[atom.cp] =3D 0 - atom.use =3D list(plus) - data[atom.cp].append(atom) - cp_counts[atom.cp] +=3D 1 - return data, cp_counts + cpvs=3DNone, + system_flags=3DNone, + # override-able for testing + _get_flags=3Dget_flags, + _get_used=3Dget_installed_use + ): + """Data gathering and analysis function determines + the difference between the current default USE flag settings + and the currently installed pkgs recorded USE flag settings + + @type cpvs: list + @param cpvs: optional list of [cat/pkg-ver,...] to analyze or + defaults to entire installed pkg db + @type: system_flags: list + @param system_flags: the current default USE flags as defined + by portage.settings["USE"].split() + @type _get_flags: function + @param _get_flags: ovride-able for testing, + defaults to gentoolkit.enalyze.lib.get_flags + @param _get_used: ovride-able for testing, + defaults to gentoolkit.enalyze.lib.get_installed_use + @rtype dict. {cpv:['flag1', '-flag2',...]} + """ + if cpvs is None: + cpvs =3D VARDB.cpv_all() + cpvs.sort() + data =3D {} + cp_counts =3D {} + # pass them in to override for tests + flags =3D FlagAnalyzer(system_flags, + filter_defaults=3DTrue, + target=3D"USE", + _get_flags=3D_get_flags, + _get_used=3Dget_installed_use + ) + for cpv in cpvs: + plus, minus, unset =3D flags.analyse_cpv(cpv) + atom =3D Atom("=3D"+cpv) + atom.slot =3D VARDB.aux_get(atom.cpv, ["SLOT"])[0] + for flag in minus: + plus.add("-"+flag) + if len(plus): + if atom.cp not in data: + data[atom.cp] =3D [] + if atom.cp not in cp_counts: + cp_counts[atom.cp] =3D 0 + atom.use =3D list(plus) + data[atom.cp].append(atom) + cp_counts[atom.cp] +=3D 1 + return data, cp_counts =20 =20 def cpv_all_diff_keywords( - cpvs=3DNone, - system_keywords=3DNone, - use_portage=3DFalse, - # override-able for testing - keywords=3Dportage.settings["ACCEPT_KEYWORDS"], - analyser =3D None - ): - """Analyze the installed pkgs 'keywords' for difference from ACCEPT_= KEYWORDS - - @param cpvs: optional list of [cat/pkg-ver,...] to analyze or - defaults to entire installed pkg db - @param system_keywords: list of the system keywords - @param keywords: user defined list of keywords to check and report o= n - or reports on all relevant keywords found to have been used. - @param _get_kwds: overridable function for testing - @param _get_used: overridable function for testing - @rtype dict. {keyword:{"stable":[cat/pkg-ver,...], - "testing":[cat/pkg-ver,...]} - """ - if cpvs is None: - cpvs =3D VARDB.cpv_all() - keyword_users =3D {} - cp_counts =3D {} - for cpv in cpvs: - if cpv.startswith("virtual"): - continue - if use_portage: - keyword =3D analyser.get_inst_keyword_cpv(cpv) - else: - pkg =3D Package(cpv) - keyword =3D analyser.get_inst_keyword_pkg(pkg) - #print "returned keyword =3D", cpv, keyword, keyword[0] - key =3D keyword[0] - if key in ["~", "-"] and keyword not in system_keywords: - atom =3D Atom("=3D"+cpv) - if atom.cp not in keyword_users: - keyword_users[atom.cp] =3D [] - if atom.cp not in cp_counts: - cp_counts[atom.cp] =3D 0 - if key in ["~"]: - atom.keyword =3D keyword - atom.slot =3D VARDB.aux_get(atom.cpv, ["SLOT"])[0] - keyword_users[atom.cp].append(atom) - cp_counts[atom.cp] +=3D 1 - elif key in ["-"]: - #print "adding cpv to missing:", cpv - atom.keyword =3D "**" - atom.slot =3D VARDB.aux_get(atom.cpv, ["SLOT"])[0] - keyword_users[atom.cp].append(atom) - cp_counts[atom.cp] +=3D 1 - return keyword_users, cp_counts + cpvs=3DNone, + system_keywords=3DNone, + use_portage=3DFalse, + # override-able for testing + keywords=3Dportage.settings["ACCEPT_KEYWORDS"], + analyser =3D None + ): + """Analyze the installed pkgs 'keywords' for difference from ACCEPT_KEY= WORDS + + @param cpvs: optional list of [cat/pkg-ver,...] to analyze or + defaults to entire installed pkg db + @param system_keywords: list of the system keywords + @param keywords: user defined list of keywords to check and report on + or reports on all relevant keywords found to have been used. + @param _get_kwds: overridable function for testing + @param _get_used: overridable function for testing + @rtype dict. {keyword:{"stable":[cat/pkg-ver,...], + "testing":[cat/pkg-ver,...]} + """ + if cpvs is None: + cpvs =3D VARDB.cpv_all() + keyword_users =3D {} + cp_counts =3D {} + for cpv in cpvs: + if cpv.startswith("virtual"): + continue + if use_portage: + keyword =3D analyser.get_inst_keyword_cpv(cpv) + else: + pkg =3D Package(cpv) + keyword =3D analyser.get_inst_keyword_pkg(pkg) + #print "returned keyword =3D", cpv, keyword, keyword[0] + key =3D keyword[0] + if key in ["~", "-"] and keyword not in system_keywords: + atom =3D Atom("=3D"+cpv) + if atom.cp not in keyword_users: + keyword_users[atom.cp] =3D [] + if atom.cp not in cp_counts: + cp_counts[atom.cp] =3D 0 + if key in ["~"]: + atom.keyword =3D keyword + atom.slot =3D VARDB.aux_get(atom.cpv, ["SLOT"])[0] + keyword_users[atom.cp].append(atom) + cp_counts[atom.cp] +=3D 1 + elif key in ["-"]: + #print "adding cpv to missing:", cpv + atom.keyword =3D "**" + atom.slot =3D VARDB.aux_get(atom.cpv, ["SLOT"])[0] + keyword_users[atom.cp].append(atom) + cp_counts[atom.cp] +=3D 1 + return keyword_users, cp_counts =20 =20 class Rebuild(ModuleBase): - """Installed db analysis tool to query the installed databse - and produce/output stats for USE flags or keywords/mask. - The 'rebuild' action output is in the form suitable for file type ou= tput - to create a new package.use, package.keywords, package.unmask - type files in the event of needing to rebuild the - /etc/portage/* user configs - """ - def __init__(self): - ModuleBase.__init__(self) - self.module_name =3D "rebuild" - self.options =3D { - "use": False, - "keywords": False, - "unmask": False, - "verbose": False, - "quiet": False, - "exact": False, - "pretend": False, - "prefix": False, - "portage": True, - "slot": False - #"unset": False - } - self.module_opts =3D { - "-p": ("pretend", "boolean", True), - "--pretend": ("pretend", "boolean", True), - "-e": ("exact", "boolean", True), - "--exact": ("exact", "boolean", True), - "-s": ("slot", "boolean", True), - "--slot": ("slot", "boolean", True), - "-v": ("verbose", "boolean", True), - "--verbose": ("verbose", "boolean", True), - } - self.formatted_options =3D [ - (" -h, --help", "Outputs this useage message"), - (" -p, --pretend", "Does not actually create the files.")= , - (" ", "It directs the outputs to the screen"), - (" -e, --exact", "will atomize the package with a"), - (" ", "leading '=3D' and include the version"), - (" -s, --slot", "will atomize the package with a"), - (" ", "leading '=3D' and include the slot") - ] - self.formatted_args =3D [ - (" use", - "causes the action to analyze the installed packages USE fla= gs"), - (" keywords", - "causes the action to analyze the installed packages keyword= s"), - (" unmask", - "causes the action to analyze the installed packages " + \ - "current mask status") - ] - self.short_opts =3D "hepsv" - self.long_opts =3D ("help", "exact", "pretend", "slot", "verbose= ") - self.need_queries =3D True - self.arg_spec =3D "TargetSpec" - self.arg_options =3D ['use', 'keywords', 'unmask'] - self.arg_option =3D False - self.warning =3D ( - " CAUTION", - "This is beta software and some features/options are incompl= ete,", - "some features may change in future releases includig its na= me.", - "The file generated is saved in your home directory", - "Feedback will be appreciated, http://bugs.gentoo.org") - - - - def run(self, input_args, quiet=3DFalse): - """runs the module - - @param input_args: input arguments to be parsed - """ - self.options['quiet'] =3D quiet - query =3D self.main_setup(input_args) - query =3D self.validate_query(query) - if query in ["use"]: - self.rebuild_use() - elif query in ["keywords"]: - self.rebuild_keywords() - elif query in ["unmask"]: - self.rebuild_unmask() - - - def rebuild_use(self): - if not self.options["quiet"]: - print() - print(" -- Scanning installed packages for USE flag setting= s that") - print(" do not match the default settings") - system_use =3D portage.settings["USE"].split() - output =3D RebuildPrinter( - "use", self.options["pretend"], self.options["exact"], - self.options['slot']) - pkgs, cp_counts =3D cpv_all_diff_use(system_flags=3Dsystem_use) - pkg_count =3D len(pkgs) - if self.options["verbose"]: - print() - print((pp.emph(" -- Found ") + pp.number(str(pkg_count)) + - pp.emph(" packages that need entries"))) - #print pp.emph(" package.use to maintain their current s= etting") - if pkgs: - pkg_keys =3D sorted(pkgs) - #print len(pkgs) - if self.options["pretend"] and not self.options["quiet"]: - print() - print(pp.globaloption( - " -- These are the installed packages & use flags "= + - "that were detected")) - print(pp.globaloption(" to need use flag settings ot= her " + - "than the defaults.")) - print() - elif not self.options["quiet"]: - print(" -- preparing pkgs for file entries") - for pkg in pkg_keys: - output(pkg, pkgs[pkg], cp_counts[pkg]) - if self.options['verbose']: - message =3D (pp.emph(" ") + - pp.number(str(pkg_count)) + - pp.emph(" different packages")) - print() - print(pp.globaloption(" -- Totals")) - print(message) - #print - #unique =3D list(unique_flags) - #unique.sort() - #print unique - if not self.options["pretend"]: - filepath =3D os.path.expanduser('~/package.use.test') - self.save_file(filepath, output.lines) - - def rebuild_keywords(self): - print("Module action not yet available") - print() - """This will scan the installed packages db and analyze the - keywords used for installation and produce a report on them. - """ - system_keywords =3D portage.settings["ACCEPT_KEYWORDS"].split() - output =3D RebuildPrinter( - "keywords", self.options["pretend"], self.options["exact"], - self.options['slot']) - arch =3D portage.settings["ARCH"] - if self.options["prefix"]: - # build a new keyword for testing - system_keywords =3D "~" + arch + "-linux" - if self.options["verbose"] or self.options["prefix"]: - print("Current system ARCH =3D", arch) - print("Current system ACCEPT_KEYWORDS =3D", system_keywords) - self.analyser =3D KeywordAnalyser( arch, system_keywords, VARDB) - #self.analyser.set_order(portage.settings["USE"].split()) - # only for testing - test_use =3D portage.settings["USE"].split() - if self.options['prefix'] and 'prefix' not in test_use: - print("REBUILD_KEYWORDS() 'prefix' flag not found in system"= , - "USE flags!!! appending for testing") - print() - test_use.append('prefix') - self.analyser.set_order(test_use) - # /end testing - - cpvs =3D VARDB.cpv_all() - #print "Total number of installed ebuilds =3D", len(cpvs) - pkgs, cp_counts =3D cpv_all_diff_keywords( - cpvs=3Dcpvs, - system_keywords=3Dsystem_keywords, - use_portage=3Dself.options['portage'], - analyser =3D self.analyser - ) - #print([pkgs[p][0].cpv for p in pkgs]) - if pkgs: - pkg_keys =3D sorted(pkgs) - #print(len(pkgs)) - if self.options["pretend"] and not self.options["quiet"]: - print() - print(pp.globaloption( - " -- These are the installed packages & keywords " = + - "that were detected")) - print(pp.globaloption(" to need keyword settings oth= er " + - "than the defaults.")) - print() - elif not self.options["quiet"]: - print(" -- preparing pkgs for file entries") - for pkg in pkg_keys: - output(pkg, pkgs[pkg], cp_counts[pkg]) - if not self.options['quiet']: - if self.analyser.mismatched: - print("_________________________________________________= ") - print(("The following packages were found to have a \n" = + - "different recorded ARCH than the current system ARC= H")) - for cpv in self.analyser.mismatched: - print("\t", pp.cpv(cpv)) - print("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D") - print("Total number of entries in report =3D", - pp.output.red(str(len(pkg_keys)))) - if self.options["verbose"]: - print("Total number of installed ebuilds =3D", - pp.output.red(str(len(cpvs)))) - print() - if not self.options["pretend"]: - filepath =3D os.path.expanduser('~/package.keywords.test= ') - self.save_file(filepath, output.lines) - - - def rebuild_unmask(self): - print("Module action not yet available") - print() - - - def save_file(self, filepath, data): - """Writes the data to the file determined by filepath - - @param filepath: string. eg. '/path/to/filename' - @param data: list of lines to write to filepath - """ - if not self.options["quiet"]: - print(' - Saving file: %s' %filepath) - with open(filepath, "w") as output: - output.write('\n'.join(data)) - print(" - Done") + """Installed db analysis tool to query the installed databse + and produce/output stats for USE flags or keywords/mask. + The 'rebuild' action output is in the form suitable for file type outpu= t + to create a new package.use, package.keywords, package.unmask + type files in the event of needing to rebuild the + /etc/portage/* user configs + """ + def __init__(self): + ModuleBase.__init__(self) + self.module_name =3D "rebuild" + self.options =3D { + "use": False, + "keywords": False, + "unmask": False, + "verbose": False, + "quiet": False, + "exact": False, + "pretend": False, + "prefix": False, + "portage": True, + "slot": False + #"unset": False + } + self.module_opts =3D { + "-p": ("pretend", "boolean", True), + "--pretend": ("pretend", "boolean", True), + "-e": ("exact", "boolean", True), + "--exact": ("exact", "boolean", True), + "-s": ("slot", "boolean", True), + "--slot": ("slot", "boolean", True), + "-v": ("verbose", "boolean", True), + "--verbose": ("verbose", "boolean", True), + } + self.formatted_options =3D [ + (" -h, --help", "Outputs this useage message"), + (" -p, --pretend", "Does not actually create the files."), + (" ", "It directs the outputs to the screen"), + (" -e, --exact", "will atomize the package with a"), + (" ", "leading '=3D' and include the version"), + (" -s, --slot", "will atomize the package with a"), + (" ", "leading '=3D' and include the slot") + ] + self.formatted_args =3D [ + (" use", + "causes the action to analyze the installed packages USE flags"), + (" keywords", + "causes the action to analyze the installed packages keywords"), + (" unmask", + "causes the action to analyze the installed packages " + \ + "current mask status") + ] + self.short_opts =3D "hepsv" + self.long_opts =3D ("help", "exact", "pretend", "slot", "verbose") + self.need_queries =3D True + self.arg_spec =3D "TargetSpec" + self.arg_options =3D ['use', 'keywords', 'unmask'] + self.arg_option =3D False + self.warning =3D ( + " CAUTION", + "This is beta software and some features/options are incomplete,", + "some features may change in future releases includig its name.", + "The file generated is saved in your home directory", + "Feedback will be appreciated, http://bugs.gentoo.org") + + + + def run(self, input_args, quiet=3DFalse): + """runs the module + + @param input_args: input arguments to be parsed + """ + self.options['quiet'] =3D quiet + query =3D self.main_setup(input_args) + query =3D self.validate_query(query) + if query in ["use"]: + self.rebuild_use() + elif query in ["keywords"]: + self.rebuild_keywords() + elif query in ["unmask"]: + self.rebuild_unmask() + + + def rebuild_use(self): + if not self.options["quiet"]: + print() + print(" -- Scanning installed packages for USE flag settings that") + print(" do not match the default settings") + system_use =3D portage.settings["USE"].split() + output =3D RebuildPrinter( + "use", self.options["pretend"], self.options["exact"], + self.options['slot']) + pkgs, cp_counts =3D cpv_all_diff_use(system_flags=3Dsystem_use) + pkg_count =3D len(pkgs) + if self.options["verbose"]: + print() + print((pp.emph(" -- Found ") + pp.number(str(pkg_count)) + + pp.emph(" packages that need entries"))) + #print pp.emph(" package.use to maintain their current setting") + if pkgs: + pkg_keys =3D sorted(pkgs) + #print len(pkgs) + if self.options["pretend"] and not self.options["quiet"]: + print() + print(pp.globaloption( + " -- These are the installed packages & use flags " + + "that were detected")) + print(pp.globaloption(" to need use flag settings other " + + "than the defaults.")) + print() + elif not self.options["quiet"]: + print(" -- preparing pkgs for file entries") + for pkg in pkg_keys: + output(pkg, pkgs[pkg], cp_counts[pkg]) + if self.options['verbose']: + message =3D (pp.emph(" ") + + pp.number(str(pkg_count)) + + pp.emph(" different packages")) + print() + print(pp.globaloption(" -- Totals")) + print(message) + #print + #unique =3D list(unique_flags) + #unique.sort() + #print unique + if not self.options["pretend"]: + filepath =3D os.path.expanduser('~/package.use.test') + self.save_file(filepath, output.lines) + + def rebuild_keywords(self): + print("Module action not yet available") + print() + """This will scan the installed packages db and analyze the + keywords used for installation and produce a report on them. + """ + system_keywords =3D portage.settings["ACCEPT_KEYWORDS"].split() + output =3D RebuildPrinter( + "keywords", self.options["pretend"], self.options["exact"], + self.options['slot']) + arch =3D portage.settings["ARCH"] + if self.options["prefix"]: + # build a new keyword for testing + system_keywords =3D "~" + arch + "-linux" + if self.options["verbose"] or self.options["prefix"]: + print("Current system ARCH =3D", arch) + print("Current system ACCEPT_KEYWORDS =3D", system_keywords) + self.analyser =3D KeywordAnalyser( arch, system_keywords, VARDB) + #self.analyser.set_order(portage.settings["USE"].split()) + # only for testing + test_use =3D portage.settings["USE"].split() + if self.options['prefix'] and 'prefix' not in test_use: + print("REBUILD_KEYWORDS() 'prefix' flag not found in system", + "USE flags!!! appending for testing") + print() + test_use.append('prefix') + self.analyser.set_order(test_use) + # /end testing + + cpvs =3D VARDB.cpv_all() + #print "Total number of installed ebuilds =3D", len(cpvs) + pkgs, cp_counts =3D cpv_all_diff_keywords( + cpvs=3Dcpvs, + system_keywords=3Dsystem_keywords, + use_portage=3Dself.options['portage'], + analyser =3D self.analyser + ) + #print([pkgs[p][0].cpv for p in pkgs]) + if pkgs: + pkg_keys =3D sorted(pkgs) + #print(len(pkgs)) + if self.options["pretend"] and not self.options["quiet"]: + print() + print(pp.globaloption( + " -- These are the installed packages & keywords " + + "that were detected")) + print(pp.globaloption(" to need keyword settings other " + + "than the defaults.")) + print() + elif not self.options["quiet"]: + print(" -- preparing pkgs for file entries") + for pkg in pkg_keys: + output(pkg, pkgs[pkg], cp_counts[pkg]) + if not self.options['quiet']: + if self.analyser.mismatched: + print("_________________________________________________") + print(("The following packages were found to have a \n" + + "different recorded ARCH than the current system ARCH")) + for cpv in self.analyser.mismatched: + print("\t", pp.cpv(cpv)) + print("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D") + print("Total number of entries in report =3D", + pp.output.red(str(len(pkg_keys)))) + if self.options["verbose"]: + print("Total number of installed ebuilds =3D", + pp.output.red(str(len(cpvs)))) + print() + if not self.options["pretend"]: + filepath =3D os.path.expanduser('~/package.keywords.test') + self.save_file(filepath, output.lines) + + + def rebuild_unmask(self): + print("Module action not yet available") + print() + + + def save_file(self, filepath, data): + """Writes the data to the file determined by filepath + + @param filepath: string. eg. '/path/to/filename' + @param data: list of lines to write to filepath + """ + if not self.options["quiet"]: + print(' - Saving file: %s' %filepath) + with open(filepath, "w") as output: + output.write('\n'.join(data)) + print(" - Done") =20 =20 def main(input_args): - """Common starting method by the analyze master - unless all modules are converted to this class method. + """Common starting method by the analyze master + unless all modules are converted to this class method. =20 - @param input_args: input args as supplied by equery master module. - """ - query_module =3D Rebuild() - query_module.run(input_args, gentoolkit.CONFIG['quiet']) + @param input_args: input args as supplied by equery master module. + """ + query_module =3D Rebuild() + query_module.run(input_args, gentoolkit.CONFIG['quiet']) =20 # vim: set ts=3D4 sw=3D4 tw=3D79: =20