【问题标题】:Re-write write-protected file重写写保护文件
【发布时间】:2016-06-29 13:04:21
【问题描述】:

如果需要,文件每 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 命令中添加一些东西来覆盖写保护文件吗?

【问题讨论】:

  • 你明白写保护是什么意思吗?
  • 是的。我知道这并不是最好的设置。关于如何解决这个问题的任何建议?
  • 去掉写保护以后再放回去。
  • 如何在我的 shell 命令中删除它?谢谢!

标签: python linux bash snakemake


【解决方案1】:

看一下os标准库包:

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

它允许 chmod,但有以下警告:

虽然 Windows 支持 chmod(),但您只能使用它设置文件的只读标志(通过 stat.S_IWRITEstat.S_IREAD 常量或相应的整数值)。所有其他位都被忽略。

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

检查原始文件权限
ls -l [your file name]

stat -c %a [your file name]

将保护更改为 with

chmod 777 [your file name]

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

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

【讨论】:

  • 谢谢。 linux shell命令有没有等价的命令?
  • 谢谢@ivan7707 我最初确实要求python,你是对的。但是在改变了一些事情之后,我最终在 bash 脚本中需要它。
猜你喜欢
  • 1970-01-01
  • 2014-05-17
  • 2020-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-02
  • 1970-01-01
相关资源
最近更新 更多