Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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,
        )
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
        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'
Exemplo n.º 5
0
    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)