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

Cosmetics

This commit is contained in:
Guillaume Ayoub 2017-05-26 11:21:06 +02:00
parent 3123d1aa8c
commit c442fce012

View file

@ -41,13 +41,15 @@ from . import (
def export_storage(config, path): def export_storage(config, path):
"""Export the storage for Radicale 2.0.0""" """Export the storage for Radicale 2.0.0."""
import json import json
import shutil import shutil
import tempfile import tempfile
from . import ical, pathutils, storage from . import ical, pathutils, storage
storage.load() storage.load()
print("INFO: Exporting storage for Radicale 2.0.0 to '%s'" % path) print("INFO: Exporting storage for Radicale 2.0.0 to '%s'" % path)
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"))
@ -59,29 +61,33 @@ def export_storage(config, path):
collection.path, collection.path,
os.path.join(temp, "root", "collection-root")) os.path.join(temp, "root", "collection-root"))
except ValueError: except ValueError:
print("WARNING: Skipping unsafe collection '/%s'" % print(
collection.path) "WARNING: Skipping unsafe collection '/%s'" %
collection.path)
continue continue
remaining_collections.extend(collection.children(collection.path)) remaining_collections.extend(collection.children(collection.path))
os.makedirs(filesystem_path) os.makedirs(filesystem_path)
with collection.props as props: with collection.props as props:
if props: if props:
with open(os.path.join(filesystem_path, ".Radicale.props"), props_filename = os.path.join(
"w") as f: filesystem_path, ".Radicale.props")
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:
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 collection" print(
" '/%s'") % (component.name, collection.path)) "WARNING: Skipping unsafe item '%s' from collection"
" '/%s'" % (component.name, collection.path))
continue continue
items = [component] items = [component]
if collection.resource_type == "calendar": if collection.resource_type == "calendar":
items.extend(collection.timezones) items.extend(collection.timezones)
text = ical.serialize( text = ical.serialize(
collection.tag, collection.headers, items) collection.tag, collection.headers, items)
with open(os.path.join(filesystem_path, component.name), component_filename = os.path.join(
"wb") as f: filesystem_path, component.name)
with open(component_filename, "wb") as f:
f.write(text.encode("utf-8")) f.write(text.encode("utf-8"))
try: try:
os.rename(os.path.join(temp, "root"), path) os.rename(os.path.join(temp, "root"), path)