misc.path: add chmod, mkdir, and backup
This commit is contained in:
parent
649507fdaa
commit
944b2be072
|
@ -29,6 +29,8 @@ class SqlDatabase:
|
|||
self.SetupCache()
|
||||
|
||||
|
||||
## Leaving link to example code for read-only sqlite for later use
|
||||
## https://github.com/pudo/dataset/issues/136#issuecomment-128693122
|
||||
def __create_engine(self, dbtype, kwargs):
|
||||
engine_args = []
|
||||
engine_kwargs = {}
|
||||
|
|
|
@ -398,6 +398,10 @@ class Path(object):
|
|||
raise FileExistsError('File or directory already exists:', target.str())
|
||||
|
||||
|
||||
def __parse_perm_octal(self, mode):
|
||||
return mode if type(mode) == oct else eval(f'0o{mode}')
|
||||
|
||||
|
||||
def size(self):
|
||||
return self.__path.stat().st_size
|
||||
|
||||
|
@ -438,6 +442,11 @@ class Path(object):
|
|||
copyfile(self.str(), target.str())
|
||||
|
||||
|
||||
def backup(self, ext='backup', overwrite=False):
|
||||
target = f'{self.__path.parent}.{ext}'
|
||||
self.copy(target, overwrite)
|
||||
|
||||
|
||||
def move(self, path, overwrite=False):
|
||||
self.copy(path, overwrite=overwrite)
|
||||
self.delete()
|
||||
|
@ -517,10 +526,22 @@ class Path(object):
|
|||
return self
|
||||
|
||||
|
||||
def touch(self, mode=0o666):
|
||||
self.__path.touch(mode, self.exist)
|
||||
def chmod(self, mode=None):
|
||||
octal = self.__parse_perm_octal(mode)
|
||||
self.__path.chmod(octal)
|
||||
|
||||
return True if self.__path.exists() else False
|
||||
|
||||
def touch(self, mode=0o666):
|
||||
octal = __parse_perm_octal(mode)
|
||||
self.__path.touch(octal, self.exist)
|
||||
|
||||
return self.exists()
|
||||
|
||||
|
||||
def mkdir(self):
|
||||
self.__path.mkdir(parents=self.parents, exist_ok=self.exist)
|
||||
|
||||
return self.exists()
|
||||
|
||||
|
||||
def load_json(self):
|
||||
|
|
Loading…
Reference in a new issue