コード例 #1
0
ファイル: base.py プロジェクト: T30rGRB7/calibre-python3
def reset_field_metadata():
    global field_metadata
    field_metadata = FieldMetadata()
コード例 #2
0
ファイル: base.py プロジェクト: T30rGRB7/calibre-python3
    'user_metadata': {},
    'cover_data': (None, None),
    'tags': [],
    'identifiers': {},
    'languages': [],
    'device_collections': [],
    'author_sort_map': {},
    'authors': [_('Unknown')],
    'author_sort': _('Unknown'),
    'title': _('Unknown'),
    'user_categories': {},
    'author_link_map': {},
    'language': 'und'
}

field_metadata = FieldMetadata()


def reset_field_metadata():
    global field_metadata
    field_metadata = FieldMetadata()


ck = lambda typ: icu_lower(typ).strip().replace(':', '').replace(',', '')
cv = lambda val: val.strip().replace(',', '|')


class Metadata(object):
    '''
    A class representing all the metadata for a book. The various standard metadata
    fields are available as attributes of this object. You can also stick
コード例 #3
0
 def __init__(self):
     self.field_metadata = FieldMetadata()
コード例 #4
0
ファイル: backend.py プロジェクト: kobolabs/calibre
    def __init__(self,
                 library_path,
                 default_prefs=None,
                 read_only=False,
                 restore_all_prefs=False,
                 progress_callback=lambda x, y: True):
        try:
            if isbytestring(library_path):
                library_path = library_path.decode(filesystem_encoding)
        except:
            import traceback
            traceback.print_exc()

        self.field_metadata = FieldMetadata()

        self.library_path = os.path.abspath(library_path)
        self.dbpath = os.path.join(library_path, 'metadata.db')
        self.dbpath = os.environ.get('CALIBRE_OVERRIDE_DATABASE_PATH',
                                     self.dbpath)

        if iswindows and len(
                self.library_path) + 4 * self.PATH_LIMIT + 10 > 259:
            raise ValueError(
                _('Path to library too long. Must be less than'
                  ' %d characters.') % (259 - 4 * self.PATH_LIMIT - 10))
        exists = self._exists = os.path.exists(self.dbpath)
        if not exists:
            # Be more strict when creating new libraries as the old calculation
            # allowed for max path lengths of 265 chars.
            if (iswindows and
                    len(self.library_path) > self.WINDOWS_LIBRARY_PATH_LIMIT):
                raise ValueError(
                    _('Path to library too long. Must be less than'
                      ' %d characters.') % self.WINDOWS_LIBRARY_PATH_LIMIT)

        if read_only and os.path.exists(self.dbpath):
            # Work on only a copy of metadata.db to ensure that
            # metadata.db is not changed
            pt = PersistentTemporaryFile('_metadata_ro.db')
            pt.close()
            shutil.copyfile(self.dbpath, pt.name)
            self.dbpath = pt.name

        if not os.path.exists(os.path.dirname(self.dbpath)):
            os.makedirs(os.path.dirname(self.dbpath))

        self._conn = None
        if self.user_version == 0:
            self.initialize_database()

        if not os.path.exists(self.library_path):
            os.makedirs(self.library_path)
        self.is_case_sensitive = is_case_sensitive(self.library_path)

        SchemaUpgrade(self.conn, self.library_path, self.field_metadata)

        # Guarantee that the library_id is set
        self.library_id

        # Fix legacy triggers and columns
        self.conn.execute('''
        DROP TRIGGER IF EXISTS author_insert_trg;
        CREATE TEMP TRIGGER author_insert_trg
            AFTER INSERT ON authors
            BEGIN
            UPDATE authors SET sort=author_to_author_sort(NEW.name) WHERE id=NEW.id;
        END;
        DROP TRIGGER IF EXISTS author_update_trg;
        CREATE TEMP TRIGGER author_update_trg
            BEFORE UPDATE ON authors
            BEGIN
            UPDATE authors SET sort=author_to_author_sort(NEW.name)
            WHERE id=NEW.id AND name <> NEW.name;
        END;
        UPDATE authors SET sort=author_to_author_sort(name) WHERE sort IS NULL;
        ''')

        self.initialize_prefs(default_prefs, restore_all_prefs,
                              progress_callback)
        self.initialize_custom_columns()
        self.initialize_tables()
コード例 #5
0
ファイル: json_codec.py プロジェクト: zyhong/calibre
 def __init__(self, field_metadata=None):
     self.field_metadata = field_metadata or FieldMetadata()