重写写保护文件

Re-write write-protected file

如果需要,每 4 小时使用新信息更新文件 - 即是否已为该特定文件处理任何新信息(文件对应于人)。

我正在 运行 此命令将我的 .stp 文件(每 4 小时更新一次)转换为 .xml 文件。

rule convert_waveform_stp:
    input:  '/data01/stpfiles/{file}.Stp'
    output: '/data01/workspace/bm_data/xmlfiles/{file}.xml'
    shell:
        '''
        mono /data01/workspace/bm_software/convert.exe {input} -o {output}
        '''

我的脚本在 Snakemake 中(基于 python),但我通过 shell 命令 运行 convert.exe

我在已经使用 convert.exe 处理过的文件上收到错误消息。它们被 convert.exe 保存为写保护,并且没有选项可以在可执行文件本身中绕过它。

错误信息:

ProtectedOutputException in line 14 of /home/Snakefile:
Write-protected output files for rule convert_waveform_stp:
/data01/workspace/bm_data/xmlfiles/PID_1234567.xml

我仍然希望它们被写保护,但也希望能够根据需要更新它们。

我可以在我的 shell 命令中添加一些东西来覆盖写保护的文件吗?

看看os标准库包:

https://docs.python.org/3.5/library/os.html?highlight=chmod#os.chmod

它允许 chmod,但需要注意以下事项:

Although Windows supports chmod(), you can only set the file’s read-only flag with it (via the stat.S_IWRITE and stat.S_IREAD constants or a corresponding integer value). All other bits are ignored.

@VickiT05,我以为你想要它 python。试试这个:

检查原始文件权限

ls -l [your file name]

stat -c %a [your file name]

将保护更改为

chmod 777 [your file name]

改回原始文件模式或您想要的任何模式

chmod [original file protection mode] [your file name]