Fix compatibility between python2 and 3
This commit is contained in:
@ -36,7 +36,7 @@ FILESYSTEM_ENCODING = sys.getfilesystemencoding()
|
||||
|
||||
try:
|
||||
from dulwich.repo import Repo
|
||||
GIT_REPOSITORY = Repo(FOLDER).encode(FILESYSTEM_ENCODING)
|
||||
GIT_REPOSITORY = Repo(FOLDER)
|
||||
except:
|
||||
GIT_REPOSITORY = None
|
||||
|
||||
@ -53,7 +53,7 @@ def open(path, mode="r"):
|
||||
# On exit
|
||||
if GIT_REPOSITORY and mode == "w":
|
||||
path = os.path.relpath(abs_path, FOLDER)
|
||||
GIT_REPOSITORY.stage([path.encode(FILESYSTEM_ENCODING)])
|
||||
GIT_REPOSITORY.stage([path])
|
||||
committer = config.get("git", "committer")
|
||||
GIT_REPOSITORY.do_commit("Commit by Radicale", committer=committer)
|
||||
# pylint: enable=W0622
|
||||
|
@ -25,6 +25,7 @@ Multi files per calendar filesystem storage backend.
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
import sys
|
||||
|
||||
from . import filesystem
|
||||
from .. import ical
|
||||
@ -50,7 +51,10 @@ class Collection(filesystem.Collection):
|
||||
components = [i for i in items if isinstance(i, ical.Component)]
|
||||
for component in components:
|
||||
text = ical.serialize(self.tag, headers, [component] + timezones)
|
||||
path = os.path.join(self._path, component.name)
|
||||
name = (
|
||||
component.name if sys.version_info[0] >= 3 else
|
||||
component.name.encode(filesystem.FILESYSTEM_ENCODING))
|
||||
path = os.path.join(self._path, name)
|
||||
with filesystem.open(path, "w") as fd:
|
||||
fd.write(text)
|
||||
|
||||
|
Reference in New Issue
Block a user