Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucian Branescu Mihaila <lucian.branescu@gmail.com>2009-07-22 17:12:06 (GMT)
committer Lucian Branescu Mihaila <lucian.branescu@gmail.com>2009-07-22 17:12:06 (GMT)
commit881bacdcc1f3ada9f15d0af8d2f47818a51085aa (patch)
tree4b25f8af4705151a35aa99e4eaf469e91e0b91bd
parent0cf67314a0aa32024511598135302bd314871524 (diff)
Fix userscript and userstyle path bugs
-rw-r--r--ssb.py41
-rw-r--r--usercode.py39
-rw-r--r--webactivity.py45
3 files changed, 68 insertions, 57 deletions
diff --git a/ssb.py b/ssb.py
index b46569b..3e4f7b7 100644
--- a/ssb.py
+++ b/ssb.py
@@ -14,8 +14,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-import shutil
import os
+import shutil
import tempfile
import zipfile
import ConfigParser
@@ -23,7 +23,7 @@ import logging
from fnmatch import fnmatch
from sugar.activity import activity
-from sugar.bundle.activitybundle import ActivityBundle
+from sugar.bundle import activitybundle
from sugar.datastore import datastore
from sugar import profile
@@ -36,8 +36,25 @@ IGNORE_FILES = ['.gitignore', 'MANIFEST', '*.pyc', '*~', '*.bak',
def get_is_ssb(activity):
'''determine if the activity is an SSB'''
return activity.get_bundle_id().startswith(DOMAIN_PREFIX)
+
+def copy_profile():
+ '''get the data from the bundle and into the profile'''
+ ssb_data_path = os.path.join(activity.get_bundle_path(), 'data/ssb_data')
+ data_path = os.path.join(activity.get_activity_root(), 'data')
+
+ if os.path.isdir(ssb_data_path):
+ # we can't use shutil.copytree for the entire dir
+ for i in os.listdir(ssb_data_path):
+ src = os.path.join(ssb_data_path, i)
+ dst = os.path.join(data_path, i)
+ if not os.path.exists(dst):
+ if os.path.isdir(src):
+ shutil.copytree(src, dst)
+ else: # is there a better way?
+ shutil.copy(src, dst)
def list_files(base_dir, ignore_dirs=None, ignore_files=None):
+ '''from bundlebuilder.py'''
result = []
base_dir = os.path.abspath(base_dir)
@@ -72,22 +89,6 @@ def remove_paths(paths, root=None):
except OSError:
logging.warning('failed to remove: ' + path)
-def copy_profile():
- '''get the data from the bundle and into the profile'''
- ssb_data_path = os.path.join(activity.get_bundle_path(), 'data/ssb_data')
- data_path = os.path.join(activity.get_activity_root(), 'data')
-
- if os.path.isdir(ssb_data_path):
- # we can't use shutil.copytree for the entire dir
- for i in os.listdir(ssb_data_path):
- src = os.path.join(ssb_data_path, i)
- dst = os.path.join(data_path, i)
- if not os.path.exists(dst):
- if os.path.isdir(src):
- shutil.copytree(src, dst)
- else: # is there a better way?
- shutil.copy(src, dst)
-
class SSBCreator(object):
def __init__(self, title, uri):
self.title = title
@@ -145,7 +146,7 @@ class SSBCreator(object):
# copy profile
ssb_data_path = os.path.join(self.ssb_path, 'data/ssb_data')
shutil.copytree(self.data_path, ssb_data_path)
-
+
# delete undesirable things from the profile
remove_paths(['Cache', 'cookies.sqlite'],
root=os.path.join(ssb_data_path, 'gecko'))
@@ -172,7 +173,7 @@ class SSBCreator(object):
def install(self):
'''install the generated .xo bundle'''
- bundle = ActivityBundle(self.xo_path)
+ bundle = activitybundle.ActivityBundle(self.xo_path)
bundle.install()
def show_in_journal(self):
diff --git a/usercode.py b/usercode.py
index cda8d90..7dbe945 100644
--- a/usercode.py
+++ b/usercode.py
@@ -16,6 +16,7 @@
import os
import logging
+from urlparse import urlparse
from gettext import gettext as _
import gobject
@@ -38,6 +39,12 @@ SCRIPTS_PATH = os.path.join(activity.get_activity_root(),
'data/userscripts')
STYLE_PATH = os.path.join(activity.get_activity_root(),
'data/style.user.css')
+
+# make sure the userscript dir exists
+if not os.path.isdir(SCRIPTS_PATH):
+ os.mkdir(SCRIPTS_PATH)
+# make sure userstyle sheet exists
+open(STYLE_PATH, 'w').close()
class Dialog(gtk.Window):
def __init__(self, width=None, height=None):
@@ -70,10 +77,12 @@ class SourceEditor(viewsource.SourceDisplay):
def write(self, path=None):
open(path or self.file_path, 'w').write(self.text)
+ logging.debug('@@@@@ %s %s %s' % (self.text, path, self.file_path))
class ScriptFileViewer(viewsource.FileViewer):
def __init__(self, path):
- initial_filename = os.listdir(path)[0]
+ ls = os.listdir(path)
+ initial_filename = ls[0] if len(ls) > 0 else None
viewsource.FileViewer.__init__(self, path, initial_filename)
def get_selected_file(self):
@@ -187,7 +196,6 @@ class ScriptEditor(Dialog):
def __file_selected_cb(self, view, file_path):
self._editor.file_path = self._fileview.get_selected_file()
-
def add_script(location):
cls = components.classes["@mozilla.org/network/io-service;1"]
io_service = cls.getService(interfaces.nsIIOService)
@@ -212,14 +220,30 @@ def add_script(location):
browser_persist.saveURI(location_uri, None, None, None, None, file_uri)
def script_exists(location):
- cls = components.classes["@mozilla.org/network/io-service;1"]
- io_service = cls.getService(interfaces.nsIIOService)
- location_uri = io_service.newURI(location, None, None)
-
- if os.path.isfile(os.path.join(SCRIPTS_PATH, location_uri.path)):
+ script_name = os.path.basename(urlparse(location).path)
+
+ if os.path.isfile(os.path.join(SCRIPTS_PATH, script_name)):
return True
else:
return False
+
+def save_document(browser):
+ cls = components.classes["@mozilla.org/network/io-service;1"]
+ io_service = cls.getService(interfaces.nsIIOService)
+
+ cls = components.classes[ \
+ '@mozilla.org/embedding/browser/nsWebBrowserPersist;1']
+ browser_persist = cls.getService(interfaces.nsIWebBrowserPersist)
+
+
+ file_path = os.path.join(activity.get_activity_root(),
+ 'data/saved/x.html')
+ file_uri = io_service.newURI('file://'+file_path, None, None)
+ data_path = os.path.join(activity.get_activity_root(), 'data/saved/x')
+ data_uri = io_service.newURI('file://'+data_path, None, None)
+
+ browser_persist.saveDocument(browser.dom_window.document,
+ file_uri, data_uri, None, 0, 0)
class Injector():
_com_interfaces_ = interfaces.nsIDOMEventListener
@@ -232,6 +256,7 @@ class Injector():
def handleEvent(self, event):
self.head.appendChild(self.script)
+ logging.debug('%^^%^^ actual inject')
def attach_to(self, window):
# set up the script element to be injected
diff --git a/webactivity.py b/webactivity.py
index 478c073..7f35f2a 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -134,6 +134,7 @@ hulahop.set_app_version(os.environ['SUGAR_BUNDLE_VERSION'])
hulahop.startup(_profile_path)
from xpcom import components
+from xpcom.components import interfaces
def _set_accept_languages():
''' Set intl.accept_languages based on the locale
@@ -413,23 +414,6 @@ class WebActivity(activity.Activity):
"data/index.html")
self._browser.load_uri(default_page)
- cls = components.classes["@mozilla.org/network/io-service;1"]
- io_service = cls.getService(interfaces.nsIIOService)
-
- cls = components.classes[ \
- '@mozilla.org/embedding/browser/nsWebBrowserPersist;1']
- browser_persist = cls.getService(interfaces.nsIWebBrowserPersist)
-
-
- file_path = os.path.join(activity.get_activity_root(),
- 'data/saved/x.html')
- file_uri = io_service.newURI('file://'+file_path)
- data_path = os.path.join(activity.get_activity_root(), 'data/saved/x')
- data_uri = io_service.newURI('file://'+data_path)
-
- browser_persist.saveDocument(None, file_uri, data_uri, None, None,
- None)
-
def _session_history_changed_cb(self, session_history, link):
_logger.debug('NewPage: %s.' %link)
self.current = link
@@ -554,7 +538,7 @@ class WebActivity(activity.Activity):
def _overwrite_bookmarklet_response_cb(self, alert, response_id):
self.remove_alert(alert)
- name, url = alert._bm
+ name, url = alert._bm # unpack the argument
if response_id is gtk.RESPONSE_OK:
self._bm_store.remove(name)
self._bm_store.add(name, url)
@@ -579,7 +563,8 @@ class WebActivity(activity.Activity):
if response_id is gtk.RESPONSE_OK:
usercode.add_script(alert._location)
- def _userscript_inject_cb(self, listener, script_path):
+ def _userscript_inject_cb(self, listener, script_path):
+ logging.debug('Injecting %s' % script_path)
usercode.Injector(script_path).attach_to(self._browser.dom_window)
def _add_link(self):
@@ -682,14 +667,14 @@ class WebActivity(activity.Activity):
downloadmanager.remove_all_downloads()
self.close(force=True)
- def handle_view_source(self):
- logging.debug('##### local view source')
- logging.debug('@@@@@ %s' % usercode.STYLE_PATH)
- view_source = viewsource.ViewSource(self.get_xid(),
- self.get_bundle_path(),
- usercode.STYLE_PATH,
- self.get_title())
- #view_source.show()
-
- #def get_document_path(self, async_cb, async_err_cb):
- # self._browser.get_source(async_cb, async_err_cb)
+ #def handle_view_source(self):
+ # logging.debug('##### local view source')
+ # logging.debug('@@@@@ %s' % usercode.STYLE_PATH)
+ # view_source = viewsource.ViewSource(self.get_xid(),
+ # self.get_bundle_path(),
+ # usercode.STYLE_PATH,
+ # self.get_title())
+ # view_source.show()
+
+ def get_document_path(self, async_cb, async_err_cb):
+ self._browser.get_source(async_cb, async_err_cb)