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

clear()[source]#

Clear the list of projects.

clear_namespace(interpreter, project)[source]#
close(name=None, proj_path=None)[source]#

Close current project.

TODO:

not yet implemented

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

default()[source]#
Returns:

a default empty 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()
generate_item_id(item)[source]#
instantiate(item)[source]#
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

load_default()[source]#
load_items(group=None)[source]#
load_settings()[source]#
notify(sender, event=None)[source]#

This function is called by observed objects

Parameters:
  • sender – the observed object which send notification

  • event – the data associated to the notification

patch_item(item)[source]#
static search_path()[source]#

Return a list of all path containing projects

update_namespace(interpreter)[source]#

Definition: Update namespace

write_settings()[source]#

Add a new path to the settings.

openalea.core.project.manager.get_criteria(project)[source]#
openalea.core.project.manager.main()[source]#

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'#
add(category, obj=None, **kwargs)[source]#
add_item(category, obj=None, **kwargs)[source]#
config_filename = 'oaproject.cfg'#
delete()[source]#
get(category, name, **kwargs)[source]#
get_item(category, filename)[source]#
get_model(filename)[source]#
get_runnable_model(name)[source]#
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

items(category, **kwds)[source]#
move(dest)[source]#
property name#
property path#
property projectdir#
remove(category, obj=None, **kwargs)[source]#
remove_item(category, obj=None, **kwargs)[source]#
rename(new)[source]#
rename_item(category, old, new)[source]#
run(filename, *args, **kwargs)[source]#
run_model(model, *args, **kwargs)[source]#
save()[source]#

Save a manifest file on disk. It name is defined by config_filename.

It contains list of files that are inside project (manifest) and metadata (author, version, …).

save_metadata()[source]#
start(*args, **kwargs)[source]#

Load controls if available, execute all files in startup.

stop(*args, **kwargs)[source]#
valid_item_name(category, name)[source]#

openalea.core.project.serialization module#

class openalea.core.project.serialization.ProjectLoader[source]#

Bases: object

dtype = ['IProject']#
load(path, protocol=None, **kwds)[source]#
options = ['config_filename=oaproject.cfg', 'default_metadata']#
protocols = ['inode/directory']#
update(obj, path, protocol=None, **kwds)[source]#
class openalea.core.project.serialization.ProjectSaver[source]#

Bases: AbstractSaver

dtype = ['IProject']#
options = [{'interface': 'IStr', 'name': 'mode', 'value': 'all', 'values': ['all', 'metadata']}]#
protocols = ['inode/directory']#
save(obj, path, protocol=None, **kwds)[source]#

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