http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11449
Revision: 11449 Author: drtrigon Date: 2013-04-25 08:29:15 +0000 (Thu, 25 Apr 2013) Log Message: ----------- new features; +2 thirdparty modules for externals (crontab, lunatic)
Modified Paths: -------------- branches/rewrite/README branches/rewrite/externals/README branches/rewrite/scripts/script_wui.py
Added Paths: ----------- branches/rewrite/externals/patch-lua
Modified: branches/rewrite/README =================================================================== --- branches/rewrite/README 2013-04-24 17:30:40 UTC (rev 11448) +++ branches/rewrite/README 2013-04-25 08:29:15 UTC (rev 11449) @@ -2,5 +2,5 @@ improvements, such as full API usage and a pythonic package layout.
If you want to run the rewrite as a stand-alone package, please also download the -pywikipedia-rewrite.externals package below, and place it's contents in the -externals/ subdirectory. +the contents of the externals/ subdirectory. Confer externals/README for more +information.
Modified: branches/rewrite/externals/README =================================================================== --- branches/rewrite/externals/README 2013-04-24 17:30:40 UTC (rev 11448) +++ branches/rewrite/externals/README 2013-04-25 08:29:15 UTC (rev 11449) @@ -1,3 +1,25 @@ External dependencies for the rewrite branch. This package is only necessary to run pywikibot from a fully self-sufficient (no other dependencies other than -python 2.6+) directory. This is especially useful on Windows. +python 2.6+) directory. This is especially useful on Windows. + +Usually - under normal circumstances - these packages should be installed +separately elsewhere in the OS by the standard package managing system. + +If you want to run the rewrite as a stand-alone package, please also download +the contents of the externals/ subdirectory. Furthermore this includes git +repos and zip archives like: + +* parse-crontab: Parse and use crontab schedules in Python - Version .14 + (from https://github.com/josiahcarlson/parse-crontab) + Checkout the gip repository and copy the 'crontab' dir into the path + 'externals/crontab' afterwards. + +* lunatic-python: Two-way bridge between Python and Lua - Version 1.0 + (from http://labix.org/lunatic-python) + Download the zip archive and unpack the 'lunatic-python-1.0' dir into the + path 'externals/_lua' afterwards. + Patch package dir in order to work with newer lua (>= 5.1) versions + $ patch -p1 -d [path-to-install-dir]/_lua < [path-to-externals]/patch-lua + and you are done. + For the sake of completeness, the command invoked to create the patch was: + $ diff -Naur lunatic-python-1.0 _lua > patch-lua
Added: branches/rewrite/externals/patch-lua =================================================================== --- branches/rewrite/externals/patch-lua (rev 0) +++ branches/rewrite/externals/patch-lua 2013-04-25 08:29:15 UTC (rev 11449) @@ -0,0 +1,127 @@ +diff -Naur lunatic-python-1.0/__init__.py _lua/__init__.py +--- lunatic-python-1.0/__init__.py 1970-01-01 01:00:00.000000000 +0100 ++++ _lua/__init__.py 2013-04-25 10:10:06.007753009 +0200 +@@ -0,0 +1,38 @@ ++# patches applied for compatibility with lua5.1: ++# https://github.com/bastibe/lunatic-python/issues/1 ++# http://lua-users.org/wiki/LunaticPython ++ ++import sys, os ++ ++scriptdir = os.path.dirname(sys.argv[0]) ++if not os.path.isabs(scriptdir): ++ scriptdir = os.path.abspath(os.path.join(os.curdir, scriptdir)) ++ ++libdir = os.path.join(scriptdir, '../externals/_lua/build/lib.linux-x86_64-%s.%s' % sys.version_info[:2]) ++if not os.path.exists(libdir): ++ os.makedirs(libdir) ++# path has to exist BEFORE appending, otherwise the re-import fails ++sys.path.append(libdir) ++ ++try: ++ # try to import ++ from lua import * ++except ImportError, e: ++ print "(re-)compilation triggered because of: '%s'" % e ++ ++ cur = os.path.abspath(os.curdir) ++ os.chdir( os.path.join(scriptdir, '../externals/_lua') ) ++ ++ # remove/reset if existing already ++ if os.path.exists(os.path.join(libdir, 'lua.so')): ++ os.remove( os.path.join(libdir, 'lua.so') ) ++ ++ # compile python module (may be use 'distutil' instead of 'make' here) ++ if os.system("python setup.py build"): ++ #if os.system("make"): ++ raise ImportError("'lua.so' could not be compiled!") ++ ++ os.chdir( cur ) ++ ++ # re-try to import ++ from lua import * +diff -Naur lunatic-python-1.0/python.lua _lua/python.lua +--- lunatic-python-1.0/python.lua 2003-12-13 05:37:57.000000000 +0100 ++++ _lua/python.lua 2012-12-28 22:09:07.000000000 +0100 +@@ -1,6 +1,6 @@ + local path = os.getenv("LUA_SOPATH") + if path then +- func = loadlib(path.."/lua-python.so", "luaopen_python") ++ func = package.loadlib(path.."/lua-python.so", "luaopen_python") + if func then + func() + return +@@ -10,7 +10,7 @@ + local loaded = false + for i = 10, 2, -1 do + for j = 10, 2, -1 do +- func = loadlib(string.format(modmask, i, j), "luaopen_python") ++ func = package.loadlib(string.format(modmask, i, j), "luaopen_python") + if func then + loaded = true + func() +diff -Naur lunatic-python-1.0/setup.py _lua/setup.py +--- lunatic-python-1.0/setup.py 2005-10-19 01:10:07.000000000 +0200 ++++ _lua/setup.py 2013-04-25 00:05:34.776479704 +0200 +@@ -1,7 +1,7 @@ + #!/usr/bin/python + from distutils.core import setup, Extension + from distutils.sysconfig import get_python_lib, get_python_version +-import os ++import os, platform + + if os.path.isfile("MANIFEST"): + os.unlink("MANIFEST") +@@ -9,7 +9,13 @@ + # You may have to change these + PYLIBS = ["python"+get_python_version(), "pthread", "util"] + PYLIBDIR = [get_python_lib(standard_lib=True)+"/config"] +-LUALIBS = ["lua", "lualib"] ++pltfrm = platform.platform().lower() ++if 'ubuntu' in pltfrm: ++ LUALIBS = ["lua5.1"] ++elif 'fedora' in pltfrm: ++ LUALIBS = ["lua"] ++else: ++ LUALIBS = ["lua5.1"] + LUALIBDIR = [] + + setup(name="lunatic-python", +@@ -31,13 +37,13 @@ + ["src/pythoninlua.c", "src/luainpython.c"], + library_dirs=PYLIBDIR, + libraries=PYLIBS, +- extra_compile_args=["-rdynamic"], ++ extra_compile_args=["-rdynamic", "-I/usr/include/lua5.1"], + extra_link_args=["-rdynamic"]), + Extension("lua", + ["src/pythoninlua.c", "src/luainpython.c"], + library_dirs=LUALIBDIR, + libraries=LUALIBS, +- extra_compile_args=["-rdynamic"], ++ extra_compile_args=["-rdynamic", "-I/usr/include/lua5.1"], + extra_link_args=["-rdynamic"]), + ], + ) +diff -Naur lunatic-python-1.0/src/luainpython.c _lua/src/luainpython.c +--- lunatic-python-1.0/src/luainpython.c 2005-10-19 01:07:02.000000000 +0200 ++++ _lua/src/luainpython.c 2012-12-28 22:09:07.000000000 +0100 +@@ -488,12 +488,12 @@ + + if (!L) { + L = lua_open(); +- luaopen_base(L); +- luaopen_table(L); +- luaopen_io(L); +- luaopen_string(L); +- luaopen_debug(L); +- luaopen_loadlib(L); ++ ++ /* loading each lib separately has some deep conflict ++ * with python's readline module so we obey the holy ++ * docs by lua people and use the magic loader. ++ */ ++ luaL_openlibs(L); + luaopen_python(L); + lua_settop(L, 0); + }
Modified: branches/rewrite/scripts/script_wui.py =================================================================== --- branches/rewrite/scripts/script_wui.py 2013-04-24 17:30:40 UTC (rev 11448) +++ branches/rewrite/scripts/script_wui.py 2013-04-25 08:29:15 UTC (rev 11449) @@ -57,8 +57,8 @@ # --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- # __version__ = '$Id$' -__framework_rev__ = '11445' # check: http://de.wikipedia.org/wiki/Hilfe:MediaWiki/Versionen -__release_ver__ = '1.5.%i' # increase minor (1.x) at re-merges with framework +__framework_rev__ = '11448' # check: http://de.wikipedia.org/wiki/Hilfe:MediaWiki/Versionen +__release_ver__ = '1.5.%s' # increase minor (1.x) at re-merges with framework #
@@ -69,10 +69,11 @@
# http://labix.org/lunatic-python try: - import lua # install f15 packages: 'lua', 'lunatic-python' + import lua # installed packages (on f15: 'lua', 'lunatic-python') except ImportError: - import dtbext._lua as lua # TS/labs (debian/ubuntu) -import dtbext.crontab + import _lua as lua # compiled in externals with patch (ubuntu on TS/labs) +# https://github.com/josiahcarlson/parse-crontab +import crontab
import pywikibot import pywikibot.botirc @@ -167,15 +168,15 @@
def do_check_CronJobs(self): # check cron/date (changes of self.refs are tracked (and reload) in on_pubmsg) - page = self.refs[self.templ] - crontab = self.refs[self.cron].get() + page = self.refs[self.templ] + ctab = self.refs[self.cron].get() # extract 'rev' and 'timestmp' from 'crontab' page text ... - for line in crontab.splitlines(): # hacky/ugly/cheap; already better done in trunk dtbext + for line in ctab.splitlines(): # hacky/ugly/cheap; already better done in trunk dtbext (rev, timestmp) = [item.strip() for item in line[1:].split(',')]
# [min] [hour] [day of month] [month] [day of week] # (date supported only, thus [min] and [hour] dropped) - entry = dtbext.crontab.CronTab(timestmp) + entry = crontab.CronTab(timestmp) # find the delay from current minute (does not return 0.0 - but next) delay = entry.next(datetime.datetime.now().replace(second=0,microsecond=0)-datetime.timedelta(microseconds=1)) #pywikibot.output(u'CRON delay for execution: %.3f (<= %i)' % (delay, bot_config['CRONMaxDelay']))