Beispiel #1
0
    def build_package(self, wraleamodule, pkgmanager):
        """ Build package and update pkgmanager """

        name = wraleamodule.__dict__.get('__name__', None)
        edit = wraleamodule.__dict__.get('__editable__', False)

        # Build Metainfo
        metainfo = dict(
            version='',
            license='',
            authors='',
            institutes='',
            description='',
            url='',
            icon='',
            alias=[], )

        for k, v in wraleamodule.__dict__.items():

            if not (k.startswith('__') and k.endswith('__')):
                continue
            k = k[2:-2]  # remove __
            if k not in metainfo:
                continue
            metainfo[k] = v

        # Build Package
        path = wraleamodule.__file__
        if (path.endswith('.pyc')):
            path = path.replace('.pyc', '.py')

        if (not edit):
            p = Package(name, metainfo, path)
        else:
            p = UserPackage(name, metainfo, path)

        # Add factories
        factories = wraleamodule.__dict__.get('__all__', [])
        for fname in factories:
            f = wraleamodule.__dict__.get(fname, None)
            try:
                if (f):
                    p.add_factory(f)
            except Exception as e:
                pkgmanager.log.add(str(e))

        pkgmanager.add_package(p)

        # Add Package Aliases
        palias = wraleamodule.__dict__.get('__alias__', [])
        for name in palias:
            if protected(name) in pkgmanager:
                alias_pkg = pkgmanager[protected(name)]
                for name_factory, factory in p.items():
                    if (name_factory not in alias_pkg and
                       (alias_pkg.name + '.' + name_factory) not in pkgmanager):
                        alias_pkg[name_factory] = factory
            else:
                pkgmanager[protected(name)] = p
Beispiel #2
0
    def add_factory(self, factory):
        """ Add to the package a factory ( node or subgraph ) """

        if (factory.name in self):
            raise Exception("Factory %s already defined. Ignored !" %
                            (factory.name, ))

        self[factory.name] = factory
        factory.package = self

        # Check validity
        # oops: this is a hack.
        # When the factory is a data factory that do not reference a file, raise an error.
        # This function return True or raise an error to have a specific diagnostic.
        try:
            factory.is_valid()

        except Exception as e:
            factory.package = None
            del (self[factory.name])
            raise e

        # Add Aliases
        if (factory.alias):
            for a in factory.alias:
                self[protected(a)] = factory
Beispiel #3
0
    def rename_package(self, old_name, new_name):
        """ Rename package 'old_name' to 'new_name' """

        self.pkgs[protected(old_name)] = self.pkgs[old_name]
        self.pkgs[new_name] = self.pkgs[old_name]
        self.pkgs[old_name].name = new_name

        if 'alias' in self.pkgs[old_name].metainfo:
            self.pkgs[old_name].metainfo['alias'].append(old_name)

        self.pkgs[old_name].write()
        del(self.pkgs[old_name])
        self.notify_listeners("update")
          name="variable",
          description="Variable",
          category="datatype",
          nodemodule="openalea.data.data",
          nodeclass="Variable",

          inputs=(dict(name='Caption', interface=IStr, value='Variable'),
                  dict(name='Object', interface=None, value=None),
                  ),
          outputs=(dict(name='Object', interface=None),)
          )

__all__.append('var_')

str_ = Fa(uid="2ec3b2a44e7111e6bff6d4bed973e64a",
          name=protected("string"),
          description="String",
          category="datatype",
          nodemodule="openalea.data.data",
          nodeclass="String",

          inputs=(dict(name="String", interface=IStr, value=''),),
          outputs=(dict(name="String", interface=IStr),),
          )

__all__.append('str_')

