Switch some formats to f-strings.

This commit is contained in:
voussoir 2018-04-15 01:13:02 -07:00
parent 0c9582598d
commit bfc4f313a9
3 changed files with 13 additions and 13 deletions

View file

@ -43,11 +43,11 @@ FILENAME_BADCHARS = '\\/:*?<>|"'
# happens after the out-of-date check occurs, so no chance of accidentally # happens after the out-of-date check occurs, so no chance of accidentally
# overwriting it. # overwriting it.
DATABASE_VERSION = 12 DATABASE_VERSION = 12
DB_INIT = ''' DB_INIT = f'''
PRAGMA cache_size = 10000; PRAGMA cache_size = 10000;
PRAGMA count_changes = OFF; PRAGMA count_changes = OFF;
PRAGMA foreign_keys = ON; PRAGMA foreign_keys = ON;
PRAGMA user_version = {user_version}; PRAGMA user_version = {DATABASE_VERSION};
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS users( CREATE TABLE IF NOT EXISTS users(
@ -178,7 +178,7 @@ CREATE TABLE IF NOT EXISTS tag_synonyms(
); );
CREATE INDEX IF NOT EXISTS index_tag_synonyms_name on tag_synonyms(name); CREATE INDEX IF NOT EXISTS index_tag_synonyms_name on tag_synonyms(name);
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
'''.format(user_version=DATABASE_VERSION) '''
def _extract_columns(create_table_statement): def _extract_columns(create_table_statement):
column_names = create_table_statement.split('(')[1].rsplit(')', 1)[0] column_names = create_table_statement.split('(')[1].rsplit(')', 1)[0]

View file

@ -244,7 +244,7 @@ class Album(ObjectBase, GroupableMixin):
return hash(self.id) return hash(self.id)
def __repr__(self): def __repr__(self):
return 'Album:{id}'.format(id=self.id) return f'Album:{self.id}'
@staticmethod @staticmethod
def normalize_description(description): def normalize_description(description):
@ -540,7 +540,7 @@ class Bookmark(ObjectBase):
self.author_id = self.normalize_author_id(db_row['author_id']) self.author_id = self.normalize_author_id(db_row['author_id'])
def __repr__(self): def __repr__(self):
return 'Bookmark:{id}'.format(id=self.id) return f'Bookmark:{self.id}'
@staticmethod @staticmethod
def normalize_title(title): def normalize_title(title):
@ -665,7 +665,7 @@ class Photo(ObjectBase):
self.__init__(self.photodb, row) self.__init__(self.photodb, row)
def __repr__(self): def __repr__(self):
return 'Photo:{id}'.format(id=self.id) return f'Photo:{self.id}'
def _uncache(self): def _uncache(self):
self.photodb.caches['photo'].remove(self.id) self.photodb.caches['photo'].remove(self.id)
@ -683,14 +683,14 @@ class Photo(ObjectBase):
# keep our current one. # keep our current one.
existing = self.has_tag(tag, check_children=True) existing = self.has_tag(tag, check_children=True)
if existing: if existing:
message = 'Preferring existing {exi:s} over {tag:s}'.format(exi=existing, tag=tag) message = f'Preferring existing {existing} over {tag}'
self.photodb.log.debug(message) self.photodb.log.debug(message)
return existing return existing
# If the new tag is more specific, remove our current one for it. # If the new tag is more specific, remove our current one for it.
for parent in tag.walk_parents(): for parent in tag.walk_parents():
if self.has_tag(parent, check_children=False): if self.has_tag(parent, check_children=False):
message = 'Preferring new {tag:s} over {par:s}'.format(tag=tag, par=parent) message = f'Preferring new {tag} over {parent}'
self.photodb.log.debug(message) self.photodb.log.debug(message)
self.remove_tag(parent) self.remove_tag(parent)
@ -1170,11 +1170,11 @@ class Tag(ObjectBase, GroupableMixin):
return hash(self.name) return hash(self.name)
def __repr__(self): def __repr__(self):
rep = 'Tag:{id}:{name}'.format(name=self.name, id=self.id) rep = f'Tag:{self.id}:{self.name}'
return rep return rep
def __str__(self): def __str__(self):
rep = 'Tag:{name}'.format(name=self.name) rep = f'Tag:{self.name}'
return rep return rep
@staticmethod @staticmethod
@ -1464,11 +1464,11 @@ class User(ObjectBase):
self.password_hash = db_row['password'] self.password_hash = db_row['password']
def __repr__(self): def __repr__(self):
rep = 'User:{id}:{username}'.format(id=self.id, username=self.username) rep = f'User:{self.id}:{self.username}'
return rep return rep
def __str__(self): def __str__(self):
rep = 'User:{username}'.format(username=self.username) rep = f'User:{self.username}'
return rep return rep

View file

@ -1362,7 +1362,7 @@ class PhotoDB(
if self.ephemeral: if self.ephemeral:
return 'PhotoDB(ephemeral=True)' return 'PhotoDB(ephemeral=True)'
else: else:
return 'PhotoDB(data_directory={datadir})'.format(datadir=repr(self.data_directory)) return f'PhotoDB(data_directory={self.data_directory})'
def _uncache(self): def _uncache(self):
self._cached_frozen_children = None self._cached_frozen_children = None