PySeq v0.2.0b documentation

PySeq is a python module that finds groups of items that follow a naming convention containing a numerical sequence index (e.g. fileA.001.png, fileA.002.png, fileA.003.png...) and serializes them into a compressed sequence string representing the entire sequence (e.g. fileA.1-3.png). It should work regardless of where the numerical sequence index is embedded in the name. For examples, see basic usage below.

Installation

Installing PySeq is easily done using setuptools. Assuming it is installed, just run the following from the command-line:

$ easy_install pyseq

Alternatively, you can install from the distribution using the setup.py script:

$ python setup.py install

Overview

PySeq comes with a command-line script called lss.

$ lss [path] [-f format] [-d]

Using the “z1” file sequence example in the “tests” directory:

% ls tests/z1*
tests/z1_001_v1.1.png   tests/z1_001_v1.4.png   tests/z1_002_v1.3.png   tests/z1_002_v2.2.png
tests/z1_001_v1.2.png   tests/z1_002_v1.1.png   tests/z1_002_v1.4.png   tests/z1_002_v2.3.png
tests/z1_001_v1.3.png   tests/z1_002_v1.2.png   tests/z1_002_v2.1.png   tests/z1_002_v2.4.png

% lss tests/z1*
   4 z1_001_v1.%d.png 1-4
   4 z1_002_v1.%d.png 1-4
   4 z1_002_v2.%d.png 1-4

% lss tests/z1* -f "%h%r%t"
z1_001_v1.1-4.png
z1_002_v1.1-4.png
z1_002_v2.1-4.png

API

Some usage examples:

Compression, or serialization, of lists of items

>>> s = Sequence(['file.0001.jpg', 'file.0002.jpg', 'file.0003.jpg'])
>>> print s
file.1-3.jpg
>>> s.append('file.0006.jpg')
>>> print s.format("%h%p%t %R")
file.%04d.jpg 1-3 6
>>> s.contains('file.0009.jpg')
True
>>> s.contains('file.0009.pic')
False

Uncompression, or deserialization, of compressed sequences strings

>>> s = uncompress('012_vb_110_v002.1-150.dpx', format="%h%r%t")
>>> len(s)
150
>>> seq = uncompress('./tests/012_vb_110_v001.%04d.png 1-10', format='%h%p%t %r')
>>> print seq.format('%04l %h%p%t %R')
  10 012_vb_110_v001.%04d.png 1-10

The following documentation is automatically generated from the source code pydocs.

exception pyseq.SequenceError

special exception for sequence errors

class pyseq.Item(path)

Sequence member file class

digits

Numerical components of item name.

dirname

Item directory name, if a filesystem item.

isSibling(item)

Determines if this and item are part of the same sequence.

Parameters:item – A pyseq.Item class object.
Returns:True if this and item are sequential siblings.
name

Item base name attribute.

parts

Non-numerical components of item name.

path

Item absolute path, if a filesystem item.

class pyseq.Sequence(items)

Extends list class with methods that handle item sequentialness.

For example:

>>> s = Sequence(['file.0001.jpg', 'file.0002.jpg', 'file.0003.jpg'])
>>> print s
file.1-3.jpg
>>> s.append('file.0006.jpg')
>>> print s.format('%04l %h%p%t %R')
   4 file.%04d.jpg 1-3 6
>>> s.contains('file.0009.jpg')
True
>>> s.contains('file.0009.pic')
False
append(item)

Adds another member to the sequence.

Parameters:item – pyseq.Item object.

SequenceError raised if item is not a sequence member.

contains(item)

Checks for sequence membership. Calls Item.isSibling() and returns True if item is part of the sequence.

For example:

>>> s = Sequence(['fileA.0001.jpg', 'fileA.0002.jpg'])
>>> print s
fileA.1-2.jpg
>>> s.contains('fileA.0003.jpg')
True
>>> s.contains('fileB.0003.jpg')
False
Parameters:item – pyseq.Item class object.
Returns:True if item is a sequence member.
end()
Returns:Last index number in sequence.
format(format='%04l %h%p%t %R')

Format the stdout string.

The following directives can be embedded in the format string. Format directives support padding, for example: “%%04l”.

Directive Meaning
%s sequence start
%e sequence end
%l sequence length
%f list of found files
%m list of missing files
%p padding, e.g. %06d
%r implied range, start-end
%R explicit range, start-end [missing]
%h string preceding sequence number
%t string after the sequence number
Parameters:format – Format string. Default is ‘%04l %h%p%t %R’.
Returns:Formatted string.
frames()
Returns:List of files in sequence.
head()
Returns:String before the sequence index number.
length()
Returns:The length of the sequence.
missing()
Returns:List of missing files.
path()
Returns:Absolute path to sequence.
start()
Returns:First index number in sequence.
tail()
Returns:String after the sequence index number.
pyseq.diff(f1, f2)

Examines diffs between f1 and f2 and deduces numerical sequence number.

For example:

>>> diff('file01_0040.rgb', 'file01_0041.rgb')
[{'frames': ('0040', '0041'), 'start': 7, 'end': 11}]
>>> diff('file3.03.rgb', 'file4.03.rgb')
[{'frames': ('3', '4'), 'start': 4, 'end': 5}]
Parameters:
  • f1 – pyseq.Item object.
  • f2 – pyseq.Item object, for comparison.
Returns:

Dictionary with keys: frames, start, end.

pyseq.uncompress(seqstring, format='%04l %h%p%t %R')

Basic uncompression or deserialization of a compressed sequence string.

For example:

>>> seq = uncompress('./tests/012_vb_110_v001.%04d.png 1-10', format='%h%p%t %r')
>>> print seq
012_vb_110_v001.1-10.png
>>> len(seq)
10
Parameters:
  • seqstring – Compressed sequence string.
  • format – Format of sequence string.
Returns:

pyseq.Sequence instance.

pyseq.getSequences(source)

Returns a list of Sequence objects given a directory or list that contain sequential members.

Get sequences in a directory:

>>> seqs = getSequences('./tests/')
>>> for s in seqs: print s
... 
012_vb_110_v001.1-10.png
012_vb_110_v002.1-10.png
alpha.txt
bnc01_TinkSO_tx_0_ty_0.101-105.tif
bnc01_TinkSO_tx_0_ty_1.101-105.tif
bnc01_TinkSO_tx_1_ty_0.101-105.tif
bnc01_TinkSO_tx_1_ty_1.101-105.tif
file.1-2.tif
file.info.03.rgb
file01_40-43.rgb
file02_44-47.rgb
file1-4.03.rgb
file_02.tif

Get sequences from a list:

>>> seqs = getSequences(['fileA.1.rgb', 'fileA.2.rgb', 'fileB.1.rgb'])
>>> for s in seqs: print s
... 
fileA.1-2.rgb
fileB.1.rgb
Parameters:source – Can be directory path or list of items.
Returns:List of pyseq.Sequence class objects.

Indices and tables

Table Of Contents

This Page