1
2 '''
3 # DESCRIPTION:
4 # Entropy Object Oriented Interface
5
6 Copyright (C) 2007-2009 Fabio Erculiani
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 '''
22
23 from __future__ import with_statement
24 import os
25 from entropy.core import Singleton
26 from entropy.output import TextInterface
27 from entropy.db import dbapi2
28 from entropy.client.interfaces.loaders import LoadersMixin
29 from entropy.client.interfaces.cache import CacheMixin
30 from entropy.client.interfaces.dep import CalculatorsMixin
31 from entropy.client.interfaces.methods import RepositoryMixin, MiscMixin, \
32 MatchMixin
33 from entropy.client.interfaces.fetch import FetchersMixin
34 from entropy.const import etpConst, etpCache
35 from entropy.core import SystemSettings, SystemSettingsPlugin
36 from entropy.misc import LogFile
37 from entropy.exceptions import SystemDatabaseError, RepositoryError
38
40
41 import entropy.tools as entropyTools
42
44
45 parser_data = {}
46
47 mask_installed = []
48 mask_installed_keys = {}
49 while (self._helper.clientDbconn != None):
50 try:
51 self._helper.clientDbconn.validateDatabase()
52 except SystemDatabaseError:
53 break
54 mc_cache = set()
55 m_list = system_settings_instance['repos_system_mask'] + \
56 system_settings_instance['system_mask']
57 for atom in m_list:
58 m_ids, m_r = self._helper.clientDbconn.atomMatch(atom,
59 multiMatch = True)
60 if m_r != 0:
61 continue
62 mykey = self.entropyTools.dep_getkey(atom)
63 if mykey not in mask_installed_keys:
64 mask_installed_keys[mykey] = set()
65 for m_id in m_ids:
66 if m_id in mc_cache:
67 continue
68 mc_cache.add(m_id)
69 mask_installed.append(m_id)
70 mask_installed_keys[mykey].add(m_id)
71 break
72
73 parser_data.update({
74 'repos_installed': mask_installed,
75 'repos_installed_keys': mask_installed_keys,
76 })
77 return parser_data
78
80 data = {
81 'cache': {},
82 }
83 return data
84
86
87 """
88 Parses Entropy client system configuration file.
89
90 @return dict data
91 """
92
93 data = {
94 'filesbackup': etpConst['filesbackup'],
95 'ignore_spm_downgrades': etpConst['spm']['ignore-spm-downgrades'],
96 'collisionprotect': etpConst['collisionprotect'],
97 'configprotect': etpConst['configprotect'][:],
98 'configprotectmask': etpConst['configprotectmask'][:],
99 'configprotectskip': etpConst['configprotectskip'][:],
100 }
101
102 cli_conf = etpConst['clientconf']
103 if not (os.path.isfile(cli_conf) and os.access(cli_conf, os.R_OK)):
104 return data
105
106 client_f = open(cli_conf,"r")
107 clientconf = [x.strip() for x in client_f.readlines() if \
108 x.strip() and not x.strip().startswith("#")]
109 client_f.close()
110 for line in clientconf:
111
112 split_line = line.split("|")
113 split_line_len = len(split_line)
114
115 if line.startswith("filesbackup|") and (split_line_len == 2):
116
117 compatopt = split_line[1].strip().lower()
118 if compatopt in ("disable", "disabled","false", "0", "no",):
119 data['filesbackup'] = False
120
121 elif line.startswith("ignore-spm-downgrades|") and \
122 (split_line_len == 2):
123
124 compatopt = split_line[1].strip().lower()
125 if compatopt in ("enable", "enabled", "true", "1", "yes"):
126 data['ignore_spm_downgrades'] = True
127
128 elif line.startswith("collisionprotect|") and (split_line_len == 2):
129
130 collopt = split_line[1].strip()
131 if collopt.lower() in ("0", "1", "2",):
132 data['collisionprotect'] = int(collopt)
133
134 elif line.startswith("configprotect|") and (split_line_len == 2):
135
136 configprotect = split_line[1].strip()
137 for myprot in configprotect.split():
138 data['configprotect'].append(
139 unicode(myprot,'raw_unicode_escape'))
140
141 elif line.startswith("configprotectmask|") and \
142 (split_line_len == 2):
143
144 configprotect = split_line[1].strip()
145 for myprot in configprotect.split():
146 data['configprotectmask'].append(
147 unicode(myprot,'raw_unicode_escape'))
148
149 elif line.startswith("configprotectskip|") and \
150 (split_line_len == 2):
151
152 configprotect = split_line[1].strip()
153 for myprot in configprotect.split():
154 data['configprotectskip'].append(
155 etpConst['systemroot']+unicode(myprot,
156 'raw_unicode_escape'))
157
158 return data
159
160
161 -class Client(Singleton, TextInterface, LoadersMixin, CacheMixin, CalculatorsMixin, \
162 RepositoryMixin, MiscMixin, MatchMixin, FetchersMixin):
163
164 - def init_singleton(self, indexing = True, noclientdb = 0,
165 xcache = True, user_xcache = False, repo_validation = True,
166 load_ugc = True, url_fetcher = None,
167 multiple_url_fetcher = None):
275
277 self.__instance_destroyed = True
278 if hasattr(self,'clientDbconn'):
279 if self.clientDbconn != None:
280 self.clientDbconn.closeDB()
281 del self.clientDbconn
282 if hasattr(self,'FileUpdates'):
283 del self.FileUpdates
284 if hasattr(self,'clientLog'):
285 self.clientLog.close()
286 if hasattr(self,'Cacher'):
287 self.Cacher.stop()
288 if hasattr(self,'SystemSettings') and \
289 hasattr(self,'sys_settings_client_plugin_id'):
290
291 if hasattr(self.SystemSettings,'remove_plugin'):
292 try:
293 self.SystemSettings.remove_plugin(
294 self.sys_settings_client_plugin_id)
295 except KeyError:
296 pass
297
298 self.close_all_repositories(mask_clear = False)
299 self.closeAllSecurity()
300 self.closeAllQA()
301
303 return self.__instance_destroyed
304
307