diff --git a/etiquette/decorators.py b/etiquette/decorators.py index dca57aa..e8d0b8b 100644 --- a/etiquette/decorators.py +++ b/etiquette/decorators.py @@ -3,6 +3,7 @@ from flask import request import functools import time import uuid +import warnings def _generate_session_token(): token = str(uuid.uuid4()) @@ -38,7 +39,7 @@ def not_implemented(function): def time_me(function): ''' - Decorator. After the function is run, print the elapsed time. + After the function is run, print the elapsed time. ''' @functools.wraps(function) def timed_function(*args, **kwargs): diff --git a/etiquette/etiquette.py b/etiquette/etiquette.py index 191431b..d79797a 100644 --- a/etiquette/etiquette.py +++ b/etiquette/etiquette.py @@ -194,6 +194,7 @@ def get_album_html(albumid): 'album.html', album=album, photos=album['photos'], + view=request.args.get('view', 'grid'), ) return response @@ -403,6 +404,9 @@ def get_search_core(): view = request.args.get('view', 'grid') search_kwargs['view'] = view + search_kwargs['extension'] = extension_string + search_kwargs['extension_not'] = extension_not_string + search_kwargs['mimetype'] = mimetype_string final_results = { 'next_page_url': next_page_url, @@ -604,4 +608,5 @@ def post_edit_tags(): if __name__ == '__main__': - site.run(threaded=True) + #site.run(threaded=True) + pass diff --git a/etiquette/etiquette_launch.py b/etiquette/etiquette_launch.py index 4f43beb..2f71625 100644 --- a/etiquette/etiquette_launch.py +++ b/etiquette/etiquette_launch.py @@ -1,5 +1,5 @@ -from gevent import monkey -monkey.patch_all() +import gevent.monkey +gevent.monkey.patch_all() import etiquette import gevent.pywsgi @@ -13,13 +13,17 @@ else: if port == 443: http = gevent.pywsgi.WSGIServer( - ('', port), - etiquette.site, - keyfile='https\\etiquette.key', - certfile='https\\etiquette.crt', + listener=('', port), + application=etiquette.site, + keyfile='C:\\git\\etiquette\\etiquette\\https\\etiquette.key', + certfile='C:\\git\\etiquette\\etiquette\\https\\etiquette.crt', ) else: - http = gevent.wsgi.WSGIServer(('', port), etiquette.site) + http = gevent.pywsgi.WSGIServer( + listener=('', port), + application=etiquette.site, + ) + print('Starting server') http.serve_forever() \ No newline at end of file diff --git a/etiquette/phototagger.py b/etiquette/phototagger.py index 212150a..29b06a8 100644 --- a/etiquette/phototagger.py +++ b/etiquette/phototagger.py @@ -44,7 +44,7 @@ except converter.ffmpeg.FFMpegError: logging.basicConfig(level=logging.DEBUG) log = logging.getLogger(__name__) -logging.getLogger("PIL.PngImagePlugin").setLevel(logging.WARNING) +logging.getLogger('PIL.PngImagePlugin').setLevel(logging.WARNING) SQL_LASTID_COLUMNS = [ 'table', @@ -55,7 +55,7 @@ SQL_ALBUM_COLUMNS = [ 'id', 'title', 'description', - 'associated_directory' + 'associated_directory', ] SQL_PHOTO_COLUMNS = [ 'id', @@ -1576,14 +1576,18 @@ class Album(ObjectBase, GroupableMixin): log.debug('Committing - add photo to album') self.photodb.commit() - def add_tag_to_all(self, tag, nested_children=True): + def add_tag_to_all(self, tag, nested_children=True, commit=True): tag = self.photodb.get_tag(tag) if nested_children: photos = self.walk_photos() else: photos = self.photos() for photo in photos: - photo.add_tag(tag) + photo.add_tag(tag, commit=False) + + if commit: + log.debug('Committing - add tag to all') + self.photodb.commit() def delete(self, delete_children=False, commit=True): log.debug('Deleting album {album:r}'.format(album=self)) @@ -1673,8 +1677,12 @@ class Photo(ObjectBase): self.duration = row_tuple[SQL_PHOTO['duration']] self.created = row_tuple[SQL_PHOTO['created']] self.thumbnail = row_tuple[SQL_PHOTO['thumbnail']] + self.real_path = pathclass.Path(self.real_filepath) def __reinit__(self): + ''' + Reload the row from the database and do __init__ with them. + ''' self.photodb.cur.execute('SELECT * FROM photos WHERE id == ?', [self.id]) row = self.photodb.cur.fetchone() self.__init__(self.photodb, row) @@ -1915,45 +1923,51 @@ class Photo(ObjectBase): If `move` is True, allow this operation to move the file. Otherwise, slashes will be considered an error. ''' - current_dir = os.path.normcase(os.path.dirname(self.real_filepath)) + old_path = self.real_path + old_path.correct_case() + new_filename = normalize_filepath(new_filename) - new_dir = os.path.normcase(os.path.dirname(new_filename)) - if new_dir == '': - new_dir = current_dir - new_abspath = os.path.join(new_dir, new_filename) + if os.path.dirname(new_filename) == '': + new_path = old_path.parent.with_child(new_filename) else: - new_abspath = os.path.abspath(new_filename) - new_dir = os.path.normcase(os.path.dirname(new_abspath)) - if (new_dir != current_dir) and not move: + new_path = pathclass.Path(new_filename) + new_path.correct_case() + + log.debug(old_path) + log.debug(new_path) + if (new_path.parent != old_path.parent) and not move: raise ValueError('Cannot move the file without param move=True') - os.makedirs(new_dir, exist_ok=True) - new_basename = os.path.basename(new_abspath) + if new_path.absolute_path == old_path.absolute_path: + raise ValueError('The new and old names are the same') - new_abs_norm = os.path.normcase(new_abspath) - current_norm = os.path.normcase(self.real_filepath) + os.makedirs(new_path.parent.absolute_path, exist_ok=True) - if new_abs_norm != current_norm: + if new_path != old_path: + # This is different than the absolute == absolute check above, because this normalizes + # the paths. It's possible on case-insensitive systems to have the paths point to the + # same place while being differently cased, thus we couldn't make the intermediate link. try: - os.link(self.real_filepath, new_abspath) + os.link(old_path.absolute_path, new_path.absolute_path) except OSError: - # Happens when trying to hardlink across disks - spinal.copy_file(self.real_filepath, new_abspath) + spinal.copy_file(old_path, new_path) self.photodb.cur.execute( 'UPDATE photos SET filepath = ? WHERE filepath == ?', - [new_abspath, self.real_filepath] + [new_path.absolute_path, old_path.absolute_path] ) if commit: - if new_abs_norm != current_norm: - os.remove(self.real_filepath) + if new_path == old_path: + # If they are equivalent but differently cased paths, just rename. + os.rename(old_path.absolute_path, new_path.absolute_path) else: - os.rename(self.real_filepath, new_abspath) + # Delete the original hardlink or copy. + os.remove(old_path.absolute_path) log.debug('Committing - rename file') self.photodb.commit() else: - queue_action = {'action': os.remove, 'args': [self.real_filepath]} + queue_action = {'action': os.remove, 'args': [old_path.absolute_path]} self.photodb.on_commit_queue.append(queue_action) self.__reinit__() diff --git a/etiquette/templates/album.html b/etiquette/templates/album.html index 7cfc47a..5078b20 100644 --- a/etiquette/templates/album.html +++ b/etiquette/templates/album.html @@ -6,7 +6,7 @@ Album {{album["title"]}} - + + + {{header.make_header()}} @@ -44,14 +46,13 @@

Photos

{% endif %} - \ No newline at end of file + + \ No newline at end of file diff --git a/etiquette/templates/albums.html b/etiquette/templates/albums.html index cf2f50c..7d6c9f6 100644 --- a/etiquette/templates/albums.html +++ b/etiquette/templates/albums.html @@ -5,13 +5,15 @@ Albums - + + + {{header.make_header()}} @@ -26,8 +28,8 @@ {% endfor %} - \ No newline at end of file + + diff --git a/etiquette/templates/photo.html b/etiquette/templates/photo.html index 541d09f..4a6d108 100644 --- a/etiquette/templates/photo.html +++ b/etiquette/templates/photo.html @@ -9,7 +9,7 @@ {% set filename = photo["id"] + "." + photo["extension"] %} {% set link = "/file/" + filename %} {% set mimetype=photo["mimetype"] %} - + + + {{header.make_header()}} @@ -150,7 +152,7 @@ - + \ No newline at end of file + + diff --git a/etiquette/templates/root.html b/etiquette/templates/root.html index 7535398..119eebd 100644 --- a/etiquette/templates/root.html +++ b/etiquette/templates/root.html @@ -1,5 +1,9 @@ + + Etiquette + + - - - Etiquette - - + {{motd}} Search @@ -35,10 +35,7 @@ a:hover Browse albums - - - - \ No newline at end of file + + diff --git a/etiquette/templates/search.html b/etiquette/templates/search.html index 595f233..52a03a3 100644 --- a/etiquette/templates/search.html +++ b/etiquette/templates/search.html @@ -7,7 +7,7 @@ - + + + {{header.make_header()}} @@ -84,8 +86,6 @@ body - - \ No newline at end of file + + diff --git a/etiquette/templates/template.html b/etiquette/templates/template.html new file mode 100644 index 0000000..68f5b3f --- /dev/null +++ b/etiquette/templates/template.html @@ -0,0 +1,23 @@ + + + + {% import "header.html" as header %} + Flasksite + + + + + + + + +
+

test

+
+ + + + +