from .__version__ import VERSION as __version__
from .constants import *
+from .decorators import *
class Backend(object):
version = __version__
"kinit", "-k", "-t", keytab, principal, **kwargs,
)
- async def exists(self, *args, **kwargs):
+ @run_in_thread
+ def exists(self, *args, **kwargs):
"""
Checks whether a file exists
"""
- return await asyncio.to_thread(os.path.exists, *args, **kwargs)
+ return os.path.exists(*args, **kwargs)
- async def makedirs(self, path, **kwargs):
+ @run_in_thread
+ def makedirs(self, path, **kwargs):
"""
Creates a new directory
"""
- return await asyncio.to_thread(os.makedirs, path, **kwargs)
+ return os.makedirs(path, **kwargs)
+
+ async def make_parent_directory(self, path):
+ """
+ Creates the parent directory of path
+ """
+ path = os.path.dirname(path)
+
+ return await self.makedirs(path, exist_ok=True)
async def copy(self, src, dst, mode=None):
"""
# Set mode
if mode:
- await asyncio.to_thread(os.chmod, dst, mode)
+ await self.chmod(dst, mode)
async def move(self, src, dst, **kwargs):
"""
# Move!
await asyncio.to_thread(shutil.move, src, dst, **kwargs)
- async def make_parent_directory(self, path):
- """
- Creates the parent directory of path
- """
- path = os.path.dirname(path)
-
- return await self.makedirs(path, exist_ok=True)
-
- async def unlink(self, path):
+ @run_in_thread
+ def unlink(self, path):
"""
Unlinks path
"""
log.debug("Unlinking %s" % path)
- await asyncio.to_thread(self._unlink, path)
-
- def _unlink(self, path):
# Unlink the file we were asked to unlink
try:
os.unlink(path)
log.debug(" Cleaned up %s..." % path)
- async def rmtree(self, path):
+ @run_in_thread
+ def rmtree(self, path):
"""
Removes a directory recursively
"""
log.debug("Removing %s..." % path)
try:
- await asyncio.to_thread(shutil.rmtree, path)
+ shutil.rmtree(path)
# Ignore if path didn't exist in the first place
except FileNotFoundError:
pass
- async def chmod(self, *args, **kwargs):
- return await asyncio.to_thread(os.chmod, *args, **kwargs)
+ @run_in_thread
+ def chmod(self, *args, **kwargs):
+ return os.chmod(*args, **kwargs)
def tempfile(self, mode="w+b", sync=False, **kwargs):
"""