检查视网膜图像文件丢失

时间:2012-06-26 22:46:50

标签: iphone

我们有一个包含大量图像和视网膜图像的项目。 有没有一种简单的方法或工具来检查每个图像是否有相关的视网膜图像文件? 我希望它可以是一个软件工具或一个简单的脚本,可以告诉我错过了哪个视网膜文件

欢迎任何评论

1 个答案:

答案 0 :(得分:1)

你可以尝试这个python脚本。请注意,它假定@ 2x图像与非视网膜版本位于同一目录中。如果将视网膜和标准图像保存在不同的文件夹中,则无法使用。它会按原样处理包含.png.jpg扩展名的文件,但可以轻松添加更多文件。

这使用* nix find命令递归获取当前工作目录中每个文件的路径。我是一个python新手,所以欢迎任何评论/修复/改进!

您可以手动运行,也可以在xcode的预编译钩子中使用它。它返回没有@ 2x版本的文件的路径。

from subprocess import check_output
from os import path
import string

# Get all the files in the current working dir, recursively
files_raw = check_output(["find","-type","f"]) 
paths = files_raw.split("\n")

# Remove the empty last element (find command ends with a newline) 
paths.pop()

for item in paths:
    # Ignore any @2x items
    if("@2x" in item):
        continue

    # Break up the path
    filename, extension = path.splitext(item)

    # Ignore files without these extensions
    if(extension not in [".png", ".jpg"]):
        continue

    # Make the rentina path and see if it's in the list of paths
    retina = filename+"@2x"+extension
    if(retina not in paths):
        print item

例如,对于此文件夹:

.:
    file.txt
    john.png
    test@2x.png
    test.png    

./more:
    cool_image.jpg
    john@2x.png
    file.png

./other:
    [empty]

跑步(在终点站):

cd /home/stecman/test-dir
python /home/stecman/missing-retina.py

输出

./john.png
./more/cool_image.jpg
./more/file.png