1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# Copyright 2005-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import portage
from portage import os
from portage.const import PRIVATE_PATH
from portage.util import writedict
class CleanConfig(object):
short_desc = "Discard any no longer installed configs from emerge's tracker list"
def __init__(self):
self._root = portage.settings["ROOT"]
self.target = os.path.join(portage.settings["EROOT"], PRIVATE_PATH, 'config')
def name():
return "cleanconfmem"
name = staticmethod(name)
def load_configlist(self):
configs = {}
with open(self.target, 'r') as configfile:
lines = configfile.readlines()
for line in lines:
ls = line.split()
configs[ls[0]] = ls[1]
return configs
def check(self, **kwargs):
onProgress = kwargs.get('onProgress', None)
configs = self.load_configlist()
messages = []
maxval = len(configs)
if onProgress:
onProgress(maxval, 0)
i = 0
keys = sorted(configs)
for config in keys:
if not os.path.exists(config):
messages.append(" %s" % config)
if onProgress:
onProgress(maxval, i+1)
i += 1
return self._format_output(messages)
def fix(self, **kwargs):
onProgress = kwargs.get('onProgress', None)
configs = self.load_configlist()
messages = []
maxval = len(configs)
if onProgress:
onProgress(maxval, 0)
i = 0
root = self._root
if root == "/":
root = None
modified = False
for config in sorted(configs):
if root is None:
full_path = config
else:
full_path = os.path.join(root, config.lstrip(os.sep))
if not os.path.exists(full_path):
modified = True
configs.pop(config)
messages.append(" %s" % config)
if onProgress:
onProgress(maxval, i+1)
i += 1
if modified:
writedict(configs, self.target)
return self._format_output(messages, True)
def _format_output(self, messages=[], cleaned=False):
output = []
if messages:
output.append('Not Installed:')
output += messages
tot = '------------------------------------\n Total %i Not installed'
if cleaned:
tot += ' ...Cleaned'
output.append(tot % len(messages))
return output
|