Skip to content

Commit b8bebcb

Browse files
committed
Step 1, changing perl to python
1 parent 26d256f commit b8bebcb

27 files changed

Lines changed: 2673 additions & 2619 deletions
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env python3
2+
# /// script
3+
# requires-python = ">=3.9"
4+
# ///
5+
6+
import re
7+
import sys
8+
9+
10+
def main() -> int:
11+
library = sys.argv[1] if len(sys.argv) > 1 else ""
12+
dst = sys.argv[2] if len(sys.argv) > 2 else ""
13+
14+
todo = [library]
15+
done: dict[str, int] = {library: 1}
16+
unresolved: dict[str, int] = {}
17+
defs: dict[str, str] = {}
18+
other: dict[str, int] = {}
19+
20+
while todo:
21+
f = todo.pop()
22+
try:
23+
fh = open(f, "r", encoding="utf-8")
24+
except OSError:
25+
raise SystemExit(f"File missing: {f}")
26+
with fh:
27+
for line in fh:
28+
m = re.match(r"^\#( )*include <(boost/.*)>", line)
29+
if m:
30+
g = re.sub(r"^\./", "", m.group(2))
31+
if g not in done:
32+
todo.append(g)
33+
done[g] = 1
34+
continue
35+
m = re.match(r'^\#( )*include "(boost/.*)"', line)
36+
if m:
37+
g = re.sub(r"^\./", "", m.group(2))
38+
if g not in done:
39+
todo.append(g)
40+
done[g] = 1
41+
continue
42+
m = re.match(r"^\#( )*include <(.*)>", line)
43+
if m:
44+
other[m.group(2)] = 1
45+
continue
46+
m = re.match(r"^\#( )*include (.*)", line)
47+
if m:
48+
k = m.group(2).rstrip("\n")
49+
unresolved[k] = 1
50+
continue
51+
m = re.match(r"^\#( )*define (GECODE_BOOST_[A-Z_]*) (.*)", line)
52+
if m:
53+
k = m.group(2)
54+
v = m.group(3).rstrip("\n")
55+
qm = re.search(r'\"(.*)\"', v)
56+
if qm:
57+
v = qm.group(1)
58+
am = re.search(r"<(.*)>", v)
59+
if am:
60+
v = am.group(1)
61+
if k in defs:
62+
defs[k] = defs[k] + "," + v
63+
else:
64+
defs[k] = v
65+
66+
for u in list(unresolved.keys()):
67+
if u in defs:
68+
for d in defs[u].split(","):
69+
if d not in done:
70+
todo.append(d)
71+
done[d] = 1
72+
73+
dirs: dict[str, int] = {}
74+
for g in sorted(done.keys()):
75+
m = re.match(r"(.*)/.*", g)
76+
if m:
77+
dirs[m.group(1)] = 1
78+
79+
for d in sorted(dirs.keys()):
80+
sys.stdout.write(f"mkdir -p \"{dst}{d}\"\n")
81+
for g in sorted(done.keys()):
82+
m = re.match(r"(.*)/.*", g)
83+
if m:
84+
d = m.group(1)
85+
sys.stdout.write(f"cp \"{g}\" \"{dst}{d}\"\n")
86+
87+
return 0
88+
89+
90+
if __name__ == "__main__":
91+
raise SystemExit(main())

misc/allexamples.perl

Lines changed: 0 additions & 60 deletions
This file was deleted.

