sync update: + data provider; refactoring; documents update
This commit is contained in:
1 parent
144e69e6c4
commit
927674e53e
9 files changed
+311
-229
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import os
|
||||
|
||||
|
||||
class Provider:
|
||||
def __init__(self, root):
|
||||
super().__init__()
|
||||
self.root = root
|
||||
|
||||
def open(self, path, mode):
|
||||
return ''
|
||||
|
||||
def scan(self, path):
|
||||
return []
|
||||
|
||||
def glob(self, pattr):
|
||||
return []
|
||||
|
||||
def copy(self, path, out):
|
||||
pass
|
||||
|
||||
def hash(self, path):
|
||||
return None
|
||||
|
||||
def size(self, path):
|
||||
return 0
|
||||
|
||||
def get_abs(self, path):
|
||||
abs = os.path.join(self.root, path)
|
||||
return os.path.normpath(abs)
|
||||
|
||||
def get_rel(self, path):
|
||||
return os.path.relpath(path, self.root)
|
||||
@@ -0,0 +1,30 @@
|
||||
import os
|
||||
from glob import glob
|
||||
|
||||
from shutil import copyfile
|
||||
|
||||
from sync.data import Provider
|
||||
from utils.hash import hash_file
|
||||
|
||||
|
||||
class FSProvider(Provider):
|
||||
def open(self, path, mode):
|
||||
return open(self.get_abs(path), mode)
|
||||
|
||||
def scan(self, path):
|
||||
return os.scandir(self.get_abs(path))
|
||||
|
||||
def glob(self, pattr):
|
||||
return glob(self.get_abs(pattr))
|
||||
|
||||
def hash(self, path):
|
||||
return hash_file(self.get_abs(path))
|
||||
|
||||
def copy(self, path, out):
|
||||
file = self.get_abs(path)
|
||||
return copyfile(file, out)
|
||||
|
||||
def size(self, path):
|
||||
file = self.get_abs(path)
|
||||
return os.path.getsize(file)
|
||||
|
||||
Reference in new issue
Block a user