openalea.core.project package#
Subpackages#
Submodules#
openalea.core.project.manager module#
- class openalea.core.project.manager.ProjectManager(items=None, item_proxy=None, autoload=['entry_points'])[source]#
Bases:
GenericManager- property cproject#
- create(name, projectdir=None, **kwargs)[source]#
Create new project and return it.
- Use:
>>> project1 = project_manager.create('project1') >>> project2 = project_manager.create('project2', '/path/to/project')
- Parameters:
name – name of project to create (str)
path – path where project will be saved. By default, path is the user path of all projects ($HOME/.openalea/projects/).
- Returns:
Project
- property defaultdir#
- discover(group=None, config_name='oaproject.cfg')[source]#
Discover projects from your disk and put them in self.projects.
Projects are not loaded, only metadata are.
- Use:
>>> project_manager.discover() >>> list_of_projects = project_manager.projects
To discover new projects, you can add path into self.repositories
project_manager.repositories.append('path/to/search/projects') project_manager.discover()
- load(name, projectdir=None, **kwargs)[source]#
Load existing project
- Use:
>>> project1 = project_manager.load('project1') >>> project2 = project_manager.load('project2', '/path/to/project')
- Parameters:
name – name of project to load. Must be a string.
projectdir – path of project to load. Must be a path (see module path.py). By default, try to guess with name only. If there are various projects with the same name, return the first.
- Returns:
Project
openalea.core.project.project module#
The Project is a structure which permits to manage different objects.
It stores metadata (alias, author, description, version, license, …) and data (src, models, images, …).
You have here the default architecture of the project saved in directory “project”.
- /project
oaproject.cfg (Configuration file) /model (Files sources, Script Python, LPy…) /control (Control, like color map or curve) /world (scene, scene 3D) /cache (Intermediary saved objects) /data (Data files like images, .dat, …) /lib (Contains python modules and packages) /startup (Preprocessing scripts)
.py (Preprocessing scripts) *import.py (Libs and packages to import in preprocessing)
- use:
project = Project(path="/path/to/proj/project") project.add(category="model", filename="hello.py", content="print 'Hello World'") project.author = "John Doe" project.description = "This project is used to said hello to everyone" project.save()
- exception openalea.core.project.project.ErrorItemExistsInProject(*args, **kargs)[source]#
Bases:
CustomException- desc = 'As item is in project yet, you cannot add it again. Use replacement instead'#
- message = 'Item %(name)s is in project yet'#
- title = 'Error: item exists in project yet.'#
- class openalea.core.project.project.Project(path, **kwargs)[source]#
Bases:
Observed- DEFAULT_CATEGORIES = {'cache': {'title': 'Temporary Data'}, 'data': {'title': 'Data'}, 'doc': {'title': 'Documentation'}, 'lib': {'title': 'Libraries'}, 'model': {'title': 'Model'}, 'startup': {'title': 'Startup'}, 'world': {'title': 'World'}}#
- DEFAULT_METADATA = {'alias': Control('alias', IStr(), value='MyProject'), 'authors': Control('author', ISequence(), value=[]), 'citation': Control('citation', IStr(), value=''), 'dependencies': Control('dependencies', ISequence(), value=[]), 'description': Control('description', IStr(), value=''), 'icon': Control('icon', IFileStr(filter="All (*)", save=False), value=''), 'license': Control('license', IStr(), value=''), 'long_description': Control('long_description', IStr(), value=''), 'url': Control('url', IStr(), value=''), 'version': Control('version', IStr(), value='0.1')}#
- MODE_COPY = 'copy'#
- MODE_LINK = 'link'#
- config_filename = 'oaproject.cfg'#
- property icon_path#
the complete path of the icon. To modify it, you have to modify the path of project, the name of project and/or the self.icon.
- Type:
return
- property name#
- property path#
- property projectdir#
openalea.core.project.serialization module#
Module contents#
Working with Project class#
You can work directly on project:
>>> from openalea.core.project import Project, get_project_dir
>>> from openalea.core.path import path
>>> # Real work on project:
>>> project_path = path(get_project_dir()) / 'project1'
>>> project1 = Project(project_path)
>>> project1.start()
Change metadata:
>>> project1.authors = "OpenAlea Consortium and John Doe"
>>> project1.description = "Test project concept with numpy"
>>> project1.long_description = ' '.join([
... 'This project import numpy. Then, it create and display a numpy eye.',
... 'We use it to test concept of Project.'])
… project file, models, … :
>>> success = project1.add(category="model", filename="hello.py", content="print('Hello World')")
>>> project1.description = "This project is used to said hello to everyone"
>>> startup_obj = project1.add(category="startup", filename="begin_numpy.py", content="import numpy as np")
>>> model_obj = project1.add(category="model", filename="eye.py", content="print np.eye(2)")
>>> project1.rename_item("model", "eye.py", "eye_numpy.py")
At this time, project is only in memory. To write it on disk, just call “project1.save()”
Creation and Manipulation with Project Manager#
- Or, you can create or load a project thanks to the project manager.
>>> from openalea.core.project import ProjectManager >>> project_manager = ProjectManager()
- Discover available projects
>>> project_manager.discover() >>> list_of_projects = project_manager.projects
- Create project in default directory or in specific one
>>> p1 = project_manager.create('project1') >>> p2 = project_manager.create(name='project2', projectdir=".")
- Load project from default directory
>>> p3 = project_manager.load('sum')
- Load project from a specific directory
>>> import openalea.oalab >>> from openalea.oalab.resources import resources_dir >>> project_dir = resources_dir >>> p4 = project_manager.load('sum', project_dir)
- Load
>>> project2 = project_manager.load("sum")
- Run startup
>>> project2.start()
- Get model
>>> model = project2.get_model("sum_int")
Search other projects#
- To search projects that are not located inside default directories:
>>> project_manager.repositories.append('/path/to/search/projects') >>> project_manager.discover() >>> list_of_projects = project_manager.projects