def _check_for_bundle(self, object_id): registry = bundleregistry.get_registry() metadata = model.get(object_id) if metadata.get('progress', '').isdigit(): if int(metadata['progress']) < 100: return bundle = misc.get_bundle(metadata) if bundle is None: return if registry.is_installed(bundle): logging.debug('_check_for_bundle bundle already installed') return if metadata['mime_type'] == JournalEntryBundle.MIME_TYPE: # JournalEntryBundle code takes over the datastore entry and # transforms it into the journal entry from the bundle -- we have # nothing more to do. try: registry.install(bundle, metadata['uid']) except (ZipExtractException, RegistrationException): logging.exception('Could not install bundle %s', bundle.get_path()) return try: registry.install(bundle) except (ZipExtractException, RegistrationException): logging.exception('Could not install bundle %s', bundle.get_path()) return metadata['bundle_id'] = bundle.get_bundle_id() model.write(metadata)
def _check_for_bundle(self, object_id): registry = bundleregistry.get_registry() metadata = model.get(object_id) if metadata.get('progress', '').isdigit(): if int(metadata['progress']) < 100: return bundle = misc.get_bundle(metadata) if bundle is None: return if registry.is_installed(bundle): logging.debug('_check_for_bundle bundle already installed') return if metadata['mime_type'] == JournalEntryBundle.MIME_TYPE: # JournalEntryBundle code takes over the datastore entry and # transforms it into the journal entry from the bundle -- we have # nothing more to do. try: registry.install(bundle, metadata['uid']) except (ZipExtractException, RegistrationException): logging.exception('Could not install bundle %s', bundle.get_path()) return try: registry.install(bundle) except (ZipExtractException, RegistrationException): logging.exception('Could not install bundle %s', bundle.get_path()) return metadata['bundle_id'] = bundle.get_bundle_id() model.write(metadata)
def __cell_title_edited_cb(self, cell, path, new_text): row = self._model[path] metadata = model.get(row[ListModel.COLUMN_UID]) metadata['title'] = new_text model.write(metadata, update_mtime=False) self.cell_title.props.editable = False self.emit('title-edit-finished')
def __cell_title_edited_cb(self, cell, path, new_text): row = self._model[path] metadata = model.get(row[ListModel.COLUMN_UID]) metadata['title'] = new_text model.write(metadata, update_mtime=False) self.cell_title.props.editable = False self.emit('title-edit-finished')
def _write_entry(self): if self._metadata.get('mountpoint', '/') == '/': model.write(self._metadata, update_mtime=False) else: old_file_path = os.path.join( self._metadata['mountpoint'], model.get_file_name(old_title, self._metadata['mime_type'])) model.write(self._metadata, file_path=old_file_path, update_mtime=False)
def __favorite_clicked_cb(self, cell, path): row = self._model[path] metadata = model.get(row[ListModel.COLUMN_UID]) if not model.is_editable(metadata): return if metadata.get('keep', 0) == '1': metadata['keep'] = '0' else: metadata['keep'] = '1' model.write(metadata, update_mtime=False)
def _write_entry(self): if self._metadata.get('mountpoint', '/') == '/': model.write(self._metadata, update_mtime=False) else: old_file_path = os.path.join( self._metadata['mountpoint'], model.get_file_name(self._metadata['title'], self._metadata['mime_type'])) model.write(self._metadata, file_path=old_file_path, update_mtime=False)
def _favorite_clicked_cb(self, cell, path): row = self._model[path] metadata = model.get(row[ListModel.COLUMN_UID]) if not model.is_editable(metadata): return if metadata.get('keep', 0) == '1': metadata['keep'] = '0' else: metadata['keep'] = '1' model.write(metadata, update_mtime=False)
def _do_finish(self): self._tarfile.close() # Add metadata to the file created metadata = model.get(self._checkpoint) metadata['description'] = _('Backup from user %s') % \ profile.get_nick_name() metadata['icon_color'] = profile.get_color().to_string() metadata['uncompressed_size'] = self._uncompressed_size metadata['mime_type'] = 'application/vnd.olpc-journal-backup' model.write(metadata, self._checkpoint) self.emit('finished')
def _do_finish(self): self._tarfile.close() # Add metadata to the file created metadata = model.get(self._checkpoint) metadata['description'] = _('Backup from user %s') % \ profile.get_nick_name() metadata['icon_color'] = profile.get_color().to_string() metadata['uncompressed_size'] = self._uncompressed_size metadata['mime_type'] = 'application/vnd.olpc-journal-backup' model.write(metadata, self._checkpoint) self.emit('finished')
def set_value(self, iterator, column, value): index = iterator.user_data self._result_set.seek(index) metadata = self._result_set.read() if column == ListModel.COLUMN_FAVORITE: metadata['keep'] = value if column == ListModel.COLUMN_TITLE: metadata['title'] = value self._updated_entries[metadata['uid']] = metadata if self._updated_callback is not None: model.updated.disconnect(self._updated_callback) model.write(metadata, update_mtime=False, ready_callback=self.__reconnect_updates_cb)
def handle_bundle_installation(metadata, force_downgrade=False): """ Check metadata for a journal entry. If the metadata corresponds to a bundle, make sure that it is installed, and return the corresponding Bundle object. Installation sometimes requires a downgrade. Downgrades will not happen unless force_downgrade is set to True. Returns a tuple of two items: 1. The corresponding Bundle object for the journal entry, or None if installation failed. 2. A flag that indicates whether bundle installation was aborted due to a downgrade being required, and force_downgrade was False """ if metadata.get('progress', '').isdigit(): if int(metadata['progress']) < 100: return None, False bundle = get_bundle(metadata) if bundle is None: return None, False registry = bundleregistry.get_registry() window = journalwindow.get_journal_window().get_window() window.set_cursor(Gdk.Cursor(Gdk.CursorType.WATCH)) Gdk.flush() try: installed = registry.install(bundle, force_downgrade) except AlreadyInstalledException: return bundle, True except (ZipExtractException, RegistrationException): logging.exception('Could not install bundle %s', bundle.get_path()) return None, False finally: window.set_cursor(None) Gdk.flush() # If we just installed a bundle, update the datastore accordingly. # We do not do this for JournalEntryBundles because the JEB code transforms # its own datastore entry and writes appropriate metadata. if installed and not isinstance(bundle, JournalEntryBundle): metadata['bundle_id'] = bundle.get_bundle_id() model.write(metadata) return bundle, False
def handle_bundle_installation(metadata, force_downgrade=False): """ Check metadata for a journal entry. If the metadata corresponds to a bundle, make sure that it is installed, and return the corresponding Bundle object. Installation sometimes requires a downgrade. Downgrades will not happen unless force_downgrade is set to True. Returns a tuple of two items: 1. The corresponding Bundle object for the journal entry, or None if installation failed. 2. A flag that indicates whether bundle installation was aborted due to a downgrade being required, and force_downgrade was False """ if metadata.get('progress', '').isdigit(): if int(metadata['progress']) < 100: return None, False bundle = get_bundle(metadata) if bundle is None: return None, False registry = bundleregistry.get_registry() window = journalwindow.get_journal_window().get_window() window.set_cursor(Gdk.Cursor(Gdk.CursorType.WATCH)) Gdk.flush() try: installed = registry.install(bundle, force_downgrade) except AlreadyInstalledException: return bundle, True except (ZipExtractException, RegistrationException): logging.exception('Could not install bundle %s', bundle.get_path()) return None, False finally: window.set_cursor(None) # If we just installed a bundle, update the datastore accordingly. # We do not do this for JournalEntryBundles because the JEB code transforms # its own datastore entry and writes appropriate metadata. if installed and not isinstance(bundle, JournalEntryBundle): metadata['bundle_id'] = bundle.get_bundle_id() model.write(metadata) return bundle, False
def _update_entry(self): # updating description bounds = self._description.get_buffer().get_bounds() old_description = self.project_metadata.get('description', None) new_description = self._description.get_buffer().get_text( bounds[0], bounds[1], include_hidden_chars=False) if old_description != new_description: self.project_metadata['description'] = new_description model.write(self.project_metadata) new_title = self._title.get_text() old_title = self.project_metadata.get('title', '') if old_title != new_title: self.project_metadata['title'] = new_title model.write(self.project_metadata)
def _update_entry(self): #updating description bounds = self._description.get_buffer().get_bounds() old_description = self.project_metadata.get('description', None) new_description = self._description.get_buffer().get_text( bounds[0], bounds[1], include_hidden_chars=False) if old_description != new_description: self.project_metadata['description'] = new_description model.write(self.project_metadata) new_title = self._title.get_text() old_title = self.project_metadata.get('title', '') if old_title != new_title: self.project_metadata['title'] = new_title model.write(self.project_metadata)
def _update_entry(self, needs_update=False): if not model.is_editable(self._metadata): return old_title = self._metadata.get('title', None) new_title = self._title.get_text() if old_title != new_title: label = glib.markup_escape_text(new_title) self._icon.palette.props.primary_text = label self._metadata['title'] = new_title self._metadata['title_set_by_user'] = '******' needs_update = True bounds = self._tags.get_buffer().get_bounds() old_tags = self._metadata.get('tags', None) new_tags = self._tags.get_buffer().get_text(bounds[0], bounds[1], include_hidden_chars=False) if old_tags != new_tags: self._metadata['tags'] = new_tags needs_update = True bounds = self._description.get_buffer().get_bounds() old_description = self._metadata.get('description', None) new_description = self._description.get_buffer().get_text( bounds[0], bounds[1], include_hidden_chars=False) if old_description != new_description: self._metadata['description'] = new_description needs_update = True if needs_update: if self._metadata.get('mountpoint', '/') == '/': model.write(self._metadata, update_mtime=False) else: old_file_path = os.path.join( self._metadata['mountpoint'], model.get_file_name(old_title, self._metadata['mime_type'])) model.write(self._metadata, file_path=old_file_path, update_mtime=False) self._update_title_sid = None
def install(self): if "SUGAR_ACTIVITY_ROOT" in os.environ: install_dir = os.path.join(os.environ["SUGAR_ACTIVITY_ROOT"], "data") else: install_dir = tempfile.gettempdir() bundle_dir = os.path.join(install_dir, self._zip_root_dir) temp_uid = self._zip_root_dir self._unzip(install_dir) try: metadata = self._read_metadata(bundle_dir) metadata["uid"] = self._uid if self._uid else temp_uid preview = self._read_preview(temp_uid, bundle_dir) if preview is not None: metadata["preview"] = dbus.ByteArray(preview) file_path = os.path.join(bundle_dir, temp_uid) model.write(metadata, file_path) finally: shutil.rmtree(bundle_dir, ignore_errors=True)
def _update_entry(self, needs_update=False): if not model.is_editable(self._metadata): return old_title = self._metadata.get('title', None) new_title = self._title.get_text() if old_title != new_title: label = glib.markup_escape_text(new_title) self._icon.palette.props.primary_text = label self._metadata['title'] = new_title self._metadata['title_set_by_user'] = '******' needs_update = True bounds = self._tags.get_buffer().get_bounds() old_tags = self._metadata.get('tags', None) new_tags = self._tags.get_buffer().get_text(bounds[0], bounds[1], include_hidden_chars=False) if old_tags != new_tags: self._metadata['tags'] = new_tags needs_update = True bounds = self._description.get_buffer().get_bounds() old_description = self._metadata.get('description', None) new_description = self._description.get_buffer().get_text( bounds[0], bounds[1], include_hidden_chars=False) if old_description != new_description: self._metadata['description'] = new_description needs_update = True if needs_update: if self._metadata.get('mountpoint', '/') == '/': model.write(self._metadata, update_mtime=False) else: old_file_path = os.path.join(self._metadata['mountpoint'], model.get_file_name(old_title, self._metadata['mime_type'])) model.write(self._metadata, file_path=old_file_path, update_mtime=False) self._update_title_sid = None
def install(self, uid=''): if 'SUGAR_ACTIVITY_ROOT' in os.environ: install_dir = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'], 'data') else: install_dir = tempfile.gettempdir() bundle_dir = os.path.join(install_dir, self._zip_root_dir) temp_uid = self._zip_root_dir self._unzip(install_dir) try: metadata = self._read_metadata(bundle_dir) metadata['uid'] = uid preview = self._read_preview(temp_uid, bundle_dir) if preview is not None: metadata['preview'] = dbus.ByteArray(preview) file_path = os.path.join(bundle_dir, temp_uid) model.write(metadata, file_path) finally: shutil.rmtree(bundle_dir, ignore_errors=True)
def install(self): if 'SUGAR_ACTIVITY_ROOT' in os.environ: install_dir = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'], 'data') else: install_dir = tempfile.gettempdir() bundle_dir = os.path.join(install_dir, self._zip_root_dir) temp_uid = self._zip_root_dir self._unzip(install_dir) try: metadata = self._read_metadata(bundle_dir) metadata['uid'] = self._uid if self._uid else temp_uid preview = self._read_preview(temp_uid, bundle_dir) if preview is not None: metadata['preview'] = dbus.ByteArray(preview) file_path = os.path.join(bundle_dir, temp_uid) model.write(metadata, file_path) finally: shutil.rmtree(bundle_dir, ignore_errors=True)