misc/allexamples.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python3
2+
# /// script
3+
# requires-python = ">=3.9"
4+
# ///
5+
6+
import os
7+
import subprocess
8+
import sys
9+
10+
11+
def run_cmd_lines(cmd: str):
12+
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
13+
assert proc.stdout is not None
14+
for line in proc.stdout:
15+
yield line
16+
proc.wait()
17+
18+
19+
def runexample(directory: str, filename: str) -> None:
20+
sys.stdout.write("------------------------------------------------------------\n")
21+
sys.stdout.write(f"Running {filename}\n")
22+
cmd = f"{directory}/examples/{filename} -time 120000 2>&1"
23+
for line in run_cmd_lines(cmd):
24+
sys.stdout.write(line)
25+
sys.stdout.write("------------------------------------------------------------\n")
26+
27+
28+
def main() -> int:
29+
directory = sys.argv[1] if len(sys.argv) > 1 else ""
30+
find_cmd = f"find {directory}/examples -maxdepth 1 -type f ! -name '*.*'"
31+
for x in run_cmd_lines(find_cmd):
32+
x = x.rstrip("\n")
33+
filename = os.path.basename(x)
34+
35+
prop: list[str] = []
36+
model: list[str] = []
37+
for line in run_cmd_lines(f"{x} -help 2>&1"):
38+
if "-propagation (" in line:
39+
l1 = line
40+
l1 = l1.split("-propagation (", 1)[1]
41+
l1 = l1.split(")", 1)[0]
42+
l1 = l1.replace(" ", "")
43+
prop = l1.split(",") if l1 else []
44+
elif "-model (" in line:
45+
l1 = line
46+
l1 = l1.split("-model (", 1)[1]
47+
l1 = l1.split(")", 1)[0]
48+
l1 = l1.replace(" ", "")
49+
model = l1.split(",") if l1 else []
50+
51+
if len(prop) == 0:
52+
if len(model) == 0:
53+
runexample(directory, filename)
54+
else:
55+
for m in model:
56+
runexample(directory, f"{filename} -model {m}")
57+
else:
58+
for p in prop:
59+
if len(model) == 0:
60+
runexample(directory, f"{filename} -propagation {p}")
61+
else:
62+
for m in model:
63+
runexample(directory, f"{filename} -propagation {p} -model {m}")
64+
return 0
65+
66+
67+
if __name__ == "__main__":
68+
raise SystemExit(main())
Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
#!/usr/bin/perl -w
1+
#!/usr/bin/env python3
2+
# /// script
3+
# requires-python = ">=3.9"
4+
# ///
25

3-
print <<EOF
4-
/*
6+
import re
7+
import sys
8+
9+
HEADER = """/*
510
* Main authors:
6-
* Guido Tack <tack\@gecode.org>
11+
* Guido Tack <tack@gecode.org>
712
*
813
* Copyright:
914
* Guido Tack, 2008
@@ -14,7 +19,7 @@
1419
*
1520
* Permission is hereby granted, free of charge, to any person obtaining
1621
* a copy of this software and associated documentation files (the
17-
* "Software"), to deal in the Software without restriction, including
22+
* \"Software\"), to deal in the Software without restriction, including
1823
* without limitation the rights to use, copy, modify, merge, publish,
1924
* distribute, sublicense, and/or sell copies of the Software, and to
2025
* permit persons to whom the Software is furnished to do so, subject to
@@ -23,7 +28,7 @@
2328
* The above copyright notice and this permission notice shall be
2429
* included in all copies or substantial portions of the Software.
2530
*
26-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31+
* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,
2732
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2833
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2934
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
@@ -33,19 +38,22 @@
3338
*
3439
*/
3540
36-
EOF
37-
;
41+
"""
42+
3843

39-
my $prev = "";
44+
def main() -> int:
45+
sys.stdout.write(HEADER)
46+
prev = ""
47+
for line in sys.stdin:
48+
if re.search(r"\#undef.*GECODE.*", line) or re.search(r".*forceinline*", line):
49+
sys.stdout.write(prev)
50+
sys.stdout.write(line)
51+
sys.stdout.write("\n")
52+
else:
53+
prev = line
54+
sys.stdout.write("// STATISTICS: support-any\n")
55+
return 0
4056

41-
while (my $l = <>) {
42-
if ($l =~ /\#undef.*GECODE.*/ || $l =~/.*forceinline*/) {
43-
print $prev;
44-
print $l;
45-
print "\n";
46-
} else {
47-
$prev = $l;
48-
}
49-
}
5057

51-
print "// STATISTICS: support-any\n";
58+
if __name__ == "__main__":
59+
raise SystemExit(main())

misc/fixmanifest.perl

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)