Skip to content
Advertisement

Re-write write-protected file

Every 4 hours files are updated with new information if needed – i.e. if any new information has been processed for that particular file (files correspond to people).

I’m running this command to convert my .stp files (those being updated every 4 hours) to .xml files.

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}
        '''

My script is in Snakemake (python based) but I’m running the convert.exe through a shell command.

I’m getting an error on the ones already processed using convert.exe. They are saved by convert.exe as write-protected and there is no option to bypass this within the executable itself.

Error Message:

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

I’d still like them to be write-protected but would also like to be able to update them as needed.

Is there something I can add to my shell command to write over the write protected files?

Advertisement

Answer

take a look at the os standard library package:

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

It allows for chmod with the following caveat:

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, I thought you wanted it in python. Try this:

Check the original file permission with

ls -l [your file name]

stat -c %a [your file name]

Change the protection to with

chmod 777 [your file name]

change back to original file mode or whatever mode you want

chmod [original file protection mode] [your file name]
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement