From: Greg Ercolano <erco@(email surpressed)> Subject: [Q+A] Nuke cross platform pathnames Date: Tue, 22 Jun 2010 19:39:33 -0400 |
Msg# 1943 View Complete Thread (4 articles) | All Threads Last Next |
> When I submit a Nuke scene file created on a Mac, the artist > has to change the path within nuke from /myserver/share to //myserver/share > in order for the render to be successful on both Mac and Windows machines. > We are using the FixPath() function in the rushscripts/.common.pl > but that doesn't seem to affect pathnames within the Nuke scripts. > > Is there a way to configure Nuke to make these changes automatically? Yes; short answer is to see Nuke's own 'customizing' documentation on handling file paths across platforms. I'm almost sure the nuke documenation is wrong with respect to those backslashes, ie: "p:\" probably needs to be e.g. "p:\\". But you can probably use front slashes and avoid the whole 'backslash as an escape character' problem, which is typical in just about all languages including python, perl, C, Java, and all the shells. |
From: Robert Minsk <rminsk@(email surpressed)> Subject: Re: [Q+A] Nuke cross platform pathnames Date: Wed, 30 Jun 2010 18:01:55 -0400 |
Msg# 1946 View Complete Thread (4 articles) | All Threads Last Next |
Greg Ercolano wrote: > Yes; short answer is to see Nuke's own 'customizing' documentation > on handling file paths across platforms. More specifically you will need to define a python function that takes a filename as an argument a returns a new filename. You then need to install it as a FilenameFilter callback (nuke.addFilenameFilter) in your sites init.py file. |
From: Greg Ercolano <erco@(email surpressed)> Subject: Re: [Q+A] Nuke cross platform pathnames Date: Wed, 30 Jun 2010 18:45:30 -0400 |
Msg# 1947 View Complete Thread (4 articles) | All Threads Last Next |
Robert Minsk wrote: > [posted to rush.general] > > Greg Ercolano wrote: >> Yes; short answer is to see Nuke's own 'customizing' documentation >> on handling file paths across platforms. > > More specifically you will need to define a python function that takes a > filename as an argument a returns a new filename. You then need to install it > as a FilenameFilter callback (nuke.addFilenameFilter) in your sites init.py file. Right; I believe the "Nuke-5.1v6-customizing.pdf" documentation cites this exact example [sic]: ---- def filenameFix(filename): if platform.system() in ("Windows", "Microsoft"): return filename.replace("/SharedDisk/", "p:\") else: return filename.replace("p:\", "/SharedDisk/") return filename ---- ..which appears to show how to replace e.g. "/SharedDisk/foo" <-> "p:\foo" depending on the platform it's running on. However, there's a few things wrong with that example I think; that backslash after the "p:" needs to be protected, otherwise python will interpret it as an escape character. Also, that final 'return filename' appears to be extraneous, as there's no way that line will ever execute. So I would suggest the following instead: ---- def filenameFix(filename): if platform.system() in ("Windows", "Microsoft"): return filename.replace("/SharedDisk/", "p:\\") else: return filename.replace("p:\\", "/SharedDisk/") ---- Another way to protect the backslashes would be to use: r"p:\" # same as "p:\\" This is pythons little way of protecting all characters between the double quotes, the leading 'r' in front of the leading double quote means "raw string", protecting the backslash from being mistaken for an escape sequence. An example that worked for a recent client who wanted to make sure UNC style pathnames were used on windows, (eg. "/bart/foo" would become "//bart/foo" on windows machines), I suggested they use: ---- import re import platform def filenameFix(filename): if platform.system() in ("Windows", "Microsoft"): return re.sub("^/*bart","//bart",filename) else: return re.sub("^/*bart","/bart",filename) ---- ..the special regex ensuring that e.g. //bart doesn't become ///bart -- Greg Ercolano, erco@(email surpressed) Seriss Corporation Rush Render Queue, http://seriss.com/rush/ Tel: (Tel# suppressed) Fax: (Tel# suppressed) Cel: (Tel# suppressed) |
From: Greg Ercolano <erco@(email surpressed)> Subject: Re: [Q+A] Nuke cross platform pathnames Date: Thu, 01 Jul 2010 14:08:00 -0400 |
Msg# 1948 View Complete Thread (4 articles) | All Threads Last Next |
Greg Ercolano wrote: > Another way to protect the backslashes would be to use: > > r"p:\" # same as "p:\\" Meh, that 'r' technique only works *if* the backslash is not at the end of the string. Since that *is* the case here, r"p:\" won't work.. you'd *have* to use "p:\\". Of course, using front slashes bypasses all this. Front slashes work fine in this context, as the Windows kernel internally understands fronts (/) and backs (\) equally well in pathnames. It's only DOS commands, and some of Microsoft's browsers that have trouble with fronts, but that's due to the design of just those Microsoft applications, and not the OS itself. -- Greg Ercolano, erco@(email surpressed) Seriss Corporation Rush Render Queue, http://seriss.com/rush/ Tel: (Tel# suppressed) Fax: (Tel# suppressed) Cel: (Tel# suppressed) |