Difference between revisions of "TruxtonFileType"

From truxwiki.com
Jump to navigation Jump to search
(Created page with "This class lets you add to the <code>FileType</code> table in Truxton. This is how you add your own file types to Truxton. =Attributes and Methods= ==<code>extension</code>=...")
 
Line 23: Line 23:
 
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>FileType</code> table.
Setting this field is optional.
+
Setting this field is optional, the default is <code>application/octet-stream</code>
  
 
==<code>parentid</code>==
 
==<code>parentid</code>==

Revision as of 16:21, 11 June 2020

This class lets you add to the FileType table in Truxton. This is how you add your own file types to Truxton.

Attributes and Methods

extension

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

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.

longname

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

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

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 int eh ID column of the FileType table.

shortname

A short name for the file type. This corresponds to the ShortName column of the FileType table. Setting this value is mandatory.

save()

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.

Sample

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__":
  main()