[Ironpython-users] Set __metaclass__ on .NET type?

Slide slide.o.mix at gmail.com
Thu Jun 21 07:22:07 CEST 2012


I am playing around with using IronPython to replace a custom language
we use to define tasks and suites of tasks for an in-house automated
testing framework. Currently we have something like

task FooTask {
    cmdline = "...";

    file somefile.txt = (.
This will have some content, and even supports variables: $VAR1
    .)
}

table SomeTable = {
    VAR1
    1
    2
    3
}

suite SomeSuite {
    FooTask(SomeTable);
}

This would permute FooTask with VAR1 for each row in the table.

This is a bit more information than you probably need, but it will
give you the feel for what I am trying to do.

I was thinking I could reuse the objects that I now create in the
parser of the custom language as base types for Python object

class FooTask(Task):
    def __init__(self, variables):
        self.SetCmdLine("....")
        self.Files.Add("somefile.txt", "This will have some content,
and even supports variables: $VAR1")

class SomeSuite(Suite):
    def __init__(self):
        self.AddItem(FooTask() * [ { "VAR1" : "1" }, {"VAR1" : "2" },
{ "VAR1" : "3" } ])

I can easily implement __mult__ and other such operations to handle
the permutation and other operations I currently support.

Now, what I _think_ I need metaclasses for is that when FooTask or
SomeSuite is created, I need to be able to add the instance to my
symbol table so I can then create the output that I need to.

Am I thinking incorrectly about the need for metaclasses? I would like
to keep as much of the details as possible away from the users, so I
was thinking if I could hook into the object creation, I could add the
instance to my symbol table in the metaclass. For this, I would need
to set __metaclass__ on the base classes (Task and Suite), which are
.NET objects, is this doable?

Am I trying to fit a square peg into a round hole in general?

Thanks for reading my ramblings :-)

slide

-- 
Website: http://earl-of-code.com


More information about the Ironpython-users mailing list