mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Convert gen-html to python 3
Print statements rewritten to python 3 functions. Each opened file now properly closed.
This commit is contained in:
parent
f18e8d0c0b
commit
d4362e576c
1 changed files with 35 additions and 25 deletions
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import __builtin__
|
import builtins
|
||||||
from pysollib.mygettext import fix_gettext
|
from pysollib.mygettext import fix_gettext
|
||||||
|
|
||||||
from pysollib.gamedb import GAME_DB
|
from pysollib.gamedb import GAME_DB
|
||||||
|
@ -13,8 +13,8 @@ from pysollib.mfxutil import latin1_to_ascii
|
||||||
pysollib_dir = '../'
|
pysollib_dir = '../'
|
||||||
|
|
||||||
|
|
||||||
__builtin__._ = lambda x: x
|
builtins._ = lambda x: x
|
||||||
__builtin__.n_ = lambda x: x
|
builtins.n_ = lambda x: x
|
||||||
|
|
||||||
import pysollib.games
|
import pysollib.games
|
||||||
import pysollib.games.mahjongg
|
import pysollib.games.mahjongg
|
||||||
|
@ -139,12 +139,14 @@ def getGameRulesFilename(n):
|
||||||
def gen_main_html():
|
def gen_main_html():
|
||||||
for infile, title in files:
|
for infile, title in files:
|
||||||
outfile = open(os.path.join('html', infile), 'w')
|
outfile = open(os.path.join('html', infile), 'w')
|
||||||
print >> outfile, main_header % title
|
print(main_header % title, file=outfile)
|
||||||
print >> outfile, open(infile).read()
|
with open(infile, 'r') as file:
|
||||||
|
print(file.read(), file=outfile)
|
||||||
s = '<a href="index.html">Back to the index</a>'
|
s = '<a href="index.html">Back to the index</a>'
|
||||||
if infile == 'index.html':
|
if infile == 'index.html':
|
||||||
s = ''
|
s = ''
|
||||||
print >> outfile, main_footer % s
|
print(main_footer % s, file=outfile)
|
||||||
|
outfile.close()
|
||||||
|
|
||||||
|
|
||||||
def gen_rules_html():
|
def gen_rules_html():
|
||||||
|
@ -167,8 +169,9 @@ def gen_rules_html():
|
||||||
|
|
||||||
# open file of list of all rules
|
# open file of list of all rules
|
||||||
out_rules = open(os.path.join('html', 'rules.html'), 'w')
|
out_rules = open(os.path.join('html', 'rules.html'), 'w')
|
||||||
print >> out_rules, main_header % 'PySol - a Solitaire Game Collection'
|
print(main_header % 'PySol - a Solitaire Game Collection', file=out_rules)
|
||||||
print >> out_rules, open('rules.html').read()
|
with open('rules.html', 'r') as file:
|
||||||
|
print(file.read(), file=out_rules)
|
||||||
|
|
||||||
for id in games:
|
for id in games:
|
||||||
# create list of rules
|
# create list of rules
|
||||||
|
@ -188,7 +191,7 @@ def gen_rules_html():
|
||||||
rules_dir = 'wikipedia'
|
rules_dir = 'wikipedia'
|
||||||
else:
|
else:
|
||||||
print('missing rules for %s (file: %s)'
|
print('missing rules for %s (file: %s)'
|
||||||
% (gi.name.encode('utf-8'), rules_fn))
|
% (gi.name, rules_fn))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# print '>>>', rules_fn
|
# print '>>>', rules_fn
|
||||||
|
@ -208,34 +211,41 @@ def gen_rules_html():
|
||||||
rules_list.append((rules_dir, rules_fn, title, s))
|
rules_list.append((rules_dir, rules_fn, title, s))
|
||||||
files_list.append(rules_fn)
|
files_list.append(rules_fn)
|
||||||
# rules_list.append((rules_fn, gi.name))
|
# rules_list.append((rules_fn, gi.name))
|
||||||
print >> out_rules, '<li><a href="rules/%s">%s</a>' \
|
print('<li><a href="rules/%s">%s</a>' \
|
||||||
% (rules_fn, gi.name.encode('utf-8'))
|
% (rules_fn, gi.name), file=out_rules)
|
||||||
for n in gi.altnames:
|
for n in gi.altnames:
|
||||||
altnames.append((n, rules_fn))
|
altnames.append((n, rules_fn))
|
||||||
|
|
||||||
print >> out_rules, '</ul>\n' + \
|
print('</ul>\n' + main_footer % \
|
||||||
main_footer % '<a href="index.html">Back to the index</a>'
|
'<a href="index.html">Back to the index</a>', file=out_rules)
|
||||||
|
|
||||||
|
out_rules.close()
|
||||||
|
|
||||||
# create file of altnames
|
# create file of altnames
|
||||||
out_rules_alt = open(os.path.join('html', 'rules_alternate.html'), 'w')
|
out_rules_alt = open(os.path.join('html', 'rules_alternate.html'), 'w')
|
||||||
print >> out_rules_alt, main_header % 'PySol - a Solitaire Game Collection'
|
print(main_header % 'PySol - a Solitaire Game Collection',
|
||||||
print >> out_rules_alt, open('rules_alternate.html').read()
|
file=out_rules_alt)
|
||||||
|
with open('rules_alternate.html', 'r') as file:
|
||||||
|
print(file.read(), file=out_rules_alt)
|
||||||
altnames.sort()
|
altnames.sort()
|
||||||
for name, fn in altnames:
|
for name, fn in altnames:
|
||||||
print >> out_rules_alt, '<li> <a href="rules/%s">%s</a>' \
|
print('<li> <a href="rules/%s">%s</a>' \
|
||||||
% (fn, name.encode('utf-8'))
|
% (fn, name), file=out_rules_alt)
|
||||||
print >> out_rules_alt, '</ul>\n' + \
|
print('</ul>\n' + main_footer % \
|
||||||
main_footer % '<a href="index.html">Back to the index</a>'
|
'<a href="index.html">Back to the index</a>', file=out_rules_alt)
|
||||||
|
out_rules_alt.close()
|
||||||
|
|
||||||
# create rules
|
# create rules
|
||||||
for dir, filename, title, footer in rules_list:
|
for dir, filename, title, footer in rules_list:
|
||||||
outfile = open(os.path.join('html', 'rules', filename), 'w')
|
outfile = open(os.path.join('html', 'rules', filename), 'w', encoding='utf-8')
|
||||||
if dir == 'rules':
|
if dir == 'rules':
|
||||||
print >> outfile, (rules_header % title).encode('utf-8')
|
print(rules_header % title, file=outfile)
|
||||||
else: # d == 'wikipedia'
|
else: # d == 'wikipedia'
|
||||||
print >> outfile, (wikipedia_header % title).encode('utf-8')
|
print(wikipedia_header % title, file=outfile)
|
||||||
print >> outfile, open(os.path.join(dir, filename)).read()
|
with open(os.path.join(dir, filename), 'r', encoding='utf-8') as file:
|
||||||
print >> outfile, rules_footer % footer
|
print(file.read(), file=outfile)
|
||||||
|
print(rules_footer % footer, file=outfile)
|
||||||
|
outfile.close()
|
||||||
|
|
||||||
|
|
||||||
gen_main_html()
|
gen_main_html()
|
||||||
|
|
Loading…
Add table
Reference in a new issue