diff --git a/oml/commands.py b/oml/commands.py index 25e1fa8..d147b2e 100644 --- a/oml/commands.py +++ b/oml/commands.py @@ -134,7 +134,7 @@ def command_postupdate(*args): print('usage: -o oldversion -n newversion') sys.exit(1) if old <= '20140521-65-e14c686' and new > '20140521-65-e14c686': - if not os.path.exists(settings.db_path) and sys.platform != 'win32': + if not os.path.exists(settings.db_path): r('./ctl', 'setup') import setup setup.upgrade_db(old, new) diff --git a/oml/item/icons.py b/oml/item/icons.py index be86281..37d89fb 100644 --- a/oml/item/icons.py +++ b/oml/item/icons.py @@ -30,10 +30,7 @@ class Icons(dict): def is_available(self): folder = os.path.dirname(self._db) - base = os.path.dirname(os.path.dirname(folder)) - if os.path.exists(base): - if not os.path.exists(folder): - ox.makedirs(folder) + if os.path.exists(folder): if not os.path.exists(self._db): self.create() return os.path.exists(self._db) @@ -140,7 +137,7 @@ def get_icons_db_path(): import settings import shutil - library = os.path.normpath(os.path.expanduser(settings.preferences['libraryPath'])) + library = os.path.expanduser(settings.preferences['libraryPath']) metadata = os.path.join(library, 'Metadata') icons_db_path = os.path.join(metadata, 'icons.db') if os.path.exists(os.path.dirname(library)): diff --git a/oml/node/nodeapi.py b/oml/node/nodeapi.py index 960eecc..93c0d49 100644 --- a/oml/node/nodeapi.py +++ b/oml/node/nodeapi.py @@ -34,7 +34,7 @@ def api_requestPeering(user_id, username, message): return False def api_acceptPeering(user_id, username, message): - user = User.get(user_id, for_update=True) + user = User.get(user_id) if user: logger.debug('incoming acceptPeering event: pending: %s', user.pending) if user.pending == 'sent': @@ -50,7 +50,7 @@ def api_acceptPeering(user_id, username, message): return False def api_rejectPeering(user_id, message): - user = User.get(user_id, for_update=True) + user = User.get(user_id) if user: user.info['message'] = message user.update_peering(False) @@ -59,7 +59,7 @@ def api_rejectPeering(user_id, message): return False def api_removePeering(user_id, message): - user = User.get(user_id, for_update=True) + user = User.get(user_id) if user: user.info['message'] = message user.update_peering(False) @@ -68,7 +68,7 @@ def api_removePeering(user_id, message): return False def api_cancelPeering(user_id, message): - user = User.get(user_id, for_update=True) + user = User.get(user_id) if user: user.info['message'] = message user.update_peering(False) diff --git a/oml/node/server.py b/oml/node/server.py index 65451dc..0e5694e 100644 --- a/oml/node/server.py +++ b/oml/node/server.py @@ -121,56 +121,55 @@ class Handler(http.server.SimpleHTTPRequestHandler): else: id = None if id and len(id) == 32 and id.isalnum(): - path = None - data = None with db.session(): if preview: from item.icons import get_icon_sync try: - content = get_icon_sync(id, 'preview', 512) + data = get_icon_sync(id, 'preview', 512) except: - content = None - if content: + data = None + if data: self.send_response(200, 'ok') - mimetype = 'image/jpg' + self.send_header('Content-type', 'image/jpg') else: self.send_response(404, 'Not Found') - content = b'404 - Not Found' - mimetype = 'text/plain' + self.send_header('Content-type', 'text/plain') + data = b'404 - Not Found' + content_length = len(data) + self.send_header('Content-Length', str(content_length)) + self.end_headers() + self.write_with_limit(data, content_length) + return + file = item.models.File.get(id) + if not file: + self.send_response(404, 'Not Found') + self.send_header('Content-type', 'text/plain') + self.end_headers() + self.wfile.write(b'404 - Not Found') + return + path = file.fullpath() + mimetype = { + 'epub': 'application/epub+zip', + 'pdf': 'application/pdf', + 'txt': 'text/plain', + }.get(path.split('.')[-1], None) + self.send_response(200, 'OK') + self.send_header('Content-Type', mimetype) + self.send_header('X-Node-Protocol', settings.NODE_PROTOCOL) + if mimetype == 'text/plain': + with open(path, 'rb') as f: + content = f.read() + content = self.gzip_data(content) + content_length = len(content) else: - file = item.models.File.get(id) - if file: - path = file.fullpath() - mimetype = { - 'epub': 'application/epub+zip', - 'pdf': 'application/pdf', - 'txt': 'text/plain', - }.get(path.split('.')[-1], None) - self.send_response(200, 'OK') - else: - self.send_response(404, 'Not Found') - content = b'404 - Not Found' - mimetype = 'text/plain' - self.send_header('Content-Type', mimetype) - self.send_header('X-Node-Protocol', settings.NODE_PROTOCOL) - if mimetype == 'text/plain' and path: - with open(path, 'rb') as f: - content = f.read() - content = self.gzip_data(content) - content_length = len(content) - elif path: - content = None - content_length = os.path.getsize(path) - elif content: - content_length = len(content) - else: - content_length = 0 - self.send_header('Content-Length', str(content_length)) - self.end_headers() - if content: - self.write_with_limit(content, content_length) - elif path: - self.write_file_with_limit(path, content_length) + content = None + content_length = os.path.getsize(path) + self.send_header('Content-Length', str(content_length)) + self.end_headers() + if content: + self.write_with_limit(content, content_length) + else: + self.write_file_with_limit(path, content_length) elif len(parts) == 2 and parts[1] == 'log': self._changelog() else: diff --git a/static/js/folders.js b/static/js/folders.js index 812f8bd..f413156 100644 --- a/static/js/folders.js +++ b/static/js/folders.js @@ -340,9 +340,8 @@ oml.ui.folders = function() { var items = lists.filter(function(list) { return list.user == '' && list.type != 'library' && list.name != 'Inbox'; }); - // Library + Inbox + lists oml.$ui.folder[0].$content - .css({height: 16 + 16 + items.length * 16 + 'px'}); + .css({height: 16 + items.length * 16 + 'px'}); oml.$ui.folderList[0].options({ items: Ox.clone(items, true) })