def setFrameSet(self, frameSet): """ Set a new :class:`.FrameSet` for the sequence. Args: frameSet (:class:`.FrameSet`): the new :class:`.FrameSet` object """ if frameSet is not None and frameSet.hasSubFrames(): if all(isinstance(frame, decimal.Decimal) for frame in frameSet): frameSet = FrameSet([ utils.quantize(frame, self._decimal_places) for frame in frameSet ]) self._frameSet = frameSet
def _build_frange_part_decimal( start, stop, count, stride, min_stride, max_stride, zfill=0 ): """ Private method: builds a proper and padded subframe range string from decimal values. Args: start (decimal.Decimal): first frame stop (decimal.Decimal): last frame count (int): number of frames in range (inclusive) stride (decimal.Decimal or None): stride to use if known else None min_stride (decimal.Decimal): minimum increment that will produce correctly rounded frames max_stride (decimal.Decimal): maximum increment that will produce correctly rounded frames zfill (int): width for zero padding Returns: str: """ if stride is None: # Use an exact stride value if within allowed limits for # range, otherwise use midpoint of stride limits stride = (stop - start) / (count - 1) if not min_stride <= stride <= max_stride: stride = (min_stride + max_stride) / 2 # Minimise number of decimal places in stride stride_range = max_stride - min_stride stride_range = stride_range.as_tuple() leading_zeros = abs(len(stride_range.digits) + stride_range.exponent) stride = abs(quantize(stride, leading_zeros + 1)).normalize() # Adjust end frame if required so correct number of steps is # calculated when recreating FrameSet from frange string while abs(stop - start) / stride + 1 < count: exponent = stop.as_tuple().exponent delta = decimal.Decimal(1).scaleb(exponent) stop += delta.copy_sign(stop) start, stop = normalizeFrames([start, stop]) return FrameSet._build_frange_part(start, stop, stride, zfill=zfill)
def __init__(self, sequence, pad_style=PAD_STYLE_DEFAULT, allow_subframes=False): """Init the class """ sequence = utils.asString(sequence) if not hasattr(self, '_frameSet'): self._frameSet = None if allow_subframes: split_re = self.SPLIT_SUB_RE disk_re = self.DISK_SUB_RE else: split_re = self.SPLIT_RE disk_re = self.DISK_RE try: # the main case, padding characters in the path.1-100#.exr path, frames, self._pad, self._ext = split_re.split( sequence, 1) self._frame_pad, _, self._subframe_pad = self._pad.partition( '.') self._dir, self._base = os.path.split(path) self._frameSet = FrameSet(frames) except ValueError: # edge case 1; we've got an invalid pad for placeholder in self.PAD_MAP: if placeholder in sequence: msg = "Failed to parse FileSequence: {!r}" raise ParseException(msg.format(sequence)) # edge case 2; we've got a single frame of a sequence a_frame = disk_re.match(sequence) if a_frame: self._dir, self._base, frames, self._ext = a_frame.groups() # edge case 3: we've got a single versioned file, not a sequence if frames and not self._base.endswith('.'): self._base = self._base + frames self._pad = '' self._frame_pad = '' self._subframe_pad = '' elif not frames: self._pad = '' self._frame_pad = '' self._subframe_pad = '' self._frameSet = None else: self._frameSet = FrameSet(frames) if self._frameSet: frame_num, _, subframe_num = frames.partition('.') self._frame_pad = self.getPaddingChars( len(frame_num), pad_style=pad_style) if subframe_num: self._subframe_pad = self.getPaddingChars( len(subframe_num), pad_style=pad_style) self._pad = '.'.join( [self._frame_pad, self._subframe_pad]) else: self._pad = self._frame_pad self._subframe_pad = '' else: self._pad = '' self._frame_pad = '' self._subframe_pad = '' self._frameSet = None # edge case 4; we've got a solitary file, not a sequence else: path, self._ext = os.path.splitext(sequence) self._dir, self._base = os.path.split(path) self._pad = '' self._frame_pad = '' self._subframe_pad = '' if self._dir: self.setDirname(self._dir) self._pad_style = pad_style self._zfill = self.getPaddingNum(self._frame_pad, pad_style=pad_style) self._decimal_places = self.getPaddingNum(self._subframe_pad, pad_style=pad_style) # Round subframes to match sequence if self._frameSet is not None and self._frameSet.hasSubFrames(): self._frameSet = FrameSet([ utils.quantize(frame, self._decimal_places) for frame in self._frameSet ])