Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2012-03-19 23:01:43 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2012-03-19 23:01:43 (GMT)
commit87d18dd17f22c3e24c1595dd2fde34ca408d54dc (patch)
tree8694dc3c908230f11581f7c38962304a8431e3ed
parent33795d11e7fe845d88078bf597553dacb23913d5 (diff)
Initial implementation for handling bundles
-rwxr-xr-xmisc/aslo_sync.py73
-rw-r--r--sugar_network_server/resources/implementation.py64
2 files changed, 109 insertions, 28 deletions
diff --git a/misc/aslo_sync.py b/misc/aslo_sync.py
index 0cb29d1..6960425 100755
--- a/misc/aslo_sync.py
+++ b/misc/aslo_sync.py
@@ -34,11 +34,43 @@ MISNAMED_LICENSES = {
('creative', 'share', 'alike'): 'CC-BY-SA',
}
-
-con = mdb.connect('localhost', 'root', getpass.getpass(), 'activities')
+connection = None
+sugar_guid = None
def main():
+ global connection, sugar_guid
+
+ connection = mdb.connect('localhost',
+ 'root', getpass.getpass(), 'activities')
+
+ query = client.Context.find(title='Sugar')
+ if query.total:
+ sugar_guid = query[0]['guid']
+ else:
+ context = client.Context()
+ context['type'] = 'application'
+ context['title'] = 'Sugar'
+ context['summary'] = 'Sugar'
+ context['description'] = 'Sugar'
+ context.post()
+ sugar_guid = context['guid']
+
+ for version in ['0.82', '0.84', '0.86', '0.88', '0.90', '0.92',
+ '0.94', '0.96']:
+ impl = client.Implementation()
+ impl['context'] = sugar_guid
+ impl['license'] = ['GPLv3+']
+ impl['version'] = version
+ impl['date'] = 0
+ impl['stability'] = 'stable'
+ impl['notes'] = ''
+ impl.post()
+
+ import_versions()
+
+
+def import_versions():
rows = sqlexec("""
SELECT
addons.id,
@@ -102,36 +134,33 @@ def main():
print '-- Skip bad license %r' % alicense
continue
- query = client.Context.find(implement=[bundle_id])
- if query.total:
- assert query.total == 1
- context_guid = query[0]['guid']
+ for i in client.Context.find(implement=[bundle_id]):
+ if i['implement'] == [bundle_id]:
+ context_guid = i['guid']
+ break
else:
context_guid = context_new(addon_id, bundle_id)
- impl = client.Implementation.new()
+ impl = client.Implementation()
impl['context'] = context_guid
impl['license'] = [alicense]
impl['version'] = version
impl['date'] = int(time.mktime(release_date.timetuple()))
impl['stability'] = 'stable'
impl['notes'] = releasenotes or ''
- impl['url'] = 'http://download.sugarlabs.org/activities/%s/%s' % \
- (addon_id, filename)
impl['feed'] = {
'requires': {
- 'context': 'sugar-context-guid',
- 'constraints': [{
- 'not-before': sugar_min,
- 'before': '0.%s' % (int(sugar_max.split('.')[-1]) + 1),
- }],
+ sugar_guid: {'constraints': sugar_max},
},
}
impl.post()
+ impl.set_blob_with_url('bundle',
+ 'http://download.sugarlabs.org/activities/%s/%s' % \
+ (addon_id, filename))
def context_new(addon_id, bundle_id):
- context = client.Context.new()
+ context = client.Context()
context['type'] = 'activity'
context['implement'] = [bundle_id]
@@ -188,20 +217,18 @@ def context_new(addon_id, bundle_id):
(select max(localized_string) from translations where
id=caption),
thumbdata,
- filedata,
- filetype
+ filedata
FROM previews
WHERE
addon_id=%s
""" % addon_id):
- caption, thumb, data, mime_type = row
+ caption, thumb, data = row
- artifact = client.Artifact.new()
+ artifact = client.Artifact()
artifact['context'] = context['guid']
artifact['type'] = 'screenshot'
artifact['title'] = caption or ''
artifact['description'] = caption or ''
- artifact['mime_type'] = mime_type
artifact.post()
if thumb:
@@ -213,15 +240,19 @@ def context_new(addon_id, bundle_id):
def sqlexec(text):
- cur = con.cursor()
+ cur = connection.cursor()
cur.execute(text)
return cur.fetchall()
if __name__ == '__main__':
+ server.debug.value = 3
server.data_root.value = 'tmp/db'
server.stats_root.value = 'tmp/stats'
server.logdir.value = 'tmp/log'
+ server.index_write_queue.value = 1024 * 10
+ server.index_flush_threshold.value = 0
+ server.index_flush_timeout.value = 0
server_pid = restful_document.fork(server.resources())
diff --git a/sugar_network_server/resources/implementation.py b/sugar_network_server/resources/implementation.py
index c75989a..961a8fa 100644
--- a/sugar_network_server/resources/implementation.py
+++ b/sugar_network_server/resources/implementation.py
@@ -13,13 +13,28 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# pylint: disable-msg=E1101,E0102
+
+import os
+import zipfile
+from cStringIO import StringIO
+from ConfigParser import ConfigParser
+from os.path import exists, join
+from gettext import gettext as _
+
import active_document as ad
+import restful_document as rd
+enforce = ad.util.enforce
from sugar_network_server import env
from sugar_network_server.licenses import GOOD_LICENSES
from sugar_network_server.resources.resource import Resource
+_ASLO_DOWNLOAD_URL = 'http://download.sugarlabs.org/activities'
+_ASLO_ACTIVITIES_PATH = '/upload/activities'
+
+
class Implementation(Resource):
@ad.active_property(prefix='C',
@@ -48,21 +63,56 @@ class Implementation(Resource):
def stability(self, value):
return value
- @ad.active_property(ad.StoredProperty,
- permissions=ad.ACCESS_CREATE | ad.ACCESS_READ, default='')
+ @ad.active_property(ad.StoredProperty, typecast=dict, default={})
def feed(self, value):
return value
- @ad.active_property(full_text=True,
- permissions=ad.ACCESS_CREATE | ad.ACCESS_READ)
- def notes(self, value):
+ @feed.setter
+ def feed(self, value):
+ value.setdefault('implementations', {})
+ value['implementations'].setdefault('*-*', {})
return value
- @ad.active_property(prefix='U',
+ @ad.active_property(full_text=True,
permissions=ad.ACCESS_CREATE | ad.ACCESS_READ)
- def url(self, value):
+ def notes(self, value):
return value
@ad.active_property(ad.BlobProperty)
def bundle(self, value):
return value
+
+ def recv_blob(self, prop, url):
+ if not url.startswith(_ASLO_DOWNLOAD_URL):
+ return Resource.recv_blob(self, prop, url)
+
+ path = url[len(_ASLO_DOWNLOAD_URL):].strip('/').split('/')
+ enforce(len(path) == 2 and path[-1].endswith('.xo'),
+ _('Incorrect activities.sugarlabs.org path'))
+
+ path = join(_ASLO_ACTIVITIES_PATH, *path)
+ if exists(path):
+ try:
+ zp = zipfile.ZipFile(path)
+ extract = zp.namelist()[0].split(os.sep)[0]
+
+ activity_info_data = StringIO(
+ zp.read(join(extract, 'activity', 'activity.info')))
+ activity_info = ConfigParser()
+ activity_info.readfp(activity_info_data)
+
+ self.feed['commands'] = {
+ 'activity': activity_info.get('Activity', 'exec'),
+ }
+ except Exception, error:
+ ad.util.exception()
+ raise RuntimeError(_('Cannot read bundle: %s') % error)
+
+ self.feed['implementations']['*-*']['url'] = url
+ self.post()
+
+ def send_blob(self, prop):
+ url = self.feed['implementations']['*-*'].get('url')
+ if url:
+ raise rd.SeeOther(url)
+ return Resource.send_blob(self, prop)