Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2009-03-01 00:15:16 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2009-03-02 06:32:19 (GMT)
commitaf8c72e32f9590c4498a7f98e640239ce60cd4d9 (patch)
tree5e949f3b4c3b23aed4d72948d3cf35683265ef54
parente1da2477f69248320d33906c1bee515b73201170 (diff)
Add uid for book; add overwrite confirmation alert
-rw-r--r--book.py14
-rw-r--r--library.py31
-rw-r--r--xol.py78
3 files changed, 77 insertions, 46 deletions
diff --git a/book.py b/book.py
index 3e4d94c..01b9740 100644
--- a/book.py
+++ b/book.py
@@ -46,6 +46,7 @@ class Book(gobject.GObject):
if self._article and self._article.article_title == title:
return
+ logger.debug('set_article: %s' % title)
self.sync()
if title is None:
@@ -100,6 +101,8 @@ class Book(gobject.GObject):
shutil.rmtree(os.path.join(self.root, entry['uid']), True)
del self.map[index]
+ self.save_map()
+
self.emit('article-deleted', title)
def find(self, title):
@@ -115,25 +118,32 @@ class Book(gobject.GObject):
return None
def save_map(self):
+ data = { 'uid': self.uid,
+ 'map': self.map }
+
mapfile = file(os.path.join(self.root, 'map'), 'w')
- mapfile.write(cjson.encode(self.map))
+ mapfile.write(cjson.encode(data))
mapfile.close()
def __init__(self, preinstalled, dirname):
gobject.GObject.__init__(self)
self.root = os.path.join(get_activity_root(), dirname)
self.map = []
+ self.uid = None
self._article = None
if os.path.exists(self.root):
try:
mapfile = file(os.path.join(self.root, 'map'), 'r')
- self.map = cjson.decode(mapfile.read())
+ data = cjson.decode(mapfile.read())
+ self.uid = data['uid']
+ self.map = data['map']
if self.map:
self.props.article = self.map[0]['title']
except:
logger.debug('cannot find map file; use empty')
else:
+ self.uid = str(uuid.uuid1())
os.makedirs(self.root, 0777)
for i in preinstalled:
diff --git a/library.py b/library.py
index 8cfa503..4288993 100644
--- a/library.py
+++ b/library.py
@@ -23,7 +23,6 @@ from sugar.graphics.toggletoolbutton import ToggleToolButton
from sugar.activity.activity import ActivityToolbox
from sugar.graphics.toolcombobox import ToolComboBox
from sugar.graphics.icon import Icon
-from sugar.graphics.alert import ConfirmationAlert
from sugar.datastore import datastore
import sugar.graphics.style as style
@@ -138,6 +137,9 @@ class View(gtk.EventBox):
custom_widget, [custom, wiki])
def _article_selected_cb(self, abook, article, article_widget, notebooks):
+ if not article:
+ return
+
if not abook.map:
notebooks[0].set_current_page(0)
return
@@ -187,35 +189,14 @@ class Toolbar(gtk.Toolbar):
separator.show()
publish = ToolButton('filesave', tooltip=_('Publish selected articles'))
- publish.connect("clicked", self._publish_clicked_cb, False)
+ publish.connect("clicked", self._publish_clicked_cb)
self.insert(publish, -1)
publish.show()
self.connect('map', self._map_cb)
- def _publish_clicked_cb(self, widget, force):
- title = self.activity.metadata['title']
- jobject = datastore.find({'title': title,
- 'mime_type': 'application/vnd.olpc-content'})[0] or None
-
- if jobject and not force:
- alert = ConfirmationAlert(
- title=_('Overwrite?'),
- msg=_('A bundle by that name already exists.' \
- 'Click "OK" to overwrite it.'))
-
- def response(alert, response_id, self):
- self.activity.remove_alert(alert)
- if response_id is gtk.RESPONSE_OK:
- self._publish_clicked_cb(None, True)
-
- alert.connect('response', response, self)
- alert.show_all()
- self.activity.add_alert(alert)
- return
-
- book.custom.sync()
- xol.publish(title, jobject)
+ def _publish_clicked_cb(self, widget):
+ xol.publish(self.activity)
def _map_cb(self, widget):
self.searchentry.grab_focus()
diff --git a/xol.py b/xol.py
index c8231ff..e5dd4c9 100644
--- a/xol.py
+++ b/xol.py
@@ -1,17 +1,66 @@
# Copyright (C) IBM Corporation 2008
import os
+import gtk
import zipfile
import uuid
+import logging
from glob import glob
+from gettext import gettext as _
-from sugar.activity.activity import get_bundle_path, get_activity_root
+from sugar.activity.activity import get_bundle_path, get_activity_root, get_bundle_name
from sugar.datastore import datastore
from sugar import activity
+from sugar.graphics.alert import ConfirmationAlert
from Processing.NewtifulSoup import NewtifulStoneSoup as BeautifulStoneSoup
import book
+logger = logging.getLogger('infoslicer')
+
+def publish(activity, force=False):
+ title = activity.metadata['title']
+ jobject = datastore.find({
+ 'activity_id': activity.get_id(),
+ 'activity' : book.custom.uid})[0] or None
+
+ logger.debug('publish: title=%s jobject=%s force=%s' \
+ % (title, jobject and jobject[0].metadata['activity'], force))
+
+ if jobject:
+ if force:
+ jobject = jobject[0]
+ else:
+ alert = ConfirmationAlert(
+ title=_('Overwrite?'),
+ msg=_('A bundle by that name already exists.' \
+ 'Click "OK" to overwrite it.'))
+
+ def response(alert, response_id, activity):
+ activity.remove_alert(alert)
+ if response_id is gtk.RESPONSE_OK:
+ publish(activity, True)
+
+ alert.connect('response', response, activity)
+ alert.show_all()
+ activity.add_alert(alert)
+ jobject[0].destroy()
+ return
+ else:
+ jobject = datastore.create()
+ jobject.metadata['activity_id'] = activity.get_id()
+ jobject.metadata['activity'] = book.custom.uid
+ jobject.metadata['mime_type'] = 'application/vnd.olpc-content'
+ jobject.metadata['description'] = \
+ 'This is a bundle containing articles on %s.\n' \
+ 'To view these articles, open the \'Browse\' Activity.\n' \
+ 'Go to \'Books\', and select \'%s\'.' % (title, title)
+
+ book.custom.sync()
+ jobject.metadata['title'] = title
+ _publish(title, jobject)
+ jobject.destroy()
+
"""
@author: Matthew Bailey
@@ -19,35 +68,25 @@ This class deals with the creation of content packages, comprised of articles fr
themes, with are zipped up and installed in the relevant OS specific location. From
here they can be distributed to the consumers
"""
-def publish(title, jobject):
+def _publish(title, jobject):
zipfilename = os.path.join(get_activity_root(), 'tmp', 'publish.xol')
zip = zipfile.ZipFile(zipfilename, 'w')
- uid = str(uuid.uuid1())
+ uid = book.custom.uid
for i in glob(os.path.join(get_bundle_path(), 'Stylesheets', '*')):
zip.write(i, os.path.join(uid, 'slicecontent', os.path.basename(i)))
- info_file(zip, uid, title)
- index_redirect(zip, uid)
- dita_management(zip, uid, title)
+ _info_file(zip, uid, title)
+ _index_redirect(zip, uid)
+ _dita_management(zip, uid, title)
zip.close()
- if not jobject:
- jobject = datastore.create()
- jobject.metadata['title'] = title
- jobject.metadata['mime_type'] = 'application/vnd.olpc-content'
- jobject.metadata['description'] = \
- 'This is a bundle containing articles on %s.\n' \
- 'To view these articles, open the \'Browse\' Activity.\n' \
- 'Go to \'Books\', and select \'%s\'.' % (title, title)
-
jobject.set_file_path(zipfilename)
datastore.write(jobject)
- jobject.destroy()
-def dita_management(zip, uid, title):
+def _dita_management(zip, uid, title):
"""
Creates a DITA map, and copies the requested articles and their associated images into the zipped directories
"""
@@ -92,7 +131,7 @@ def dita_management(zip, uid, title):
zipstr(zip, os.path.join(uid, 'slicecontent', 'librarymap.ditamap'),
"\n".join(map))
-def index_redirect(zip, uid):
+def _index_redirect(zip, uid):
"""
Creates the redirecting index.html
"""
@@ -110,12 +149,13 @@ def index_redirect(zip, uid):
zipstr(zip, os.path.join(uid, 'index.html'), "\n".join(html))
-def info_file(zip, uid, title):
+def _info_file(zip, uid, title):
"""
Creates the library.info file
"""
libraryfile = ['[Library]',\
'name = %s' % uid,\
+ 'bundle_id = info.slice.%s' % uid,\
'global_name = info.slice.%s' % uid,\
'long_name = %s' % title,\
'library_version = 1',\