1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-06-26 16:45:52 +00:00

Export: Print tracebacks when debugging is enabled

This commit is contained in:
Unrud 2017-07-24 02:09:14 +02:00
parent 6336ffba6e
commit ee79db30e6

View file

@ -30,6 +30,7 @@ import sys
import optparse import optparse
import signal import signal
import threading import threading
import traceback
from wsgiref.simple_server import make_server from wsgiref.simple_server import make_server
from . import ( from . import (
@ -40,7 +41,7 @@ from . import (
# pylint: disable=R0912,R0914 # pylint: disable=R0912,R0914
def export_storage(config, path): def export_storage(config, path, debug=False):
"""Export the storage for Radicale 2.0.0.""" """Export the storage for Radicale 2.0.0."""
import json import json
import shutil import shutil
@ -60,10 +61,12 @@ def export_storage(config, path):
filesystem_path = pathutils.path_to_filesystem( filesystem_path = pathutils.path_to_filesystem(
collection.path, collection.path,
os.path.join(temp, "root", "collection-root")) os.path.join(temp, "root", "collection-root"))
except ValueError: except ValueError as e:
print( print(
"WARNING: Skipping unsafe collection '/%s'" % "WARNING: Skipping unsafe collection %r: %s" %
collection.path) ("/" + collection.path, e))
if debug:
traceback.print_exc()
continue continue
remaining_collections.extend(collection.children(collection.path)) remaining_collections.extend(collection.children(collection.path))
os.makedirs(filesystem_path) os.makedirs(filesystem_path)
@ -76,9 +79,9 @@ def export_storage(config, path):
for component in collection.components: for component in collection.components:
if not pathutils.is_safe_filesystem_path_component( if not pathutils.is_safe_filesystem_path_component(
component.name): component.name):
print( print("WARNING: Skipping unsafe item '%s' from "
"WARNING: Skipping unsafe item '%s' from collection" "collection %r" %
" '/%s'" % (component.name, collection.path)) ("/" + component.name, collection.path))
continue continue
items = [component] items = [component]
if collection.resource_type == "calendar": if collection.resource_type == "calendar":
@ -91,8 +94,10 @@ def export_storage(config, path):
f.write(text.encode("utf-8")) f.write(text.encode("utf-8"))
try: try:
shutil.move(os.path.join(temp, "root"), path) shutil.move(os.path.join(temp, "root"), path)
except OSError as e: except (OSError, shutil.Error) as e:
print("ERROR: Can't create '%s' directory: %s" % (path, e)) print("ERROR: Can't create %r directory: %s" % (path, e))
if debug:
traceback.print_exc()
exit(1) exit(1)
finally: finally:
shutil.rmtree(temp) shutil.rmtree(temp)
@ -159,7 +164,7 @@ def run():
if not configuration_found: if not configuration_found:
print("WARNING: Configuration file '%s' not found" % print("WARNING: Configuration file '%s' not found" %
options.config) options.config)
export_storage(config, options.export_storage) export_storage(config, options.export_storage, debug=options.debug)
exit(0) exit(0)
# Start logging # Start logging