本文整理汇总了Python中openalea.core.pkgmanager.PackageManager类的典型用法代码示例。如果您正苦于以下问题:Python PackageManager类的具体用法?Python PackageManager怎么用?Python PackageManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PackageManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_auto_io
def test_auto_io():
""" Test auto io"""
pm = PackageManager()
pm.init()
sg = CompositeNode()
# build the compositenode factory
val1id = sg.add_node(pm.get_node("Catalog.Data", "string"))
val2id = sg.add_node(pm.get_node("Catalog.Data", "string"))
val3id = sg.add_node(pm.get_node("Catalog.Data", "string"))
sg.connect(val1id, 0, val3id, 0)
sg.connect(val2id, 0, val3id, 0)
sgfactory = CompositeNodeFactory("testlautoio")
sg.to_factory(sgfactory, listid=[val1id, val2id, val3id], auto_io=True)
# allocate the compositenode
sg = sgfactory.instantiate()
assert sg.get_nb_input() == 2
assert sg.get_nb_output() == 1
sg.set_input(0, "to")
sg.set_input(1, "to")
sg()
res = sg.get_output(0)
assert ''.join(eval(res)) == "toto"
示例2: test1
def test1(directory):
from openalea.core.pkgmanager import PackageManager
pm = PackageManager()
pm.init(verbose=False)
obj = vlab_object(directory, pm)
pkg = obj.get_package()
pkg.write()
示例3: test_multi_in_eval
def test_multi_in_eval():
""" Test multiple out connection"""
pm = PackageManager()
pm.init()
sg = CompositeNode()
# build the compositenode factory
val1id = sg.add_node(pm.get_node("Catalog.Data", "string"))
val2id = sg.add_node(pm.get_node("Catalog.Data", "string"))
val3id = sg.add_node(pm.get_node("Catalog.Data", "string"))
sg.connect(val1id, 0, val3id, 0)
sg.connect(val2id, 0, val3id, 0)
sgfactory = CompositeNodeFactory("testlazyeval")
sg.to_factory(sgfactory)
# allocate the compositenode
sg = sgfactory.instantiate()
sg.node(val1id).set_input(0, "teststring1")
sg.node(val2id).set_input(0, "teststring2")
sg()
assert (sg.node(val3id).get_output(0) == "['teststring1', 'teststring2']")\
or \
(sg.node(val3id).get_output(0) == "['teststring2', 'teststring1']")
示例4: test_addnode
def test_addnode():
"""Test node addition"""
pm = PackageManager()
pm.init()
sg = CompositeNode()
# build the compositenode factory
val1id = sg.add_node(pm.get_node("Catalog.Data", "float"))
val2id = sg.add_node(pm.get_node("Catalog.Data", "float"))
sg.connect(val1id, 0, val2id, 0)
sgfactory = CompositeNodeFactory("testaddnode")
sg.to_factory(sgfactory)
# allocate the compositenode
sg = sgfactory.instantiate()
sg.node(val1id).set_input(0, 2.)
sg()
assert sg.node(val2id).get_output(0)==2.
# Add a new node
addid = sg.add_node(pm.get_node("Catalog.Math", "+"))
sg.connect(val1id, 0, addid, 0)
sg.connect(val2id, 0, addid, 1)
sg.to_factory(sgfactory)
sg = sgfactory.instantiate()
sg.node(val1id).set_input(0, 3.)
sg()
assert sg.node(addid).get_output(0)==6.
示例5: mimeData
def mimeData(self, modelIndexes):
item = self.itemFromIndex(modelIndexes[0])
mimeData = QtGui.QStandardItemModel.mimeData(self, modelIndexes)
(pkg_id, factory_id, mimetype) = self.get_item_info(item)
# -- marshall package and factory to the data stream, needed later --
itemData = QtCore.QByteArray()
dataStream = QtCore.QDataStream(itemData, QtCore.QIODevice.WriteOnly)
dataStream.writeString(pkg_id)
dataStream.writeString(factory_id)
mimeData.setData(mimetype, itemData)
# -- build an url --
factory = PackageManager()[pkg_id][factory_id]
if isinstance(factory, DataFactory):
url = QtCore.QUrl.fromLocalFile(factory.get_pkg_data().repr)
else:
query = ["fac="+factory_id]
ftname = type(factory).__name__
query.append("ft="+ftname)
query = reduce(lambda x,y:"&".join((x,y)), query)
url = QtCore.QUrl("oa://local/"+pkg_id+"?"+query)
mimeData.setUrls([url])
return mimeData
示例6: test_recursion_factory
def test_recursion_factory():
""" Test Recursion detection"""
pm = PackageManager()
pm.init()
pkg = Package("compositenode", {})
sgfactory1 = CompositeNodeFactory("graph1")
sgfactory2 = CompositeNodeFactory("graph2")
map(pkg.add_factory, (sgfactory1, sgfactory2))
assert len(pkg.get_names()) == 2
pm.add_package(pkg)
n1 = sgfactory1.instantiate()
n2 = sgfactory1.instantiate()
# build the compositenode factory
n1.add_node(n2)
n2.add_node(n1)
n1.to_factory(sgfactory1)
n2.to_factory(sgfactory2)
#sgfactory1.add_nodefactory ( ("compositenode", "graph2"))
#sgfactory2.add_nodefactory ( ("compositenode", "graph1"))
try:
sg = sgfactory1.instantiate()
assert False
except RecursionError:
assert True
示例7: test_data
def test_data():
"""test data"""
pm = PackageManager()
pm.init()
assert pm['pkg_test']['file1.txt']
assert pm['pkg_test']['file2.txt']
示例8: test_save_workspace
def test_save_workspace():
pm = PackageManager()
pm.init()
asession = Session()
import sys
sgfactory = CompositeNodeFactory(name="SubGraphExample",
description= "Examples",
category = "Examples",
)
sg= CompositeNode()
# build the subgraph factory
addid = sg.add_node(pm.get_node("pkg_test", "float"))
sg.to_factory(sgfactory)
instance = sgfactory.instantiate()
instance.actor(addid).set_input(0, 3)
asession.add_workspace(instance)
asession.save('test.pic')
asession.workspaces = []
asession.load('test.pic')
try:
os.remove('test.pic')
except:
os.remove('test.pic.db')
i = asession.workspaces[0]
assert type(i) == type(instance)
示例9: test_register
def test_register():
"""Test register"""
pkgmanager = PackageManager()
register_packages(pkgmanager)
assert "test" in pkgmanager.keys()
pkg = pkgmanager["Test"]
assert "sum" in pkg.keys()
assert "userclass" in pkg.keys()
assert "userfunc" in pkg.keys()
fact = pkg["sum"]
node = fact.instantiate()
assert (node.get_nb_input() == 1) and (node.get_nb_output() == 1)
fact = pkg["userfunc"]
node = fact.instantiate()
assert (node.get_nb_input() == 2) and (node.get_nb_output() == 1)
fact = pkg["userclass"]
node = fact.instantiate()
assert (node.get_nb_input() == 2) and (node.get_nb_output() == 1)
示例10: _test_lambda
def _test_lambda():
""" Test for lambda functions"""
pm = PackageManager()
pm.init()
import testnodes
testnodes.register_packages(pm)
for t, id, res in (
('LambdaFactoriel', 2, 362880),
('testlambdaFor', 3, 12),
('testlambdaFor', 9, [12, 5]),
('testorder', 4, [1., 2.]),
('TestLambda', 3, map(lambda x: (x+5)*5, range(10))),
('testlambda2', 10, filter(lambda x: x>=2 and x <= 7, range(10))),
('testlambda3', 3, map(lambda y: filter(lambda x: x>=7, y), \
[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], \
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], \
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])),
('test_str', 5, ['toto', 'toto']),
):
n = pm.get_node("TestLambda", t)
n()
print n.node(id).get_output(0), res
assert n.node(id).get_output(0) == res
示例11: test_multi_out_eval
def test_multi_out_eval():
""" Test multiple out connection"""
pm = PackageManager()
pm.init()
sg = CompositeNode()
# build the compositenode factory
val1id = sg.add_node(pm.get_node("Catalog.Data", "string"))
val2id = sg.add_node(pm.get_node("Catalog.Data", "string"))
val3id = sg.add_node(pm.get_node("Catalog.Data", "string"))
sg.connect(val1id, 0, val2id, 0)
sg.connect(val1id, 0, val3id, 0)
sgfactory = CompositeNodeFactory("testlazyeval")
sg.to_factory(sgfactory)
# allocate the compositenode
sg = sgfactory.instantiate()
sg.node(val1id).set_input(0, "teststring")
sg()
assert sg.node(val2id).get_output(0) == "teststring"
assert sg.node(val3id).get_output(0) == "teststring"
#partial evaluation
sg.node(val1id).set_input(0, "teststring2")
sg.eval_as_expression(val2id)
assert sg.node(val2id).get_output(0) == "teststring2"
sg.eval_as_expression(val3id)
assert sg.node(val3id).get_output(0) == "teststring2"
示例12: test_to_factory
def test_to_factory():
""" Create a compositenode, generate its factory and reintantiate it """
pm = PackageManager()
pm.init()
sg = CompositeNode()
n1 = pm.get_node("Catalog.Data", "float")
n2 = pm.get_node("Catalog.Data", "float")
e1 = sg.add_node(n1)
e2 = sg.add_node(n2)
sg.connect(e1, 0, e2, 0)
n1.set_input(0, 34.)
sg()
assert n2.get_output(0)==34.
sgfactory = CompositeNodeFactory("factorytest")
sg.to_factory(sgfactory)
sg2 = sgfactory.instantiate()
assert len(list(sg2.vertices()))==2+2 # two nodes + in/ou
assert len(list(sg2.edges()))==1
sg2.node(e1).set_input(0, 3.)
sg2()
assert sg2.node(e2).get_output(0)==3.
return pm, sg, sgfactory
示例13: test_search
def test_search():
pkgman = PackageManager()
pkgman.load_directory("./")
assert 'Test' in pkgman
res = pkgman.search_node("sum")
print res
assert "sum" in res[0].name
示例14: test_alias
def test_alias():
"""test_alias: aliases in PackageManager"""
pkgman = PackageManager()
pkgman.load_directory("pkg")
assert pkgman["pkg_test"]["file2.txt"]
assert pkgman["pkg_test"]["file2.txt"] is pkgman["pkg_test"]["f"]
assert pkgman["pkg_test"]["file2.txt"] is pkgman["pkg_test"]["g"]
assert pkgman["pkg_test"]["file1.txt"]
assert pkgman["pkg_test"]["aliasf1"] is pkgman["pkg_test"]["file1.txt"]
示例15: test_compositenodewriter
def test_compositenodewriter():
setup_module()
pm = PackageManager()
pm.init()
sg = CompositeNode(inputs=[dict(name="%d" % i) for i in xrange(3)],
outputs=[dict(name="%d" % i) for i in xrange(4)],
)
# build the compositenode factory
addid = sg.add_node(pm.get_node("pkg_test", "+"))
val1id = sg.add_node(pm.get_node("pkg_test", "float"))
val2id = sg.add_node(pm.get_node("pkg_test", "float"))
val3id = sg.add_node(pm.get_node("pkg_test", "float"))
sg.connect(val1id, 0, addid, 0)
sg.connect(val2id, 0, addid, 1)
sg.connect(addid, 0, val3id, 0)
sg.connect(val3id, 0, sg.id_out, 0)
sgfactory = CompositeNodeFactory("addition")
sg.to_factory(sgfactory)
# Package
metainfo = {'version': '0.0.1',
'license': 'CECILL-C',
'authors': 'OpenAlea Consortium',
'institutes': 'INRIA/CIRAD',
'description': 'Base library.',
'url': 'http://openalea.gforge.inria.fr'}
package1 = pm.create_user_package("MyTestPackage",
metainfo, os.path.curdir)
package1.add_factory(sgfactory)
print package1.keys()
assert 'addition' in package1
package1.write()
sg = sgfactory.instantiate()
sg.node(val1id).set_input(0, 2.)
sg.node(val2id).set_input(0, 3.)
# evaluation
sg()
print sg.node(val3id).get_output(0)
assert sg.node(val3id).get_output(0) == 5.
print "nb vertices", len(sg)
assert len(sg) == 6
pm.init()
newsg = pm.get_node('MyTestPackage', 'addition')
print "nb vertices", len(newsg)
assert len(newsg) == 6