SeqString does not try and determine if the numbers it is parsing from the string are actually negative or not. It always assumes a positive number. Obviously you could manually go and set certain indexes in the SeqString instance to an explicit negative, but this seems like a lot of extra parsing the user would have to do to know they have a negative frame.
from cgkit.sequence import *
s1 = SeqString('show500_seq-50_shot_200_v1_720p.-003.tif')
s1.getNums()
# [500, 50, 200, 1, 720, 3]
s2 = SeqString('show500_seq-50_shot_200_v1_720p.0003.tif')
print s1 < s2 # should be True
# False
My patch proposes adding an optional "numDelim" attribute to the constructor which lets you specify a set of delimiter characters to designative when a number like a frame would separated.
Example:
s1 = SeqString('show500_seq-50_shot_200_v1_720p.-003.tif', numDelim='.')
s1.getNums()
# [500, 50, 200, 1, 720, -3]
s2 = SeqString('show500_seq-50_shot_200_v1_720p.0003.tif', numDelim='.')
s2.getNums()
# [500, 50, 200, 1, 720, 3]
print s1 < s2
# True
# numDelims could be a character set like '._-' :
SeqString('show500_seq-50_shot_-200_v1_720p.-003.tif', numDelim='._').getNums()
[500, 50, -200, 1, 720, -3]
glob and buildSequences were also updated to pass this flag along...
>>> sequence.glob("/path/to/images/006_00_02.#.iff", numDelim='.')
[<Sequence /path/to/images//006_00_02.#.iff (-40-40)>]
patch for cgkit.sequence
Sorry for the late response (I was too busy when you posted it and then the mail moved out of sight in my inbox...).
Thanks for the patch, but I have some concerns whether this numDelim argument is really the best way to implement it. The name of the argument doesn't tell the user that this argument will turn the numbers into signed numbers. The name only seems to suggest how numbers are recognized in the first place. But would this mean that if a number is *not* preceded by one of the delimiters that it then should be treated as a string instead? Another problem is that it wouldn't be straightforward turning the sequence number in your example into a signed number as well. You would have to specify all characters as delimiters.
How about an option "signedNums" that tells the class it should treat numbers as signed numbers. The option could either be a boolean which means it applies to all numbers found or it could be a list of integers specifying the indices of the numbers that should be treated as signed numbers (also allowing negative indices).
So in your example, assuming the frame number is always the last number, you could convert the string like this:
s1 = SeqString('show500_seq-50_shot_200_v1_720p.-003.tif', signedNums=[-1])
By the way, I have to say that your file name naming conventions are quite unfortunate. The '-' character is used both as a hyphen and a minus sign. If you would use an underscore for the sequence number, you wouldn't even have to specify an index and could just treat all numbers as signed numbers.
Would this positional approach work in your case? Or are there other numbers you need to process as signed numbers and the position within the file name can change?
- Matthias -
View and moderate all "patches Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Patches"
Thanks for the comment. My reasoning for this approach was to provide a more generic application. I did not want to always assume a signed number could occur at the end, or that the user would need to know the exact indexes of the signed numbers. I felt the most useful approach would to be to simply specify the delimiter patterns representing the users naming conventions.
That example is actually not our own naming convention. I realize there i a mixture of hyphen/negative and it was purely to show an extreme. I don't want to presume to know what anyone's naming conventions might be. Only that they would have naming conventions and could easily pass the pattern along.
I have worked at a major studio before that had a naming convention which allowed for arbitrary extra 'underscore-separated descriptors at the end of the main string, just before the frame component. With that being the case, it would require more work to have to track number components by index. The simpler approach is to just define the separators once. But maybe I am just thinking too general about this.
Last edit: Anonymous 2014-09-09
Sorry again for the delay, I thought I would get a notification email if someone adds a comment, but obviously that's not the case....
Well, I can see where you are coming from and your patch works nicely in the example you were giving, but I think the semantics of the proposal are not really consistent which is why I'm hesitant to add it. In addition to the concerns mentioned in my previous comment, there is also the inconsistency that turning a string like "-5,10,-3,8" into a SeqString using a comma as a number delimiter would not convert the first number into a negative number.
Meanwhile I have actually implemented the signedNums option mentioned in my previous comment. It's committed, so if you want to play around with that you can grab the latest version from git.
As mentioned before, the option can be used to either turn all numbers into signed numbers or only some numbers by specifying their indices which may also be negative to count from the end.
I guess for those people who need to process negative numbers, this should already catch most if not all cases. Even in the example you were giving where the name may contain an arbitrary number of extra information, you said the frame number is the last component (which is probably what everyone does), so setting the index to -1 will always work (if processing all numbers as signed number is not an option for some reason).
It's only if people use a frame number that is somewhere in the middle of the file name or they use a naming convention where the minus character is used for both, negative numbers and as part of the actual name. Both things seem to be too unlikely to me that it would warrant a more complicated implementation.