Added sqlalchemy table definitions.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sun, 13 Feb 2011 18:54:07 +0000 (18:54 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sun, 13 Feb 2011 18:54:07 +0000 (18:54 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/wrpylib@773 7aebc617-e5e2-0310-91dc-80fb5f6d2477

setup.py
tests/test_mwdb.py [new file with mode: 0644]
tests/test_mwwrdb.py [new file with mode: 0644]
wrpylib/mwdb.py [new file with mode: 0644]
wrpylib/mwwrdb.py [new file with mode: 0644]
wrpylib/wrvalidators.py

index ac81ce6dd267b116f57122d85574c4f208772f45..e1aedd36936db6616288f864da44e87397b1e0b7 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
 from setuptools import setup
 
 setup(name='wrpylib',
-    version='0.0.6',
+    version='0.0.7',
     description='Winterrodeln Python Library',
     author='Philipp Spitzer',
     author_email='philipp.spitzer@winterrodeln.org',
diff --git a/tests/test_mwdb.py b/tests/test_mwdb.py
new file mode 100644 (file)
index 0000000..a1d67fd
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/python2.6
+# -*- coding: iso-8859-15 -*-
+import wrpylib.mwdb
+import sqlalchemy
+
+
+def test_page_table():
+    metadata = sqlalchemy.MetaData()
+    page_table = wrpylib.mwdb.page_table(metadata)
+
+
+def test_revision_table():
+    metadata = sqlalchemy.MetaData()
+    revision_table = wrpylib.mwdb.revision_table(metadata)
+
+
+def test_text_table():
+    metadata = sqlalchemy.MetaData()
+    text_table = wrpylib.mwdb.text_table(metadata)
+
+
+def test_categorylinks_table():
+    metadata = sqlalchemy.MetaData()
+    categorylinks_table = wrpylib.mwdb.categorylinks_table(metadata)
+
diff --git a/tests/test_mwwrdb.py b/tests/test_mwwrdb.py
new file mode 100644 (file)
index 0000000..6a42157
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/python2.6
+# -*- coding: iso-8859-15 -*-
+import wrpylib.mwwrdb
+import sqlalchemy
+
+
+def test_wrreport_table():
+    metadata = sqlalchemy.MetaData()
+    wrreport_table = wrpylib.mwwrdb.wrreport_table(metadata)
+
+
+def test_wrsledruncache_table():
+    metadata = sqlalchemy.MetaData()
+    wrsledruncache_table = wrpylib.mwwrdb.wrsledruncache_table(metadata)
+
+
+def test_wrinncache_table():
+    metadata = sqlalchemy.MetaData()
+    wrinncache_table = wrpylib.mwwrdb.wrinncache_table(metadata)
+
diff --git a/wrpylib/mwdb.py b/wrpylib/mwdb.py
new file mode 100644 (file)
index 0000000..6858c27
--- /dev/null
@@ -0,0 +1,70 @@
+#!/usr/bin/python2.6
+# -*- coding: iso-8859-15 -*-
+# $Id$
+# $HeadURL$
+"""This module contains code to make tha access of MediaWiki tables
+easy. The module uses sqlalchemy to access the database.
+"""
+from sqlalchemy import Table, Column, types
+
+
+def page_table(metadata):
+    """Returns the sqlalchemy Table representing the "page" table in MediaWiki.
+    :param metadata: metadata = sqlalchemy.MetaData()
+    """
+    return Table("page", metadata,
+    Column("page_id", types.Integer, primary_key=True),
+    Column("page_namespace", types.Integer, nullable=False),
+    Column("page_title", types.Unicode(255), nullable=False),
+    Column("page_restrictions", types.Unicode, nullable=False),
+    Column("page_counter", types.Integer, nullable=False),
+    Column("page_is_redirect", types.Integer, nullable=False),
+    Column("page_is_new", types.Integer, nullable=False),
+    Column("page_random", types.Float, nullable=False),
+    Column("page_touched", types.Unicode(14), nullable=False),
+    Column("page_latest", types.Integer, nullable=False),
+    Column("page_len", types.Integer, nullable=False),
+    )
+
+
+def revision_table(metadata):
+    """Returns the sqlalchemy Table representing the "revision" table in MediaWiki.
+    :param metadata: metadata = sqlalchemy.MetaData()
+    """
+    return Table("revision", metadata,
+    Column("rev_id", types.Integer, nullable=False, primary_key=True),
+    Column("rev_page", types.Integer, nullable=False, primary_key=True),
+    Column("rev_text_id", types.Integer, nullable=False),
+    Column("rev_comment", types.Unicode),
+    Column("rev_user", types.Integer, nullable=False),
+    Column("rev_user_text", types.Unicode(255), nullable=False),
+    Column("rev_timestamp", types.Unicode(14), nullable=False),
+    Column("rev_minor_edit", types.Integer, nullable=False),
+    Column("rev_deleted", types.Integer, nullable=False),
+    Column("rev_len", types.Integer, nullable=False),
+    Column("rev_parent_id", types.Integer, nullable=False),
+    )
+
+
+def text_table(metadata):
+    """Returns the sqlalchemy Table representing the "text" table in MediaWiki.
+    :param metadata: metadata = sqlalchemy.MetaData()
+    """
+    return Table("text", metadata,
+    Column("old_id", types.Integer, primary_key=True),
+    Column("old_text", types.Unicode),
+    Column("old_flags", types.Unicode),
+    )
+
+
+def categorylinks_table(metadata):
+    """Returns the sqlalchemy Table representing the "categorylinks" table in MediaWiki.
+    :param metadata: metadata = sqlalchemy.MetaData()
+    """
+    return Table("categorylinks", metadata,
+    Column("cl_from", types.Integer, nullable=False, primary_key=True),
+    Column("cl_to", types.Unicode(255), nullable=False, primary_key=True),
+    Column("cl_sortkey", types.Unicode, nullable=False),
+    Column("cl_timestamp", types.DateTime, nullable=False),
+    )
+
diff --git a/wrpylib/mwwrdb.py b/wrpylib/mwwrdb.py
new file mode 100644 (file)
index 0000000..5a0879b
--- /dev/null
@@ -0,0 +1,114 @@
+#!/usr/bin/python2.6
+# -*- coding: iso-8859-15 -*-
+# $Id$
+# $HeadURL$
+"""This module contains code to make tha access of winterrodeln
+tables in MediaWiki easy. The module uses sqlalchemy to access the database.
+"""
+from sqlalchemy import Table, Column, types, schema
+
+
+def wrreport_table(metadata):
+    """Returns the sqlalchemy Table representing the "wrreport" Winterrodeln table in MediaWiki.
+    Current table definition.
+    * version 1.2
+    * version 1.3 (no changes)
+    * version 1.4 (no changes)
+    :param metadata: metadata = sqlalchemy.MetaData()
+    """
+    return Table("wrreport", metadata,
+    Column("id", types.Integer, primary_key=True),
+    Column("page_id", types.Integer, schema.ForeignKey('wrsleddingcache.page_id')),
+    Column("page_title", types.Unicode(255), nullable=False),
+    Column("date_report", types.Date),
+    Column("date_entry", types.DateTime, nullable=False),
+    Column("date_invalid", types.DateTime),
+    Column("condition", types.Integer),
+    Column("description", types.Unicode),
+    Column("author_name", types.Unicode(30)),
+    Column("author_ip", types.Unicode(15)),
+    Column("author_userid", types.Integer),
+    Column("author_username", types.Unicode(30)),
+    Column("delete_date", types.DateTime),
+    Column("delete_person_name", types.Unicode(30)),
+    Column("delete_person_ip", types.Unicode(15)),
+    Column("delete_person_userid", types.Integer),
+    Column("delete_person_username", types.Unicode(30)),
+    Column("delete_reason_public", types.Unicode),
+    )
+
+
+def wrsledruncache_table(metadata):
+    """Returns the sqlalchemy Table representing the "wrsledruncache" Winterrodeln table in MediaWiki.
+    Current table definition
+    * version 1.4 (renamed table and added column walkup_possible)
+    :param metadata: metadata = sqlalchemy.MetaData()
+    """
+    return Table("wrsledruncache", metadata,
+    Column("page_id", types.Integer, primary_key=True),
+    Column("page_title", types.Unicode(255)),
+    Column("position_latitude", types.Float),
+    Column("position_longitude", types.Float),
+    Column("top_latitude", types.Float),
+    Column("top_longitude", types.Float),
+    Column("top_elevation", types.Integer),
+    Column("bottom_latitude", types.Float),
+    Column("bottom_longitude", types.Float),
+    Column("bottom_elevation", types.Integer),
+    Column("length", types.Integer),
+    Column("difficulty", types.Integer),
+    Column("avalanches", types.Integer),
+    Column("operator", types.Unicode(255)),
+    Column("public_transport", types.Integer),
+    Column("walkup_possible", types.Boolean),
+    Column("walkup_time", types.Integer),
+    Column("walkup_separate", types.Float),
+    Column("walkup_separate_comment", types.Unicode(255)),
+    Column("lift", types.Boolean),
+    Column("lift_details", types.Unicode(255)),
+    Column("night_light", types.Float),
+    Column("night_light_comment", types.Unicode(255)),
+    Column("night_light_days", types.Integer),
+    Column("night_light_days_comment", types.Unicode(255)),
+    Column("sled_rental", types.Boolean),
+    Column("sled_rental_comment", types.Unicode(255)),
+    Column("cachet", types.Unicode(255)),
+    Column("information_web", types.Unicode(255)),
+    Column("information_phone", types.Unicode(255)),
+    Column("image", types.Unicode(255)),
+    Column("show_in_overview", types.Boolean),
+    Column("forum_id", types.Integer),
+    Column("under_construction", types.Boolean),
+    )
+
+
+def wrinncache_table(metadata):
+    """Returns the sqlalchemy Table representing the "wrinncache" Winterrodeln table in MediaWiki.
+    Current table definition
+    * version 1.3 (changes made from version 1.2)
+    * version 1.4 (no changes)
+    :param metadata: metadata = sqlalchemy.MetaData()
+    """
+    return Table("wrinncache", metadata,
+    Column("page_id", types.Integer, primary_key=True),
+    Column("page_title", types.Unicode(255)),
+    Column("position_latitude", types.Float),
+    Column("position_longitude", types.Float),
+    Column("position_elevation", types.Integer),
+    Column("seats", types.Integer),
+    Column("overnight", types.Boolean),
+    Column("overnight_comment", types.Unicode(255)),
+    Column("smoker_area", types.Boolean),
+    Column("nonsmoker_area", types.Boolean),
+    Column("sled_rental", types.Boolean),
+    Column("sled_rental_comment", types.Unicode(255)),
+    Column("mobile_provider", types.Unicode),
+    Column("homepage", types.Unicode(255)),
+    Column("email_list", types.Unicode),
+    Column("phone_list", types.Unicode),
+    Column("image", types.Unicode(255)),
+    Column("sledding_list", types.Unicode),
+    Column("under_construction", types.Boolean),
+    )
+
+
index cbfac19f90e816f9d1cf859e327419e3d42bf944..bad2e857ea1ce12616255413df2c0f817a6bba6e 100644 (file)
@@ -1,5 +1,7 @@
 #!/usr/bin/python2.6
 # -*- coding: iso-8859-15 -*-
+# $Id$
+# $HeadURL$
 """This file contains "validators" that convert between string and python (database) representation
 of properties used in the "Rodelbahnbox" and "Gasthausbox".
 The "to_python" method has to get a unicode argument.