Inheritance diagram for nipy.io.imageformats.filetuples:
Classes for containing filename pairs, triplets etc, with expected extensions
Bases: object
Class to accept and check filenames for compatibility with standard
Methods
add_type | |
get_file_of_type | |
get_filenames | |
set_file_of_type | |
set_filenames |
Initialize FileTuples object
Parameters : | types : sequence of sequences, iptional
default_type : None or string, optional
ignored_suffixes : sequence of strings, optional
enforce_extensions : {True, False}, optional
|
---|
Examples
>>> fn = FileTuples((('t1', '.ext1'), ('t2', '.ext2')))
>>> fn.types
(('t1', '.ext1'), ('t2', '.ext2'))
>>> fn.get_filenames()
(None, None)
>>> fn.default_type
't1'
>>> fn = FileTuples((('t1', '.ext1'), ('t2', '.ext2')), default_type='t2')
>>> fn.default_type
't2'
>>> fn = FileTuples((('t1', '.ext1'), ('t2', '.ext2')), ignored_suffixes=('.bz2', '.gz'))
Add a type to the type list
Parameters : | name : string
extension : string
|
---|---|
Returns : | None : |
Examples
>>> fn = FileTuples()
>>> fn.types
()
>>> fn.get_file_of_type('all')
()
>>> fn.default_type
>>> fn.add_type('test', '.tst')
>>> fn.types
(('test', '.tst'),)
>>> fn.get_file_of_type('all')
(None,)
>>> fn.default_type
'test'
>>> fn.add_type('test2', '.tst2')
>>> fn.default_type
'test'
Get files of specified type
Parameters : | typespec : string
|
---|---|
Returns : | files : file, or tuple
|
Examples
>>> fn = FileTuples(types=(('t1',),('t2',)))
>>> fn.get_file_of_type()
(None, None)
>>> fn.get_file_of_type('all')
(None, None)
>>> fn.get_file_of_type('t1')
>>> fn.set_file_of_type('t1', 'test_file')
>>> fn.get_file_of_type('all')
('test_file', None)
>>> fn.get_file_of_type('t1')
'test_file'
Get filenames from object
Parameters : | None : |
---|---|
Returns : | filenames : tuple of string
|
Set value of file for given type name name
Parameters : | name : string
fileobj : string or file-like object
|
---|
Examples
>>> fn = FileTuples((('t1', 'ext1'),('t2', 'ext2')))
>>> fn.enforce_extensions = True
>>> fn.set_file_of_type('t1', 'test_name.ext1')
>>> fn.get_file_of_type('t1')
'test_name.ext1'
>>> fn.ignored_suffixes = (('.gz',))
>>> fn.set_file_of_type('t1', 'test_name.ext1.gz')
>>> fn.get_file_of_type('t1')
'test_name.ext1.gz'
Set filename(s) from example filename
Parameters : | filename : string
|
---|---|
Returns : | None : |
Examples
>>> fn = FileTuples(types=(('t1','.ext1'),('t2', '.ext2')))
>>> fn.enforce_extensions = True
>>> fn.set_filenames('/path/test.ext1')
>>> fn.get_filenames()
('/path/test.ext1', '/path/test.ext2')
>>> fn.set_filenames('/path/test.ext2')
>>> fn.get_filenames()
('/path/test.ext1', '/path/test.ext2')
>>> # bare file roots without extensions get them added
>>> fn.set_filenames('/path/test')
>>> fn.get_filenames()
('/path/test.ext1', '/path/test.ext2')
>>> fn.enforce_extensions = False
>>> fn.set_filenames('/path/test.funny')
>>> fn.get_filenames()
('/path/test.funny', '/path/test.ext2')