==================================== ``grail.compass.projectinfo`` module ==================================== .. include:: ..\version.h .. contents:: Table of Contents :backlinks: top ----------- Description ----------- Allows access to the contents of a MineSightŪ Compass project file via a :c:`ProjectInfo` object. The project file often contains critical information needed to compose a runfile. This module gives a clean way to, * load in a project file * access the contents of a project file * mutate and commit those contents of the project file .. Note:: Changes to a :c:`ProjectInfo` will not be persisted until a :f:`save()` method is executed. This is because we keep a local copy of the Project files contents (for quick access), and modifications to the local copy do not effect the on-disk copy. ----------------- ProjectInfo Class ----------------- class :dc:`ProjectInfo([loadfrom])` Contains information read from a MineSightŪ Compass project file. Allows you to load a project file and access a local copy of the project files contents. In addition you can mutate the local copy and (optional) commit those mutations via the :f:`save()` method. :c:`ProjectInfo` can be loaded either from the constructor or via the :f:`load()` method. Usage: Accessing the contents of a ProjectInfo file is done much the same as accessing the contents of a dictionary. An example would be, .. Python:: prj = ProjectInfo(loadfrom="myproj.prj") file08 = prj.get(projectinfo.FILE08_TAG) to change the contents of a the "file08" parameter you would: .. Python:: prj = ProjectInfo(loadfrom="myproj.prj") prj.set(projectinfo.FILE08_TAG, "mynewvalue") # commit your modifications prj.save() The :a:`loadfrom` path indicates what project file should be read in order to construct the :c:`ProjectInfo` object. A default value of :a:`None` implies that an empty :c:`ProjectInfo` object is constructed. :df:`get(key)` Accesses the specified item using the obj[""] syntax (see `ProjectInfo Keys`_ for a list of valid keys). :df:`load(path)` Retrieves the contents of a project file for this object. Opens the project file, loads the resources, and closes the project file (to allow other file access/manipulations). This will generate possible exceptions, either, 1. :e:`IOError` if the file is not found [#python-lib-builtin-exceptions]_. 2. :e:`ProjectInfoError` if, a. File is not a MineSightŪ Compass Project file. b. There was an internal error reading the file. :df:`path()` Returns the path to the :c:`ProjectInfo` object. :df:`save()` Commits the local copy of the :c:`ProjectInfo` object to original path. Takes the contents of the local :c:`ProjectInfo` and commits it to the path that was originally used to load the :c:`ProjectInfo`. :df:`set(key, value)` Mutates a specified item using the obj[""] syntax (see `ProjectInfo Keys`_ for a list of valid keys). -------------------------- ProjectInfoError Exception -------------------------- exception :de:`ProjectInfoError` An error generated whenever there is an access problem in this module. Tends to map errors generated by the GalRes module (to keep things easier to understand by the callee). --------- Functions --------- :df:`CreateProjectFile(path)` *Internal usage only*. Creates a new project file at the specified path populated with default values. Goes through the process of creating a new resource file to store project settings. Then populates that project file with empty values. This is mainly for testing. ---------------- ProjectInfo Keys ---------------- :dd:`FILE08_TAG` Path to the File 8 file. :dd:`FILE09_TAG` Path to the File 9 file. :dd:`FILE11_TAG` Path to the File 11 file. :dd:`FILE12_TAG` Path to the File 12 file. :dd:`FILE13_TAG` Path to the File 13 file. :dd:`FILE14_TAG` Path to the File 14 file. :dd:`FILE15_TAG` Path to the File 15 file. :dd:`FILE25_TAG` Path to the File 25 file. :dd:`GROUP_TAG` *Internal usage only*. :dd:`PCFPATH_TAG` Access to the path for the PCF file. :dd:`USER_TAG` Name of the user. :dd:`ALL_BOOL_TAGS` *Internal usage only*. A list of all tags that are booleans inside the project file. :dd:`ALL_STR_TAGS` *Internal usage only*. A list of all tags that are strings inside the project file. :dd:`ALL_TAGS` *Internal usage only*. A list of all tags inside a project file. ---- .. [#python-lib-builtin-exceptions] "Built-in Exceptions" *Python Library Reference*. 19 December 2001. 1 June 2004.