updated on Sat Jan 14 00:11:12 UTC 2012
[aur-mirror.git] / deheader / python3.patch
blobca11d5ca192fb08f1fdde762f16816482fabf001
1 --- ./deheader (original)
2 +++ ./deheader (refactored)
3 @@ -29,7 +29,7 @@
4 The last line of the output is a statistical summary of operations.
5 """
7 -import sys, os, getopt, time, re, operator, commands
8 +import sys, os, getopt, time, re, operator, subprocess
10 BATON_DEBUG = 1
11 PROGRESS_DEBUG = 2
12 @@ -1243,19 +1243,19 @@
13 if not os.path.isdir(root):
14 if excludes and excludes.search(root):
15 if verbose > 1:
16 - print "deheader: %s excluded" % root
17 + print("deheader: %s excluded" % root)
18 elif InclusionMap.c_source(root):
19 self.files.append(root)
20 else:
21 - print >>sys.stderr, "deheader: can't analyze %s" % root
22 + print("deheader: can't analyze %s" % root, file=sys.stderr)
23 else:
24 for root, dirs, files in os.walk(root):
25 - dirs = filter(lambda x: not x.startswith("."), dirs)
26 + dirs = [x for x in dirs if not x.startswith(".")]
27 for name in files:
28 path = os.path.join(root, name)
29 if excludes and excludes.search(path):
30 if verbose > 1:
31 - print "deheader: %s excluded" % root
32 + print("deheader: %s excluded" % root)
33 elif InclusionMap.c_source(path):
34 self.files.append(path)
35 self.depends_on = {}
36 @@ -1277,15 +1277,15 @@
37 elif line.startswith("#include"):
38 if verbosity >= PROGRESS_DEBUG:
39 name = trim(line)
40 - print "deheader: %s includes %s" % (sourcefile, name)
41 + print("deheader: %s includes %s" % (sourcefile, name))
42 if ignore and ignore.search(line):
43 if verbosity >= PROGRESS_DEBUG:
44 - print "deheader: ignoring %s (exclusion match with %s)." % (name, ignore.pattern)
45 + print("deheader: ignoring %s (exclusion match with %s)." % (name, ignore.pattern))
46 continue
47 if not conditions or conditions == ["S_SPLINT_S"]:
48 includes.append(line)
49 elif verbose > 1:
50 - print "deheader: ignoring %s (conditional inclusion)" % name
51 + print("deheader: ignoring %s (conditional inclusion)" % name)
52 for (r, c, h) in compiled:
53 if c.search(line):
54 if not set(h).issubset(set(seen)):
55 @@ -1299,7 +1299,7 @@
56 trimmedcount[ref] = trimmedcount.get(ref, 0) + 1
57 for ref in trimmedcount:
58 if trimmedcount[ref] > 1:
59 - print "deheader: %s has more than one inclusion of %s" % (sourcefile, ref)
60 + print("deheader: %s has more than one inclusion of %s" % (sourcefile, ref))
61 def forget(self, sourcefile, header):
62 "Forget a header dependency."
63 self.depends_on[sourcefile].remove(header)
64 @@ -1340,7 +1340,7 @@
65 elif trimmed[0] == '<':
66 return trimmed.split('>')[0] + ">"
67 else:
68 - return `line`
69 + return repr(line)
71 def testcompile(source, maker, msg="", verbosity=0, showerrs=False):
72 "Test-compile a sourcefile. Return the status and the compilation time"
73 @@ -1350,7 +1350,7 @@
74 os.remove(derived)
75 command = maker + " " + derived
76 start = time.time()
77 - (status, output) = commands.getstatusoutput(command)
78 + (status, output) = subprocess.getstatusoutput(command)
79 end = time.time()
80 if (os.WIFEXITED(status) and os.WEXITSTATUS(status) != 0 and showerrs) or verbosity >= COMMAND_DEBUG:
81 sys.stdout.write(output)
82 @@ -1361,8 +1361,8 @@
83 else:
84 explain = "succeeded"
85 if verbosity >= PROGRESS_DEBUG:
86 - print "deheader: %s%s %s." \
87 - % (sourcefile, msg, explain)
88 + print("deheader: %s%s %s." \
89 + % (sourcefile, msg, explain))
90 if os.path.exists(derived):
91 os.remove(derived)
92 return (status, end - start)
93 @@ -1387,7 +1387,7 @@
94 for required in requirements:
95 if required in header:
96 if verbosity >= PROGRESS_DEBUG:
97 - print "deheader: in %s, %s prevents uninclusion of %s" % (sourcefile, trigger, trim(header))
98 + print("deheader: in %s, %s prevents uninclusion of %s" % (sourcefile, trigger, trim(header)))
99 retain += 1
100 if not retain:
101 saveit.remove_headers([header])
102 @@ -1404,10 +1404,10 @@
103 baton.end()
104 # Missing-require detection. Can't be merged with duplicate-header
105 # detection because this has to be done after unneeded headers are removed.
106 - stillhere = map(trim, includes)
107 + stillhere = list(map(trim, includes))
108 for (requirement, trigger) in requires:
109 if not set(requirement).issubset(stillhere):
110 - print "deheader: in %s, %s portability requires %s." % (sourcefile, trigger, ",".join(requirement))
111 + print("deheader: in %s, %s portability requires %s." % (sourcefile, trigger, ",".join(requirement)))
112 return unneeded
114 def deheader(sourcefile, maker, includes, requires, remove, verbose):
115 @@ -1421,7 +1421,7 @@
116 includes[:], requires, verbose)
117 if unneeded:
118 for line in unneeded:
119 - print "deheader: remove %s from %s" % (trim(line), sourcefile)
120 + print("deheader: remove %s from %s" % (trim(line), sourcefile))
121 if remove:
122 remove_it = SaveForModification(sourcefile)
123 remove_it.remove_headers(unneeded)
124 @@ -1429,7 +1429,7 @@
125 del remove_it
126 return Summary([sourcefile], includes, unneeded)
127 else:
128 - print >>sys.stderr, "deheader: basic compilation failed on %s" % (sourcefile,)
129 + print("deheader: basic compilation failed on %s" % (sourcefile,), file=sys.stderr)
130 return Summary([sourcefile], includes, [])
132 # After-action analysis starts here
133 @@ -1472,8 +1472,8 @@
134 elif switch in ('-v', '--verbose'):
135 verbose += 1
136 elif switch in ('-V', '--version'):
137 - print "deheader", version
138 - raise SystemExit, 0
139 + print("deheader", version)
140 + raise SystemExit(0)
141 elif switch in ('-x', '--exclude'):
142 excludes.append(val)
143 if not ignores:
144 @@ -1497,7 +1497,7 @@
145 stats = Summary()
146 for summary in summaries:
147 stats = stats + summary
148 - print "deheader: saw", stats
149 - raise SystemExit, 0
150 + print("deheader: saw", stats)
151 + raise SystemExit(0)
153 # End