summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevan Franchini <twitch153@gentoo.org>2013-12-01 03:35:04 -0500
committerDevan Franchini <twitch153@gentoo.org>2014-01-24 22:12:05 -0500
commit89a991a2b20b149c672c9054a1f9ed5305d5a6b5 (patch)
treee84ad1016ed50fb91d7bf8d0a28f2ac279063ab0
parentWebappConfig/db.py: Adds prune_db() function. (diff)
downloadwebapp-config-89a991a2b20b149c672c9054a1f9ed5305d5a6b5.tar.gz
webapp-config-89a991a2b20b149c672c9054a1f9ed5305d5a6b5.tar.bz2
webapp-config-89a991a2b20b149c672c9054a1f9ed5305d5a6b5.zip
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
-rw-r--r--WebappConfig/config.py24
-rw-r--r--WebappConfig/db.py35
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