pyffi.formats.egt
— EGT (.egt)¶
An .egt file contains texture tones for the different races.
Implementation¶
-
class
pyffi.formats.egt.
EgtFormat
¶ Bases:
pyffi.object_models.xml.FileFormat
This class implements the EGT format.
-
class
FileSignature
(**kwargs)¶ Bases:
pyffi.object_models.xml.basic.BasicBase
Basic type which implements the header of a EGT file.
-
get_detail_display
()¶ Return an object that can be used to display the instance.
-
get_hash
(data=None)¶ Return a hash value for this value.
- Returns
An immutable object that can be used as a hash.
-
get_size
(data=None)¶ Return number of bytes the header segtng occupies in a file.
- Returns
Number of bytes.
-
read
(stream, data)¶ Read header string from stream and check it.
- Parameters
stream (file) – The stream to read from.
-
write
(stream, data)¶ Write the header segtng to stream.
- Parameters
stream (file) – The stream to write to.
-
-
class
FileVersion
(template=None, argument=None, parent=None)¶ Bases:
pyffi.object_models.xml.basic.BasicBase
-
get_detail_display
()¶ Return an object that can be used to display the instance.
-
get_hash
(data=None)¶ Returns a hash value (an immutable object) that can be used to identify the object uniquely.
-
get_size
(data=None)¶ Returns size of the object in bytes.
-
get_value
()¶ Return object value.
-
read
(stream, data)¶ Read object from file.
-
set_value
(value)¶ Set object value.
-
write
(stream, data)¶ Write object to file.
-
-
class
Header
(template=None, argument=None, parent=None)¶ Bases:
pyffi.formats.egt._Header
,pyffi.object_models.Data
A class to contain the actual egt data.
-
get_global_child_nodes
(edge_filter=(True, True))¶ Generator which yields all children of this item in the global view, of given edge type (default is edges of type 0).
Override this method.
- Returns
Generator for global node children.
-
inspect
(stream)¶ Quickly checks if stream contains EGT data, and reads everything up to the arrays.
- Parameters
stream (file) – The stream to inspect.
-
inspect_quick
(stream)¶ Quickly checks if stream contains EGT data, by looking at the first 8 bytes. Reads the signature and the version.
- Parameters
stream (file) – The stream to inspect.
-
read
(stream)¶ Read a egt file.
- Parameters
stream (
file
) – The stream from which to read.
-
write
(stream)¶ Write a egt file.
- Parameters
stream (
file
) – The stream to which to write.
-
-
byte
¶ alias of
pyffi.object_models.common.Byte
-
char
¶ alias of
pyffi.object_models.common.Char
-
float
¶ alias of
pyffi.object_models.common.Float
-
int
¶ alias of
pyffi.object_models.common.Int
-
short
¶ alias of
pyffi.object_models.common.Short
-
ubyte
¶ alias of
pyffi.object_models.common.UByte
-
uint
¶ alias of
pyffi.object_models.common.UInt
-
ushort
¶ alias of
pyffi.object_models.common.UShort
-
class
Regression tests¶
Read a EGT file¶
>>> # check and read egt file
>>> from os.path import dirname
>>> dirpath = __file__
>>> for i in range(4): #recurse up to root repo dir
... dirpath = dirname(dirpath)
>>> repo_root = dirpath
>>> format_root = os.path.join(repo_root, 'tests', 'formats', 'egt')
>>> file = os.path.join(format_root, 'test.egt')
>>> stream = open(file, 'rb')
>>> data = EgtFormat.Data()
>>> data.inspect(stream)
>>> # do some stuff with header?
>>> data.read(stream) # doctest: +ELLIPSIS
>>> # do more stuff?
Parse all EGT files in a directory tree¶
>>> for stream, data in EgtFormat.walkData(format_root):
... try:
... # the replace call makes the doctest also pass on windows
... os_path = stream.name
... split = (os_path.split(os.sep))[-4:]
... rejoin = os.path.join(*split).replace(os.sep, "/")
... print("reading %s" % rejoin)
... except Exception:
... print(
... "Warning: read failed due corrupt file,"
... " corrupt format description, or bug.") # doctest: +REPORT_NDIFF
reading tests/formats/egt/test.egt
Create an EGT file from scratch and write to file¶
>>> data = EgtFormat.Data()
>>> from tempfile import TemporaryFile
>>> stream = TemporaryFile()
>>> data.write(stream)