diff --git a/cista/__main__.py b/cista/__main__.py index 7054c11..49f535c 100755 --- a/cista/__main__.py +++ b/cista/__main__.py @@ -1,13 +1,13 @@ -import re import sys from pathlib import Path from docopt import docopt -from . import app, config, droppy, httpredir, pwgen, serve -from ._version import version +from cista import app, config, droppy, serve, server80 +from cista._version import version +from cista.util import pwgen -app, httpredir.app # Needed for Sanic multiprocessing +app, server80.app # Needed for Sanic multiprocessing doc = f"""Cista {version} - A file storage for the web. diff --git a/cista/app.py b/cista/app.py index 7e7c098..baae3ea 100755 --- a/cista/app.py +++ b/cista/app.py @@ -7,11 +7,10 @@ from sanic import Forbidden, Sanic, SanicException, errorpages from sanic.log import logger from sanic.response import html, json, redirect -from . import config, session, watching -from .auth import authbp -from .fileio import FileServer -from .protocol import ControlBase, ErrorMsg, FileRange, StatusMsg - +from cista import config, session, watching +from cista.auth import authbp +from cista.fileio import FileServer +from cista.protocol import ControlBase, ErrorMsg, FileRange, StatusMsg app = Sanic("cista") fileserver = FileServer() diff --git a/cista/auth.py b/cista/auth.py index 64538b8..d17de74 100755 --- a/cista/auth.py +++ b/cista/auth.py @@ -8,7 +8,7 @@ import msgspec from html5tagger import Document from sanic import BadRequest, Blueprint, Forbidden, html, json, redirect -from . import config, session +from cista import config, session _argon = argon2.PasswordHasher() _droppyhash = re.compile(r'^([a-f0-9]{64})\$([a-f0-9]{8})$') diff --git a/cista/fileio.py b/cista/fileio.py index 6bedc7e..5e52bd2 100755 --- a/cista/fileio.py +++ b/cista/fileio.py @@ -1,13 +1,13 @@ import asyncio import os import unicodedata -from pathlib import Path, PurePosixPath +from pathlib import PurePosixPath from pathvalidate import sanitize_filepath -from . import config, protocol -from .asynclink import AsyncLink -from .lrucache import LRUCache +from cista import config +from cista.util.asynclink import AsyncLink +from cista.util.lrucache import LRUCache def fuid(stat) -> str: diff --git a/cista/protocol.py b/cista/protocol.py index 494fe8e..a9a9225 100755 --- a/cista/protocol.py +++ b/cista/protocol.py @@ -1,12 +1,13 @@ from __future__ import annotations + import shutil +import msgspec from sanic import BadRequest + from cista import config from cista.fileio import sanitize_filename -import msgspec - ## Control commands class ControlBase(msgspec.Struct, tag_field="op", tag=str.lower): diff --git a/cista/serve.py b/cista/serve.py index 42fae78..35f978a 100755 --- a/cista/serve.py +++ b/cista/serve.py @@ -4,7 +4,7 @@ from pathlib import Path from sanic import Sanic -from . import config +from cista import config def run(dev=False): @@ -15,8 +15,8 @@ def run(dev=False): os.environ["SANIC_IGNORE_PRODUCTION_WARNING"] = "1" if opts.get("ssl"): # Run plain HTTP redirect/acme server on port 80 - from . import httpredir - httpredir.app.prepare(port=80, motd=False) + from . import server80 + server80.app.prepare(port=80, motd=False) domain = opts["host"] opts["ssl"] = str(config.conffile.parent / domain) app.prepare(**opts, motd=False, dev=dev, auto_reload=dev, access_log=True) diff --git a/cista/httpredir.py b/cista/server80.py similarity index 96% rename from cista/httpredir.py rename to cista/server80.py index 8b03213..9119a00 100644 --- a/cista/httpredir.py +++ b/cista/server80.py @@ -1,6 +1,6 @@ from sanic import Sanic, exceptions, response -app = Sanic("http_redirect") +app = Sanic("server80") # Send all HTTP users to HTTPS @app.exception(exceptions.NotFound, exceptions.MethodNotSupported) diff --git a/cista/session.py b/cista/session.py index 7d0bc94..ea030d1 100755 --- a/cista/session.py +++ b/cista/session.py @@ -2,7 +2,7 @@ from time import time import jwt -from .config import derived_secret +from cista.config import derived_secret session_secret = lambda: derived_secret("session") max_age = 60 # Seconds since last login diff --git a/cista/asynclink.py b/cista/util/asynclink.py similarity index 100% rename from cista/asynclink.py rename to cista/util/asynclink.py diff --git a/cista/lrucache.py b/cista/util/lrucache.py similarity index 100% rename from cista/lrucache.py rename to cista/util/lrucache.py diff --git a/cista/pwgen.py b/cista/util/pwgen.py similarity index 100% rename from cista/pwgen.py rename to cista/util/pwgen.py diff --git a/cista/watching.py b/cista/watching.py index 85ab984..02ad054 100755 --- a/cista/watching.py +++ b/cista/watching.py @@ -2,13 +2,12 @@ import asyncio import threading import time from pathlib import Path, PurePosixPath -from socket import timeout import inotify.adapters import msgspec -from . import config -from .protocol import DirEntry, FileEntry, UpdateEntry +from cista import config +from cista.protocol import DirEntry, FileEntry, UpdateEntry pubsub = {} tree = {"": None} diff --git a/tests/test_lrucache.py b/tests/test_lrucache.py index 40ad70c..9903e13 100644 --- a/tests/test_lrucache.py +++ b/tests/test_lrucache.py @@ -3,7 +3,7 @@ from unittest.mock import Mock import pytest -from cista.lrucache import LRUCache # Replace with actual import +from cista.util.lrucache import LRUCache # Replace with actual import def mock_open(key):