DrTrigon has submitted this change and it was merged. Change subject: improvement; clean-up of sum_cat_disc and panel-stylesheets, introduce config ......................................................................
improvement; clean-up of sum_cat_disc and panel-stylesheets, introduce config Change-Id: Ifd0c3fc181fd3d7afeeb4370e4991f69f392519d --- A public_html/cgi-bin/config.py M public_html/cgi-bin/ps_plain.py M public_html/cgi-bin/ps_wikinew.py M public_html/cgi-bin/sum_cat_disc.py 4 files changed, 71 insertions(+), 46 deletions(-) Approvals: DrTrigon: Verified; Looks good to me, approved diff --git a/public_html/cgi-bin/config.py b/public_html/cgi-bin/config.py new file mode 100644 index 0000000..1a19136 --- /dev/null +++ b/public_html/cgi-bin/config.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +""" +Configuration variables (config for cgi-bin scripts) +""" + +## @package config +# @brief configuration variables +# +# @copyright Dr. Trigon, 2008-2013 +# +# @section FRAMEWORK +# +# Python wikipedia robot framework, DrTrigonBot. +# @see http://pywikipediabot.sourceforge.net/ +# @see http://de.wikipedia.org/wiki/Benutzer:DrTrigonBot +# +# @section LICENSE +# +# Distributed under the terms of the MIT license. +# @see http://de.wikipedia.org/wiki/MIT-Lizenz +# +__version__='$Id$' +# + + +# === labs conversion patch: variables === === === +# +ver_desc = { 'ts': ['trunk', 'rewrite'], + 'labs': ['compat', 'core'], } + +localdir = { 'ts': ['..', 'DrTrigonBot', '.'], + 'labs': ['..', 'public_html', 'logs', '.'], } + +bot_path = { 'ts': ["../../pywikipedia/", "../../rewrite/"], + 'labs': ["../pywikibot-compat/", "../pywikibot-core/"], } + +db_conf = { 'ts': ['u_%(user)s', "wiki-p.userdb.toolserver.org"], + 'labs': ['%(user)s__%(dbname)s', "wiki.labsdb"], } diff --git a/public_html/cgi-bin/ps_plain.py b/public_html/cgi-bin/ps_plain.py index 3f1de14..6ae7617 100644 --- a/public_html/cgi-bin/ps_plain.py +++ b/public_html/cgi-bin/ps_plain.py @@ -120,3 +120,25 @@ secure = s1 return secure + + +# === labs conversion patch: functions === === === +# +def change_logo(content, environ): + # labs patch: adopt logo for labs server instead of TS (default) + TS = 'http://upload.wikimedia.org/wikipedia/commons/thumb/b/be/Wikimedia_Community_Logo-Toolserver.svg/135px-Wikimedia_Community_Logo-Toolserver.svg.png' + labs = 'http://upload.wikimedia.org/wikipedia/commons/thumb/6/60/Wikimedia_labs_logo.svg/135px-Wikimedia_labs_logo.svg.png' + if ('HTTP_HOST' in environ) and (not (environ['HTTP_HOST'] == 'toolserver.org')): + content = content.replace(TS, labs) + return content + +def host(environ): + if ('HTTP_HOST' in environ) and (not (environ['HTTP_HOST'] == 'toolserver.org')): + return 'labs' + else: + return 'ts' + + +# === labs conversion patch: variables === === === +# +from config import * diff --git a/public_html/cgi-bin/ps_wikinew.py b/public_html/cgi-bin/ps_wikinew.py index ab2eb86..76a3106 100644 --- a/public_html/cgi-bin/ps_wikinew.py +++ b/public_html/cgi-bin/ps_wikinew.py @@ -90,34 +90,3 @@ </body> </html> """ - - -# === labs conversion patch: functions === === === -# -def change_logo(content, environ): - # labs patch: adopt logo for labs server instead of TS (default) - TS = 'http://upload.wikimedia.org/wikipedia/commons/thumb/b/be/Wikimedia_Community_Logo-Toolserver.svg/135px-Wikimedia_Community_Logo-Toolserver.svg.png' - labs = 'http://upload.wikimedia.org/wikipedia/commons/thumb/6/60/Wikimedia_labs_logo.svg/135px-Wikimedia_labs_logo.svg.png' - if ('HTTP_HOST' in environ) and (not (environ['HTTP_HOST'] == 'toolserver.org')): - content = content.replace(TS, labs) - return content - -def host(environ): - if ('HTTP_HOST' in environ) and (not (environ['HTTP_HOST'] == 'toolserver.org')): - return 'labs' - else: - return 'ts' - - -# === labs conversion patch: variables === === === -ver_desc = { 'ts': ['trunk', 'rewrite'], - 'labs': ['compat', 'core'], } - -localdir = { 'ts': ['..', 'DrTrigonBot', '.'], - 'labs': ['..', 'public_html', 'logs', '.'], } - -bot_path = { 'ts': ["../../pywikipedia/", "../../rewrite/"], - 'labs': ["../pywikibot-compat/", "../pywikibot-core/"], } - -db_conf = { 'ts': ['u_drtrigon', "wiki-p.userdb.toolserver.org"], - 'labs': ['u_drtrigon', "wiki.labsdb"], } diff --git a/public_html/cgi-bin/sum_cat_disc.py b/public_html/cgi-bin/sum_cat_disc.py index 79ba434..16d3c40 100755 --- a/public_html/cgi-bin/sum_cat_disc.py +++ b/public_html/cgi-bin/sum_cat_disc.py @@ -41,6 +41,7 @@ import datetime import os, re, sys import locale +import ConfigParser import MySQLdb, _mysql_exceptions @@ -186,9 +187,8 @@ """SELECT VERSION();""", ] -if style.host(os.environ) == 'ts': - # https://wiki.toolserver.org/view/Database_access#wiki - _SQL_query_wiki_info = \ +_SQL_query_wiki_info = { +'ts': # https://wiki.toolserver.org/view/Database_access#wiki """SELECT lang, CONCAT("sql-s", server) AS dbserver, @@ -196,10 +196,8 @@ CONCAT("//", DOMAIN, script_path, "api.php") AS url FROM toolserver.wiki WHERE family = "wikipedia" - ORDER BY SIZE DESC LIMIT %s;""" -else: - # https://wikitech.wikimedia.org/wiki/Nova_Resource:Tools/Help#Metadata_database - _SQL_query_wiki_info = \ + ORDER BY SIZE DESC LIMIT %s;""", +'labs': # https://wikitech.wikimedia.org/wiki/Nova_Resource:Tools/Help#Metadata_database """SELECT lang, slice, @@ -207,7 +205,8 @@ url FROM meta_p.wiki WHERE family = "wikipedia" - ORDER BY SIZE DESC LIMIT %s;""" + ORDER BY SIZE DESC LIMIT %s;""", } +_SQL_query_wiki_info = _SQL_query_wiki_info[style.host(os.environ)] _SQL_create_database = \ """CREATE DATABASE IF NOT EXISTS %s""" @@ -223,13 +222,10 @@ cnf_file = os.path.join(bot_path, "../.my.cnf") -db_name = db_conf[0] -if style.host(os.environ) == 'labs': - import ConfigParser - config = ConfigParser.RawConfigParser() - config.read(cnf_file) - user_name = config.get('client', 'user').replace("'", "") - db_name = '%s__%s' % (user_name, db_name) +config = ConfigParser.RawConfigParser() +config.read(cnf_file) +user_name = config.get('client', 'user').replace("'", "") +db_name = db_conf[0] % {'user': user_name, 'dbname': 'u_%s' % user_name} # === code === === === -- To view, visit https://gerrit.wikimedia.org/r/104476 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ifd0c3fc181fd3d7afeeb4370e4991f69f392519d Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/bots/drtrigonbot Gerrit-Branch: master Gerrit-Owner: DrTrigon <[email protected]> Gerrit-Reviewer: DrTrigon <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
