mirror of
https://github.com/altlinux/gpupdate.git
synced 2025-03-21 18:50:38 +03:00
Added the ability to use wildcards for delete files in appliers/file_cp.py
This commit is contained in:
parent
1d31c72946
commit
1f0e417ff1
@ -45,16 +45,23 @@ class Files_cp:
|
||||
self.hidden = str2bool(file_obj.hidden)
|
||||
self.suppress = str2bool(file_obj.suppress)
|
||||
self.username = username
|
||||
self.fromPathFiles = self.get_list_files()
|
||||
if self.fromPath:
|
||||
self.fromPathFiles = self.get_list_files()
|
||||
self.act()
|
||||
|
||||
def get_target_file(self, targetPath, fromPath):
|
||||
def get_target_file(self, targetPath:Path, fromFile:Path) -> Path:
|
||||
try:
|
||||
if fromPath and targetPath.is_dir():
|
||||
if self.hidden:
|
||||
return targetPath.joinpath('.' + fromPath.name)
|
||||
if fromFile:
|
||||
check = set(str(targetPath).split('/')) & set(str(fromFile).split('/'))
|
||||
if len(check) < 2 :
|
||||
targetPath.mkdir(parents = True, exist_ok = True)
|
||||
else:
|
||||
return targetPath.joinpath(fromPath.name)
|
||||
targetPath.parent.mkdir(parents = True, exist_ok = True)
|
||||
targetPath = targetPath.parent
|
||||
if self.hidden:
|
||||
return targetPath.joinpath('.' + fromFile.name)
|
||||
else:
|
||||
return targetPath.joinpath(fromFile.name)
|
||||
|
||||
else:
|
||||
if not self.hidden:
|
||||
@ -73,34 +80,37 @@ class Files_cp:
|
||||
shutil.os.chmod(targetFile, int('664', base = 8))
|
||||
|
||||
def _create_action(self):
|
||||
for fromPath in self.fromPathFiles:
|
||||
for fromFile in self.fromPathFiles:
|
||||
try:
|
||||
targetFile = self.get_target_file(self.targetPath, fromPath)
|
||||
targetFile = self.get_target_file(self.targetPath, fromFile)
|
||||
if not targetFile.exists():
|
||||
targetFile.write_bytes(fromPath.read_bytes())
|
||||
targetFile.write_bytes(fromFile.read_bytes())
|
||||
if self.username:
|
||||
shutil.chown(targetFile, self.username)
|
||||
self.set_read_only(targetFile)
|
||||
except Exception as exc:
|
||||
logdata = dict()
|
||||
logdata['exc'] = exc
|
||||
logdata['fromPath'] = fromPath
|
||||
logdata['fromPath'] = fromFile
|
||||
logdata['targetPath'] = self.targetPath
|
||||
logdata['targetFile'] = targetFile
|
||||
log('D164', logdata)
|
||||
|
||||
def _delete_action(self):
|
||||
targetPathSplit = self.targetPath.split('/')
|
||||
targetPathSplit = str(self.targetPath).split('/')
|
||||
pattern = self.is_pattern(targetPathSplit)
|
||||
list_target = list()
|
||||
tPath = None
|
||||
if not pattern:
|
||||
list_target.append(Path(self.targetPath))
|
||||
list_target.append(self.targetPath)
|
||||
else:
|
||||
tPath = Path(targetPathSplit[:-1])
|
||||
files = [x for x in tPath.iterdir() if x.is_file()]
|
||||
tPath = Path('/'.join(targetPathSplit[:-1]))
|
||||
files = [str(x).split('/')[-1] for x in tPath.iterdir() if x.is_file()]
|
||||
list_target = fnmatch.filter(files, targetPathSplit[-1])
|
||||
|
||||
for targetFile in list_target:
|
||||
if tPath:
|
||||
targetFile = tPath.joinpath(targetFile)
|
||||
try:
|
||||
if targetFile.exists():
|
||||
targetFile.unlink()
|
||||
@ -163,10 +173,11 @@ class Files_cp:
|
||||
logdata['exc'] = exc
|
||||
log('W13', logdata)
|
||||
elif self.fromPath and len(fromPathSplit) > 2:
|
||||
ls_files = self.file_cache.get_ls_smbdir(self.fromPath[:-1])
|
||||
exact_path = '/'.join(fromPathSplit[:-1])
|
||||
ls_files = self.file_cache.get_ls_smbdir(exact_path)
|
||||
filtered_ls_files = fnmatch.filter(ls_files, fromPathSplit[-1])
|
||||
if filtered_ls_files:
|
||||
ls_from_paths = [self.fromPath[:-1] + file_s for file_s in filtered_ls_files]
|
||||
ls_from_paths = [exact_path +'/'+ file_s for file_s in filtered_ls_files]
|
||||
for from_path in ls_from_paths:
|
||||
try:
|
||||
self.file_cache.store(from_path)
|
||||
@ -178,7 +189,7 @@ class Files_cp:
|
||||
log('W13', logdata)
|
||||
else:
|
||||
try:
|
||||
fromLocalPath = Path(self.fromPath[:-1])
|
||||
fromLocalPath = Path(exact_path)
|
||||
if fromLocalPath.is_dir():
|
||||
ls = [fromFile for fromFile in fromLocalPath.iterdir() if fromFile.is_file()]
|
||||
for fromPath in ls:
|
||||
|
Loading…
x
Reference in New Issue
Block a user