public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Devan Franchini" <twitch153@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/
Date: Sun,  1 Dec 2013 08:44:37 +0000 (UTC)	[thread overview]
Message-ID: <1385886904.a07f5921e24e4777b03abe9dbec97ddce2015cb0.twitch153@gentoo> (raw)

commit:     a07f5921e24e4777b03abe9dbec97ddce2015cb0
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Sun Dec  1 08:35:04 2013 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> 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 


             reply	other threads:[~2013-12-01  8:44 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-01  8:44 Devan Franchini [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-06-19 19:19 [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/ Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-05-17  3:54 Devan Franchini
2015-05-17  3:44 Devan Franchini
2015-05-17  3:19 Devan Franchini
2015-05-17  2:51 Devan Franchini
2015-05-17  2:42 Devan Franchini
2015-05-17  2:28 Devan Franchini
2015-05-17  0:38 Devan Franchini
2015-05-16  2:16 Devan Franchini
2014-11-18  0:03 Devan Franchini
2014-11-17 23:58 Devan Franchini
2014-11-17 23:42 Devan Franchini
2014-11-14  1:14 Devan Franchini
2014-10-16 19:18 Devan Franchini
2014-10-15 13:27 Devan Franchini
2014-10-15 13:27 Devan Franchini
2014-10-15 13:27 Devan Franchini
2014-10-14 19:13 Devan Franchini
2014-10-14 17:14 Devan Franchini
2014-10-09 18:02 Devan Franchini
2014-10-09 17:58 Devan Franchini
2014-10-09 17:52 Devan Franchini
2014-09-23 17:09 Devan Franchini
2014-04-26 19:33 Devan Franchini
2014-01-24 21:45 Devan Franchini
2014-01-22 15:32 Devan Franchini
2014-01-08  4:03 Devan Franchini
2014-01-04  1:40 Devan Franchini
2014-01-04  1:13 Devan Franchini
2013-12-19  6:34 Devan Franchini
2013-12-10  1:34 Devan Franchini
2013-12-09  8:31 Devan Franchini
2013-12-01  8:50 Devan Franchini
2013-11-05 22:17 Devan Franchini
2013-11-05 22:17 Devan Franchini
2013-10-29  2:18 Devan Franchini
2013-10-27 19:27 Devan Franchini
2013-10-27  2:26 Devan Franchini
2013-10-19  3:34 Devan Franchini
2013-10-18  3:39 Devan Franchini
2013-10-10  3:46 Devan Franchini
2013-10-10  3:41 Devan Franchini
2013-10-10  3:36 Devan Franchini
2013-10-10  2:00 Devan Franchini
2013-09-23  3:51 Devan Franchini
2013-09-23  1:13 Devan Franchini
2013-09-23  1:06 Devan Franchini
2013-09-23  0:19 Devan Franchini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1385886904.a07f5921e24e4777b03abe9dbec97ddce2015cb0.twitch153@gentoo \
    --to=twitch153@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox