2

设置:Synology 与 Docker 运行 Home-Assistant 与 HACS 集成和 pyscript。

我做了以下两个功能:

@service

def getListOfFiles(dirName):
    import os
    # create a list of file and sub directories 
    # names in the given directory
    listOfFile = os.listdir(dirName)
    allFiles = list()
    # Iterate over all the entries
    for entry in listOfFile:
        # Create full path
        fullPath = os.path.join(dirName, entry)
        # If entry is a directory then get the list of files in this directory 
        if os.path.isdir(fullPath):
            allFiles = allFiles + getListOfFiles(fullPath)
        else:
            if fullPath.endswith('jpg'):
                allFiles.append(fullPath)
            elif fullPath.endswith('jpeg'):
                allFiles.append(fullPath)
            elif fullPath.endswith('png'):
                allFiles.append(fullPath)
    return allFiles

@service
def slideshow():
    import random
    import os
    import shutil
    path = '/Slideshow'
    listOfFiles = getListOfFiles(path)
    random_image = random.choice([x for x in listOfFiles])
    image_path = '{}'.format(random_image)
    shutil.copy2(image_path, '/config/www/slide.jpg')

现在一切正常,但目标文件 (slide.jpg) 的大小永远不会正确。它在 10kB - 1000kB 之间变化,而原始图像通常在 7-10 MB 之间。

有什么建议么?

在 Mac 上运行相同的代码(当然,具有不同的源和目标)可以完美运行。

使用 .copyfile 和 .copy 的结果相同

4

1 回答 1

0

所以经过大量的挖掘,问题被发现了。Synology 会创建一个目录:/@eaDir/为每个带有 S、M、L 缩略图的文件创建一个目录,结果证明这是根本原因。这(有时)是正在传输的文件,而不是假定的图像,因此尺寸较小。

于 2021-11-03T13:30:26.007 回答