add read-only mode
This commit is contained in:
parent
b08619d9e5
commit
e279cfe6c3
|
@ -1,4 +1,4 @@
|
|||
FROM ubuntu:disco AS main
|
||||
FROM ubuntu:focal AS main
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y python3-pip && \
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import sys
|
||||
import json
|
||||
import logging
|
||||
import cherrypy
|
||||
|
@ -134,10 +135,11 @@ class ClientCache(object):
|
|||
|
||||
|
||||
class MediaWeb(object):
|
||||
def __init__(self, cache, templater, options):
|
||||
def __init__(self, cache, templater, options, readonly=False):
|
||||
self.tpl = templater
|
||||
self.cache = cache
|
||||
self.options = options
|
||||
self.readonly = readonly
|
||||
|
||||
def render(self, template, **kwargs):
|
||||
"""
|
||||
|
@ -148,6 +150,7 @@ class MediaWeb(object):
|
|||
moves=self.cache.moves,
|
||||
shows=self.cache.data.shows,
|
||||
user=cherrypy.request.login,
|
||||
argv=sys.argv,
|
||||
**kwargs,
|
||||
**self.get_default_vars())
|
||||
|
||||
|
@ -174,7 +177,9 @@ class MediaWeb(object):
|
|||
if cherrypy.request.method == "POST" and (dest or otherdest): # TODO maybe support otherdest list per client
|
||||
target = os.path.join(client.pathmap[0],
|
||||
otherdest or dest)
|
||||
client.rpc.core.move_storage([thash], target)
|
||||
logging.info("rpc: moving %s to %s", thash, target)
|
||||
if not self.readonly:
|
||||
client.rpc.core.move_storage([thash], target)
|
||||
self.cache.refresh()
|
||||
raise cherrypy.HTTPRedirect("/home")
|
||||
|
||||
|
@ -236,19 +241,27 @@ class MediaWeb(object):
|
|||
# hard link into library
|
||||
showdir = os.path.dirname(local_library_path)
|
||||
if not os.path.exists(showdir):
|
||||
os.makedirs(showdir)
|
||||
os.link(local_torrent_path, local_library_path)
|
||||
logging.info("creating %s", showdir)
|
||||
if not self.readonly:
|
||||
os.makedirs(showdir)
|
||||
|
||||
logging.info("linking %s -> %s", local_torrent_path, local_library_path)
|
||||
if not self.readonly:
|
||||
os.link(local_torrent_path, local_library_path)
|
||||
|
||||
client_stashdir = os.path.join(pmap[0],
|
||||
self.options["stashprefix"],
|
||||
get_mapped_stashdir(self.options["trackermap"], torrent["trackers"]))
|
||||
|
||||
# move deluge path to stash dir
|
||||
client.rpc.core.move_storage([torrent["hash"]], client_stashdir)
|
||||
logging.info("rpc: moving %s to stash dir %s", torrent["hash"], client_stashdir)
|
||||
if not self.readonly:
|
||||
client.rpc.core.move_storage([torrent["hash"]], client_stashdir)
|
||||
|
||||
# label torrent as sorted
|
||||
client.rpc.label.set_torrent(torrent["hash"], self.options["label_done"])
|
||||
logging.info("rpc: labeling %s as %s", torrent["hash"], self.options["label_done"])
|
||||
if not self.readonly:
|
||||
client.rpc.label.set_torrent(torrent["hash"], self.options["label_done"])
|
||||
|
||||
return result, None
|
||||
|
||||
|
@ -329,6 +342,7 @@ def main():
|
|||
|
||||
parser = argparse.ArgumentParser(description="mediaweb server")
|
||||
parser.add_argument("-c", "--config", required=True, help="config file path")
|
||||
parser.add_argument("--readonly", action="store_true", help="run in read-only mode")
|
||||
parser.add_argument('--debug', action="store_true", help="enable development options")
|
||||
args = parser.parse_args()
|
||||
|
||||
|
@ -345,7 +359,7 @@ def main():
|
|||
"stashprefix": cfg["stashprefix"],
|
||||
"trackermap": cfg["trackermap"],
|
||||
"label": cfg["label"],
|
||||
"label_done": cfg["label_done"]
|
||||
"label_done": cfg["label_done"],
|
||||
}
|
||||
|
||||
tpl_dir = os.path.join(APPROOT, "templates")
|
||||
|
@ -367,7 +381,7 @@ def main():
|
|||
rpc_cache.add_client(DelugeRPCClient(uri.hostname, port, uri.username, uri.password, decode_utf8=True),
|
||||
tuple(client["pathmap"]))
|
||||
|
||||
web = MediaWeb(rpc_cache, tpl, options)
|
||||
web = MediaWeb(rpc_cache, tpl, options, args.readonly)
|
||||
cherrypy.tree.mount(web, '/', {'/': {'tools.auth_basic.on': True,
|
||||
'tools.auth_basic.realm': 'mediaweb',
|
||||
'tools.auth_basic.checkpassword': validate_password, },
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
backports.functools-lru-cache==1.5
|
||||
certifi==2019.6.16
|
||||
cheroot==6.5.5
|
||||
CherryPy==18.1.2
|
||||
deluge-client==1.7.1
|
||||
fuzzywuzzy==0.17.0
|
||||
jaraco.functools==2.0
|
||||
Jinja2==2.10.1
|
||||
MarkupSafe==1.1.1
|
||||
more-itertools==7.2.0
|
||||
portend==2.5
|
||||
pytz==2019.2
|
||||
sentry-sdk==0.7.9
|
||||
six==1.12.0
|
||||
tempora==1.14.1
|
||||
urllib3==1.25.3
|
||||
certifi==2021.5.30
|
||||
cheroot==8.5.2
|
||||
CherryPy==18.6.1
|
||||
deluge-client==1.9.0
|
||||
fuzzywuzzy==0.18.0
|
||||
jaraco.classes==3.2.1
|
||||
jaraco.collections==3.4.0
|
||||
jaraco.functools==3.3.0
|
||||
jaraco.text==3.5.1
|
||||
Jinja2==3.0.1
|
||||
MarkupSafe==2.0.1
|
||||
more-itertools==8.9.0
|
||||
portend==2.7.1
|
||||
pytz==2021.1
|
||||
sentry-sdk==1.3.1
|
||||
six==1.16.0
|
||||
tempora==4.1.1
|
||||
urllib3==1.26.6
|
||||
zc.lockfile==2.0
|
||||
|
|
|
@ -6,4 +6,5 @@
|
|||
<link type="text/css" rel="stylesheet" href="/static/styles.css" media="all" />
|
||||
</head>
|
||||
{% block body %}{% endblock %}
|
||||
<!-- {{ argv|join(' ') }} -->
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue