Difference between revisions of "TruxtonFileType"
(→id) |
(→Sample) |
||
| (6 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | This class lets you add to the <code>FileType</code> table in Truxton. | + | This class lets you add to the <code>[FileType]</code> table in Truxton from [https://www.python.org/ Python]. |
| − | + | It is how you add your own file types to Truxton. | |
=Attributes and Methods= | =Attributes and Methods= | ||
| − | + | ==<code>extension: str</code>== | |
| − | ==<code>extension</code>== | ||
The most common [https://en.wikipedia.org/wiki/Filename_extension file name extension] associated with this file type. | The most common [https://en.wikipedia.org/wiki/Filename_extension file name extension] associated with this file type. | ||
Setting this value is optional. | Setting this value is optional. | ||
| − | This corresponds to the <code>Extension</code> column of the <code>FileType</code> table. | + | This corresponds to the <code>[Extension]</code> column of the <code><nowiki>[</nowiki>[[FileType Table|FileType]]<nowiki>]</nowiki></code> table. |
| − | ==<code>id</code>== | + | ==<code>id: int</code>== |
An 16-bit integer value for the file type. | An 16-bit integer value for the file type. | ||
Setting this value is optional. | Setting this value is optional. | ||
If you don't, one will be randomly chosen for you during the <code>save()</code> call. | If you don't, one will be randomly chosen for you during the <code>save()</code> call. | ||
| − | This corresponds to the <code>ID</code> column of the <code>FileType</code> table. | + | This corresponds to the <code>[ID]</code> column of the <code><nowiki>[</nowiki>[[FileType Table|FileType]]<nowiki>]</nowiki></code> table. |
The valid range of values is 11,000 through 32,767. | The valid range of values is 11,000 through 32,767. | ||
| − | ==<code>longname</code>== | + | ==<code>longname: str</code>== |
A description of the file type. | A description of the file type. | ||
| − | This corresponds to the <code>LongName</code> column of the <code>FileType</code> table. | + | This corresponds to the <code>[LongName]</code> column of the <code><nowiki>[</nowiki>[[FileType Table|FileType]]<nowiki>]</nowiki></code> table. |
Setting this field is optional, if it is not set, the value of <code>shortname</code> will be used. | Setting this field is optional, if it is not set, the value of <code>shortname</code> will be used. | ||
| − | ==<code>mimetype</code>== | + | ==<code>mimetype: str</code>== |
The [https://en.wikipedia.org/wiki/Media_type MIME type] most commonly associated with the file type. | The [https://en.wikipedia.org/wiki/Media_type MIME type] most commonly associated with the file type. | ||
| − | This corresponds to the <code>MIME</code> column of the <code>FileType</code> table. | + | This corresponds to the <code>[MIME]</code> column of the <code><nowiki>[</nowiki>[[FileType Table|FileType]]<nowiki>]</nowiki></code> table. |
Setting this field is optional, the default is <code>application/octet-stream</code> | Setting this field is optional, the default is <code>application/octet-stream</code> | ||
| − | ==<code>parentid</code>== | + | ==<code>parentid: int</code>== |
An 16-bit integer value for the more generic type of this file type. | An 16-bit integer value for the more generic type of this file type. | ||
Setting this value is optional. | Setting this value is optional. | ||
| − | This corresponds to the <code>ParentFileTypeID</code> column of the <code>FileType</code> table. | + | This corresponds to the <code>[ParentFileTypeID]</code> column of the <code><nowiki>[</nowiki>[[FileType Table|FileType]]<nowiki>]</nowiki></code> table. |
| − | If you do set this value, it should appear | + | If you do set this value, it should appear in the <code>[ID]</code> column of the <code><nowiki>[</nowiki>[[FileType Table|FileType]]<nowiki>]</nowiki></code> table. |
| − | ==<code>shortname</code>== | + | ==<code>shortname: str</code>== |
A short name for the file type. | A short name for the file type. | ||
| − | This corresponds to the <code>ShortName</code> column of the <code>FileType</code> table. | + | This corresponds to the <code>[ShortName]</code> column of the <code><nowiki>[</nowiki>[[FileType Table|FileType]]<nowiki>]</nowiki></code> table. |
Setting this value is mandatory. | Setting this value is mandatory. | ||
| − | ==<code>save()</code>== | + | ==<code>save() -> boolean</code>== |
| − | This will commit the information to the <code>FileType</code> table. | + | This will commit the information to the <code><nowiki>[</nowiki>[[FileType Table|FileType]]<nowiki>]</nowiki></code> table. |
It will return [https://docs.python.org/3/library/constants.html#True True] if the record was saved to the database, [https://docs.python.org/3/library/constants.html#False False] if there was an error. | It will return [https://docs.python.org/3/library/constants.html#True True] if the record was saved to the database, [https://docs.python.org/3/library/constants.html#False False] if there was an error. | ||
| + | |||
| + | ==<code>updateaveragefilesize(file_size: int) -> boolean</code>== | ||
| + | This will update the <code>[AverageFileSize]</code> column of the <code><nowiki>[</nowiki>[[FileType Table|FileType]]<nowiki>]</nowiki></code> table for this file type. | ||
| + | It will return [https://docs.python.org/3/library/constants.html#True True] if the record was updated in the database, [https://docs.python.org/3/library/constants.html#False False] if there was an error. | ||
| + | |||
| + | ==<code>updatemaximumfilesize(file_size: int) -> boolean</code>== | ||
| + | This will update the <code>[MaximumCarveFileSize]</code> column of the <code><nowiki>[</nowiki>[[FileType Table|FileType]]<nowiki>]</nowiki></code> table for this file type. | ||
| + | It will return [https://docs.python.org/3/library/constants.html#True True] if the record was updated in the database, [https://docs.python.org/3/library/constants.html#False False] if there was an error. | ||
| + | |||
| + | ==<code>updateminimumfilesize(file_size: int) -> boolean</code>== | ||
| + | This will update the <code>[MinimumCarveFileSize]</code> column of the <code><nowiki>[</nowiki>[[FileType Table|FileType]]<nowiki>]</nowiki></code> table for this file type. | ||
| + | It will return [https://docs.python.org/3/library/constants.html#True True] if the record was updated in the database, [https://docs.python.org/3/library/constants.html#False False] if there was an error. | ||
=Sample= | =Sample= | ||
| − | + | <source lang="Python" highlight="8,10-14,16"> | |
| − | < | + | import sys |
| + | sys.path.append('C:/Program Files/Truxton/SDK') | ||
import truxton | import truxton | ||
| Line 62: | Line 74: | ||
if __name__ == "__main__": | if __name__ == "__main__": | ||
| − | main() | + | sys.exit(main()) |
| − | </ | + | </source> |
Latest revision as of 15:10, 27 January 2024
This class lets you add to the [FileType] table in Truxton from Python.
It is how you add your own file types to Truxton.
Contents
Attributes and Methods
extension: str
The most common file name extension associated with this file type.
Setting this value is optional.
This corresponds to the [Extension] column of the [FileType] table.
id: int
An 16-bit integer value for the file type.
Setting this value is optional.
If you don't, one will be randomly chosen for you during the save() call.
This corresponds to the [ID] column of the [FileType] table.
The valid range of values is 11,000 through 32,767.
longname: str
A description of the file type.
This corresponds to the [LongName] column of the [FileType] table.
Setting this field is optional, if it is not set, the value of shortname will be used.
mimetype: str
The MIME type most commonly associated with the file type.
This corresponds to the [MIME] column of the [FileType] table.
Setting this field is optional, the default is application/octet-stream
parentid: int
An 16-bit integer value for the more generic type of this file type.
Setting this value is optional.
This corresponds to the [ParentFileTypeID] column of the [FileType] table.
If you do set this value, it should appear in the [ID] column of the [FileType] table.
shortname: str
A short name for the file type.
This corresponds to the [ShortName] column of the [FileType] table.
Setting this value is mandatory.
save() -> boolean
This will commit the information to the [FileType] table.
It will return True if the record was saved to the database, False if there was an error.
updateaveragefilesize(file_size: int) -> boolean
This will update the [AverageFileSize] column of the [FileType] table for this file type.
It will return True if the record was updated in the database, False if there was an error.
updatemaximumfilesize(file_size: int) -> boolean
This will update the [MaximumCarveFileSize] column of the [FileType] table for this file type.
It will return True if the record was updated in the database, False if there was an error.
updateminimumfilesize(file_size: int) -> boolean
This will update the [MinimumCarveFileSize] column of the [FileType] table for this file type.
It will return True if the record was updated in the database, False if there was an error.
Sample
import sys
sys.path.append('C:/Program Files/Truxton/SDK')
import truxton
def main():
t = truxton.create()
file_type = t.newfiletype()
file_type.parentid = truxton.Type_XML
file_type.shortname = "MyType"
file_type.longname = "A custom file type derived from XML for demo purposes"
file_type.extension = "xm2"
file_type.mimetype = "text/xml"
file_type.save()
print( "ID is " + str(file_type.id))
if __name__ == "__main__":
sys.exit(main())