openalea.vpltk.project package¶
Submodules¶
openalea.vpltk.project.configobj module¶
- exception openalea.vpltk.project.configobj.ConfigObjError(message='', line_number=None, line='')[source]¶
Bases: exceptions.SyntaxError
This is the base class for all errors that ConfigObj raises. It is a subclass of SyntaxError.
- exception openalea.vpltk.project.configobj.NestingError(message='', line_number=None, line='')[source]¶
Bases: openalea.vpltk.project.configobj.ConfigObjError
This error indicates a level of nesting that doesn’t match.
- exception openalea.vpltk.project.configobj.ParseError(message='', line_number=None, line='')[source]¶
Bases: openalea.vpltk.project.configobj.ConfigObjError
This error indicates that a line is badly written. It is neither a valid key = value line, nor a valid section marker line.
- exception openalea.vpltk.project.configobj.DuplicateError(message='', line_number=None, line='')[source]¶
Bases: openalea.vpltk.project.configobj.ConfigObjError
The keyword or section specified already exists.
- exception openalea.vpltk.project.configobj.ConfigspecError(message='', line_number=None, line='')[source]¶
Bases: openalea.vpltk.project.configobj.ConfigObjError
An error occured whilst parsing a configspec.
- class openalea.vpltk.project.configobj.ConfigObj(infile=None, options=None, configspec=None, encoding=None, interpolation=True, raise_errors=False, list_values=True, create_empty=False, file_error=False, stringify=True, indent_type=None, default_encoding=None, unrepr=False, write_empty_values=False, _inspec=False)[source]¶
Bases: openalea.vpltk.project.configobj.Section
An object to read, create, and write config files.
- reload()[source]¶
Reload a ConfigObj from file.
This method raises a ReloadError if the ConfigObj doesn’t have a filename attribute pointing to a file.
- validate(validator, preserve_errors=False, copy=False, section=None)[source]¶
Test the ConfigObj against a configspec.
It uses the validator object from validate.py.
To run validate on the current ConfigObj, call:
test = config.validate(validator)
(Normally having previously passed in the configspec when the ConfigObj was created - you can dynamically assign a dictionary of checks to the configspec attribute of a section though).
It returns True if everything passes, or a dictionary of pass/fails (True/False). If every member of a subsection passes, it will just have the value True. (It also returns False if all members fail).
In addition, it converts the values from strings to their native types if their checks pass (and stringify is set).
If preserve_errors is True (False is default) then instead of a marking a fail with a False, it will preserve the actual exception object. This can contain info about the reason for failure. For example the VdtValueTooSmallError indicates that the value supplied was too small. If a value (or section) is missing it will still be marked as False.
You must have the validate module to use preserve_errors=True.
You can then use the flatten_errors function to turn your nested results dictionary into a flattened list of failures - useful for displaying meaningful error messages.
- write(outfile=None, section=None)[source]¶
Write the current ConfigObj as a file
tekNico: FIXME: use StringIO instead of real files
>>> filename = a.filename >>> a.filename = 'test.ini' >>> a.write() >>> a.filename = filename >>> a == ConfigObj('test.ini', raise_errors=True) 1 >>> import os >>> os.remove('test.ini')
- class openalea.vpltk.project.configobj.SimpleVal[source]¶
Bases: object
A simple validator. Can be used to check that all members expected are present.
To use it, provide a configspec with all your members in (the value given will be ignored). Pass an instance of SimpleVal to the validate method of your ConfigObj. validate will return True if all members are present, or a dictionary with True/False meaning present/missing. (Whole missing sections will be replaced with False)
- exception openalea.vpltk.project.configobj.InterpolationError(message='', line_number=None, line='')[source]¶
Bases: openalea.vpltk.project.configobj.ConfigObjError
Base class for the two interpolation errors.
- exception openalea.vpltk.project.configobj.InterpolationLoopError(option)[source]¶
Bases: openalea.vpltk.project.configobj.InterpolationError
Maximum interpolation depth exceeded in string interpolation.
- exception openalea.vpltk.project.configobj.MissingInterpolationOption(option)[source]¶
Bases: openalea.vpltk.project.configobj.InterpolationError
A value specified for interpolation was missing.
- exception openalea.vpltk.project.configobj.RepeatSectionError(message='', line_number=None, line='')[source]¶
Bases: openalea.vpltk.project.configobj.ConfigObjError
This error indicates additional sections in a section with a __many__ (repeated) section.
- exception openalea.vpltk.project.configobj.ReloadError[source]¶
Bases: exceptions.IOError
A ‘reload’ operation failed. This exception is a subclass of IOError.
- exception openalea.vpltk.project.configobj.UnreprError(message='', line_number=None, line='')[source]¶
Bases: openalea.vpltk.project.configobj.ConfigObjError
An error parsing in unrepr mode.
- exception openalea.vpltk.project.configobj.UnknownType[source]¶
Bases: exceptions.Exception
- openalea.vpltk.project.configobj.flatten_errors(cfg, res, levels=None, results=None)[source]¶
An example function that will turn a nested dictionary of results (as returned by ConfigObj.validate) into a flat list.
cfg is the ConfigObj instance being checked, res is the results dictionary returned by validate.
(This is a recursive function, so you shouldn’t use the levels or results arguments - they are used by the function.)
Returns a list of keys that failed. Each member of the list is a tuple:
([list of sections...], key, result)
If validate was called with preserve_errors=False (the default) then result will always be False.
list of sections is a flattened list of sections that the key was found in.
If the section was missing (or a section was expected and a scalar provided - or vice-versa) then key will be None.
If the value (or section) was missing then result will be False.
If validate was called with preserve_errors=True and a value was present, but failed the check, then result will be the exception object returned. You can use this as a string that describes the failure.
For example The value “3” is of the wrong type.
- openalea.vpltk.project.configobj.get_extra_values(conf, _prepend=())[source]¶
Find all the values and sections not in the configspec from a validated ConfigObj.
get_extra_values returns a list of tuples where each tuple represents either an extra section, or an extra value.
The tuples contain two values, a tuple representing the section the value is in and the name of the extra values. For extra values in the top level section the first member will be an empty tuple. For values in the ‘foo’ section the first member will be ('foo',). For members in the ‘bar’ subsection of the ‘foo’ section the first member will be ('foo', 'bar').
NOTE: If you call get_extra_values on a ConfigObj instance that hasn’t been validated it will return an empty list.
openalea.vpltk.project.loader module¶
- class openalea.vpltk.project.loader.BGEOMLoader[source]¶
Bases: openalea.vpltk.project.loader.ILoader
Specific loader that is used to manipulate PlantGL objects
- default_name = 'BGEOMLoader'¶
- input_format = '*.BGEOM'¶
- class openalea.vpltk.project.loader.CPickleLoader[source]¶
Bases: openalea.vpltk.project.loader.ILoader
Specific loader that use cPickle.loads
- default_name = 'CPickleLoader'¶
- input_format = '*'¶
- class openalea.vpltk.project.loader.GenericLoader[source]¶
Bases: object
Classical loader that read file
- default_name = 'GenericLoader'¶
- input_format = '*.py'¶
- class openalea.vpltk.project.loader.ILoader[source]¶
Bases: object
Generic interface class for loaders
openalea.vpltk.project.manager module¶
- class openalea.vpltk.project.manager.ProjectManager[source]¶
Bases: object
Object which manage projects: creation, loading, saving, searching, ...
It is a singleton.
- create(project_name, project_path=None)[source]¶
Create new project and return it.
Use: >>> project1 = project_manager.create('project1') >>> project2 = project_manager.create('project2', '/path/to/project')
Parameters: - project_name – name of project to create (str)
- project_path – path where project will be saved. By default, project_path is the user path of all projects ($HOME/.openalea/projects/).
Returns: Project
- discover()[source]¶
Discover projects from your disk and put them in self.projects.
Projects are not loaded, only metadata are.
Use: >>> project_manager.discover() >>> print project_manager.projects
To discover new projects, you can add path into self.find_links
project_manager.find_links.append('path/to/search/projects') project_manager.discover()
- get_current()[source]¶
Returns: current active project
Use: >>> project = project_manager.get_current()
- instance = None¶
- load(project_name, project_path=None)[source]¶
Load existing project
Use: >>> project1 = project_manager.load('project1') >>> project2 = project_manager.load('project2', '/path/to/project')
Parameters: - project_name – name of project to load. Must be a string.
- project_path – path of project to load. Must be a path (see module path.py). By default, the path is the openaelea.core.settings.get_project_dir() ($HOME/.openalea/projects/).
Returns: Project
openalea.vpltk.project.project module¶
The Project is a structure which permit to manage different objects.
It store metadata (name, author, description, version, license, ...) and data (src, models, images, ...).
You have here the default architecture of the project named “project_name”, stored in your computer.
/project_name | oaproject.cfg (Configuration file) /src (Files sources, Script Python, LPy...) /control (Control, like color map or curve) /scene (scene, scene 3D) /cache (Intermediary saved objects) /data (Data files like images, .dat, ...) /startup (Preprocessing scripts)
|
use: | project1 = Project(project_name="mynewproj", project_path="/path/to/proj")
project1.start()
project1.add(category="src", name"hello.py", value="print 'Hello World'")
project1.author = "John Doe"
project1.description = "This project is used to said hello to everyone"
project1.save()
|
---|
- class openalea.vpltk.project.project.Project(project_name, project_path, icon='', author='OpenAlea Consortium', author_email='', description='', long_description='', citation='', url='', dependencies=, []license='CeCILL-C', version='0.1')[source]¶
Bases: object
- add(category, name, value)[source]¶
Add an object in the project
Parameters: - category – type of object to add (“src”, “control”, “scene”, ...)
- name – filename of the object to add (path or str)
- value – to add (string)
- add_script(name, script)[source]¶
Add a src in the project
Deprecated: replace by add() method
Parameters: - name – filename of the src to add (path or str)
- script – to add (string)
See also
- get(category, name)[source]¶
Search an object inside project and return it.
Parameters: - category – category of object to get
- name – name of object to get
Returns: object named name in the category category if it exists. Else, None.
Use: >>> get(category="src", name="myscript.py")
See also
- load()[source]¶
Realize a total loading of project (contrary to load_manifest()).
- Load manifest load_manifest()
- Read data files listed in manifest and fill project object.
See also
- load_manifest()[source]¶
Partially load a project from a manifest file.
- Read manifest file (oaproject.cfg).
- Load metadata inside project from manifest.
- Load filenames of data files inside project from manifest.
- Not load data ! If you want to load data, please use load().
Warning: load metadata and list of filenames but does not load files See also
- remove(category, name)[source]¶
Remove an object in the project
Remove nothing on disk.
Parameters: - category – category of object to remove (“src”, “control”, “scene”, ...) (str)
- name – filename of the src to remove (path or str)
- remove_script(name)[source]¶
Add a src in the project
Remove nothing on disk.
Deprecated: replace by remove() method Parameters: name – filename of the src to remove (path or str) See also
- rename(category, old_name, new_name)[source]¶
Rename a src, a scene or a control in the project. If category is project, rename the entire project.
Parameters: - category – Can be “src”, “control”, “scene” or “project” (str)
- old_name – current name of thing to rename (str)
- new_name – future name of thing to rename (str)
- save()[source]¶
Save project on disk.
- Save data files.
- Save metadata and list on previously saved data into a manifest file (oaproject.cfg).
See also
- save_manifest()[source]¶
Save a manifest file on disk. His name is “oaproject.cfg”.
It contains list of files that are inside project (manifest) and metadata (author, version, ...).
See also
openalea.vpltk.project.saver module¶
- class openalea.vpltk.project.saver.BGEOMSaver[source]¶
Bases: object
Specific loader that is used to manipulate PlantGL objects
- default_name = 'BGEOMSaver'¶
- output_format = '*.BGEOM'¶
- class openalea.vpltk.project.saver.CPickleSaver[source]¶
Bases: object
Specific saver that use cPickle.dump
- default_name = 'CPickleSaver'¶
- output_format = '*'¶
- class openalea.vpltk.project.saver.GenericSaver[source]¶
Bases: object
Classical saver that write str(obj) into file
- default_name = 'GenericSaver'¶
- output_format = '*.py'¶
Module contents¶
Project and Project Manager Quick Start¶
You can work directly on project:
project1 = Project(project_name="mynewproj", project_path="/path/to/proj")
project1.rename("project", "mynewproj", "hello_project")
project1.import()
project1.authors = "OpenAlea Consortium and John Doe"
project1.description = "Test project concept with numpy"
project1.long_description = '''This project import numpy.
Then, it create and display a numpy eye.
We use it to test concept of Project.''
project1.add(category="scripts", name"hello.py", value="print 'Hello World'")
project1.description = "This project is used to said hello to everyone"
project1.add("startup", "begin_numpy.py", "import numpy as np")
project1.add("scripts", "eye.py", "print np.eye(2)")
project1.rename("scripts", "eye.py", "eye_numpy.py")
project1.save()
Or, you can create or load a project thanks to the project manager.
from openalea.vpltk.project.manager import ProjectManager
# Instanciate ProjectManager
project_manager = ProjectManager()
# Discover available projects
project_manager.discover()
print project_manager.projects
# Create project in default directory or in specific one
p1 = project_manager.create('project1')
p2 = project_manager.create('project2', '/path/to/project')
# Load project from default directory or in specific one
p3 = project_manager.load('project3')
p4 = project_manager.load('project4', '/path/to/project')
# Load
project2 = project_manager.load("numpy_project")
# Run startup
project2.import()
# Run script
project2.run_script("eye_numpy.py")
To search projects that are not located inside default directories:
project_manager.find_links.append('path/to/search/projects')
project_manager.discover()
print project_manager.projects