Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2013-05-26 16:26:15 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2013-05-26 16:26:15 (GMT)
commit98ebf9d7851e96b6d1c4ea0b8cb18b9d50b22081 (patch)
tree7bf096ef9742e91512bf481bd04da808d087a625
parent3d4c5f19ef5cd178e00b62be659af20c6c9fafe8 (diff)
Index authors by ASLO nickname
-rwxr-xr-xmisc/aslo-patch-authors130
-rwxr-xr-xmisc/aslo-sync19
-rw-r--r--sugar_network/resources/volume.py2
3 files changed, 142 insertions, 9 deletions
diff --git a/misc/aslo-patch-authors b/misc/aslo-patch-authors
new file mode 100755
index 0000000..1c80b04
--- /dev/null
+++ b/misc/aslo-patch-authors
@@ -0,0 +1,130 @@
+#!/usr/bin/env python
+# -*- coding: utf8 -*-
+
+# Copyright (C) l013 Aleksey Lim
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from optparse import OptionParser
+
+import MySQLdb as mdb
+
+from sugar_network import db
+from sugar_network.node import data_root
+from sugar_network.resources.volume import Volume
+from sugar_network.toolkit import Option
+
+
+ASLO_GUID = 'd26cef70447160f31a7497cc0320f23a4e383cc3'
+
+UNKNOWN_USERS = {
+ 41: u'Mario César Señoranis Ayala',
+ 4195: u'Andrés Aguirre',
+ 35: u' Ridderman',
+ 6842: u'Juan Ignacio Rodríguez Rodríguez',
+ 9462: u'Cristian García Rea',
+ 9823: u'Nicolás Furquez',
+ 5808: u'Enzo Ludueña',
+ 199: u'Tony Anderson',
+ 60: u'Jameson Quinn',
+ 52: u'Oneyda Ortega',
+ 76: u'milan zimmermann',
+ }
+
+
+mysql_server = Option(
+ 'MySQL server',
+ default='localhost', name='mysql_server')
+mysql_database = Option(
+ 'MySQL database',
+ default='activities', name='mysql_database')
+mysql_user = Option(
+ 'MySQL user',
+ default='root', name='mysql_user')
+mysql_password = Option(
+ 'MySQL password',
+ name='mysql_password')
+
+Option.seek('aslo', [mysql_server, mysql_user, mysql_password, mysql_database])
+Option.seek('node', [data_root])
+Option.parse_args(OptionParser(), config_files=['~/.config/sweets/config'])
+
+db.index_write_queue.value = 1024 * 10
+db.index_flush_threshold.value = 0
+db.index_flush_timeout.value = 0
+
+my_connection = mdb.connect('localhost', 'activities', 'Sugar8ME', 'activities')
+my_connection = mdb.connect(mysql_server.value, mysql_user.value,
+ mysql_password.value, mysql_database.value)
+
+
+def sqlexec(text):
+ cursor = my_connection.cursor()
+ cursor.execute(text)
+ return cursor.fetchall()
+
+
+def new_authors(doc):
+ result = {}
+ for user, props in doc['author'].items():
+ if user == ASLO_GUID:
+ result[ASLO_GUID] = {
+ 'role': 1,
+ 'order': 1,
+ 'name': 'Activity Library',
+ }
+ continue
+ if user in users_by_nickname:
+ nickname = user
+ fullname = users_by_nickname[nickname]
+ else:
+ fullname = props.get('name') or user
+ if fullname in users_by_fullname:
+ nickname = users_by_fullname[fullname] or fullname
+ else:
+ print '-- No %r/%r user' % (user, fullname)
+ nickname = user
+ result[nickname] = {'role': 2, 'order': 2, 'name': fullname}
+ return result
+
+
+users_by_fullname = {}
+users_by_nickname = {}
+for uid, nickname, fullname in sqlexec("""
+ SELECT
+ id,
+ nickname,
+ IF(firstname!="",
+ CONCAT_WS(' ', firstname, lastname),
+ nickname)
+ FROM users
+ """):
+ if uid in UNKNOWN_USERS:
+ users_by_fullname[UNKNOWN_USERS[uid]] = nickname
+ users_by_fullname[fullname] = nickname
+ users_by_nickname[nickname] = fullname
+
+
+volume = Volume(data_root.value)
+volume.populate()
+
+try:
+ for document in ('context', 'review'):
+ documents, __ = volume[document].find(limit=db.MAX_LIMIT)
+ for doc in documents:
+ authors = new_authors(doc)
+ if authors:
+ volume[document].update(doc.guid, author=authors)
+finally:
+ volume.close()
diff --git a/misc/aslo-sync b/misc/aslo-sync
index 2faff7c..766d6ca 100755
--- a/misc/aslo-sync
+++ b/misc/aslo-sync
@@ -289,6 +289,7 @@ class Application(application.Application):
reviews.title,
reviews.body,
reviews.rating,
+ users.nickname,
IF(users.firstname!="",
CONCAT_WS(' ', users.firstname, users.lastname),
users.nickname)
@@ -300,7 +301,8 @@ class Application(application.Application):
reply_to IS NULL AND versions.addon_id = %s
""" % addon_id
directory = self.volume['review']
- for guid, created, title, content, rating, author in self.sqlexec(sql):
+ for guid, created, title, content, rating, nickname, author in \
+ self.sqlexec(sql):
if directory.exists(str(guid)):
continue
directory.create(
@@ -311,7 +313,7 @@ class Application(application.Application):
title=self.get_i18n_field(title),
content=self.get_i18n_field(content),
rating=rating,
- author=self.authors(author),
+ author=self.authors(nickname, author),
)
def sync_versions(self, addon_id, bundle_id):
@@ -459,8 +461,8 @@ class Application(application.Application):
implement=bundle_id, title={}, summary={}, description={},
author=self.authors(), layer=['public'], ctime=0, mtime=0)
- created, modified, title, summary, description, homepage, name = \
- self.sqlexec("""
+ created, modified, title, summary, description, homepage, nickname, \
+ author = self.sqlexec("""
SELECT
addons.created,
addons.modified,
@@ -469,6 +471,7 @@ class Application(application.Application):
addons.description,
(select max(localized_string) from translations where
id=addons.homepage),
+ users.nickname,
IF(users.firstname != '',
CONCAT_WS(' ', users.firstname, users.lastname),
users.nickname)
@@ -515,7 +518,7 @@ class Application(application.Application):
description=self.get_i18n_field(description),
homepage=homepage or '',
tags=list(tags),
- author=self.authors(name),
+ author=self.authors(nickname, author),
ctime=created,
mtime=modified)
@@ -610,14 +613,14 @@ class Application(application.Application):
cursor.execute(text)
return cursor.fetchall()
- def authors(self, original=None):
+ def authors(self, nickname=None, original=None):
result = {
ASLO_GUID: {
'role': 1, 'order': 0, 'name': 'Activity Library',
},
}
- if original:
- result[original] = {
+ if nickname:
+ result[nickname] = {
'role': 2, 'order': 1, 'name': original,
}
return result
diff --git a/sugar_network/resources/volume.py b/sugar_network/resources/volume.py
index 0600d33..3840d0e 100644
--- a/sugar_network/resources/volume.py
+++ b/sugar_network/resources/volume.py
@@ -33,7 +33,7 @@ def _reprcast_authors(value):
for guid, props in value.items():
if 'name' in props:
yield props['name']
- else:
+ if not (props['role'] | AUTHOR_INSYSTEM):
yield guid
else:
yield value