[Tutor] "File exists, overwrite?" dialog help
pedro
pedrooconnell at gmail.com
Wed Jul 29 04:44:36 CEST 2009
Hi I am learning python for use in Nuke (image compositing software). I
would like to test if a file exists and receive a warning if it does.
To do a Nuke command line render, it looks something like this:
/Applications/Nuke5.1v5/Nuke5.1v5.app/Contents/MacOS/Nuke5.1v5 -iX
WriteComp '/Volumes/sgtb/comp_v05.nk'
Where "WriteComp" is the name of a write node within the nuke script
'/Volumes/sgtb/comp_v05.nk'.
The problem with the above command line command is that it overwrites
the files that "WriteComp" points to without warning me. So what I
would like to do is have the command line (or python) ask "File exists,
overwrite?" Below I have some code which tests whether the file already
exists by parsing the Nuke script. It is working fine. I am not sure
how to combine the script below with the command line command above so
that the above command won't be executed unless I am first asked "File
exists, overwrite?"
#################start
import re, linecache, shutil, sys, os
theFile = (sys.argv[1])
lines = theFile.readlines()
theFile.close()
pattern = re.compile(' name WriteComp')
for i, line in enumerate(lines):
if pattern.search(line):
theWriteFilePath = linecache.getline(theFile.name, i-1)
#nukeFilePathAsString =
nukeFilePathContainerAsString =
'/'.join((theWriteFilePath.split()[1]).split('/')[:-1])
nukeImageAsString = '/'.join((theWriteFilePath.split()[1]).split('/')[-1:])
nukeImageWithZeroesAsString = nukeImageAsString.split('.')[0] +
'.0001.' + nukeImageAsString.split('.')[2]
thePythonFriendlyFilePath = nukeFilePathContainerAsString + '/'+
nukeImageWithZeroesAsString
#print thePythonFriendlyFilePath
if os.path.exists(thePythonFriendlyFilePath):
print 'yes'
#########################end
Thanks
Pete
More information about the Tutor
mailing list