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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
From: Martin Jansa <martin.jansa@lge.com>
Date: Thu, 12 Dec 2019 07:22:55 -0800
Subject: *.py: use python3 explicitly and migrate with 2to3
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Forwarded: https://github.com/pyzy/pyzy/pull/4
* python2 is EOL, use python3
https://python3statement.org/
* fixes build on hosts without python (2) installed
rm -f android.db; \
../../../../git/data/db/android/create_db.py ../../../../git/data/db/android/rawdict_utf16_65105_freq.txt | work/qemux86-webos-linux/pyzy/0.1.0+gitAUTOINC+d774746656-r0/recipe-sysroot-native/usr/bin/sqlite3 android.db || \
( rm -f android.db ; exit 1 )
/usr/bin/env: ‘python’: No such file or directory
hosttools/mkdir -p 'work/qemux86-webos-linux/pyzy/0.1.0+gitAUTOINC+d774746656-r0/image/usr/share/pyzy/db'
hosttools/install -c -m 644 ../../../../git/data/db/android/android.db 'work/qemux86-webos-linux/pyzy/0.1.0+gitAUTOINC+d774746656-r0/image/usr/share/pyzy/db'
hosttools/install: cannot stat '../../../../git/data/db/android/android.db': No such file or directory
Makefile:395: recipe for target 'install-main_dbDATA' failed
make[4]: *** [install-main_dbDATA] Error 1
Signed-off-by: Martin Jansa <martin.jansa@lge.com>
---
data/db/android/create_db.py | 28 ++++++++++++++--------------
scripts/addheader.py | 8 ++++----
scripts/update-simptrad-table.py | 24 ++++++++++++------------
tools/googlecode_upload.py | 24 ++++++++++++------------
4 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/data/db/android/create_db.py b/data/db/android/create_db.py
index 4fff1d0..2da5bff 100755
--- a/data/db/android/create_db.py
+++ b/data/db/android/create_db.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
from pydict import *
from id import *
from valid_hanzi import *
@@ -9,7 +9,7 @@ def get_sheng_yun(pinyin):
return None, None
if pinyin == "ng":
return "", "en"
- for i in xrange(2, 0, -1):
+ for i in range(2, 0, -1):
t = pinyin[:i]
if t in SHENGMU_DICT:
return t, pinyin[len(t):]
@@ -17,13 +17,13 @@ def get_sheng_yun(pinyin):
def read_phrases(filename):
buf = file(filename).read()
- buf = unicode(buf, "utf16")
+ buf = str(buf, "utf16")
buf = buf.strip()
- for l in buf.split(u'\n'):
- hanzi, freq, flag, pinyin = l.split(u' ', 3)
+ for l in buf.split('\n'):
+ hanzi, freq, flag, pinyin = l.split(' ', 3)
freq = float(freq)
pinyin = pinyin.split()
- if any(map(lambda c: c not in valid_hanzi, hanzi)):
+ if any([c not in valid_hanzi for c in hanzi]):
continue
yield hanzi, freq, pinyin
@@ -33,9 +33,9 @@ def create_db(filename):
# con.execute ("PRAGMA synchronous = NORMAL;")
# con.execute ("PRAGMA temp_store = MEMORY;")
# con.execute ("PRAGMA default_cache_size = 5000;")
- print "PRAGMA synchronous = NORMAL;"
- print "PRAGMA temp_store = MEMORY;"
- print "PRAGMA default_cache_size = 5000;"
+ print("PRAGMA synchronous = NORMAL;")
+ print("PRAGMA temp_store = MEMORY;")
+ print("PRAGMA default_cache_size = 5000;")
sql = "CREATE TABLE py_phrase_%d (phrase TEXT, freq INTEGER, %s);"
@@ -44,7 +44,7 @@ def create_db(filename):
for j in range(0, i + 1):
column.append ("s%d INTEGER" % j)
column.append ("y%d INTEGER" % j)
- print sql % (i, ",".join(column))
+ print(sql % (i, ",".join(column)))
# con.execute(sql % (i, column))
# con.commit()
@@ -60,7 +60,7 @@ def create_db(filename):
records_new.append((hanzi, i, pinyin))
records_new.reverse()
- print "BEGIN;"
+ print("BEGIN;")
insert_sql = "INSERT INTO py_phrase_%d VALUES (%s);"
for hanzi, freq, pinyin in records_new:
columns = []
@@ -72,9 +72,9 @@ def create_db(filename):
values = "'%s', %d, %s" % (hanzi.encode("utf8"), freq, ",".join(map(str,columns)))
sql = insert_sql % (len(hanzi) - 1, values)
- print sql
- print "COMMIT;"
- print "VACUUM;"
+ print(sql)
+ print("COMMIT;")
+ print("VACUUM;")
def main():
create_db(sys.argv[1])
diff --git a/scripts/addheader.py b/scripts/addheader.py
index 09e628e..7874105 100644
--- a/scripts/addheader.py
+++ b/scripts/addheader.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import sys
def add_header(name, header):
@@ -6,13 +6,13 @@ def add_header(name, header):
lines = fin.readlines()
with file(name, "w") as fout:
for l in header:
- print >> fout, l,
+ print(l, end=' ', file=fout)
if lines[0].startswith("/*") and lines[0].endswith("*/\n"):
pass
else:
- print >> fout, lines[0],
+ print(lines[0], end=' ', file=fout)
for l in lines[1:]:
- print >> fout, l,
+ print(l, end=' ', file=fout)
def main():
with file("header") as f:
diff --git a/scripts/update-simptrad-table.py b/scripts/update-simptrad-table.py
index 64d3d45..39c5e60 100755
--- a/scripts/update-simptrad-table.py
+++ b/scripts/update-simptrad-table.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import sys
sys.path.append(".")
@@ -6,7 +6,7 @@ from ZhConversion import *
from valid_hanzi import *
def convert(s, d, n):
- out = u""
+ out = ""
end = len(s)
begin = 0
while begin < end:
@@ -20,9 +20,9 @@ def convert(s, d, n):
return out
def filter_more(records, n):
- han = filter(lambda (k, v): len(k) <= n, records)
+ han = [k_v1 for k_v1 in records if len(k_v1[0]) <= n]
hand = dict(han)
- hanm = filter(lambda (k, v): convert(k, hand, n) != v, records)
+ hanm = [k_v2 for k_v2 in records if convert(k_v2[0], hand, n) != k_v2[1]]
return hanm + han
def filter_func(args):
@@ -46,24 +46,24 @@ def filter_func(args):
return True
def get_records():
- records = zh2Hant.items()
+ records = list(zh2Hant.items())
- records = filter(filter_func, records)
+ records = list(filter(filter_func, records))
- maxlen = max(map(lambda (k,v): len(k), records))
+ maxlen = max([len(k_v[0]) for k_v in records])
for i in range(1, maxlen - 1):
records = filter_more(records, i)
- records = map(lambda (k, v): (k.encode("utf8"), v.encode("utf8")), records)
+ records = [(k_v3[0].encode("utf8"), k_v3[1].encode("utf8")) for k_v3 in records]
records.sort()
return maxlen, records
def main():
- print "static const char *simp_to_trad[][2] = {"
+ print("static const char *simp_to_trad[][2] = {")
maxlen, records = get_records()
for s, ts in records:
- print ' { "%s", "%s" },' % (s, ts)
- print "};"
- print '#define SIMP_TO_TRAD_MAX_LEN (%d)' % maxlen
+ print(' { "%s", "%s" },' % (s, ts))
+ print("};")
+ print('#define SIMP_TO_TRAD_MAX_LEN (%d)' % maxlen)
if __name__ == "__main__":
main()
diff --git a/tools/googlecode_upload.py b/tools/googlecode_upload.py
index d2d5f97..e72b21e 100755
--- a/tools/googlecode_upload.py
+++ b/tools/googlecode_upload.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# Copyright 2006, 2007 Google Inc. All Rights Reserved.
# Author: danderson@google.com (David Anderson)
@@ -48,7 +48,7 @@
__author__ = 'danderson@google.com (David Anderson)'
-import httplib
+import http.client
import os.path
import optparse
import getpass
@@ -95,7 +95,7 @@ def upload(file, project_name, user_name, password, summary, labels=None):
'Content-Type': content_type,
}
- server = httplib.HTTPSConnection(upload_host)
+ server = http.client.HTTPSConnection(upload_host)
server.request('POST', upload_uri, body, headers)
resp = server.getresponse()
server.close()
@@ -177,17 +177,17 @@ def upload_find_auth(file_path, project_name, summary, labels=None,
user_name = sys.stdin.readline().rstrip()
if password is None:
# Read password if not loaded from svn config, or on subsequent tries.
- print 'Please enter your googlecode.com password.'
- print '** Note that this is NOT your Gmail account password! **'
- print 'It is the password you use to access Subversion repositories,'
- print 'and can be found here: http://code.google.com/hosting/settings'
+ print('Please enter your googlecode.com password.')
+ print('** Note that this is NOT your Gmail account password! **')
+ print('It is the password you use to access Subversion repositories,')
+ print('and can be found here: http://code.google.com/hosting/settings')
password = getpass.getpass()
status, reason, url = upload(file_path, project_name, user_name, password,
summary, labels)
# Returns 403 Forbidden instead of 401 Unauthorized for bad
# credentials as of 2007-07-17.
- if status in [httplib.FORBIDDEN, httplib.UNAUTHORIZED]:
+ if status in [http.client.FORBIDDEN, http.client.UNAUTHORIZED]:
# Rest for another try.
user_name = password = None
tries = tries - 1
@@ -235,12 +235,12 @@ def main():
options.summary, labels,
options.user, options.password)
if url:
- print 'The file was uploaded successfully.'
- print 'URL: %s' % url
+ print('The file was uploaded successfully.')
+ print('URL: %s' % url)
return 0
else:
- print 'An error occurred. Your file was not uploaded.'
- print 'Google Code upload server said: %s (%s)' % (reason, status)
+ print('An error occurred. Your file was not uploaded.')
+ print('Google Code upload server said: %s (%s)' % (reason, status))
return 1
|