From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 5D02B138247 for ; Sun, 1 Dec 2013 08:44:42 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 34CFFE08E0; Sun, 1 Dec 2013 08:44:41 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 7A941E08E0 for ; Sun, 1 Dec 2013 08:44:40 +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 41A8333DAC9 for ; Sun, 1 Dec 2013 08:44:39 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id E6534E54AB for ; Sun, 1 Dec 2013 08:44:37 +0000 (UTC) From: "Devan Franchini" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Devan Franchini" Message-ID: <1385886904.a07f5921e24e4777b03abe9dbec97ddce2015cb0.twitch153@gentoo> Subject: [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/ X-VCS-Repository: proj/webapp-config X-VCS-Files: WebappConfig/config.py WebappConfig/db.py X-VCS-Directories: WebappConfig/ X-VCS-Committer: twitch153 X-VCS-Committer-Name: Devan Franchini X-VCS-Revision: a07f5921e24e4777b03abe9dbec97ddce2015cb0 X-VCS-Branch: experimental Date: Sun, 1 Dec 2013 08:44:37 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 4189f2dc-c8f8-4fe0-a5c5-b9b5c9b5a593 X-Archives-Hash: 61042c6f45627cb6b68949eac2452c55 commit: a07f5921e24e4777b03abe9dbec97ddce2015cb0 Author: Devan Franchini gentoo org> AuthorDate: Sun Dec 1 08:35:04 2013 +0000 Commit: Devan Franchini gentoo org> CommitDate: Sun Dec 1 08:35:04 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=a07f5921 WebappConfig/{db,config}.py: Adds support for prune-database() function. This renames the prune-db() function to prune-database() as well as adding a command line option to call the function and implements it in config.py. X-Gentoo-Bug: 490090 X-Gentoo-Bug-URL: https://bugs.gentoo.org/490090 --- WebappConfig/config.py | 24 ++++++++++++++++++++++-- WebappConfig/db.py | 35 +++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/WebappConfig/config.py b/WebappConfig/config.py index 1c09488..4df2f27 100644 --- a/WebappConfig/config.py +++ b/WebappConfig/config.py @@ -565,7 +565,7 @@ class Config: group.add_option('-V', '--verbose', - action='store_true', + action='store_true', help = 'Output even more information than normal' ) @@ -593,6 +593,14 @@ class Config: 'or version number as arguments to restrict the ' 'listing.') + group.add_option('--prune-database', + '--pd', + type = 'choice', + choices = ['pretend', + 'clean'], + help = 'This will list all outdated entries in ' + 'the webapp-config "database".') + group.add_option('--show-installed', '--si', action='store_true', @@ -932,7 +940,7 @@ class Config: # set the action to be performed work = ['install', 'clean', 'upgrade', 'list_installs', 'list_servers', 'list_unused_installs', - 'show_installed', 'show_postinst', + 'prune_database', 'show_installed', 'show_postinst', 'show_postupgrade', 'check_config', 'query'] for i in work: @@ -940,6 +948,9 @@ class Config: self.work = i break + if options.__dict__.get('prune_database'): + self.prune_action = options.__dict__.get('prune_database') + OUT.debug('Checking command line arguments', 1) if len(args) > 0: @@ -1134,6 +1145,15 @@ class Config: self.create_webapp_db( self.maybe_get('cat'), self.maybe_get('pn'), self.maybe_get('pvr')).listinstalls() + if self.work == 'prune_database': + # Get the handler for the virtual install db. If the action is equal + # to clean, then it'll simply prune the "db" of outdated entries. + # If it's not set to clean, then it'll list the outdated entries + # in the db to be cleaned out. + self.__r = wrapper.get_root(self) + self.create_webapp_db( self.maybe_get('cat'), + self.maybe_get('pn'), + self.maybe_get('pvr')).prune_database(self.prune_action) if self.work == 'show_installed': diff --git a/WebappConfig/db.py b/WebappConfig/db.py index 37bfdc9..d0913a9 100644 --- a/WebappConfig/db.py +++ b/WebappConfig/db.py @@ -424,42 +424,49 @@ class WebappDB(AppHierarchy): return result - def prune_db(self): + def prune_database(self, action): ''' Prunes the installs files to ensure no webapp is incorrectly listed as installed. ''' loc = self.read_db() - + + print(action) if not loc and self.__v: OUT.die('No virtual installs found!') files = self.list_locations() keys = sorted(loc) + if action != 'clean': + OUT.warn('This is a list of all outdated entries that would be removed: ') for j in keys: for i in loc[j]: appdir = i[3].strip() # We check to see if the webapp is installed. + # TODO: Fix algorithm to see if this is an outdated + # entry. if not os.path.exists(appdir+'/.webapp'): if self.__v: OUT.warn('No .webapp file found in dir: ') OUT.warn(appdir) OUT.warn('Assuming webapp is no longer installed.') OUT.warn('Pruning entry from database.') - - for installs in files.keys(): - contents = open(installs).readlines() - new_entries = '' - for entry in contents: - # Grab all the other entries but the one that - # isn't installed. - if not re.search('.* ' + appdir +'\\n', entry): - new_entries += entry - f = open(installs, 'w') - f.write(new_entries) - f.close() + if action == 'clean': + for installs in files.keys(): + contents = open(installs).readlines() + new_entries = '' + for entry in contents: + # Grab all the other entries but the one that + # isn't installed. + if not re.search('.* ' + appdir +'\\n', entry): + new_entries += entry + f = open(installs, 'w') + f.write(new_entries) + f.close() + else: + OUT.warn(appdir) def has_installs(self): ''' Return True in case there are any virtual install locations