1 |
commit: e90e838718c737a1d41e4b8bc64e9e520d65270b |
2 |
Author: Paul Varner <fuzzyray <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Nov 24 19:59:02 2015 +0000 |
4 |
Commit: Paul Varner <fuzzyray <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Nov 24 19:59:02 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=e90e8387 |
7 |
|
8 |
Fix the file open() calls to work with Python 2 |
9 |
|
10 |
The generalized file open call needs to look like: |
11 |
with open(_unicode_encode(path, encoding=_encodings['fs'])) as open_file |
12 |
|
13 |
pym/gentoolkit/deprecated/helpers.py | 4 ++-- |
14 |
pym/gentoolkit/eclean/exclude.py | 4 ++-- |
15 |
pym/gentoolkit/enalyze/rebuild.py | 2 +- |
16 |
pym/gentoolkit/equery/uses.py | 4 ++-- |
17 |
pym/gentoolkit/equery/which.py | 2 +- |
18 |
pym/gentoolkit/eshowkw/keywords_header.py | 4 ++-- |
19 |
pym/gentoolkit/glsa/__init__.py | 4 ++-- |
20 |
pym/gentoolkit/helpers.py | 6 +++--- |
21 |
pym/gentoolkit/revdep_rebuild/analyse.py | 2 +- |
22 |
pym/gentoolkit/revdep_rebuild/cache.py | 14 +++++++------- |
23 |
pym/gentoolkit/revdep_rebuild/collect.py | 6 +++--- |
24 |
pym/gentoolkit/revdep_rebuild/settings.py | 4 ++-- |
25 |
12 files changed, 28 insertions(+), 28 deletions(-) |
26 |
|
27 |
diff --git a/pym/gentoolkit/deprecated/helpers.py b/pym/gentoolkit/deprecated/helpers.py |
28 |
index c3a72dc..81fa45c 100644 |
29 |
--- a/pym/gentoolkit/deprecated/helpers.py |
30 |
+++ b/pym/gentoolkit/deprecated/helpers.py |
31 |
@@ -100,8 +100,8 @@ def find_system_packages(prefilter=None): |
32 |
def find_world_packages(prefilter=None): |
33 |
"""Returns a tuple of lists, first list is resolved world packages, |
34 |
seond is unresolved package names.""" |
35 |
- f = open(_unicode_encode(portage.root+portage.WORLD_FILE), |
36 |
- encoding=_encodings['fs']) |
37 |
+ f = open(_unicode_encode(portage.root+portage.WORLD_FILE, |
38 |
+ encoding=_encodings['fs'])) |
39 |
pkglist = f.readlines() |
40 |
resolved = [] |
41 |
unresolved = [] |
42 |
|
43 |
diff --git a/pym/gentoolkit/eclean/exclude.py b/pym/gentoolkit/eclean/exclude.py |
44 |
index 5a13186..d19c1d1 100644 |
45 |
--- a/pym/gentoolkit/eclean/exclude.py |
46 |
+++ b/pym/gentoolkit/eclean/exclude.py |
47 |
@@ -82,8 +82,8 @@ def parseExcludeFile(filepath, output): |
48 |
} |
49 |
output("Parsing Exclude file: " + filepath) |
50 |
try: |
51 |
- file_ = open(_unicode_encode(filepath), |
52 |
- encoding=_encodings['fs'], mode="r") |
53 |
+ file_ = open(_unicode_encode(filepath, |
54 |
+ encoding=_encodings['fs']), mode="r") |
55 |
except IOError: |
56 |
raise ParseExcludeFileException("Could not open exclusion file: " + |
57 |
filepath) |
58 |
|
59 |
diff --git a/pym/gentoolkit/enalyze/rebuild.py b/pym/gentoolkit/enalyze/rebuild.py |
60 |
index 3f9527a..11feb31 100644 |
61 |
--- a/pym/gentoolkit/enalyze/rebuild.py |
62 |
+++ b/pym/gentoolkit/enalyze/rebuild.py |
63 |
@@ -352,7 +352,7 @@ class Rebuild(ModuleBase): |
64 |
""" |
65 |
if not self.options["quiet"]: |
66 |
print(' - Saving file: %s' %filepath) |
67 |
- with open(_unicode_encode(filepath), encoding=_encodings['fs'], mode="w") as output: |
68 |
+ with open(_unicode_encode(filepath, encoding=_encodings['fs']), mode="w") as output: |
69 |
output.write('\n'.join(data)) |
70 |
print(" - Done") |
71 |
|
72 |
|
73 |
diff --git a/pym/gentoolkit/equery/uses.py b/pym/gentoolkit/equery/uses.py |
74 |
index 7717710..79ed00f 100644 |
75 |
--- a/pym/gentoolkit/equery/uses.py |
76 |
+++ b/pym/gentoolkit/equery/uses.py |
77 |
@@ -136,7 +136,7 @@ def get_global_useflags(): |
78 |
# Get global USE flag descriptions |
79 |
try: |
80 |
path = os.path.join(settings["PORTDIR"], 'profiles', 'use.desc') |
81 |
- with open(_unicode_encode(path), encoding=_encodings['fs']) as open_file: |
82 |
+ with open(_unicode_encode(path, encoding=_encodings['fs'])) as open_file: |
83 |
for line in open_file: |
84 |
if line.startswith('#'): |
85 |
continue |
86 |
@@ -156,7 +156,7 @@ def get_global_useflags(): |
87 |
for path in glob(os.path.join(settings["PORTDIR"], |
88 |
'profiles', 'desc', '*.desc')): |
89 |
try: |
90 |
- with open(_unicode_encode(path), encoding=_encodings['fs']) as open_file: |
91 |
+ with open(_unicode_encode(path, encoding=_encodings['fs'])) as open_file: |
92 |
for line in open_file: |
93 |
if line.startswith('#'): |
94 |
continue |
95 |
|
96 |
diff --git a/pym/gentoolkit/equery/which.py b/pym/gentoolkit/equery/which.py |
97 |
index ea03b90..0d30a8d 100644 |
98 |
--- a/pym/gentoolkit/equery/which.py |
99 |
+++ b/pym/gentoolkit/equery/which.py |
100 |
@@ -62,7 +62,7 @@ def print_help(with_description=True): |
101 |
|
102 |
def print_ebuild(ebuild_path): |
103 |
"""Output the ebuild to std_out""" |
104 |
- with open(_unicode_encode(ebuild_path), encoding=_encodings['fs']) as f: |
105 |
+ with open(_unicode_encode(ebuild_path, encoding=_encodings['fs'])) as f: |
106 |
lines = f.readlines() |
107 |
print("\n\n") |
108 |
print("".join(lines)) |
109 |
|
110 |
diff --git a/pym/gentoolkit/eshowkw/keywords_header.py b/pym/gentoolkit/eshowkw/keywords_header.py |
111 |
index 9ca0364..7bf71d0 100644 |
112 |
--- a/pym/gentoolkit/eshowkw/keywords_header.py |
113 |
+++ b/pym/gentoolkit/eshowkw/keywords_header.py |
114 |
@@ -31,7 +31,7 @@ def load_profile_data(portdir=None, repo='gentoo'): |
115 |
|
116 |
try: |
117 |
arch_list = os.path.join(portdir, 'profiles', 'arch.list') |
118 |
- with open(_unicode_encode(arch_list), encoding=_encodings['fs']) as f: |
119 |
+ with open(_unicode_encode(arch_list, encoding=_encodings['fs'])) as f: |
120 |
for line in f: |
121 |
line = line.split('#', 1)[0].strip() |
122 |
if line: |
123 |
@@ -47,7 +47,7 @@ def load_profile_data(portdir=None, repo='gentoo'): |
124 |
None: 3, |
125 |
} |
126 |
profiles_list = os.path.join(portdir, 'profiles', 'profiles.desc') |
127 |
- with open(_unicode_encode(profiles_list), encoding=_encodings['fs']) as f: |
128 |
+ with open(_unicode_encode(profiles_list, encoding=_encodings['fs'])) as f: |
129 |
for line in f: |
130 |
line = line.split('#', 1)[0].split() |
131 |
if line: |
132 |
|
133 |
diff --git a/pym/gentoolkit/glsa/__init__.py b/pym/gentoolkit/glsa/__init__.py |
134 |
index 0d670b7..30a5ae2 100644 |
135 |
--- a/pym/gentoolkit/glsa/__init__.py |
136 |
+++ b/pym/gentoolkit/glsa/__init__.py |
137 |
@@ -704,8 +704,8 @@ class Glsa: |
138 |
@returns: None |
139 |
""" |
140 |
if not self.isInjected(): |
141 |
- checkfile = open(_unicode_encode(self.config["CHECKFILE"]), |
142 |
- encoding=_encodings['fs'], mode="a+") |
143 |
+ checkfile = open(_unicode_encode(self.config["CHECKFILE"], |
144 |
+ encoding=_encodings['fs']), mode="a+") |
145 |
checkfile.write(self.nr+"\n") |
146 |
checkfile.close() |
147 |
return None |
148 |
|
149 |
diff --git a/pym/gentoolkit/helpers.py b/pym/gentoolkit/helpers.py |
150 |
index f9da6cd..b7314b9 100644 |
151 |
--- a/pym/gentoolkit/helpers.py |
152 |
+++ b/pym/gentoolkit/helpers.py |
153 |
@@ -194,8 +194,8 @@ class ChangeLog(object): |
154 |
|
155 |
result = [] |
156 |
partial_entries = [] |
157 |
- with open(_unicode_encode(self.changelog_path), |
158 |
- encoding=_encodings['fs'], errors="replace") as log: |
159 |
+ with open(_unicode_encode(self.changelog_path, |
160 |
+ encoding=_encodings['fs'], errors="replace")) as log: |
161 |
for line in log: |
162 |
if line.startswith('#'): |
163 |
continue |
164 |
@@ -464,7 +464,7 @@ def get_bintree_cpvs(predicate=None): |
165 |
def print_file(path): |
166 |
"""Display the contents of a file.""" |
167 |
|
168 |
- with open(_unicode_encode(path), encoding=_encodings['fs'], mode="rb") as open_file: |
169 |
+ with open(_unicode_encode(path, encoding=_encodings['fs']), mode="rb") as open_file: |
170 |
lines = open_file.read() |
171 |
pp.uprint(lines.strip()) |
172 |
|
173 |
|
174 |
diff --git a/pym/gentoolkit/revdep_rebuild/analyse.py b/pym/gentoolkit/revdep_rebuild/analyse.py |
175 |
index 0f89b03..056e421 100644 |
176 |
--- a/pym/gentoolkit/revdep_rebuild/analyse.py |
177 |
+++ b/pym/gentoolkit/revdep_rebuild/analyse.py |
178 |
@@ -83,7 +83,7 @@ def extract_dependencies_from_la(la, libraries, to_check, logger): |
179 |
if not os.path.exists(_file): |
180 |
continue |
181 |
|
182 |
- for line in open(_unicode_encode(_file), encoding=_encodings['fs'], mode='r').readlines(): |
183 |
+ for line in open(_unicode_encode(_file, encoding=_encodings['fs']), mode='r').readlines(): |
184 |
line = line.strip() |
185 |
if line.startswith('dependency_libs='): |
186 |
match = re.match("dependency_libs='([^']+)'", line) |
187 |
|
188 |
diff --git a/pym/gentoolkit/revdep_rebuild/cache.py b/pym/gentoolkit/revdep_rebuild/cache.py |
189 |
index 31ee2c9..36f0f72 100644 |
190 |
--- a/pym/gentoolkit/revdep_rebuild/cache.py |
191 |
+++ b/pym/gentoolkit/revdep_rebuild/cache.py |
192 |
@@ -30,8 +30,8 @@ def read_cache(temp_path=DEFAULTS['DEFAULT_TMP_DIR']): |
193 |
} |
194 |
try: |
195 |
for key,val in ret.items(): |
196 |
- _file = open(_unicode_encode(os.path.join(temp_path, key)), |
197 |
- encoding=_encodings['fs']) |
198 |
+ _file = open(_unicode_encode(os.path.join(temp_path, key), |
199 |
+ encoding=_encodings['fs'])) |
200 |
for line in _file.readlines(): |
201 |
val.add(line.strip()) |
202 |
#libraries.remove('\n') |
203 |
@@ -54,14 +54,14 @@ def save_cache(logger, to_save={}, temp_path=DEFAULTS['DEFAULT_TMP_DIR']): |
204 |
os.makedirs(temp_path) |
205 |
|
206 |
try: |
207 |
- _file = open(_unicode_encode(os.path.join(temp_path, 'timestamp')), |
208 |
- encoding=_encodings['fs'], mode='w') |
209 |
+ _file = open(_unicode_encode(os.path.join(temp_path, 'timestamp'), |
210 |
+ encoding=_encodings['fs']), mode='w') |
211 |
_file.write(str(int(time.time()))) |
212 |
_file.close() |
213 |
|
214 |
for key,val in to_save.items(): |
215 |
- _file = open(_unicode_encode(os.path.join(temp_path, key)), |
216 |
- encoding=_encodings['fs'], mode='w') |
217 |
+ _file = open(_unicode_encode(os.path.join(temp_path, key), |
218 |
+ encoding=_encodings['fs']), mode='w') |
219 |
for line in val: |
220 |
_file.write(line + '\n') |
221 |
_file.close() |
222 |
@@ -89,7 +89,7 @@ def check_temp_files(temp_path=DEFAULTS['DEFAULT_TMP_DIR'], max_delay=3600, |
223 |
return False |
224 |
|
225 |
try: |
226 |
- _file = open(_unicode_encode(timestamp_path), encoding=_encodings['fs']) |
227 |
+ _file = open(_unicode_encode(timestamp_path, encoding=_encodings['fs'])) |
228 |
timestamp = int(_file.readline()) |
229 |
_file .close() |
230 |
except Exception as ex: |
231 |
|
232 |
diff --git a/pym/gentoolkit/revdep_rebuild/collect.py b/pym/gentoolkit/revdep_rebuild/collect.py |
233 |
index 758bcf7..1b406e8 100644 |
234 |
--- a/pym/gentoolkit/revdep_rebuild/collect.py |
235 |
+++ b/pym/gentoolkit/revdep_rebuild/collect.py |
236 |
@@ -35,7 +35,7 @@ def parse_conf(conf_file, visited=None, logger=None): |
237 |
|
238 |
for conf in conf_file: |
239 |
try: |
240 |
- with open(_unicode_encode(conf), encoding=_encodings['fs']) as _file: |
241 |
+ with open(_unicode_encode(conf, encoding=_encodings['fs'])) as _file: |
242 |
for line in _file.readlines(): |
243 |
line = line.strip() |
244 |
if line.startswith('#'): |
245 |
@@ -76,8 +76,8 @@ def prepare_search_dirs(logger, settings): |
246 |
|
247 |
#try: |
248 |
with open(_unicode_encode(os.path.join( |
249 |
- portage.root, settings['DEFAULT_ENV_FILE'])), |
250 |
- encoding=_encodings['fs'], mode='r') as _file: |
251 |
+ portage.root, settings['DEFAULT_ENV_FILE']), |
252 |
+ encoding=_encodings['fs']), mode='r') as _file: |
253 |
for line in _file.readlines(): |
254 |
line = line.strip() |
255 |
match = re.match("^export (ROOT)?PATH='([^']+)'", line) |
256 |
|
257 |
diff --git a/pym/gentoolkit/revdep_rebuild/settings.py b/pym/gentoolkit/revdep_rebuild/settings.py |
258 |
index 257bd3a..e9a021a 100644 |
259 |
--- a/pym/gentoolkit/revdep_rebuild/settings.py |
260 |
+++ b/pym/gentoolkit/revdep_rebuild/settings.py |
261 |
@@ -137,8 +137,8 @@ def parse_revdep_config(revdep_confdir): |
262 |
masked_files = os.environ.get('LD_LIBRARY_MASK', '') |
263 |
|
264 |
for _file in os.listdir(revdep_confdir): |
265 |
- for line in open(_unicode_encode(os.path.join(revdep_confdir, _file)), |
266 |
- encoding=_encodings['fs']): |
267 |
+ for line in open(_unicode_encode(os.path.join(revdep_confdir, _file), |
268 |
+ encoding=_encodings['fs'])): |
269 |
line = line.strip() |
270 |
#first check for comment, we do not want to regex all lines |
271 |
if not line.startswith('#'): |