Ticket #2859: 0001-added-support-for-copying-bundle-fixed-bundle_name-p.patch
File 0001-added-support-for-copying-bundle-fixed-bundle_name-p.patch, 6.5 KB (added by walter, 12 years ago) |
---|
-
src/jarabe/view/viewsource.py
From 5edd70ac27c3091076c8dd396e9d59623acd58bd Mon Sep 17 00:00:00 2001 From: Walter Bender <walter.bender@gmail.com> Date: Wed, 25 May 2011 17:59:36 -0400 Subject: [PATCH] added support for copying bundle; fixed bundle_name parsing error Organization: Sugar Labs Foundation --- src/jarabe/view/viewsource.py | 69 +++++++++++++++++++++++++++++++++-------- 1 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/jarabe/view/viewsource.py b/src/jarabe/view/viewsource.py index a1c0be3..120b3c7 100644
a b 1 1 # Copyright (C) 2008 One Laptop Per Child 2 2 # Copyright (C) 2009 Tomeu Vizoso, Simon Schampijer 3 # Copyright (C) 2011 Walter Bender 3 4 # 4 5 # This program is free software; you can redistribute it and/or modify 5 6 # it under the terms of the GNU General Public License as published by … … 16 17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 18 18 19 import os 20 import subprocess 19 21 import logging 20 22 from gettext import gettext as _ 21 23 … … map_activity_to_window = {} 44 46 45 47 46 48 def setup_view_source(activity): 49 47 50 service = activity.get_service() 51 48 52 if service is not None: 49 53 try: 50 54 service.HandleViewSource() 51 return55 # return 52 56 except dbus.DBusException, e: 53 57 expected_exceptions = ['org.freedesktop.DBus.Error.UnknownMethod', 54 58 'org.freedesktop.DBus.Python.NotImplementedError'] … … def setup_view_source(activity): 82 86 logging.exception('Exception occured in GetDocumentPath():') 83 87 84 88 if bundle_path is None and document_path is None: 85 _logger.debug('Activity with outbundle_path nor document_path')89 _logger.debug('Activity with neither bundle_path nor document_path') 86 90 return 87 91 88 92 view_source = ViewSource(window_xid, bundle_path, document_path, … … class ViewSource(gtk.Window): 97 101 def __init__(self, window_xid, bundle_path, document_path, title): 98 102 gtk.Window.__init__(self) 99 103 100 logging.debug('ViewSource paths: %r %r', bundle_path, document_path)101 102 104 self.set_decorated(False) 103 105 self.set_position(gtk.WIN_POS_CENTER_ALWAYS) 104 106 self.set_border_width(style.LINE_WIDTH) … … class ViewSource(gtk.Window): 132 134 133 135 activity_bundle = ActivityBundle(bundle_path) 134 136 command = activity_bundle.get_command() 137 file_path = '' 135 138 if len(command.split(' ')) > 1: 136 name = command.split(' ')[1].split('.')[0] 137 file_name = name + '.py' 139 name = command.split(' ')[1].split('.')[-1] 140 tmppath = command.split(' ')[1].replace('.', '/') 141 file_name = tmppath[0:-(len(name) + 1)] + '.py' 138 142 path = os.path.join(activity_bundle.get_path(), file_name) 139 143 self._selected_file = path 140 144 … … class ViewSource(gtk.Window): 201 205 class DocumentButton(RadioToolButton): 202 206 __gtype_name__ = 'SugarDocumentButton' 203 207 204 def __init__(self, file_name, document_path, title ):208 def __init__(self, file_name, document_path, title, bundle=False): 205 209 RadioToolButton.__init__(self) 206 210 207 211 self._document_path = document_path … … class DocumentButton(RadioToolButton): 218 222 self.set_icon_widget(icon) 219 223 icon.show() 220 224 221 menu_item = MenuItem(_('Keep')) 222 icon = Icon(icon_name='document-save', icon_size=gtk.ICON_SIZE_MENU, 223 xo_color=XoColor(self._color)) 224 menu_item.set_image(icon) 225 if bundle: 226 menu_item = MenuItem(_('Copy')) 227 icon = Icon(icon_name='edit-copy', icon_size=gtk.ICON_SIZE_MENU, 228 xo_color=XoColor(self._color)) 229 menu_item.connect('activate', self.__copy_to_home) 230 else: 231 menu_item = MenuItem(_('Keep')) 232 icon = Icon(icon_name='document-save', icon_size=gtk.ICON_SIZE_MENU, 233 xo_color=XoColor(self._color)) 234 menu_item.connect('activate', self.__keep_in_journal_cb) 225 235 226 menu_item. connect('activate', self.__keep_in_journal_cb)236 menu_item.set_image(icon) 227 237 self.props.palette.menu.append(menu_item) 228 238 menu_item.show() 229 239 240 def __copy_to_home(self, menu_item): 241 ''' Make a local copy of the activity bundle in 242 $HOME/Activities as MyActivity and change the bundle_id to 243 bundle_id_my_copy''' 244 # TODO: Check to see if MyActivity already exisits 245 home_activities = os.path.join(os.environ['HOME'], 'Activities') 246 new_bundle_name = 'My' + self._document_path.split('/')[-1] 247 command_line = ['cp', '-r', self._document_path, 248 os.path.join(home_activities, new_bundle_name)] 249 _logger.debug(subprocess.call(command_line)) 250 251 # Modify bundle_id in new activity.info file 252 fold = open(os.path.join(home_activities, new_bundle_name, 'activity', 253 'activity.info'), 'r') 254 fnew = open(os.path.join(home_activities, new_bundle_name, 'activity', 255 'new_activity.info'), 'w') 256 for line in fold: 257 tokens = line.split('=') 258 if tokens[0].rstrip() == 'bundle_id': 259 new_bundle_id = tokens[1].strip() + '_my_copy' 260 fnew.write('%s = %s\n' % (tokens[0].rstrip(), new_bundle_id)) 261 else: 262 fnew.write(line) 263 fold.close 264 fnew.close 265 command_line = ['mv', os.path.join(home_activities, new_bundle_name, 266 'activity', 'new_activity.info'), 267 os.path.join(home_activities, new_bundle_name, 268 'activity', 'activity.info')] 269 _logger.debug(subprocess.call(command_line)) 270 230 271 def __keep_in_journal_cb(self, menu_item): 231 272 mime_type = mime.get_from_file_name(self._document_path) 232 273 if mime_type == 'application/octet-stream': … … class Toolbar(gtk.Toolbar): 283 324 self._add_separator() 284 325 285 326 if bundle_path is not None and os.path.exists(bundle_path): 286 activity_button = RadioToolButton() 327 # activity_button = RadioToolButton() 328 activity_button = DocumentButton(file_name, bundle_path, title, 329 bundle=True) 287 330 icon = Icon(file=file_name, 288 331 icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR, 289 332 fill_color=style.COLOR_TRANSPARENT.get_svg(),