Python Traceback:没有错误,但没有来自脚本的输出

时间:2013-12-03 09:41:55

标签: python tar traceback

enter code here我正在将Eclipse与PyDev结合使用并尝试使用简单的脚本:

编辑代码:

import time
import os
import json
import tarfile
source_config='/Users/brendanryan/scripting/brendan.json'
backup_dir = '/myapp/target/'

def main():

        with open(source_config) as f:
                data = json.load(f)
                for entry in data["source_include"]:
                    #base_filename = os.path.basename(entry)
                    #source_dirs = [ name for name in os.listdir(entry) if os.path.isdir(os.path.join(entry, name)) ]
                    full_dir = os.path.join(entry)
                    tar = tarfile.open(os.path.join(backup_dir, '.tar.gzip'), 'w:gz')
                    tar.add(full_dir)
                    tar.close()

if __name__ == '__main__':
        main()

JSON:

{
    "source_type": "folder",
    "tar_type": "gzip",
    "tar_max_age": "10",
    "source_include": ["/myapp/conf", "/myapp/db"],
    "target_path": "/myapp/target"
}

这是支持工作。但它没有。当代码被破坏时,我有各种各样的Tracebacks可以使用...而且我的意思是全部。现在,我只是得到“”......没有错误,没有输出,没有结果.tar.gz,当我运行时没有任何东西。 我愿意尝试任何事情让它立即发挥作用......

对于初学者来说,这应该是读取json(它们是变量)并使用它来选择源文件夹,然后tar.gz它们并将生成的档案放在另一个文件夹中。我不知道该怎么做,但实际上只需要获取“source_include”中的所有文件夹,tar.gz并用当前日期命名它会很棒。那太棒了!

编辑:添加主()...感谢! 因此,通过编辑,现在回溯:

再次编辑:现在,没有追溯。再次。没有输出......

粗言秽语已经消失(Eclipse说现在代码很酷)......但没有输出。 Al all,就像没有reslutant档案一样。回到原点。

2 个答案:

答案 0 :(得分:4)

您实际上似乎根本没有调用main功能。要调用函数,您需要使用括号:main()

(如果你要做的就是打印无用的预制信息,你不应该抓住异常。最好让异常传播,这样你就可以看到实际上出了什么问题。 )

答案 1 :(得分:0)

ValueError: Expecting , delimiter: line 6 column 2 (char 120告诉我你的JSON文件中有错误。

JSON:
{
    "source_type": "folder",
    "tar_type": "gzip",
    "tar_max_age": "10",
    "source_include": ["/myapp/conf", "/myapp/db"], !!!COMMA GOES HERE
    "target_path": "/myapp/target"
}
相关问题