summarylogtreecommitdiffstats
path: root/mpss-gen-symver-map-python3-compat.patch
blob: f9647343caa75aebdaf972612c2442f3a0377687 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
From fce5af28b47bc6b8bbedf06bbf29a1c293f3220f Mon Sep 17 00:00:00 2001
From: Marcel Huber <marcelhuberfoo@gmail.com>
Date: Fri, 29 Jul 2016 09:29:51 +0200
Subject: work with python3.x and python2.x

---
 gen-symver-map | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git mpss-gen-symver-map/gen-symver-map mpss-gen-symver-map/gen-symver-map
index 6dfa395..e33a46f 100755
--- mpss-gen-symver-map/gen-symver-map
+++ mpss-gen-symver-map/gen-symver-map
@@ -7,12 +7,19 @@
 #
 # See example.c for a demonstration of the various macros.
 
-import sys, re, ConfigParser
+from __future__ import print_function
+import sys, re
+try:
+    # python 3.x
+    import configparser
+except ImportError:
+    # python 2.x
+    import ConfigParser as configparser
 from subprocess import Popen, PIPE
 
 def parsecfg(fn):
     global VERNAME, VERDEPS
-    c = ConfigParser.RawConfigParser()
+    c = configparser.RawConfigParser()
     c.read(fn)
 
     VERNAME, = c.sections()  # there may be only one
@@ -63,27 +70,27 @@ def symmap(symtab):
                 assert version in vermap  # must be in VERDEPS
                 vermap[version].append(sym)
         except AssertionError:
-            print >>sys.stderr, 'CURRENT SYMBOL:', sym
-            print >>sys.stderr, 'VERSIONS:', o + d + c
+            print('CURRENT SYMBOL:', sym, file=sys.stderr)
+            print('VERSIONS:', o + d + c, file=sys.stderr)
             raise
     return vermap
 
 def printmap(f, vermap, fns):
     def tag(version):
         return '%s_%s' % (VERNAME, version)
-    print >>f, '/* Version script generated from %s */' % fns
+    print('/* Version script generated from %s */' % fns, file=f)
     for i, (version, deps) in enumerate(VERDEPS):
-        print >>f
-        print >>f, '%s {' % tag(version)
+        print(file=f)
+        print('%s {' % tag(version), file=f)
         if vermap[version]:
-            print >>f, 'global:'
+            print('global:', file=f)
         for symbol in sorted(vermap[version]):
-            print >>f, '\t%s;' % symbol
+            print('\t%s;' % symbol, file=f)
         if i == 0:
-            print >>f, 'local:'
-            print >>f, '\t*;'
+            print('local:', file=f)
+            print('\t*;', file=f)
         deps = [tag(d) for d in deps]
-        print >>f, '}%s;' % (' ' + ' '.join(deps) if deps else '')
+        print('}%s;' % (' ' + ' '.join(deps) if deps else ''), file=f)
 
 def main(argv):
     i = argv.index('--')
@@ -97,7 +104,7 @@ def main(argv):
     # parse each file on the command line
     symtab = {}
     for fn in argv:
-        p = Popen(cmd + ['-DGENMAP_PARSING_PASS', '-E', fn], stdout=PIPE)
+        p = Popen(cmd + ['-DGENMAP_PARSING_PASS', '-E', fn], stdout=PIPE, universal_newlines=True)
         findsyms(symtab, p.communicate()[0])
 
     # compute the version map and apply sanity checks
-- 
2.9.2