Re: [cgkit-user] Sequences - Pattern for equal name
Brought to you by:
mbaas
|
From: Matthias B. <mat...@gm...> - 2009-12-16 21:49:30
|
Hi Ygor,
> Im new to cgkit and first of all I would like to give my congrats for
> such interesting package.
Thanks!
> 1. Im creating a tool that will archive Shake and Nuke scripts, so Im
> trying to use the sequence module to handle the input files.
> Currently Im not able to use the CopySequence class to copy my files
> keeping the same filename, the only thing I would like to change is
> the path. I really dont need to change the filename, padding pattern
> and so on. Im looking to the same functionality as seqcp.py gives me,
> input sequence and output path. Is there any pattern, scheme or
> anything else that would give me this option?!
If the dstName argument of the CopySequence class refers to a directory,
then the input files will keep their name. I will add this to the docs
(I just noticed that this is not mentioned there).
Here is an example using the OutputNameGenerator class (which is what
the CopySequence class uses to produce source/destination name pairs):
>>> from cgkit.sequence import *
>>> seqs = buildSequences(["spam1_1.tif", "spam1_2.tif", "spam1_5.tif"])
>>> for src,dst in OutputNameGenerator(seqs, "targetdir"):
... print src,"->",dst
...
spam1_1.tif -> targetdir/spam1_1.tif
spam1_2.tif -> targetdir/spam1_2.tif
spam1_5.tif -> targetdir/spam1_5.tif
In this example, "targetdir" must be an existing directory, otherwise it
is interpreted as the new name for the sequence.
But if you never need to rename sequences, then maybe it would be enough
to just use the os.path module to construct the output paths (assuming
you somehow managed to get a list of the source files).
> 2. I will have to match the strings that I get from Shake and Nuke
> with the files themselves. The problem is, I have strings that just
> represents the numbering of the files instead of refering to the
> exact padding on them. IE. shot001.1-230#.iff doesn't gives me any
> hint if it has a three, four or five digit padding.
Does that string come from a Shake script? If so, then the '#' indicates
that it's a 4-padded number.
> Would be the
> 'usual' or 'right' way of matching this by testing the lenght of the
> filepadding with something like len(fileName.split('.')[1])!?
Well, you don't have to use split() to get to the numbers. You could use
the SeqString class (that's basically what the module is for, handling
strings that contain numbers):
>>> s = SeqString("shot001.0017.iff")
>>> s.numCount()
2
(there are 2 numbers in the file name)
>>> s.getNumWidth(-1)
4
(the last number is a 4-padded number)
>>> s.getNum(-1)
17
(the value of the last number is 17)
>>> s.getNumStr(-1)
'0017'
(this is the number as a string, just as it appears in the file name)
Also have a look at the match() method which you could use to check what
sequence a file name belongs to. You could also use the buildSequences()
function or the glob() function (the one in the sequence module, not the
one in the glob module) to create sequences from a directory content and
then just work out which of the sequences file name pattern was
referring to.
I hope that helped.
Cheers,
- Matthias -
|