git » pygen » commit ac40ee7

Update samples to python3, and fix print statement

author Alberto Bertogli
2023-08-23 16:29:33 UTC
committer Alberto Bertogli
2023-08-23 16:29:33 UTC
parent 101016555b3ab3776c6dd283bd26d00ddded54e8

Update samples to python3, and fix print statement

pygen +1 -1
samples/1/hdr.pgh +1 -1
samples/1/sample.html.pg +2 -2
samples/2/src/a/hdr.pgh +1 -1
samples/2/src/a/sample.html.pg +2 -2
samples/3/src/a.txt.pg +1 -1
samples/generate.sh +13 -0

diff --git a/pygen b/pygen
index 56ab158..9369f38 100755
--- a/pygen
+++ b/pygen
@@ -98,7 +98,7 @@ def gen_from(src, dst, environ=None, incpath=None):
 
         elif line.startswith("#print"):
             s = line.split(" ", 1)[1]
-            s = "print " + s
+            s = "print(" + s + ")"
             exec(s, environ)
 
         else:
diff --git a/samples/1/hdr.pgh b/samples/1/hdr.pgh
index 4495334..a708566 100644
--- a/samples/1/hdr.pgh
+++ b/samples/1/hdr.pgh
@@ -1,4 +1,4 @@
 <head>
-#py print "<title>" + title + "</title>"
+#py print("<title>" + title + "</title>")
 </head>
 
diff --git a/samples/1/sample.html.pg b/samples/1/sample.html.pg
index c5185ba..daa47e5 100644
--- a/samples/1/sample.html.pg
+++ b/samples/1/sample.html.pg
@@ -8,7 +8,7 @@
 To generate an html file from this, run <tt>pygen gen sample.html.pg</tt>.<br>
 
 This is the main body<br>
-#py print "One-line python statement"
+#py print("One-line python statement")
 <p>
 
 #print "Shortcut to print<br>"
@@ -17,7 +17,7 @@ Some more static text.<p>
 #py:
 i = 1
 l = ['a', 2, 'b']
-print 'Some variables:', i, l
+print('Some variables:', i, l)
 #endpy
 
 The end!
diff --git a/samples/2/src/a/hdr.pgh b/samples/2/src/a/hdr.pgh
index 4495334..a708566 100644
--- a/samples/2/src/a/hdr.pgh
+++ b/samples/2/src/a/hdr.pgh
@@ -1,4 +1,4 @@
 <head>
-#py print "<title>" + title + "</title>"
+#py print("<title>" + title + "</title>")
 </head>
 
diff --git a/samples/2/src/a/sample.html.pg b/samples/2/src/a/sample.html.pg
index c5185ba..daa47e5 100644
--- a/samples/2/src/a/sample.html.pg
+++ b/samples/2/src/a/sample.html.pg
@@ -8,7 +8,7 @@
 To generate an html file from this, run <tt>pygen gen sample.html.pg</tt>.<br>
 
 This is the main body<br>
-#py print "One-line python statement"
+#py print("One-line python statement")
 <p>
 
 #print "Shortcut to print<br>"
@@ -17,7 +17,7 @@ Some more static text.<p>
 #py:
 i = 1
 l = ['a', 2, 'b']
-print 'Some variables:', i, l
+print('Some variables:', i, l)
 #endpy
 
 The end!
diff --git a/samples/3/src/a.txt.pg b/samples/3/src/a.txt.pg
index 4b991e4..2b3809e 100644
--- a/samples/3/src/a.txt.pg
+++ b/samples/3/src/a.txt.pg
@@ -1,4 +1,4 @@
 #py:
-print "Hello hello!"
+print("Hello hello!")
 #endpy
 
diff --git a/samples/generate.sh b/samples/generate.sh
new file mode 100755
index 0000000..f122586
--- /dev/null
+++ b/samples/generate.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+set -e
+
+cd "$(dirname "$0")"
+
+for i in 1 2 3; do
+	echo "## $i"
+	mkdir -p .out-$i
+	../pygen autogen $i .out-$i/
+	echo
+done
+