From d7500a119172a74aadd1ff46e936d5b71add719b Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 18 May 2016 16:08:27 +0200 Subject: [PATCH] create new platform_posix module move common posix cython code there. --- borg/platform_darwin.pyx | 7 +------ borg/platform_freebsd.pyx | 7 +------ borg/platform_linux.pyx | 8 ++------ borg/platform_posix.pyx | 5 +++++ setup.py | 8 +++++++- 5 files changed, 16 insertions(+), 19 deletions(-) create mode 100644 borg/platform_posix.pyx diff --git a/borg/platform_darwin.pyx b/borg/platform_darwin.pyx index fde6ca0f5..fb94d9c84 100644 --- a/borg/platform_darwin.pyx +++ b/borg/platform_darwin.pyx @@ -1,14 +1,9 @@ import os from .helpers import user2uid, group2gid, safe_decode, safe_encode +from .platform_posix import swidth API_VERSION = 3 -cdef extern from "wchar.h": - cdef int wcswidth(const Py_UNICODE *str, size_t n) - -def swidth(s): - return wcswidth(s, len(s)) - cdef extern from "sys/acl.h": ctypedef struct _acl_t: pass diff --git a/borg/platform_freebsd.pyx b/borg/platform_freebsd.pyx index 0d02cd06c..eae730f49 100644 --- a/borg/platform_freebsd.pyx +++ b/borg/platform_freebsd.pyx @@ -1,5 +1,6 @@ import os from .helpers import posix_acl_use_stored_uid_gid, safe_encode, safe_decode +from .platform_posix import swidth API_VERSION = 3 @@ -7,12 +8,6 @@ cdef extern from "errno.h": int errno int EINVAL -cdef extern from "wchar.h": - cdef int wcswidth(const Py_UNICODE *str, size_t n) - -def swidth(s): - return wcswidth(s, len(s)) - cdef extern from "sys/types.h": int ACL_TYPE_ACCESS int ACL_TYPE_DEFAULT diff --git a/borg/platform_linux.pyx b/borg/platform_linux.pyx index 9a509efdb..142185f3b 100644 --- a/borg/platform_linux.pyx +++ b/borg/platform_linux.pyx @@ -5,16 +5,12 @@ import stat from .helpers import posix_acl_use_stored_uid_gid, user2uid, group2gid, safe_decode, safe_encode from .platform_base import SyncFile as BaseSyncFile +from .platform_posix import swidth + from libc cimport errno API_VERSION = 3 -cdef extern from "wchar.h": - cdef int wcswidth(const Py_UNICODE *str, size_t n) - -def swidth(s): - return wcswidth(s, len(s)) - cdef extern from "sys/types.h": int ACL_TYPE_ACCESS int ACL_TYPE_DEFAULT diff --git a/borg/platform_posix.pyx b/borg/platform_posix.pyx new file mode 100644 index 000000000..f2a8e1773 --- /dev/null +++ b/borg/platform_posix.pyx @@ -0,0 +1,5 @@ +cdef extern from "wchar.h": + cdef int wcswidth(const Py_UNICODE *str, size_t n) + +def swidth(s): + return wcswidth(s, len(s)) diff --git a/setup.py b/setup.py index 741070cc5..a11de388b 100644 --- a/setup.py +++ b/setup.py @@ -40,6 +40,7 @@ compress_source = 'borg/compress.pyx' crypto_source = 'borg/crypto.pyx' chunker_source = 'borg/chunker.pyx' hashindex_source = 'borg/hashindex.pyx' +platform_posix_source = 'borg/platform_posix.pyx' platform_linux_source = 'borg/platform_linux.pyx' platform_darwin_source = 'borg/platform_darwin.pyx' platform_freebsd_source = 'borg/platform_freebsd.pyx' @@ -60,6 +61,7 @@ try: 'borg/crypto.c', 'borg/chunker.c', 'borg/_chunker.c', 'borg/hashindex.c', 'borg/_hashindex.c', + 'borg/platform_posix.c', 'borg/platform_linux.c', 'borg/platform_freebsd.c', 'borg/platform_darwin.c', @@ -75,13 +77,14 @@ except ImportError: crypto_source = crypto_source.replace('.pyx', '.c') chunker_source = chunker_source.replace('.pyx', '.c') hashindex_source = hashindex_source.replace('.pyx', '.c') + platform_posix_source = platform_posix_source.replace('.pyx', '.c') platform_linux_source = platform_linux_source.replace('.pyx', '.c') platform_freebsd_source = platform_freebsd_source.replace('.pyx', '.c') platform_darwin_source = platform_darwin_source.replace('.pyx', '.c') from distutils.command.build_ext import build_ext if not on_rtd and not all(os.path.exists(path) for path in [ compress_source, crypto_source, chunker_source, hashindex_source, - platform_linux_source, platform_freebsd_source]): + platform_posix_source, platform_linux_source, platform_freebsd_source]): raise ImportError('The GIT version of Borg needs Cython. Install Cython or use a released version.') @@ -286,6 +289,9 @@ if not on_rtd: Extension('borg.chunker', [chunker_source]), Extension('borg.hashindex', [hashindex_source]) ] + if sys.platform.startswith(('linux', 'freebsd', 'darwin')): + ext_modules.append(Extension('borg.platform_posix', [platform_posix_source])) + if sys.platform == 'linux': ext_modules.append(Extension('borg.platform_linux', [platform_linux_source], libraries=['acl'])) elif sys.platform.startswith('freebsd'):