コード例 #1
0
ファイル: edit.py プロジェクト: juvenal/ebmeta
def run(arguments=None, new_yaml_text=None):
    """Run this action."""

    path = ebmeta.arguments.filename
    ebook = ebook_factory(path)
    metadata = ebook.get_metadata()
    template_str = template.get_file_content('{}.yaml'.format(ebook.type))
    yaml_text = opf_to_yaml(metadata, template_str)

    if new_yaml_text:
        result = new_yaml_text
    else:
        try:
            result = edit_string(yaml_text, 'Edit Ebook Metadata')
        except ZenityCancelled:
            log.debug('Operation was cancelled.')
            return

    if result == yaml_text.strip():
        log.debug('No change was made.')
    elif result:
        log.debug('Writing changes to ebook file.')
        d1 = yaml.load(yaml_text)
        d2 = yaml.load(result)
        changes = dict()
        for key in d2.keys():
            if key == 'description':
                if (d1[key] or '').strip() != (d2[key] or '').strip():
                    changes[key] = d2[key]
            if key == 'authors':
                if d1[key] != d2[key]:
                    changes[key] = d2[key]
                    if d2.has_key('author sort'):
                        changes['author sort'] = d2['author sort']
            if key == 'title':
                if d1[key] != d2[key]:
                    changes[key] = d2[key]
                    if d2.has_key('title sort'):
                        changes['title sort'] = d2['title sort']
            else:
                if d1[key] != d2[key]: changes[key] = d2[key]
        log.debug('The following keys changed: %s', ' '.join(changes.keys()))

        backup.run()  # backup only if backup doesn't exist

        if ebook.type == 'pdf':
            write_changes_pdf(ebook, changes)
        else:
            write_changes(ebook, changes)
コード例 #2
0
ファイル: edit.py プロジェクト: Fizcus/ebmeta
def run(new_yaml_text=None):
    """Run this action."""

    path = ebmeta.arguments.filename
    ebook = ebook_factory(path)
    opf = ebook.opf
    template_str = template.get_file_content("{}.yaml".format(ebook.type))
    yaml_text = opf_to_yaml(opf, template_str)

    if new_yaml_text:
        result = new_yaml_text
    else:
        try:
            result = edit_string(yaml_text, "Edit Ebook Metadata")
        except ZenityCancelled:
            log.debug("Operation was cancelled.")
            return

    if result.strip() == yaml_text.strip():
        log.debug("No change was made.")
    elif result:
        log.debug("Writing changes to ebook file.")
        d1 = yaml.load(yaml_text)
        d2 = yaml.load(result)
        if (ebook.type == 'epub') and (not d2.get('uuid')):
            # ensure the new metadata has a uuid
            d2['uuid'] = ebmeta.new_id()
        changes = dict()
        for key in d2.keys():
            if key == 'description':
                if (d1[key] or "").strip() != (d2[key] or "").strip(): changes[key] = d2[key]
            if key == 'authors':
                if d1[key] != d2[key]:
                    changes[key] = d2[key]
                    if d2.has_key('author sort'): changes['author sort'] = d2['author sort']
            if key == 'title':
                if d1[key] != d2[key]:
                    changes[key] = d2[key]
                    if d2.has_key('title sort'): changes['title sort'] = d2['title sort']
            else:
                if d1[key] != d2[key]: changes[key] = d2[key]
        log.debug("The following keys changed: %s", ' '.join(changes.keys()))

        backup.run() # backup only if backup doesn't exist

        if ebook.type == 'pdf':
            write_changes_pdf(ebook, changes)
        else:
            write_changes(ebook, changes)
コード例 #3
0
ファイル: edit.py プロジェクト: bkidwell/ebmeta
def run(arguments=None, new_yaml_text=None):
    """Run this action."""

    path = ebmeta.arguments.filename
    ebook = ebook_factory(path)
    metadata = ebook.get_metadata()
    template_str = template.get_file_content('{}.yaml'.format(ebook.type))
    yaml_text = opf_to_yaml(metadata, template_str)

    if new_yaml_text:
        result = new_yaml_text
    else:
        try:
            result = edit_string(yaml_text, 'Edit Ebook Metadata')
        except ZenityCancelled:
            log.debug('Operation was cancelled.')
            return

    if result == yaml_text.strip():
        log.debug('No change was made.')
    elif result:
        log.debug('Writing changes to ebook file.')
        d1 = yaml.load(yaml_text)
        d2 = yaml.load(result)
        changes = dict()
        for key in d2.keys():
            if key == 'description':
                if (d1[key] or '').strip() != (d2[key] or '').strip(): changes[key] = d2[key]
            if key == 'authors':
                if d1[key] != d2[key]:
                    changes[key] = d2[key]
                    if d2.has_key('author sort'): changes['author sort'] = d2['author sort']
            if key == 'title':
                if d1[key] != d2[key]:
                    changes[key] = d2[key]
                    if d2.has_key('title sort'): changes['title sort'] = d2['title sort']
            else:
                if d1[key] != d2[key]: changes[key] = d2[key]
        log.debug('The following keys changed: %s', ' '.join(changes.keys()))

        backup.run() # backup only if backup doesn't exist

        if ebook.type == 'pdf':
            write_changes_pdf(ebook, changes)
        else:
            write_changes(ebook, changes)
コード例 #4
0
ファイル: display.py プロジェクト: juvenal/ebmeta
def run(arguments):
    """Run this action."""

    path = arguments.filename
    ebook = ebook_factory(path)

    width = 0
    m = ebook.get_metadata()
    for key in m.keys():
        if len(key) > width:
            width = len(key)
    width += 1

    for key, value in ebook.get_metadata().items():
        if isinstance(value, str):
            value_txt = value
        elif isinstance(value, list):
            value_txt = '; '.join(value)
        else:
            value_txt = repr(value)
        print(key + ':' + (' ' * (width - len(key))) + value_txt)
コード例 #5
0
ファイル: display.py プロジェクト: Fizcus/ebmeta
def run():
    """Run this action."""

    path = ebmeta.arguments.filename
    ebook = ebook_factory(path)
    print unicode(ebook.opf)