From 30c363d1c2b7d0ff55be9c376499cdbfc5e7a1e8 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 5 Aug 2009 19:06:59 -0400 Subject: [PATCH] New util to convert mysql table descriptions to a wiki table. --- utils/fix_table_desc.py | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 utils/fix_table_desc.py diff --git a/utils/fix_table_desc.py b/utils/fix_table_desc.py new file mode 100644 index 00000000..bad6c373 --- /dev/null +++ b/utils/fix_table_desc.py @@ -0,0 +1,42 @@ +#!/usr/bin/python + +import re + +desc = """ ++-------------+---------------------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++-------------+---------------------+------+-----+---------+----------------+ +| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment | +| tourneyId | int(10) unsigned | NO | MUL | NULL | | +| playerId | int(10) unsigned | NO | MUL | NULL | | +| payinAmount | int(11) | NO | | NULL | | +| rank | int(11) | NO | | NULL | | +| winnings | int(11) | NO | | NULL | | +| comment | text | YES | | NULL | | +| commentTs | datetime | YES | | NULL | | ++-------------+---------------------+------+-----+---------+----------------+ +""" + +table = """ +{| border="1" +|+Gametypes Table +""" + +# get rid of the verticle spacing and clean up +desc = re.sub("[\+\-]+", "", desc) +desc = re.sub("^\n+", "", desc) # there's probably a better way +desc = re.sub("\n\n", "\n", desc) + +# the first line is the header info +temp, desc = re.split("\n", desc, 1) +temp = re.sub("\|", "!", temp) +temp = re.sub(" !", " !!", temp) +table += temp + " Comments\n" + +# the rest is he body of the table +for line in re.split("\n", desc): + line = re.sub(" \|", " ||", line) + table += "|+\n" + line + "\n" + +table += "|}\n" +print table \ No newline at end of file