Error when moving files without parent folders

This will check if file ends with a know video extension, if so
use os.makedirs to create a folder at destination and update rsync
destination with this folder.
This commit is contained in:
2023-08-22 20:21:26 +02:00
parent 7dcbd60de4
commit 12f6d1bf3f
2 changed files with 19 additions and 3 deletions

View File

@@ -12,7 +12,7 @@ except Exception:
sys.exit(1)
from logger import logger
from utils import getConfig, readAvgSpeedFromDisk, writeAvgSpeedToDisk
from utils import getConfig, readAvgSpeedFromDisk, writeAvgSpeedToDisk, VIDEO_EXTENSIONS
ESTIMATED_TRANSFER_SPEED=readAvgSpeedFromDisk()
TRANSFER_SPEED_UNIT="Mb/s"
@@ -118,8 +118,16 @@ def transferFiles(files, localPath, remotePath, host=None, user=None):
file = os.path.join(remotePath, file)
spaceEscapedFile = file.replace(' ', '\\ ')
# check if file is folder-less, if so create folder and update localPath
folderedLocalPath = None
filename, fileExtension = os.path.splitext(file)
if fileExtension in VIDEO_EXTENSIONS:
folderedLocalPath = os.path.join(localPath, filename)
os.makedirs(folderedLocalPath)
# Build rsync command
if host and user:
cmd = "rsync -rz {}@{}:'{}' '{}'".format(user, host, spaceEscapedFile, localPath)
cmd = "rsync -rz {}@{}:'{}' '{}'".format(user, host, spaceEscapedFile, folderedLocalPath or localPath)
else:
cmd = "rsync -rz '{}' '{}'".format(spaceEscapedFile, localPath)