Gentoo Archives: gentoo-commits

From: Brian Dolbec <brian.dolbec@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/layman:master commit in: layman/
Date: Wed, 27 Apr 2011 10:59:44
Message-Id: b68a9eaead31e08460460a13d999444118784a59.dol-sen@gentoo
1 commit: b68a9eaead31e08460460a13d999444118784a59
2 Author: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
3 AuthorDate: Mon Feb 21 11:37:13 2011 +0000
4 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
5 CommitDate: Thu Feb 24 06:49:58 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=b68a9eae
7
8 Change most exceptions raised to output.errors().
9 set functions to return True/False.
10
11 Signed-off-by: Brian Dolbec <brian.dolbec <AT> gmail.com>
12
13 ---
14 layman/makeconf.py | 39 +++++++++++++++++++++++++--------------
15 1 files changed, 25 insertions(+), 14 deletions(-)
16
17 diff --git a/layman/makeconf.py b/layman/makeconf.py
18 index fdd10c4..b6f5d90 100644
19 --- a/layman/makeconf.py
20 +++ b/layman/makeconf.py
21 @@ -69,14 +69,16 @@ class MakeConf:
22
23 def __init__(self, config, overlays):
24
25 + self.config = config
26 self.path = config['make_conf']
27 self.storage = config['storage']
28 self.data = ''
29 self.db = overlays
30 self.overlays = []
31 self.extra = []
32 + self.output = config['output']
33
34 - self.read()
35 + self.read(True)
36
37 def add(self, overlay):
38 '''
39 @@ -104,7 +106,7 @@ class MakeConf:
40 >>> os.unlink(write)
41 '''
42 self.overlays.append(overlay)
43 - self.write()
44 + return self.write()
45
46 def delete(self, overlay):
47 '''
48 @@ -134,9 +136,9 @@ class MakeConf:
49 self.overlays = [i
50 for i in self.overlays
51 if i.name != overlay.name]
52 - self.write()
53 + return self.write()
54
55 - def read(self):
56 + def read(self, raise_error=False):
57 '''
58 Read the list of registered overlays from /etc/make.conf.
59
60 @@ -160,8 +162,13 @@ class MakeConf:
61 overlays = self.my_re.search(self.data)
62
63 if not overlays:
64 - raise Exception('Did not find a PORTDIR_OVERLAY entry in file ' +
65 - self.path +'! Did you specify the correct file?')
66 + msg = 'MakeConf: read(); Did not find a ' + \
67 + 'PORTDIR_OVERLAY entry in file ' + \
68 + self.path +'! Did you specify the correct file?'
69 + if raise_error:
70 + raise Exception(msg)
71 + self.output.error(msg)
72 + return False
73
74 overlays = [i.strip()
75 for i in overlays.group(1).split('\n')
76 @@ -181,7 +188,6 @@ class MakeConf:
77 # about. The user probably added them manually
78 self.extra.append(i)
79
80 -
81 else:
82 self.overlays = []
83 self.data = 'PORTDIR_OVERLAY="\n"\n'
84 @@ -189,6 +195,7 @@ class MakeConf:
85 self.extra = [i for i in self.extra
86 if (i != '$PORTDIR_OVERLAY'
87 and i != '${PORTDIR_OVERLAY}')]
88 + return True
89
90 def write(self):
91 '''
92 @@ -238,9 +245,10 @@ class MakeConf:
93 content = self.my_re.sub(overlays, self.data)
94
95 if not self.my_re.search(content):
96 - raise Exception('Ups, failed to set a proper PORTDIR_OVERLAY entry '
97 - 'in file ' + self.path +'! Did not overwrite the fi'
98 - 'le.')
99 + self.output.error('MakeConf: write(); Oops, failed to set a '
100 + 'proper PORTDIR_OVERLAY entry in file '
101 + + self.path +'! Did not overwrite the file.')
102 + return False
103
104 try:
105 make_conf = codecs.open(self.path, 'w', 'utf-8')
106 @@ -250,8 +258,10 @@ class MakeConf:
107 make_conf.close()
108
109 except Exception, error:
110 - raise Exception('Failed to read "' + self.path + '".\nError was:\n'
111 - + str(error))
112 + self.output.error('MakeConf: write(); Failed to write "'
113 + + self.path + '".\nError was:\n' + str(error))
114 + return False
115 + return True
116
117 def content(self):
118 '''
119 @@ -265,5 +275,6 @@ class MakeConf:
120 make_conf.close()
121
122 except Exception, error:
123 - raise Exception('Failed to read "' + self.path + '".\nError was:\n'
124 - + str(error))
125 + self.output.error('MakeConf: content(); Failed to read "' +
126 + self.path + '".\nError was:\n' + str(error))
127 + raise error