text = Fa(uid="33ab90204e7111e6bff6d4bed973e64a",
          name=protected("text"),
          description="Text",
          category="datatype",
#
#       Distributed under the Cecill-C License.
#       See accompanying file LICENSE.txt or copy at
#           http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html
#
#       OpenAlea WebSite : http://openalea.gforge.inria.fr
#
################################################################################
""" catalog.model """

__revision__ = " $Id$ "

from openalea.core import Factory as Fa
from openalea.core.pkgdict import protected

__name__ = protected("openalea.model")
# __name__ = "openalea.model"
__alias__ = [
    "catalog.model",
]

__version__ = '0.0.1'
__license__ = 'CECILL-C'
__authors__ = 'OpenAlea Consortium'
__institutes__ = 'INRIA/CIRAD'
__description__ = 'Models.'
__url__ = 'http://openalea.gforge.inria.fr'

__all__ = ['linear']

linear = Fa(
var_ = Factory( name="variable", 
               description="Variable", 
               category="datatype", 
               nodemodule="openalea.data.data",
               nodeclass="Variable",
               
               inputs=(dict(name='Caption', interface=IStr, value='Variable'),
                       dict(name='Object', interface=None, value=None),
                       ),
               outputs=(dict(name='Object', interface=None),)
               )

__all__.append('var_')

str_ = Factory( name=protected("string"), 
              description="String", 
              category="datatype", 
              nodemodule="openalea.data.data",
              nodeclass="String",
              
              inputs=(dict(name="String", interface=IStr, value=''),),
              outputs=(dict(name="String", interface=IStr),),
              )

__all__.append('str_')


text = Factory( name=protected("text"), 
              description="Text", 
              category="datatype", 
Beispiel #7
0
whilemulti2 = Factory(name="while multivariate2", 
             description="While Loop (Multivariate)", 
             category="flow control", 
             nodemodule="openalea.core.system.systemnodes",
             nodeclass="while_multi2",
             inputs = (dict(name="InitValues", interface=ISequence, value=[]),  
                       dict(name="Test", interface=IFunction, value=None),  
                       dict(name="Functions", interface=IFunction, value=None),  
                       ),
             outputs = ( dict(name="Results", interface=ISequence), ),
             )


__all__.append('whilemulti2')

cmd = Factory(name=protected("command"), 
             description="Call a system command", 
             category="System", 
             nodemodule="openalea.core.system.systemnodes",
             nodeclass="system_cmd",
             inputs = (dict(name="commands", interface=ISequence, value=[], 
                            desc='List of command strings'),  
                       ),
             outputs = ( dict(name="stdout", interface=None, desc='result'), 
                         dict(name="stderr", interface=None, desc='result'), ),
                     )



__all__.append('cmd')
#       Distributed under the Cecill-C License.
#       See accompanying file LICENSE.txt or copy at
#           http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html
# 
#       OpenAlea WebSite : http://openalea.gforge.inria.fr
#
################################################################################
""" catalog.model """

__revision__=" $Id$ "


from openalea.core import *
from openalea.core.pkgdict import protected

__name__ = protected("openalea.model")
#__name__ = "openalea.model"
__alias__ = ["catalog.model", ]

__version__ = '0.0.1'
__license__ = 'CECILL-C'
__authors__ = 'OpenAlea Consortium'
__institutes__ = 'INRIA/CIRAD'
__description__ = 'Models.'
__url__ = 'http://openalea.gforge.inria.fr'

__all__ = ['linear']

    
linear = Factory( name=protected("linearmodel"), 
                  description="Linear Model", 
Beispiel #9
0
class Package(PackageDict):
    """
    A Package is a dictionnary of node factory.
    Each node factory is able to generate node and their widgets.

    Meta informations are associated with a package.
    """

    # type information for drag and drop.
    mimetype = "openalea/package"

    def __init__(self, name, metainfo, path=None):
        """
        Create a Package

        :param name: a unique string used as a unique identifier for the package
        :param path: path where the package lies (a directory or a full wralea path)
        :param metainfo: a dictionnary for metainformation.

        Attended keys for the metainfo parameters are:
            - license: a string ex GPL, LGPL, Cecill, Cecill-C
            - version: a string
            - authors: a string
            - institutes: a string
            - url: a string
            - description: a string for the package description
            - publication: optional string for publications

        """

        PackageDict.__init__(self)

        self.name = name
        self.metainfo = metainfo

        # package directory

        if (not path):
            # package directory
            import inspect
            # get the path of the file which call this function
            call_path = os.path.abspath(inspect.stack()[1][1])
            self.path = os.path.dirname(call_path)
            self.wralea_path = call_path

        # wralea.py path is specified
        else:
            if (not os.path.exists(path)):
                os.mkdir(path)
            if (not os.path.isdir(path)):
                self.path = os.path.dirname(path)
                self.wralea_path = path

            else:
                self.path = path
                self.wralea_path = os.path.join(self.path, "__wralea__.py")

            #wralea_name = name.replace('.', '_')

    def is_directory(self):
        """
        New style package.
        A package is embeded in a unique directory.
        This directory can not contain more than one package.
        Thus, you can move, copy or delete a package by acting on the directory without ambiguity.

        Return True if the package is embeded in a directory.
        """
        return self.wralea_path.endswith("__wralea__.py")

    def is_editable(self):
        """
        A convention (for the GUI) to ensure that the user can modify the package.
        """
        return False

    def get_pkg_files(self):
        """
        Return the list of python filename of the package.
        The filename are relative to self.path
        """

        #assert self.is_directory()

        ret = []
        for file in os.listdir(self.path):
            src = os.path.join(self.path, file)
            if (not os.path.isfile(src) or
               file.endswith(".pyc") or
               file.startswith(".")):
                continue
            ret.append(file)

        return ret

    def remove_files(self):
        """ Remove pkg files """
        assert False

    def reload(self):
        """ Reload all python file of the package """

        sources = self.get_pkg_files()

        s = set()  # set of full path name
        for f in sources:
            if (f.endswith('.py')):
                f += 'c'

            s.add(os.path.abspath(os.path.join(self.path, f)))

        for module in sys.modules.values():
            if (not module):
                continue
            try:
                modulefile = os.path.abspath(module.__file__)
                if (modulefile in s):
                    module.oa_invalidate = True
                    reload(module)
                    print "Reloaded ", module.__name__
            except:
                pass

    def get_wralea_path(self):
        """ Return the full path of the wralea.py (if set) """
        return self.wralea_path

    def get_id(self):
        """ Return the package id """
        return self.name

    def get_tip(self):
        """ Return the package description """

        str = "<b>Package:</b>%s<br/>\n" % (self.name, )
        try:
            str += "<b>Description : </b>%s<br/>\n" % (self.metainfo['description'].replace('\n', '<br/>'), )
        except:
            pass
        try:
            str += "<b>Authors :</b> %s<br/>\n" % (self.metainfo['authors'],)
        except:
            pass
        try:
            str += "<b>Institutes :</b> %s<br/>\n" % (self.metainfo['institutes'], )
        except:
            pass

        try:
            str += "<b>URL : </b>%s<br/>\n" % (self.metainfo['url'], )
        except:
            pass

        return str

    def get_metainfo(self, key):
        """
        Return a meta information.
        See the standard key in the __init__ function documentation.

        :param key: todo
        """
        return self.metainfo.get(key, "")

    def add_factory(self, factory):
        """ Add to the package a factory ( node or subgraph ) """

        if (factory.name in self):
            raise Exception("Factory %s already defined. Ignored !" % (factory.name, ))

        self[factory.name] = factory
        factory.package = self

        # Check validity
        # oops: this is a hack.
        # When the factory is a data factory that do not reference a file, raise an error.
        # This function return True or raise an error to have a specific diagnostic.
        try:
            factory.is_valid()

        except Exception, e:
            factory.package = None
            del(self[factory.name])
            raise e

        # Add Aliases
        if (factory.alias):
            for a in factory.alias:
                self[protected(a)] = factory
#
#       Distributed under the Cecill-C License.
#       See accompanying file LICENSE.txt or copy at
#           http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html
# 
#       OpenAlea WebSite : http://openalea.gforge.inria.fr
#
################################################################################
""" catalog.model """

__revision__ = " $Id$ "

from openalea.core import Factory as Fa
from openalea.core.pkgdict import protected

__name__ = protected("openalea.model")
# __name__ = "openalea.model"
__alias__ = ["catalog.model", ]

__version__ = '0.0.1'
__license__ = 'CECILL-C'
__authors__ = 'OpenAlea Consortium'
__institutes__ = 'INRIA/CIRAD'
__description__ = 'Models.'
__url__ = 'http://openalea.gforge.inria.fr'

__all__ = ['linear']

linear = Fa(uid="8005f33e4e7611e6bff6d4bed973e64a",
            name=protected("linearmodel"),
            description="Linear Model",
Beispiel #11
0
    nodemodule="operator",
    nodeclass="add",
)

range_ = Factory(
    name="range",
    description="Returns an arithmetic progression of integers",
    category="Python",
    nodemodule="nodes",
    nodeclass="pyrange",
)

__all__.append('range_')

list_ = Factory(
    name=protected("list"),
    description="Python list",
    category="datatype",
    nodemodule="nodes",
    nodeclass="List",
    inputs=(dict(name="List", interface=ISequence), ),
    outputs=(dict(name="List", interface=ISequence), ),
)

__all__.append('list_')

map_ = Factory(
    name="map",
    description="Apply a function on a sequence",
    category="Functional",
    inputs=(dict(name='func',
Beispiel #12
0
        nodemodule="operator",
        nodeclass="add",
        )



range_ = Factory(name="range",
                 description="Returns an arithmetic progression of integers",
                 category="Python",
                 nodemodule="nodes",
                 nodeclass="pyrange",
                 )

__all__.append('range_')

list_ = Factory( name=protected("list"),
                 description="Python list",
                 category="datatype",
                 nodemodule="nodes",
                 nodeclass="List",

                 inputs=(dict(name="List", interface=ISequence),),
                 outputs=(dict(name="List", interface=ISequence),),
                 )

__all__.append('list_')


map_ = Factory( name="map",
               description="Apply a function on a sequence",
               category="Functional",