1 |
commit: f3834ca7725ca26f66bdb00ae022b96819083be7 |
2 |
Author: André Erdmann <dywi <AT> mailerd <DOT> de> |
3 |
AuthorDate: Mon Jan 27 14:57:51 2014 +0000 |
4 |
Commit: André Erdmann <dywi <AT> mailerd <DOT> de> |
5 |
CommitDate: Mon Jan 27 14:57:51 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=f3834ca7 |
7 |
|
8 |
query_config: use roverlay.util.fileio |
9 |
|
10 |
This allows to read/write compressed files in --from-file mode. |
11 |
|
12 |
--- |
13 |
roverlay/scripts/query_config.py | 25 ++++++++++++------------- |
14 |
1 file changed, 12 insertions(+), 13 deletions(-) |
15 |
|
16 |
diff --git a/roverlay/scripts/query_config.py b/roverlay/scripts/query_config.py |
17 |
index f8a3c6f..0452a11 100644 |
18 |
--- a/roverlay/scripts/query_config.py |
19 |
+++ b/roverlay/scripts/query_config.py |
20 |
@@ -53,6 +53,7 @@ import sys |
21 |
|
22 |
import roverlay.core |
23 |
import roverlay.strutil |
24 |
+import roverlay.util.fileio |
25 |
from roverlay.config.entryutil import iter_config_keys |
26 |
|
27 |
__all__ = [ 'query_config_main', ] |
28 |
@@ -275,13 +276,11 @@ def query_config_main ( is_installed ): |
29 |
# list of 2-tuples ( line, set<varnames> ) |
30 |
input_lines = list() |
31 |
config_keys = set() |
32 |
- with open ( argv.from_file, 'rt' ) as FH: |
33 |
- for line in FH.readlines(): |
34 |
- varnames = set ( RE_VAR_REF.findall ( line ) ) |
35 |
- input_lines.append ( ( line, varnames ) ) |
36 |
- config_keys |= varnames |
37 |
- # -- end for |
38 |
- # -- end with |
39 |
+ for line in roverlay.util.fileio.read_text_file ( argv.from_file ): |
40 |
+ varnames = set ( RE_VAR_REF.findall ( line ) ) |
41 |
+ input_lines.append ( ( line, varnames ) ) |
42 |
+ config_keys |= varnames |
43 |
+ # -- end for line |
44 |
|
45 |
num_missing, cvars = get_vardict ( config, argv, config_keys ) |
46 |
del num_missing |
47 |
@@ -320,8 +319,9 @@ def query_config_main ( is_installed ): |
48 |
if argv.outfile == '-': |
49 |
stream.write ( ''.join ( output_lines ) ) |
50 |
else: |
51 |
- with open ( argv.outfile, 'wt' ) as FH: |
52 |
- FH.write ( ''.join ( output_lines ) ) |
53 |
+ roverlay.util.fileio.write_text_file ( |
54 |
+ argv.outfile, output_lines, append_newlines=False |
55 |
+ ) |
56 |
# -- end write output_lines |
57 |
|
58 |
return EX_MISS if vars_missing else EX_OK |
59 |
@@ -329,10 +329,9 @@ def query_config_main ( is_installed ): |
60 |
# --from-file (without --outfile): read config keys from file |
61 |
elif argv.from_file: |
62 |
config_keys = set() |
63 |
- with open ( argv.from_file, 'rt' ) as FH: |
64 |
- for line in FH.readlines(): |
65 |
- config_keys.update ( RE_VAR_REF.findall ( line ) ) |
66 |
- # -- end with |
67 |
+ for line in roverlay.util.fileio.read_text_file ( argv.from_file ): |
68 |
+ config_keys.update ( RE_VAR_REF.findall ( line ) ) |
69 |
+ # -- end for line |
70 |
|
71 |
if main__print_variables ( config, argv, stream, config_keys ): |
72 |
return EX_MISS |