1 |
commit: a07f5921e24e4777b03abe9dbec97ddce2015cb0 |
2 |
Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Dec 1 08:35:04 2013 +0000 |
4 |
Commit: Devan Franchini <twitch153 <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Dec 1 08:35:04 2013 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=a07f5921 |
7 |
|
8 |
WebappConfig/{db,config}.py: Adds support for prune-database() function. |
9 |
|
10 |
This renames the prune-db() function to prune-database() as well as |
11 |
adding a command line option to call the function and implements it |
12 |
in config.py. |
13 |
|
14 |
X-Gentoo-Bug: 490090 |
15 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/490090 |
16 |
|
17 |
--- |
18 |
WebappConfig/config.py | 24 ++++++++++++++++++++++-- |
19 |
WebappConfig/db.py | 35 +++++++++++++++++++++-------------- |
20 |
2 files changed, 43 insertions(+), 16 deletions(-) |
21 |
|
22 |
diff --git a/WebappConfig/config.py b/WebappConfig/config.py |
23 |
index 1c09488..4df2f27 100644 |
24 |
--- a/WebappConfig/config.py |
25 |
+++ b/WebappConfig/config.py |
26 |
@@ -565,7 +565,7 @@ class Config: |
27 |
|
28 |
group.add_option('-V', |
29 |
'--verbose', |
30 |
- action='store_true', |
31 |
+ action='store_true', |
32 |
help = 'Output even more information than normal' |
33 |
) |
34 |
|
35 |
@@ -593,6 +593,14 @@ class Config: |
36 |
'or version number as arguments to restrict the ' |
37 |
'listing.') |
38 |
|
39 |
+ group.add_option('--prune-database', |
40 |
+ '--pd', |
41 |
+ type = 'choice', |
42 |
+ choices = ['pretend', |
43 |
+ 'clean'], |
44 |
+ help = 'This will list all outdated entries in ' |
45 |
+ 'the webapp-config "database".') |
46 |
+ |
47 |
group.add_option('--show-installed', |
48 |
'--si', |
49 |
action='store_true', |
50 |
@@ -932,7 +940,7 @@ class Config: |
51 |
# set the action to be performed |
52 |
work = ['install', 'clean', 'upgrade', 'list_installs', |
53 |
'list_servers', 'list_unused_installs', |
54 |
- 'show_installed', 'show_postinst', |
55 |
+ 'prune_database', 'show_installed', 'show_postinst', |
56 |
'show_postupgrade', 'check_config', 'query'] |
57 |
|
58 |
for i in work: |
59 |
@@ -940,6 +948,9 @@ class Config: |
60 |
self.work = i |
61 |
break |
62 |
|
63 |
+ if options.__dict__.get('prune_database'): |
64 |
+ self.prune_action = options.__dict__.get('prune_database') |
65 |
+ |
66 |
OUT.debug('Checking command line arguments', 1) |
67 |
|
68 |
if len(args) > 0: |
69 |
@@ -1134,6 +1145,15 @@ class Config: |
70 |
self.create_webapp_db( self.maybe_get('cat'), |
71 |
self.maybe_get('pn'), |
72 |
self.maybe_get('pvr')).listinstalls() |
73 |
+ if self.work == 'prune_database': |
74 |
+ # Get the handler for the virtual install db. If the action is equal |
75 |
+ # to clean, then it'll simply prune the "db" of outdated entries. |
76 |
+ # If it's not set to clean, then it'll list the outdated entries |
77 |
+ # in the db to be cleaned out. |
78 |
+ self.__r = wrapper.get_root(self) |
79 |
+ self.create_webapp_db( self.maybe_get('cat'), |
80 |
+ self.maybe_get('pn'), |
81 |
+ self.maybe_get('pvr')).prune_database(self.prune_action) |
82 |
|
83 |
if self.work == 'show_installed': |
84 |
|
85 |
|
86 |
diff --git a/WebappConfig/db.py b/WebappConfig/db.py |
87 |
index 37bfdc9..d0913a9 100644 |
88 |
--- a/WebappConfig/db.py |
89 |
+++ b/WebappConfig/db.py |
90 |
@@ -424,42 +424,49 @@ class WebappDB(AppHierarchy): |
91 |
|
92 |
return result |
93 |
|
94 |
- def prune_db(self): |
95 |
+ def prune_database(self, action): |
96 |
''' |
97 |
Prunes the installs files to ensure no webapp |
98 |
is incorrectly listed as installed. |
99 |
''' |
100 |
|
101 |
loc = self.read_db() |
102 |
- |
103 |
+ |
104 |
+ print(action) |
105 |
if not loc and self.__v: |
106 |
OUT.die('No virtual installs found!') |
107 |
|
108 |
files = self.list_locations() |
109 |
keys = sorted(loc) |
110 |
|
111 |
+ if action != 'clean': |
112 |
+ OUT.warn('This is a list of all outdated entries that would be removed: ') |
113 |
for j in keys: |
114 |
for i in loc[j]: |
115 |
appdir = i[3].strip() |
116 |
# We check to see if the webapp is installed. |
117 |
+ # TODO: Fix algorithm to see if this is an outdated |
118 |
+ # entry. |
119 |
if not os.path.exists(appdir+'/.webapp'): |
120 |
if self.__v: |
121 |
OUT.warn('No .webapp file found in dir: ') |
122 |
OUT.warn(appdir) |
123 |
OUT.warn('Assuming webapp is no longer installed.') |
124 |
OUT.warn('Pruning entry from database.') |
125 |
- |
126 |
- for installs in files.keys(): |
127 |
- contents = open(installs).readlines() |
128 |
- new_entries = '' |
129 |
- for entry in contents: |
130 |
- # Grab all the other entries but the one that |
131 |
- # isn't installed. |
132 |
- if not re.search('.* ' + appdir +'\\n', entry): |
133 |
- new_entries += entry |
134 |
- f = open(installs, 'w') |
135 |
- f.write(new_entries) |
136 |
- f.close() |
137 |
+ if action == 'clean': |
138 |
+ for installs in files.keys(): |
139 |
+ contents = open(installs).readlines() |
140 |
+ new_entries = '' |
141 |
+ for entry in contents: |
142 |
+ # Grab all the other entries but the one that |
143 |
+ # isn't installed. |
144 |
+ if not re.search('.* ' + appdir +'\\n', entry): |
145 |
+ new_entries += entry |
146 |
+ f = open(installs, 'w') |
147 |
+ f.write(new_entries) |
148 |
+ f.close() |
149 |
+ else: |
150 |
+ OUT.warn(appdir) |
151 |
|
152 |
def has_installs(self): |
153 |
''' Return True in case there are any virtual install locations |