Move updatewrmapcache.py to scripts folder.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Tue, 17 Dec 2019 20:23:53 +0000 (20:23 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Tue, 17 Dec 2019 20:23:53 +0000 (20:23 +0000)
git-svn-id: http://www.winterrodeln.org/svn/wrpylib/trunk@2870 7aebc617-e5e2-0310-91dc-80fb5f6d2477

scripts/updatewrmapcache.py [new file with mode: 0755]

diff --git a/scripts/updatewrmapcache.py b/scripts/updatewrmapcache.py
new file mode 100755 (executable)
index 0000000..2ea300d
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/python2.7
+# -*- coding: iso-8859-15 -*-
+"""Updates the wrmappathcache and wrmappointcache tables (by calling wrpylib.wrmwcache.update_wrmapcache()).
+Can be used in a python session or at the command line.
+
+Command line usage:
+$ python updatewrmapcache.py inifile1.ini ...
+
+One or more .ini configuration files can be given.
+At the end, the following entries have to be present:
+
+    [mysql]
+    host=localhost
+    dbname=philipp_winterrodeln_wiki
+    user_name=philipp_www
+    user_pass=YYYYYY
+"""
+
+import sys
+import ConfigParser
+from sqlalchemy.engine import create_engine
+import wrpylib.wrmwcache
+
+
+def update_wrmapcache(inifile):
+    """
+    :param inifile: filename of an .ini file or a list of .ini files.
+    """
+    config = ConfigParser.SafeConfigParser()
+    config.read(inifile)
+
+    host = config.get('mysql', 'host')
+    dbname = config.get('mysql', 'dbname')
+    user = config.get('mysql', 'user_name')
+    passwd = config.get('mysql', 'user_pass')
+
+    engine = create_engine('mysql://{user}@{host}:3306/{dbname}?charset=utf8&passwd={passwd}&use_unicode=0'.format(host=host, dbname=dbname, user=user, passwd=passwd))
+    # "use_unicode=0": see: https://sourceforge.net/tracker/?func=detail&aid=2837134&group_id=22307&atid=374932
+    wrpylib.wrmwcache.update_wrmapcache(engine.connect())
+
+
+if __name__ == '__main__':
+    if len(sys.argv) >= 2:
+        update_wrmapcache(sys.argv[1:])
+    else:
+        print 'Usage:\n{0} infile1.ini [inifile2.ini ...]'.format(sys.argv[0])
+        print 'See: http://www.winterrodeln.org/trac/wiki/ConfigIni'
+