mirror of
https://github.com/Kozea/Radicale.git
synced 2025-06-26 16:45:52 +00:00
Export: Print invalid collection and component
This commit is contained in:
parent
ee79db30e6
commit
4a0964529f
1 changed files with 64 additions and 33 deletions
|
@ -54,9 +54,18 @@ def export_storage(config, path, debug=False):
|
|||
temp = tempfile.mkdtemp(prefix="Radicale.export.")
|
||||
try:
|
||||
os.mkdir(os.path.join(temp, "root"))
|
||||
remaining_collections = list(ical.Collection.from_path("/", depth="0"))
|
||||
try:
|
||||
remaining_collections = list(
|
||||
ical.Collection.from_path("/", depth="0"))
|
||||
except Exception as e:
|
||||
print("ERROR: Failed to find child collections of %r: %s" %
|
||||
("/", e))
|
||||
if debug:
|
||||
traceback.print_exc()
|
||||
exit(1)
|
||||
while remaining_collections:
|
||||
collection = remaining_collections.pop(0)
|
||||
try:
|
||||
try:
|
||||
filesystem_path = pathutils.path_to_filesystem(
|
||||
collection.path,
|
||||
|
@ -68,7 +77,15 @@ def export_storage(config, path, debug=False):
|
|||
if debug:
|
||||
traceback.print_exc()
|
||||
continue
|
||||
remaining_collections.extend(collection.children(collection.path))
|
||||
try:
|
||||
remaining_collections.extend(collection.children(
|
||||
collection.path))
|
||||
except Exception as e:
|
||||
print("ERROR: Failed to find child collections of %r: %s" %
|
||||
("/", e))
|
||||
if debug:
|
||||
traceback.print_exc()
|
||||
exit(1)
|
||||
os.makedirs(filesystem_path)
|
||||
with collection.props as props:
|
||||
if props:
|
||||
|
@ -77,6 +94,7 @@ def export_storage(config, path, debug=False):
|
|||
with open(props_filename, "w") as f:
|
||||
json.dump(props, f)
|
||||
for component in collection.components:
|
||||
try:
|
||||
if not pathutils.is_safe_filesystem_path_component(
|
||||
component.name):
|
||||
print("WARNING: Skipping unsafe item '%s' from "
|
||||
|
@ -92,6 +110,19 @@ def export_storage(config, path, debug=False):
|
|||
filesystem_path, component.name)
|
||||
with open(component_filename, "wb") as f:
|
||||
f.write(text.encode("utf-8"))
|
||||
except Exception as e:
|
||||
print("ERROR: Failed to export component %r from "
|
||||
"collection %r: %s" %
|
||||
(component.name, "/" + collection.path, e))
|
||||
if debug:
|
||||
traceback.print_exc()
|
||||
exit(1)
|
||||
except Exception as e:
|
||||
print("ERROR: Failed to export collection %r: %s" %
|
||||
("/" + collection.path, e))
|
||||
if debug:
|
||||
traceback.print_exc()
|
||||
exit(1)
|
||||
try:
|
||||
shutil.move(os.path.join(temp, "root"), path)
|
||||
except (OSError, shutil.Error) as e:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue