def _convert_entry(root, document): try: metadata_loaded = pickle.loads(document.get_data()) except pickle.PickleError as e: logging.debug( 'Convert DS-0 Journal entries: ' 'error converting metadata: %s', e) return if not ('activity_id' in metadata_loaded and 'mime_type' in metadata_loaded and 'title' in metadata_loaded): return metadata = {} uid = _get_id(document) if uid is None: return for key, value in list(metadata_loaded.items()): metadata[str(key)] = str(value[0]) if 'uid' not in metadata: metadata['uid'] = uid filename = metadata.pop('filename', None) if not filename: return if not os.path.exists(os.path.join(root, filename)): return if not metadata.get('title'): metadata['title'] = _('Untitled') fn = model.get_file_name(metadata['title'], metadata['mime_type']) new_filename = model.get_unique_file_name(root, fn) os.rename(os.path.join(root, filename), os.path.join(root, new_filename)) filename = new_filename preview_path = os.path.join(root, _JOURNAL_0_METADATA_DIR, 'preview', uid) if os.path.exists(preview_path): preview_fname = filename + '.preview' new_preview_path = os.path.join(root, model.JOURNAL_METADATA_DIR, preview_fname) if not os.path.exists(new_preview_path): shutil.copy(preview_path, new_preview_path) metadata_fname = filename + '.metadata' metadata_path = os.path.join(root, model.JOURNAL_METADATA_DIR, metadata_fname) if not os.path.exists(metadata_path): (fh, fn) = tempfile.mkstemp(dir=root) os.write(fh, json.dumps(metadata)) os.close(fh) os.rename(fn, metadata_path) logging.debug( 'Convert DS-0 Journal entries: entry converted: ' 'file=%s metadata=%s', os.path.join(root, filename), metadata)
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 _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 _convert_entry(root, document): try: metadata_loaded = cPickle.loads(document.get_data()) except cPickle.PickleError as e: logging.debug("Convert DS-0 Journal entries: " "error converting metadata: %s", e) return if not ("activity_id" in metadata_loaded and "mime_type" in metadata_loaded and "title" in metadata_loaded): return metadata = {} uid = _get_id(document) if uid is None: return for key, value in metadata_loaded.items(): metadata[str(key)] = str(value[0]) if "uid" not in metadata: metadata["uid"] = uid filename = metadata.pop("filename", None) if not filename: return if not os.path.exists(os.path.join(root, filename)): return if not metadata.get("title"): metadata["title"] = _("Untitled") fn = model.get_file_name(metadata["title"], metadata["mime_type"]) new_filename = model.get_unique_file_name(root, fn) os.rename(os.path.join(root, filename), os.path.join(root, new_filename)) filename = new_filename preview_path = os.path.join(root, _JOURNAL_0_METADATA_DIR, "preview", uid) if os.path.exists(preview_path): preview_fname = filename + ".preview" new_preview_path = os.path.join(root, model.JOURNAL_METADATA_DIR, preview_fname) if not os.path.exists(new_preview_path): shutil.copy(preview_path, new_preview_path) metadata_fname = filename + ".metadata" metadata_path = os.path.join(root, model.JOURNAL_METADATA_DIR, metadata_fname) if not os.path.exists(metadata_path): (fh, fn) = tempfile.mkstemp(dir=root) os.write(fh, json.dumps(metadata)) os.close(fh) os.rename(fn, metadata_path) logging.debug( "Convert DS-0 Journal entries: entry converted: " "file=%s metadata=%s", os.path.join(root, filename), 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 _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 _convert_entry(root, document): try: metadata_loaded = cPickle.loads(document.get_data()) except cPickle.PickleError as e: logging.debug('Convert DS-0 Journal entries: ' 'error converting metadata: %s', e) return if not ('activity_id' in metadata_loaded and 'mime_type' in metadata_loaded and 'title' in metadata_loaded): return metadata = {} uid = _get_id(document) if uid is None: return for key, value in metadata_loaded.items(): metadata[str(key)] = str(value[0]) if 'uid' not in metadata: metadata['uid'] = uid filename = metadata.pop('filename', None) if not filename: return if not os.path.exists(os.path.join(root, filename)): return if not metadata.get('title'): metadata['title'] = _('Untitled') fn = model.get_file_name(metadata['title'], metadata['mime_type']) new_filename = model.get_unique_file_name(root, fn) os.rename(os.path.join(root, filename), os.path.join(root, new_filename)) filename = new_filename preview_path = os.path.join(root, _JOURNAL_0_METADATA_DIR, 'preview', uid) if os.path.exists(preview_path): preview_fname = filename + '.preview' new_preview_path = os.path.join(root, model.JOURNAL_METADATA_DIR, preview_fname) if not os.path.exists(new_preview_path): shutil.copy(preview_path, new_preview_path) metadata_fname = filename + '.metadata' metadata_path = os.path.join(root, model.JOURNAL_METADATA_DIR, metadata_fname) if not os.path.exists(metadata_path): (fh, fn) = tempfile.mkstemp(dir=root) os.write(fh, json.dumps(metadata)) os.close(fh) os.rename(fn, metadata_path) logging.debug('Convert DS-0 Journal entries: entry converted: ' 'file=%s metadata=%s', os.path.join(root, filename), metadata)
for key, value in metadata_loaded.items(): metadata[str(key)] = str(value[0]) if 'uid' not in metadata: metadata['uid'] = uid filename = metadata.pop('filename', None) if not filename: return if not os.path.exists(os.path.join(root, filename)): return if not metadata.get('title'): metadata['title'] = _('Untitled') fn = model.get_file_name(metadata['title'], metadata['mime_type']) new_filename = model.get_unique_file_name(root, fn) os.rename(os.path.join(root, filename), os.path.join(root, new_filename)) filename = new_filename preview_path = os.path.join(root, _JOURNAL_0_METADATA_DIR, 'preview', uid) if os.path.exists(preview_path): preview_fname = filename + '.preview' new_preview_path = os.path.join(root, model.JOURNAL_METADATA_DIR, preview_fname) if not os.path.exists(new_preview_path): shutil.copy(preview_path, new_preview_path)
for key, value in metadata_loaded.items(): metadata[str(key)] = str(value[0]) if "uid" not in metadata: metadata["uid"] = uid filename = metadata.pop("filename", None) if not filename: return if not os.path.exists(os.path.join(root, filename)): return if not metadata.get("title"): metadata["title"] = _("Untitled") fn = model.get_file_name(metadata["title"], metadata["mime_type"]) new_filename = model.get_unique_file_name(root, fn) os.rename(os.path.join(root, filename), os.path.join(root, new_filename)) filename = new_filename preview_path = os.path.join(root, _JOURNAL_0_METADATA_DIR, "preview", uid) if os.path.exists(preview_path): preview_fname = filename + ".preview" new_preview_path = os.path.join(root, model.JOURNAL_METADATA_DIR, preview_fname) if not os.path.exists(new_preview_path): shutil.copy(preview_path, new_preview_path) metadata_fname = filename + ".metadata" metadata_path = os.path.join(root, model.JOURNAL_METADATA_DIR, metadata_fname) if not os.path.exists(metadata_path): (fh, fn) = tempfile.mkstemp(dir=root)
for key, value in metadata_loaded.items(): metadata[str(key)] = str(value[0]) if 'uid' not in metadata: metadata['uid'] = uid filename = metadata.pop('filename', None) if not filename: return if not os.path.exists(os.path.join(root, filename)): return if not metadata.get('title'): metadata['title'] = _('Untitled') fn = model.get_file_name(metadata['title'], metadata['mime_type']) new_filename = model.get_unique_file_name(root, fn) os.rename(os.path.join(root, filename), os.path.join(root, new_filename)) filename = new_filename preview_path = os.path.join(root, _JOURNAL_0_METADATA_DIR, 'preview', uid) if os.path.exists(preview_path): preview_fname = filename + '.preview' new_preview_path = os.path.join(root, model.JOURNAL_METADATA_DIR, preview_fname) if not os.path.exists(new_preview_path): shutil.copy(preview_path, new_preview_path) metadata_fname = filename + '.metadata' metadata_path = os.path.join(root, model.JOURNAL_METADATA_DIR,