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.")
|
temp = tempfile.mkdtemp(prefix="Radicale.export.")
|
||||||
try:
|
try:
|
||||||
os.mkdir(os.path.join(temp, "root"))
|
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:
|
while remaining_collections:
|
||||||
collection = remaining_collections.pop(0)
|
collection = remaining_collections.pop(0)
|
||||||
|
try:
|
||||||
try:
|
try:
|
||||||
filesystem_path = pathutils.path_to_filesystem(
|
filesystem_path = pathutils.path_to_filesystem(
|
||||||
collection.path,
|
collection.path,
|
||||||
|
@ -68,7 +77,15 @@ def export_storage(config, path, debug=False):
|
||||||
if debug:
|
if debug:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
continue
|
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)
|
os.makedirs(filesystem_path)
|
||||||
with collection.props as props:
|
with collection.props as props:
|
||||||
if props:
|
if props:
|
||||||
|
@ -77,6 +94,7 @@ def export_storage(config, path, debug=False):
|
||||||
with open(props_filename, "w") as f:
|
with open(props_filename, "w") as f:
|
||||||
json.dump(props, f)
|
json.dump(props, f)
|
||||||
for component in collection.components:
|
for component in collection.components:
|
||||||
|
try:
|
||||||
if not pathutils.is_safe_filesystem_path_component(
|
if not pathutils.is_safe_filesystem_path_component(
|
||||||
component.name):
|
component.name):
|
||||||
print("WARNING: Skipping unsafe item '%s' from "
|
print("WARNING: Skipping unsafe item '%s' from "
|
||||||
|
@ -92,6 +110,19 @@ def export_storage(config, path, debug=False):
|
||||||
filesystem_path, component.name)
|
filesystem_path, component.name)
|
||||||
with open(component_filename, "wb") as f:
|
with open(component_filename, "wb") as f:
|
||||||
f.write(text.encode("utf-8"))
|
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:
|
try:
|
||||||
shutil.move(os.path.join(temp, "root"), path)
|
shutil.move(os.path.join(temp, "root"), path)
|
||||||
except (OSError, shutil.Error) as e:
|
except (OSError, shutil.Error) as e:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue