Sitic has uploaded a new change for review. https://gerrit.wikimedia.org/r/227164
Change subject: Switch to python 3 ...................................................................... Switch to python 3 \o/ gevent added python 3 support two weeks ago. The switch is needed for mediawiki-utilities to check if a revision was reverted. Change-Id: I1c49eb7b3c68be860cf6a4a0ee3713a3f244bae2 --- M backend/celery/api.py M backend/celery/tasks.py M backend/server/__init__.py M backend/server/flask_mwoauth/__init__.py M scripts/celery.grid.sh M setup.py 6 files changed, 40 insertions(+), 47 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/labs/tools/crosswatch refs/changes/64/227164/1 diff --git a/backend/celery/api.py b/backend/celery/api.py index fb6146d..7a4870f 100644 --- a/backend/celery/api.py +++ b/backend/celery/api.py @@ -38,7 +38,8 @@ self.redis = StrictRedis( host=config.redis_server, port=config.redis_port, - db=config.redis_db + db=config.redis_db, + decode_responses=True ) def publish(self, message): diff --git a/backend/celery/tasks.py b/backend/celery/tasks.py index 6afd300..5c2ab90 100644 --- a/backend/celery/tasks.py +++ b/backend/celery/tasks.py @@ -4,6 +4,7 @@ # Copyright (C) 2015 Jan Lebert from __future__ import absolute_import from __future__ import unicode_literals +from builtins import range from uuid import uuid4 from contextlib import closing @@ -16,7 +17,7 @@ def chunks(l, n): """Yield successive n-sized chunks from l.""" - for i in xrange(0, len(l), n): + for i in range(0, len(l), n): yield l[i:i+n] @@ -49,7 +50,8 @@ db = MySQLdb.connect( host='centralauth.labsdb', user=config.sql_user, - passwd=config.sql_passwd + passwd=config.sql_passwd, + charset='utf8' ) projects = [] @@ -57,7 +59,7 @@ cur.execute("SELECT lu_wiki FROM centralauth_p.localuser WHERE lu_name=%s;", [username]) # NOQA result = cur.fetchall() for row in result: - project = row[0] + project = row[0].decode("utf-8") try: wiki = wikis[project] if 'closed' not in wiki and project not in preload_projects: @@ -84,7 +86,8 @@ db = MySQLdb.connect( host='s4.labsdb', user=config.sql_user, - passwd=config.sql_passwd + passwd=config.sql_passwd, + charset='utf8' ) with closing(db.cursor()) as cur: for wiki in project_chunk: @@ -221,7 +224,7 @@ mw = MediaWiki(access_token=access_token, redis_channel=redis_channel) wikis = mw.wikis() - for project, notifications in notifications.iteritems(): + for project, notifications in notifications.items(): projecturl = wikis[project]['url'] mw = MediaWiki(host=projecturl, access_token=access_token, redis_channel=redis_channel) diff --git a/backend/server/__init__.py b/backend/server/__init__.py index 185ecd2..7264fe6 100644 --- a/backend/server/__init__.py +++ b/backend/server/__init__.py @@ -69,7 +69,7 @@ def run(port): - logging.basicConfig(level=logging.DEBUG, + logging.basicConfig(level=logging.INFO, format='%(asctime)s %(name)-12s %(levelname)-8s' + ' %(message)s', datefmt='%m-%d %H:%M') diff --git a/backend/server/flask_mwoauth/__init__.py b/backend/server/flask_mwoauth/__init__.py index a05e110..b9ae9d8 100644 --- a/backend/server/flask_mwoauth/__init__.py +++ b/backend/server/flask_mwoauth/__init__.py @@ -8,31 +8,13 @@ # Licensed under the MIT License // http://opensource.org/licenses/MIT # -__version__ = '0.1.35' - -import urllib +from future.moves.urllib.parse import urlencode from flask import request, session, Blueprint, make_response, redirect, render_template -from flask_oauth import OAuth, OAuthRemoteApp, OAuthException, parse_response +from flask_oauthlib.client import OAuth, OAuthException import json - -class MWOAuthRemoteApp(OAuthRemoteApp): - def handle_oauth1_response(self): - """Handles an oauth1 authorization response. The return value of - this method is forwarded as first argument to the handling view - function. - """ - client = self.make_client() - resp, content = client.request('%s&oauth_verifier=%s' % ( - self.expand_url(self.access_token_url), - request.args['oauth_verifier'], - ), self.access_token_method) - print resp, content - data = parse_response(resp, content) - if not self.status_okay(resp): - raise OAuthException('Invalid response from ' + self.name, - type='invalid_response', data=data) - return data +import logging +log = logging.getLogger('test') class MWOAuth(object): @@ -50,18 +32,22 @@ self.toolname = toolname self.consumer_version = consumer_version + request_url_params = {'title': 'Special:OAuth/initiate', + 'oauth_callback': 'oob'} + access_token_params = {'title': 'Special:OAuth/token'} self.oauth = OAuth() - self.mwoauth = MWOAuthRemoteApp(self.oauth, 'mw.org', - base_url = base_url + "/index.php", - request_token_url=base_url + "/index.php", - request_token_params = {'title': 'Special:OAuth/initiate', - 'oauth_callback': 'oob'}, - access_token_url=base_url + "/index.php?title=Special:OAuth/token", + self.mwoauth = self.oauth.remote_app( + 'mw.org', + base_url=base_url + "/index.php", + request_token_url=base_url + "/index.php?" + + urlencode(request_url_params), + request_token_params=None, + access_token_url=base_url + "/index.php?" + + urlencode(access_token_params), authorize_url=clean_url + '/Special:OAuth/authorize', consumer_key=consumer_key, consumer_secret=consumer_secret, ) - self.oauth.remote_apps['mw.org'] = self.mwoauth @self.mwoauth.tokengetter def get_mwo_token(token=None): @@ -71,19 +57,18 @@ @self.bp.route('/login') def login(): - redirector = self.mwoauth.authorize() + uri_params = {'oauth_consumer_key': self.mwoauth.consumer_key} + redirector = self.mwoauth.authorize(**uri_params) if 'next' in request.args: oauth_token = session[self.mwoauth.name + '_oauthtok'][0] session[oauth_token + '_target'] = request.args['next'] - redirector.headers['Location'] += "&oauth_consumer_key=" +\ - self.mwoauth.consumer_key return redirector @self.bp.route('/oauth-callback') - @self.mwoauth.authorized_handler - def oauth_authorized(resp): + def oauth_authorized(): + resp = self.mwoauth.authorized_response() if resp is None: return 'You denied the request to sign in.' session['mwo_token'] = ( @@ -134,7 +119,7 @@ url = url or self.base_url return self.mwoauth.post(url + "/api.php?" + - urllib.urlencode(api_query), + urlencode(api_query), content_type="text/plain").data def get_current_user(self, cached=True): diff --git a/scripts/celery.grid.sh b/scripts/celery.grid.sh index 43281b2..d90c2c6 100755 --- a/scripts/celery.grid.sh +++ b/scripts/celery.grid.sh @@ -1,4 +1,5 @@ #!/bin/bash -source $HOME/.virtualenvs/backend/bin/activate +venv=$HOME/.virtualenvs/backend/bin +source ${venv}/activate cd `dirname $0` -celery -A backend worker -l info -n crosswatch$1.%n --concurrency=500 -P gevent +${venv}/celery -A backend worker -l info -n crosswatch$1.%n --concurrency=500 -P gevent diff --git a/setup.py b/setup.py index 38fd545..c8804a3 100644 --- a/setup.py +++ b/setup.py @@ -22,13 +22,16 @@ 'requests-oauthlib', 'requests[security]', 'mwoauth', - 'MySQL-python', - 'flask-oauth', + 'mysqlclient', + 'flask-oauthlib', + 'flask', 'sockjs-tornado', 'tornado-redis', 'tornado', 'celery', - 'redis' + 'redis', + 'future', + 'six' # celery won't start without it in python3 ], dependency_links=[ "git+https://gerrit.wikimedia.org/r/p/labs/tools/crosswatch.git@kombu#egg=kombu-3.0.26" # NOQA -- To view, visit https://gerrit.wikimedia.org/r/227164 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1c49eb7b3c68be860cf6a4a0ee3713a3f244bae2 Gerrit-PatchSet: 1 Gerrit-Project: labs/tools/crosswatch Gerrit-Branch: master Gerrit-Owner: Sitic <jan.leb...@online.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits