def gen_rules_html(): # ls = glob(os.path.join('rules', '*.html')) rules_ls = os.listdir('rules') rules_ls.sort() wikipedia_ls = os.listdir('wikipedia') wikipedia_ls.sort() games = GAME_DB.getGamesIdSortedByName() rules_list = [] files_list = [] for fn, tt in rules_files: rules_list.append(('rules', fn, tt, '')) files_list.append(fn) for fn, tt in wikipedia_files: rules_list.append(('wikipedia', fn, tt, '')) files_list.append(fn) altnames = [] # open file of list of all rules out_rules = open(os.path.join('html', 'rules.html'), 'w') print >> out_rules, main_header % 'PySol - a Solitaire Game Collection' print >> out_rules, open('rules.html').read() for id in games: # create list of rules gi = GAME_DB.get(id) rules_fn = gi.rules_filename if not rules_fn: rules_fn = getGameRulesFilename(gi.name) if rules_fn in files_list: continue if rules_fn in rules_ls: rules_dir = 'rules' elif rules_fn in wikipedia_ls: rules_dir = 'wikipedia' else: print('missing rules for %s (file: %s)' % (gi.name.encode('utf-8'), rules_fn)) continue # print '>>>', rules_fn title = 'PySol - Rules for ' + gi.name s = '' if gi.si.game_type == GI.GT_HANAFUDA: s = '<a href="../hanafuda.html">General Flower Card rules</a>' elif gi.si.game_type == GI.GT_DASHAVATARA_GANJIFA: s = '<a href="../ganjifa.html">About Ganjifa</a>' elif gi.si.game_type == GI.GT_HEXADECK: s = '<a href="../hexadeck.html">General Hex A Deck rules</a>' elif gi.si.game_type == GI.GT_MUGHAL_GANJIFA: s = '<a href="../ganjifa.html">About Ganjifa</a>' # print '***', gi.name, '***' rules_list.append((rules_dir, rules_fn, title, s)) files_list.append(rules_fn) # rules_list.append((rules_fn, gi.name)) print >> out_rules, '<li><a href="rules/%s">%s</a>' \ % (rules_fn, gi.name.encode('utf-8')) for n in gi.altnames: altnames.append((n, rules_fn)) print >> out_rules, '</ul>\n' + \ main_footer % '<a href="index.html">Back to the index</a>' # create file of altnames out_rules_alt = open(os.path.join('html', 'rules_alternate.html'), 'w') print >> out_rules_alt, main_header % 'PySol - a Solitaire Game Collection' print >> out_rules_alt, open('rules_alternate.html').read() altnames.sort() for name, fn in altnames: print >> out_rules_alt, '<li> <a href="rules/%s">%s</a>' \ % (fn, name.encode('utf-8')) print >> out_rules_alt, '</ul>\n' + \ main_footer % '<a href="index.html">Back to the index</a>' # create rules for dir, filename, title, footer in rules_list: outfile = open(os.path.join('html', 'rules', filename), 'w') if dir == 'rules': print >> outfile, (rules_header % title).encode('utf-8') else: # d == 'wikipedia' print >> outfile, (wikipedia_header % title).encode('utf-8') print >> outfile, open(os.path.join(dir, filename)).read() print >> outfile, rules_footer % footer
def gen_rules_html(): # ls = glob(os.path.join('rules', '*.html')) rules_ls = os.listdir('rules') rules_ls.sort() wikipedia_ls = os.listdir('wikipedia') wikipedia_ls.sort() games = GAME_DB.getGamesIdSortedByName() rules_list = [] files_list = [] for fn, tt in rules_files: rules_list.append(('rules', fn, tt, '')) files_list.append(fn) for fn, tt in wikipedia_files: rules_list.append(('wikipedia', fn, tt, '')) files_list.append(fn) altnames = [] # open file of list of all rules out_rules = open(os.path.join('html', 'rules.html'), 'w') print(_fmt(main_header, {'title': 'PySol - a Solitaire Game Collection'}), file=out_rules) with open('rules.html', 'r') as file: print(file.read(), file=out_rules) for id in games: # create list of rules gi = GAME_DB.get(id) rules_fn = gi.rules_filename if not rules_fn: rules_fn = _get_game_rules_filename(gi.name) if rules_fn in rules_ls: rules_dir = 'rules' elif rules_fn in wikipedia_ls: rules_dir = 'wikipedia' else: print('missing rules for %s (file: %s)' % (gi.name, rules_fn)) continue # print '>>>', rules_fn if rules_fn not in files_list: title = 'PySol - Rules for ' + gi.name s = '' if gi.si.game_type == GI.GT_HANAFUDA: s = '<a href="../hanafuda.html">General Flower Card rules</a>' elif gi.si.game_type == GI.GT_DASHAVATARA_GANJIFA or \ gi.si.game_type == GI.GT_MUGHAL_GANJIFA: s = '<a href="../ganjifa.html">About Ganjifa</a>' elif gi.si.game_type == GI.GT_HEXADECK: s = '<a href="../hexadeck.html">General Hex A Deck rules</a>' rules_list.append((rules_dir, rules_fn, title, s)) files_list.append(rules_fn) # rules_list.append((rules_fn, gi.name)) print('<li><a href="rules/%s">%s</a>' % (rules_fn, gi.name), file=out_rules) for n in gi.altnames: altnames.append((n, rules_fn)) print('</ul>\n' + _fmt( main_footer, {'back_to_index_link': '<a href="index.html">Back to the index</a>'}), file=out_rules) out_rules.close() # create file of altnames out_rules_alt = open(os.path.join('html', 'rules_alternate.html'), 'w') print(_fmt(main_header, {'title': 'PySol - a Solitaire Game Collection'}), file=out_rules_alt) with open('rules_alternate.html', 'r') as file: print(file.read(), file=out_rules_alt) altnames.sort() for name, fn in altnames: print('<li> <a href="rules/%s">%s</a>' % (fn, name), file=out_rules_alt) print('</ul>\n' + _fmt( main_footer, {'back_to_index_link': '<a href="index.html">Back to the index</a>'}), file=out_rules_alt) out_rules_alt.close() # create rules for dir, filename, title, footer in rules_list: outfile = open(os.path.join('html', 'rules', filename), 'w', encoding='utf-8') if dir == 'rules': print(_fmt(rules_header, {'title': title}), file=outfile) else: # d == 'wikipedia' print(_fmt(wikipedia_header, {'title': title}), file=outfile) with open(os.path.join(dir, filename), 'r', encoding='utf-8') as file: print(file.read(), file=outfile) print(_fmt(rules_footer, {'footer': footer}), file=outfile) outfile.close()