Gentoo Archives: gentoo-commits

From: Patrice Clement <monsieurp@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/javatoolkit:master commit in: src/py/
Date: Sat, 12 Aug 2017 08:50:13
Message-Id: 1502527800.c5a30f5dc7a54d81714a30f7f8140347db173e8f.monsieurp@gentoo
1 commit: c5a30f5dc7a54d81714a30f7f8140347db173e8f
2 Author: Patrice Clement <monsieurp <AT> gentoo <DOT> org>
3 AuthorDate: Fri Aug 11 17:42:34 2017 +0000
4 Commit: Patrice Clement <monsieurp <AT> gentoo <DOT> org>
5 CommitDate: Sat Aug 12 08:50:00 2017 +0000
6 URL: https://gitweb.gentoo.org/proj/javatoolkit.git/commit/?id=c5a30f5d
7
8 use context managers wherever possible
9
10 src/py/xml-rewrite-2.py | 28 ++++++++++++----------------
11 1 file changed, 12 insertions(+), 16 deletions(-)
12
13 diff --git a/src/py/xml-rewrite-2.py b/src/py/xml-rewrite-2.py
14 index 721147b..2b4702d 100755
15 --- a/src/py/xml-rewrite-2.py
16 +++ b/src/py/xml-rewrite-2.py
17 @@ -204,8 +204,6 @@ parameters will break the script."""
18 print("ERROR: " + message)
19 sys.exit(1)
20
21 -# if len(sys.argv) == 1:
22 -# usage(True)
23 options_list = [
24 make_option(
25 "-f",
26 @@ -320,8 +318,7 @@ parameters will break the script."""
27 if options.doAdd and (len(options.values or []) != len(options.attributes or [])
28 or len(options.source_values or []) != len(options.source_attributes or [])
29 or len(options.target_values or []) != len(options.target_attributes or [])):
30 - error(
31 - "You must give attribute(s)/value(s) for every element you are changing.")
32 + error("You must give attribute(s)/value(s) for every element you are changing.")
33
34 # End Invalid Arguments Check
35
36 @@ -354,17 +351,16 @@ parameters will break the script."""
37 dirname = os.path.dirname(file)
38 if dirname != '': # for file = build.xml comes out as ''
39 os.chdir(os.path.dirname(file))
40 - f = open(os.path.basename(file), "r")
41 - if options.gentoo_classpath:
42 - rewriter.process(f, add_gentoo_classpath)
43 - else:
44 - rewriter.process(f)
45 - os.chdir(cwd)
46 - f.close()
47 - # Then write it back to the file
48 - f = open(file, "w")
49 - rewriter.write(f)
50 - f.close()
51 +
52 + with open(os.path.basename(file), 'r') as f:
53 + if options.gentoo_classpath:
54 + rewriter.process(f, add_gentoo_classpath)
55 + else:
56 + rewriter.process(f)
57 +
58 + # Then write it back out to the file
59 + with open(file, 'w') as f:
60 + rewriter.write(f)
61
62 else:
63 if options.gentoo_classpath:
64 @@ -375,4 +371,4 @@ parameters will break the script."""
65
66
67 if __name__ == '__main__':
68 - main()
69 + main()
70 \ No newline at end of file