Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
namespace-intersection defined; stubbing autonomy readout for agent-d…
Browse files Browse the repository at this point in the history
…erived objs
  • Loading branch information
mvr committed Mar 18, 2012
1 parent e06942e commit 65a15e2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/cortex/services/web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .eventdemo import rootpage
from cortex.mixins import LocalQueue

class Web(Service, LocalQueue):
class Web(LocalQueue, Service):
""" Stub Service:
start: brief description of service start-up here
stop: brief description service shutdown here
Expand Down Expand Up @@ -67,7 +67,7 @@ def start(self):
self.universe.reactor.callWhenRunning(go)
Service.start(self)

def run(self):
def asdrun(self):
""" see docs for ThreadedIterator """
while self.started:
self.iterate()
Expand All @@ -77,9 +77,9 @@ def _post_init(self, **kargs):
""" initialize the local queue """
self.init_q()

def iterate(self):
def asdfiterate(self):
""" """
#report('iterating')
report('iterating')
return
e = self.pop_q()
if not e:
Expand Down
2 changes: 2 additions & 0 deletions lib/cortex/services/web/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def template(self):
else:
ctx.update(source=get_source(self.target))
if isinstance(self.target, Agent):
from cortex.mixins.autonomy import Autonomy
T = template('objects/agent')
ctx.update(autonomy=NSPart(self.target).intersection(NSPart(Autonomy)))
elif self.target == Universe:
T = template('objects/universe')
elif isinstance(self.target, types.MethodType):
Expand Down
23 changes: 22 additions & 1 deletion lib/cortex/services/web/templates/objects/agent.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@


{%block page_title%}{{obj_name}}{%endblock%}
{%block obj_type%}AGENT{%endblock%}
{%block obj_type%}AGENT(base)){%endblock%}

{%block obj_nav%}
<a href="javascript:$('#autonomy').toggle()">Autonomy Aspect</a>
{{super()}}
{%endblock%}

{%block obj_namespace%}
{{super()}}
Expand All @@ -15,3 +20,19 @@
{% with namespace=data%}{%include "objects/_namespace.html"%}{%endwith%}
</td>
{%endblock%}


{%block obj_main%}
<table>
<tr>
<td>agent etc
</td></tr>
<tr class=hidden id=autonomy>
<td>
<strong>Autonomy:</strong>
{% with namespace=autonomy%}{%include "objects/_namespace.html"%}{%endwith%}
</td>
</tr>
</table>
{{super()}}
{%endblock%}
9 changes: 9 additions & 0 deletions lib/cortex/util/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ def subclasses_of(self, thing, strict=True):
test = lambda obj: issubclass(obj,kls)
return self.generic(test)

def intersection(self, other):
if isinstance(other, (dict,NSPart)):
other = getattr(other, 'namespace', other)
result = [ [k,self[k]] for k in self.namespace if k in other]
else:
raise RuntimeError,'niy'
result = dict(result)
return result if self.dictionaries else self.__class__(result)

# Begin aliases, shortcuts
################################################################################
NSPart = NamespacePartitioner = NamespacePartition
Expand Down

0 comments on commit 65a15e2

Please sign in to comment.