From 1fc2ed09f58c05c5817f2a2d6cadc48040f3d9f9 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 19 Feb 2020 23:56:09 -0800 Subject: [PATCH] Remove commit argument from ALL methods. @transaction does it. --- etiquette/objects.py | 66 ++++++++++++++++++++++---------------------- etiquette/photodb.py | 16 +++++------ 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/etiquette/objects.py b/etiquette/objects.py index e121b89..6558540 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -89,7 +89,7 @@ class GroupableMixin: for parent in parents: parent.add_children(children) - def add_child(self, member, *, commit=False): + def add_child(self, member): self.assert_same_type(member) if member == self: @@ -112,7 +112,7 @@ class GroupableMixin: self.photodb._cached_frozen_children = None - def add_children(self, members, *, commit=False): + def add_children(self, members): for member in members: self.add_child(member) @@ -122,7 +122,7 @@ class GroupableMixin: if self.photodb != other.photodb: raise TypeError(f'Objects must belong to the same PhotoDB.') - def delete(self, *, delete_children=False, commit=False): + def delete(self, *, delete_children=False): ''' Delete this object's relationships to other groupables. Any unique / specific deletion methods should be written within the @@ -184,7 +184,7 @@ class GroupableMixin: row = self.photodb.sql_select_one(query, [self.id, member.id]) return row is not None - def remove_child(self, member, *, commit=False): + def remove_child(self, member): if not self.has_child(member): return @@ -283,7 +283,7 @@ class Album(ObjectBase, GroupableMixin): @decorators.required_feature('album.edit') @decorators.transaction - def add_associated_directory(self, path, *, commit=False): + def add_associated_directory(self, path): ''' Add a directory from which this album will pull files during rescans. These relationships are not unique and multiple albums @@ -308,7 +308,7 @@ class Album(ObjectBase, GroupableMixin): @decorators.required_feature('album.edit') @decorators.transaction - def add_photo(self, photo, *, commit=False): + def add_photo(self, photo): if self.has_photo(photo): return @@ -316,7 +316,7 @@ class Album(ObjectBase, GroupableMixin): @decorators.required_feature('album.edit') @decorators.transaction - def add_photos(self, photos, *, commit=False): + def add_photos(self, photos): existing_photos = set(self.get_photos()) photos = set(photos) photos = photos.difference(existing_photos) @@ -326,7 +326,7 @@ class Album(ObjectBase, GroupableMixin): # Photo.add_tag already has @required_feature @decorators.transaction - def add_tag_to_all(self, tag, *, nested_children=True, commit=False): + def add_tag_to_all(self, tag, *, nested_children=True): ''' Add this tag to every photo in the album. Saves you from having to write the for-loop yourself. @@ -346,7 +346,7 @@ class Album(ObjectBase, GroupableMixin): @decorators.required_feature('album.edit') @decorators.transaction - def delete(self, *, delete_children=False, commit=False): + def delete(self, *, delete_children=False): self.photodb.log.debug('Deleting %s', self) GroupableMixin.delete(self, delete_children=delete_children) self.photodb.sql_delete(table='album_associated_directories', pairs={'albumid': self.id}) @@ -363,7 +363,7 @@ class Album(ObjectBase, GroupableMixin): @decorators.required_feature('album.edit') @decorators.transaction - def edit(self, title=None, description=None, *, commit=False): + def edit(self, title=None, description=None): ''' Change the title or description. Leave None to keep current value. ''' @@ -465,12 +465,12 @@ class Album(ObjectBase, GroupableMixin): @decorators.required_feature('album.edit') @decorators.transaction - def remove_photo(self, photo, *, commit=False): + def remove_photo(self, photo): self._remove_photo(photo) @decorators.required_feature('album.edit') @decorators.transaction - def remove_photos(self, photos, *, commit=False): + def remove_photos(self, photos): existing_photos = set(self.get_photos()) photos = set(photos) photos = photos.intersection(existing_photos) @@ -575,13 +575,13 @@ class Bookmark(ObjectBase): @decorators.required_feature('bookmark.edit') @decorators.transaction - def delete(self, *, commit=False): + def delete(self): self.photodb.sql_delete(table='bookmarks', pairs={'id': self.id}) self._uncache() @decorators.required_feature('bookmark.edit') @decorators.transaction - def edit(self, title=None, url=None, *, commit=False): + def edit(self, title=None, url=None): ''' Change the title or URL. Leave None to keep current. ''' @@ -665,7 +665,7 @@ class Photo(ObjectBase): @decorators.required_feature('photo.add_remove_tag') @decorators.transaction - def add_tag(self, tag, *, commit=False): + def add_tag(self, tag): tag = self.photodb.get_tag(name=tag) existing = self.has_tag(tag, check_children=False) @@ -715,7 +715,7 @@ class Photo(ObjectBase): # Photo.add_tag already has @required_feature add_remove_tag @decorators.transaction - def copy_tags(self, other_photo, *, commit=False): + def copy_tags(self, other_photo): ''' Take all of the tags owned by other_photo and apply them to this photo. ''' @@ -724,7 +724,7 @@ class Photo(ObjectBase): @decorators.required_feature('photo.edit') @decorators.transaction - def delete(self, *, delete_file=False, commit=False): + def delete(self, *, delete_file=False): ''' Delete the Photo and its relation to any tags and albums. ''' @@ -748,7 +748,7 @@ class Photo(ObjectBase): #@decorators.time_me @decorators.required_feature('photo.generate_thumbnail') @decorators.transaction - def generate_thumbnail(self, *, commit=False, **special): + def generate_thumbnail(self, **special): ''' special: For videos, you can provide a `timestamp` to take the thumbnail at. @@ -867,17 +867,17 @@ class Photo(ObjectBase): # Photo.rename_file already has @required_feature @decorators.transaction - def move_file(self, directory, commit=False): + def move_file(self, directory): directory = pathclass.Path(directory) directory.assert_is_directory() new_path = directory.with_child(self.real_path.basename) new_path.assert_not_exists() - self.rename_file(new_path.absolute_path, move=True, commit=commit) + self.rename_file(new_path.absolute_path, move=True) #@decorators.time_me @decorators.required_feature('photo.reload_metadata') @decorators.transaction - def reload_metadata(self, *, commit=False): + def reload_metadata(self): ''' Load the file's height, width, etc as appropriate for this type of file. ''' @@ -937,7 +937,7 @@ class Photo(ObjectBase): @decorators.required_feature('photo.edit') @decorators.transaction - def relocate(self, new_filepath, *, allow_duplicates=False, commit=False): + def relocate(self, new_filepath, *, allow_duplicates=False): ''' Point the Photo object to a different filepath. @@ -965,7 +965,7 @@ class Photo(ObjectBase): @decorators.required_feature('photo.add_remove_tag') @decorators.transaction - def remove_tag(self, tag, *, commit=False): + def remove_tag(self, tag): tag = self.photodb.get_tag(name=tag) self.photodb.log.debug('Removing %s from %s', tag, self) @@ -983,7 +983,7 @@ class Photo(ObjectBase): @decorators.required_feature('photo.edit') @decorators.transaction - def rename_file(self, new_filename, *, move=False, commit=False): + def rename_file(self, new_filename, *, move=False): ''' Rename the file on the disk as well as in the database. @@ -1054,7 +1054,7 @@ class Photo(ObjectBase): @decorators.required_feature('photo.edit') @decorators.transaction - def set_searchhidden(self, searchhidden, *, commit=False): + def set_searchhidden(self, searchhidden): data = { 'id': self.id, 'searchhidden': bool(searchhidden), @@ -1065,7 +1065,7 @@ class Photo(ObjectBase): @decorators.required_feature('photo.edit') @decorators.transaction - def set_override_filename(self, new_filename, *, commit=False): + def set_override_filename(self, new_filename): if new_filename is not None: cleaned = helpers.remove_path_badchars(new_filename) cleaned = cleaned.strip() @@ -1158,7 +1158,7 @@ class Tag(ObjectBase, GroupableMixin): @decorators.required_feature('tag.edit') @decorators.transaction - def add_synonym(self, synname, *, commit=False): + def add_synonym(self, synname): synname = self.photodb.normalize_tagname(synname) if synname == self.name: @@ -1180,7 +1180,7 @@ class Tag(ObjectBase, GroupableMixin): @decorators.required_feature('tag.edit') @decorators.transaction - def convert_to_synonym(self, mastertag, *, commit=False): + def convert_to_synonym(self, mastertag): ''' Convert this tag into a synonym for a different tag. All photos which possess the current tag will have it replaced with the @@ -1243,7 +1243,7 @@ class Tag(ObjectBase, GroupableMixin): @decorators.required_feature('tag.edit') @decorators.transaction - def delete(self, *, delete_children=False, commit=False): + def delete(self, *, delete_children=False): self.photodb.log.debug('Deleting %s', self) self.photodb._cached_frozen_children = None GroupableMixin.delete(self, delete_children=delete_children) @@ -1254,7 +1254,7 @@ class Tag(ObjectBase, GroupableMixin): @decorators.required_feature('tag.edit') @decorators.transaction - def edit(self, description=None, *, commit=False): + def edit(self, description=None): ''' Change the description. Leave None to keep current value. ''' @@ -1286,7 +1286,7 @@ class Tag(ObjectBase, GroupableMixin): @decorators.required_feature('tag.edit') @decorators.transaction - def remove_synonym(self, synname, *, commit=False): + def remove_synonym(self, synname): ''' Delete a synonym. This will have no effect on photos or other synonyms because @@ -1309,7 +1309,7 @@ class Tag(ObjectBase, GroupableMixin): @decorators.required_feature('tag.edit') @decorators.transaction - def rename(self, new_name, *, apply_to_synonyms=True, commit=False): + def rename(self, new_name, *, apply_to_synonyms=True): ''' Rename the tag. Does not affect its relation to Photos or tag groups. ''' @@ -1393,7 +1393,7 @@ class User(ObjectBase): @decorators.required_feature('user.edit') @decorators.transaction - def set_display_name(self, display_name, *, commit=False): + def set_display_name(self, display_name): display_name = self.normalize_display_name( display_name, max_length=self.photodb.config['user']['max_display_name_length'], diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 4fb46ef..cc6a0f0 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -83,7 +83,6 @@ class PDBAlbumMixin: *, associated_directory=None, author=None, - commit=False, photos=None, ): ''' @@ -134,7 +133,7 @@ class PDBBookmarkMixin: @decorators.required_feature('bookmark.new') @decorators.transaction - def new_bookmark(self, url, title=None, *, author=None, commit=False): + def new_bookmark(self, url, title=None, *, author=None): # These might raise exceptions. title = objects.Bookmark.normalize_title(title) url = objects.Bookmark.normalize_url(url) @@ -213,7 +212,6 @@ class PDBPhotoMixin: *, allow_duplicates=False, author=None, - commit=False, do_metadata=True, do_thumbnail=True, searchhidden=False, @@ -277,7 +275,7 @@ class PDBPhotoMixin: return photo @decorators.transaction - def purge_deleted_files(self, photos=None, *, commit=False): + def purge_deleted_files(self, photos=None): ''' Delete Photos whose corresponding file on disk is missing. @@ -294,7 +292,7 @@ class PDBPhotoMixin: photo.delete() @decorators.transaction - def purge_empty_albums(self, albums=None, *, commit=False): + def purge_empty_albums(self, albums=None): if albums is None: to_check = set(self.get_albums()) else: @@ -914,7 +912,7 @@ class PDBTagMixin: @decorators.required_feature('tag.new') @decorators.transaction - def new_tag(self, tagname, description=None, *, author=None, commit=False): + def new_tag(self, tagname, description=None, *, author=None): ''' Register a new tag and return the Tag object. ''' @@ -1074,7 +1072,7 @@ class PDBUserMixin: @decorators.required_feature('user.new') @decorators.transaction - def register_user(self, username, password, *, display_name=None, commit=False): + def register_user(self, username, password, *, display_name=None): # These might raise exceptions. self.assert_valid_username(username) @@ -1122,7 +1120,6 @@ class PDBUtilMixin: new_photo_kwargs={}, new_photo_ratelimit=None, recurse=True, - commit=False, ): ''' Create an album, and add the directory's contents to it recursively. @@ -1239,7 +1236,8 @@ class PDBUtilMixin: else: return None - def easybake(self, ebstring, author=None, *, commit=False): + @decorators.transaction + def easybake(self, ebstring, author=None): ''' Easily create tags, groups, and synonyms with a string like "group1.group2.tag+synonym"