ogt.ogt_doc.*¶
-
class
ogt.ogt_doc.
OGTDocument
[source]¶ Class
OGTDocument
represents an ags file and contains the groups (OGTGroup
).from ogt import ogt_doc doc = ogt_doc.OGTDocument() err = doc.load_ags4_file("/path/to/my.ags") if err: print err else: # print the groups index print doc.groups_index() # Headings in the SAMP group print doc.group("SAMP").headings() # Return a list of units used in the document print doc.units()
-
append_group
(grp)[source]¶ Appends an :class;`~ogt.ogt_group.OGTGroup` instance to this document
Parameters: grp (OGTGroup) -- The group object to add Returns: An Error message is group exists, else None
-
csv_rows
= None¶ A list of a list of csv rows
-
error_rows
= None¶ A list of rows with errors
-
group
(group_code)[source]¶ Parameters: group_code (str) -- Four character group code Returns: An instance of OGTGroup
if exists, else None
-
groups_sort
()[source]¶ Return a list of group_codes in preferred order (see
groups_sort()
)
-
lines
= None¶ A list of strings with original source lines
-
load_ags4_file
(ags4_file_path)[source]¶ Loads document from an ags4 formatted file
Parameters: ags4_file_path (str) -- absolute or relative path to file, will be at source_file_path Return type: str Returns: A String if an error else None Todo
Ensure we can read ascii
-
load_ags4_string
(ags4_str)[source]¶ Load document from an ags4 formatted string
Hackers guide This is a tthree step parsing process. -
Parameters: ags4_str (str) -- string to load Return type: str Returns: An Error message if string not loaded, else None
-
source
= None¶ The original source files contents as string
-
source_file_path
= None¶ Full path to original source file, if any
-
to_dict
(include_source=False, edit_mode=False, include_stats=False)[source]¶ Return the document data
Parameters: Return type: Returns: A dict with the data
-
to_json
(include_source=False, edit_mode=False, minify=False, include_stats=False)[source]¶ Return the document data in JSON format
Parameters: Return type: Returns: A tuple with:
- None if error else a str with JSON encoded data
- An error string is error occured, else None
-
to_yaml
(include_source=False, edit_mode=False, include_stats=False)[source]¶ Return the document data in YAML format
Parameters: Return type: Returns: A tuple with:
- None if error else a str with YAML encoded data
- An error string is error occured, else None
-
types
()[source]¶ Shortcut to TYPE group
Return type: tuple Returns: - An instance of
OGTGroup
if exists, else None - bool = True if group found in document, else false
- An instance of
-
units
()[source]¶ Shortcut to UNIT group
Return type: tuple Returns: - An instance of
OGTGroup
if exists, else None - bool = True if group found in document, else false
- An instance of
-
write
(ext='json', beside=False, file_path=None, include_source=False, edit_mode=False, minify=False, zip=False, overwrite=False, include_stats=False)[source]¶ Write out the data to file in the selected format
Parameters: - ext (str) -- The file format, see
FORMATS
- beside (bool) --
Save the output file alongside the original with extention appended, eg
- Source = /path/to/myproject.ags
- Output = /path/to/myproject.ags.json
- file_path (str) -- Relative or absolute path to write to including extention
- include_source (bool) -- If True, the original ags source is also included.
- zip (bool) -- If True, the original and converted file are packaged in a zip
- minify (bool) -- If True, all white space is removed from output file
- overwrite (bool) -- If True, the target file is overwritten, otherwise an error is returned
Returns: A tuple with
- A Message string if no errors, else None
- Any Error that occured, otherwise None
Note
Note
- Either `beside=True` or a `file_path` is required, otherwise and error occurs
- If both are provided, and error is returned
- ext (str) -- The file format, see
-
-
ogt.ogt_doc.
create_doc_from_ags4_file
(ags_file_path)[source]¶ Convenience function to create and load an OGTDocument from an ags file
doc, err = ogt_doc.create_doc_from_ags4_file("/path/to/my.ags") if err: print err else: print doc.group("PROJ")
-
ogt.ogt_doc.
create_doc_from_json_file
(json_file_path)[source]¶ Creates a document from a JSON formatted file
doc, err = ogt_doc.create_doc_from_json_file("/path/to/my.json") if err: print err
Parameters: json_file_path (str) -- absolute or relative path to file Return type: tuple Returns: A tuple containing - An
OGTDocument
object on success, else None - An Error message if error, otherwise None
- An