def start_task(self): from Axon.Introspector import Introspector from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.Internet.TCPClient import TCPClient self.p = Pipeline(Introspector(), TCPClient(*self.visualiser_addr)) self.p.activate()
def test_Message_chunkDeChunk_remainsintact(self): from Kamaelia.Chassis.Pipeline import Pipeline syncmessage = "XXXXXXXXXXXXXXXXXXXXXXX" File = open("../../Examples/SimpleGraphicalApps/Ticker/Ulysses").read() chunks = [File[y:y+20] for y in xrange(0,len(File),20) ] chunker = Framing.DataChunker(syncmessage=syncmessage) dechunker = Framing.DataDeChunker(syncmessage=syncmessage) system = Pipeline( chunker, dechunker, ).activate() Dummy = Axon.Component.component() system.link((system, "outbox"),(Dummy, "inbox")) system.link((system, "signal"),(Dummy, "control")) for chunk in chunks: system._deliver(chunk, "inbox") activeScheduler = system.schedulerClass.run.main() for _ in xrange(2000): activeScheduler.next() resultchunks = [] try: while 1: # chunk = system._collect("outbox") chunk = Dummy.recv("inbox") resultchunks.append(chunk) except IndexError: pass # We collect all items in the outbox result = "".join(resultchunks) self.assertEqual(File[:20],result[:20])
class IntrospectorTask(Task): def __init__(self, bus=None): Task.__init__(self, bus) self.p = None self.visualiser_addr = None def start_task(self): from Axon.Introspector import Introspector from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.Internet.TCPClient import TCPClient self.p = Pipeline(Introspector(), TCPClient(*self.visualiser_addr)) self.p.activate() def stop_task(self): from Axon.Ipc import shutdownMicroprocess from Kamaelia.Util.OneShot import OneShot o = OneShot(msg=shutdownMicroprocess()) o.link((o, 'outbox'), (self.p, 'control')) o.activate()
def setup_initialise(self,*children,**otherargs): self.children=children[:] self.scheduler = scheduler() scheduler.run = self.scheduler self.pipeline = Pipeline(*children, **otherargs) self.inSrc = Dummy() self.inSrc.link((self.inSrc,"outbox"), (self.pipeline,"inbox")) self.inSrc.link((self.inSrc,"signal"), (self.pipeline,"control")) self.outDest = Dummy() self.outDest.link((self.pipeline,"outbox"), (self.outDest,"inbox")) self.outDest.link((self.pipeline,"signal"), (self.outDest,"control")) self.run = self.scheduler.main()
import time import Axon from Kamaelia.Util.Backplane import * from Kamaelia.Util.Console import * from Kamaelia.Chassis.Pipeline import Pipeline class Source(Axon.ThreadedComponent.threadedcomponent): value = 1 sleep = 1 def main(self): while 1: self.send(str(self.value), "outbox") time.sleep(self.sleep) Backplane("broadcast").activate() Pipeline( Source(), SubscribeTo("broadcast"), ConsoleEchoer(), ).activate() Pipeline( ConsoleReader(), PublishTo("broadcast", forwarder=True), ConsoleEchoer(), ).run()
'timestamp': timestamp, 'ssrc': ssrc, 'extension': extension, 'csrcs': csrcs, 'marker': hasMarker, }) __kamaelia_components__ = (RTPDeframer, ) if __name__ == "__main__": from Kamaelia.Chassis.Pipeline import Pipeline # from Kamaelia.Internet.Multicast_transceiver import Multicast_transceiver from Multicast_transceiver import Multicast_transceiver from Kamaelia.Protocol.SimpleReliableMulticast import RecoverOrder from Kamaelia.File.Writing import SimpleFileWriter from Kamaelia.Util.Detuple import SimpleDetupler from Kamaelia.Util.Console import ConsoleEchoer Pipeline( Multicast_transceiver("0.0.0.0", 1600, "224.168.2.9", 0), #Multicast_transceiver("0.0.0.0", 1234, "239.255.42.42", 0), # for live555 testing SimpleDetupler(1), RTPDeframer(), RecoverOrder(), SimpleDetupler(1), SimpleDetupler("payload"), SimpleFileWriter("received.ts"), # ConsoleEchoer(), ).run()
i = argv.index("-" + f) args[flag] = True del argv[i] except ValueError: args[flag] = False rest = [a for a in argv if len(argv) > 0 and a[0] != "-"] args["__anon__"] = rest return args if __name__ == "__main__": from Kamaelia.File.Writing import SimpleFileWriter from Kamaelia.Chassis.Pipeline import Pipeline import sys args = parseargs( sys.argv[1:], { ("f", "file"): "audio.raw", ("c", "channels"): 2, ("r", "rate"): 44100, }, [("h", "help")], ) print repr(args) Pipeline(AlsaRecorder(channels=args["channels"], rate=args["rate"]), SimpleFileWriter(args["file"])).run()
Backplane("RAWINPUT").activate() Backplane("PARSEDINPUT").activate() Backplane("DISPLAYCONSOLE").activate() Image( image="kamaelia_logo.png", bgcolour=(255, 255, 255), position=(20, 20), size=(64, 64), maxpect=(64, 64), ).activate() Pipeline( SubscribeTo("RAWINPUT"), text_to_tokenlists(), Memory(), # These two can be mutually exclusive at times Repeater( ), # Which is interesting. Probably want a TPipe with some interesting control. PublishTo("PARSEDINPUT"), ).activate() Pipeline( SubscribeTo("RAWINPUT"), PublishTo("DISPLAYCONSOLE"), ).activate() Pipeline( SubscribeTo("PARSEDINPUT"), DrawingCanvas( background=0xD0D0D0, # Grey! surfacesize=(570, 650), surfaceposition=(430, 90)),
if isinstance(msg, (producerFinished, shutdownMicroprocess)): shutdown = True yield 1 __kamaelia_components__ = (SimpleDetupler, ) if __name__ == "__main__": from Kamaelia.Chassis.Pipeline import Pipeline class TupleSauce(Axon.Component.component): def main(self): while 1: self.send(("greeting", "hello", "world"), "outbox") yield 1 class CheckResultIsHello(Axon.Component.component): def main(self): while 1: while self.dataReady("inbox"): data = self.recv("inbox") if data != "hello": print "WARNING: expected", "hello", "received", data yield 1 Pipeline( TupleSauce(), SimpleDetupler(1), CheckResultIsHello(), ).run()
def capture_one(self): self.snapshot = None self.snapshot = self.camera.get_image() def main(self): self.camera.start() while 1: self.capture_one() self.send(self.snapshot, "outbox") time.sleep(self.delay) if __name__ == "__main__": from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.File.Writing import SimpleFileWriter from Kamaelia.Codec.Dirac import DiracEncoder from Kamaelia.Video.PixFormatConversion import ToYUV420_planar from Kamaelia.Util.PureTransformer import PureTransformer Pipeline( VideoCaptureSource(), PureTransformer(lambda F : \ {"rgb" : pygame.image.tostring(F, "RGB"), "size" : (352, 288), "pixformat" : "RGB_interleaved", }), ToYUV420_planar(), DiracEncoder(preset="CIF", encParams={"num_L1":0}), SimpleFileWriter("X.drc"), ).run()
sys.exit(0) resolution = dictArgs.get("screensize",(800,600)) doNavelgaze = dictArgs.pop("navelgaze", None) doIntrospect = dictArgs.pop("introspect", None) pgd = PygameDisplay(width=resolution[0],height=resolution[1]).activate() PygameDisplay.setDisplayService(pgd) if doIntrospect is not None: (server, port) = doIntrospect Pipeline( Introspector(), TCPClient(server, port) ).activate() if doNavelgaze: if "serverPort" in dictArgs: raise ValueError("Makes no sense to navelgaze and use --port option - they're mutually exclusive") app = Pipeline( Introspector(), ConsoleEchoer(forwarder=True), text_to_token_lists(), AxonVisualiser(caption="Axon / Kamaelia Visualiser", **dictArgs) ) else: app = AxonVisualiserServer(caption="Axon / Kamaelia Visualiser", **dictArgs) app.run()
if pid not in self.subscribed: print (self.spacing,"Shouldn't have received pid:",pid) else: if pid in self.notyetreceived: print (self.spacing,"Received 1st of pid:",pid) self.notyetreceived.remove(pid) if self.scheduler.time >= nextchangetime: nextchangetime = self.scheduler.time + random.randrange(10,20) self.changeSubscription() self.notyetreceived = self.subscribed[:] if self.subscribed: self.pause() yield 1 svc = ReassemblePSITablesService() src = Pipeline(Producer(),svc) Subscriber(28+0, 1,2,3,4,5).activate() Subscriber(28+25, 1,2,3,4,5).activate() # from Kamaelia.Util.Introspector import Introspector # from Kamaelia.Internet.TCPClient import TCPClient # # Pipeline(Introspector(),TCPClient("r44116",1500)).activate() print ("May take several seconds before you see any activity...") print ("---PSI Reassemblers------|---1st subscriber:------|---2nd subscriber:------") src.run()
return #if not self.anyReady(): # self.pause() yield 1 backplane = Backplane("SAMPLE") backplane.activate() producer = Producer() consumer = Consumer() published = PublishTo("SAMPLE") subscribe = SubscribeTo("SAMPLE") pipe1 = Pipeline( producer, published, ) pipe1.activate() pipe2 = Pipeline( subscribe, consumer ) consumer2 = Consumer() consumer2.activate() pipe1.link((pipe1,'signal'),(pipe2,'control')) pipe2.link((pipe2,'signal'),(backplane,'control')) backplane.link((backplane,'signal'),(consumer2,'control'))
self.pause() yield 1 if 0: mysplitter = PlugSplitter( Producer() ) mysplitter.activate() Plug(mysplitter, Consumer("consumerA") ).activate() Plug(mysplitter, Consumer("consumerB") ).activate() mysplitter.run() if 0: producer = Producer() mysplitter = PlugSplitter() pipe = Pipeline(producer, mysplitter) Plug(mysplitter, Consumer("consumerA") ).activate() Plug(mysplitter, Consumer("consumerB") ).activate() pipe.run() if 1: mysplitter = PlugSplitter() pipe = Pipeline( Producer(), mysplitter ) forwarder1 = Forwarder("forwarder") plug1 = Plug(mysplitter,forwarder1) plug1.activate() forwarder1b = Forwarder("forwarder1b")
# Inboxes not listed, since as default Outboxes = ["outbox", "signal", "toprocessor"] @staticmethod def condition(message): return int(message) == 5 @staticmethod def process(message): return "Is Johnny 5 Alive ?" def main(self): self.link((self, "toprocessor"), (TPP, "processor")) self.send(("five", self.condition, self), "toprocessor") while not self.dataReady("control"): for message in self.Inbox("inbox"): self.send(self.process(message), "outbox") if not self.anyReady(): self.pause() yield 1 self.send(self.recv("control"), "signal") from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.Util.Console import * Pipeline(ConsoleReader(), TPP, ConsoleEchoer()).activate() SimpleCondTransformer().run()
['6.inbox', 'inbox']], [['6.outbox', 'outbox'], ['6.signal', 'signal'], ['6.yuvdata', 'yuvdata'], ['6.displayctrl', 'displayctrl'] ], ('ADD', ('VideoOverlay', '6'), 'VideoOverlay', { 'configuration': { 'args': [], 'dictargs': None, 'theclass': '<class Kamaelia.UI.Pygame.VideoOverlay.VideoOverlay>', 'tupleargs': None }, 'id': ('VideoOverlay', '6'), 'instantiation': '', 'module': 'Kamaelia.UI.Pygame.VideoOverlay', 'name': 'VideoOverlay' }, None)), '6.control': ('INBOX', 'control', '6'), '6.displayctrl': ('OUTBOX', 'displayctrl', '6'), '6.inbox': ('INBOX', 'inbox', '6'), '6.outbox': ('OUTBOX', 'outbox', '6'), '6.signal': ('OUTBOX', 'signal', '6'), '6.yuvdata': ('OUTBOX', 'yuvdata', '6') } } Pipeline( Source([TESTCASE]), CodeGen(), TextOutputGUI("Basic Display"), ).run()
self.send(self.recv("control"), "signal") class Damage(Axon.Component.component): """Simple L-System damager""" def damageModel(self, model): newmodel = "" dratio = 0 if len(model) < 10: dratio = 0 if len(model) > 60: dratio = 50 for atom in model: if random.randint(0, 100) > dratio: newmodel += atom return newmodel def main(self): while not self.dataReady("control"): for model in self.Inbox("inbox"): model = self.damageModel(model) self.send(model, "outbox") yield 1 self.send(self.recv("control"), "signal") Pipeline( LSystem(), ConsoleEchoer(tag="\n", forwarder=True), # Would be nice to be a renderer Damage(), circular=True, ).run()
] def OpenCVPublisher(*args, **argd): return PublishTo("OPENCV_VOTES") Backplane("OPENCV_VOTES").activate() Backplane("PROGRAMME").activate() Backplane("OUIJAOUT").activate() Backplane("OUIJAIN").activate() Backplane("USERRESPONSE").activate() Backplane("SCHEDULECONTROL").activate() Backplane("PINGERCONTROL").activate() Pipeline( ConsoleReader(">> "), PureTransformer(lambda x: x[:-1]), PublishTo("PROGRAMME"), ).activate() testing = False template = "skip N love N ban N" if testing: Backplane("DEBUGIN").activate() Pipeline( SubscribeTo("DEBUGIN"), PublishTo("USERRESPONSE"), ).activate() Pipeline( Textbox(position=(250,48), size=(500,150)), PublishTo("DEBUGIN"),
# Copyright 2010 British Broadcasting Corporation and Kamaelia Contributors(1) # # (1) Kamaelia Contributors are listed in the AUTHORS file and at # http://www.kamaelia.org/AUTHORS - please extend this file, # not this notice. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.Util.Console import * from Kamaelia.Experimental.PythonInterpreter import InterpreterTransformer Pipeline( ConsoleReader(), InterpreterTransformer(), ConsoleEchoer(), ).run()
config = cjson.decode(raw_config) bitlyusername = config['bitlyusername'] bitlyapikey = config['bitlyapikey'] proxy = config['proxy'] READER = ConsoleReader() DECODER = PureTransformer(lambda x: cjson.decode(x)) CLEANER = TweetCleaner(['user_mentions','urls','hashtags']) WRITER = ConsoleEchoer() FIXER = RetweetFixer() SPELLING = PureTransformer(lambda x: spellingFixer(x)) LINKER = LinkResolver(bitlyusername,bitlyapikey) REQUESTER = HTTPGetter(proxy, "BBC R&D Grabber") if 0: Pipeline(READER,DECODER,CLEANER,WRITER).run() if 0: Pipeline(READER,DECODER,FIXER,WRITER).run() if 0: Graphline(READER=READER,DECODER=DECODER,LINKER=LINKER,REQUESTER=REQUESTER,WRITER=WRITER, linkages = {("READER", "outbox") : ("DECODER", "inbox"), ("DECODER", "outbox") : ("LINKER", "inbox"), ("LINKER", "urlrequests") : ("REQUESTER", "inbox"), ("REQUESTER", "outbox") : ("LINKER", "responses"), ("LINKER", "outbox") : ("WRITER", "inbox"),}).run() if 1: Graphline(READER=READER,DECODER=DECODER,LINKER=LINKER,REQUESTER=REQUESTER,FIXER=FIXER,CLEANER=CLEANER,WRITER=WRITER, linkages = {("READER", "outbox") : ("DECODER", "inbox"),
def shutdown(self): """\ Returns True if a shutdownMicroprocess or producerFinished message is received. Also passes the message on out of the "signal" outbox. """ while self.dataReady("control"): msg = self.recv("control") if isinstance(msg, shutdownMicroprocess) or isinstance(msg, producerFinished): self.send(msg, "signal") return True return False def closeDownComponent(self): """Closes the file handle""" self.file.close() __kamaelia_components__ = ( SimpleFileWriter, ) if 1: if __name__ == "__main__": from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.File.Reading import RateControlledFileReader Pipeline( RateControlledFileReader("Writing.py"), SimpleFileWriter("/tmp/tmp_Writing.py") ).run()
else: changed = True bx, by = positions_dictionary[other] dx = ax - bx dy = ay - by d = int(math.sqrt((dx * dx) + (dy * dy))) distance[(key, other)] = d if changed: self.send(repr(distance) + "\n", "outbox") # XXXX Note this is broken yield 1 Pipeline( KeyEvent(outboxes={"outbox": ""}, key_events={pygame.K_q: ("start_up", "outbox")}), Quitter(), ).activate() Backplane("PLAYERS").activate() Pipeline( MyGamesEventsComponent(up="p", down="l", left="a", right="s"), BasicSprite("cat.png", name="cat", border=40), PureTransformer(lambda x: ("Cat ", x)), PublishTo("PLAYERS"), ).activate() Pipeline( MyGamesEventsComponent(up="up", down="down", left="left", right="right"), BasicSprite("mouse.png", name="mouse", border=40),
def NetInterpreter(*args, **argv): return Pipeline( PureTransformer(lambda x: str(x).rstrip()), InterpreterTransformer(), PureTransformer(lambda x: str(x) + "\r\n>>> "), )
pass if self.dataReady("control"): self.send(self.recv("control"), "signal") else: self.send(Axon.Ipc.producerFinished(), "signal") if __name__ == "__main__": from TaggingPluggableProcessor import TaggingPluggableProcessor from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer from Kamaelia.Util.PureTransformer import PureTransformer TPP = TaggingPluggableProcessor() Pipeline(ConsoleReader(), PureTransformer(lambda x: int(x)), TPP, ConsoleEchoer()).activate() ConditionalTransformer(TPP, "EVEN", lambda x: x % 2 == 0, lambda x: "Even ! " + str(x)).activate() def isodd(x): return x % 2 == 1 def format_as_odd(x): return "Odd ! " + str(x) ConditionalTransformer(TPP, "ODD", isodd, format_as_odd).activate() class Divisible3(ConditionalTransformer): @staticmethod def condition(x):
transparent=True), PREVIOUS=Button(caption="Previous", msg="PREV", position=(0, 0), transparent=True), FIRST=Button(caption="First", msg="FIRST", position=(256, 0), transparent=True), LAST=Button(caption="Last", msg="LAST", position=(320, 0), transparent=True), linkages={ ("NEXT", "outbox"): ("CHOOSER", "inbox"), ("PREVIOUS", "outbox"): ("CHOOSER", "inbox"), ("FIRST", "outbox"): ("CHOOSER", "inbox"), ("LAST", "outbox"): ("CHOOSER", "inbox"), ("CHOOSER", "outbox"): ("IMAGE", "inbox"), }).activate() Pipeline( Button(caption="dink", msg="NEXT", position=(136, 0), transparent=True), Chooser(items=graph), chunks_to_lines(), lines_to_tokenlists(), TopologyViewer(transparency=(255, 255, 255), showGrid=False, position=(0, 0)), ).run()
def __init__(self, **argd): super(VideoCaptureSource, self).__init__(**argd) self.camera = pygame.camera.Camera(self.device, self.capturesize) self.camera.start() if self.fps != -1: self.delay = 1.0 / self.fps self.snapshot = None def capture_one(self): self.snapshot = None self.snapshot = self.camera.get_image() def main(self): while 1: self.capture_one() self.send(self.snapshot, "outbox") time.sleep(self.delay) Pipeline( VideoCaptureSource(), MessageCounter(name="ImagesIn"), PureTransformer(lambda F : \ {"rgb" : pygame.image.tostring(F, "RGB"), "size" : (352, 288), "pixformat" : "RGB_interleaved", }), ToYUV420_planar(), MessageCounter(name="DiracIn"), DiracEncoder(preset="CIF", encParams={"num_L1":0}), MessageCounter(name="DiracOut"), ).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from Axon.likefile import LikeFile, schedulerThread from Kamaelia.Codec.Vorbis import VorbisDecode, AOAudioPlaybackAdaptor from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.File.ReadFileAdaptor import ReadFileAdaptor import ao schedulerThread(slowmo=0.001).start() filename = "./snail.ogg" playStream = LikeFile(Pipeline(VorbisDecode(), AOAudioPlaybackAdaptor())) # Play the ogg data in the background oggdata = open(filename, "r+b").read() playStream.put(oggdata) while True: playStream.get() # there's no data produced but this will prevent us from exiting immediately.
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ------------------------------------------------------------------------- # # Simple test harness for integrating TCP clients and servers in one system, sharing selector components etc. # # import random from Kamaelia.Protocol.FortuneCookieProtocol import FortuneCookieProtocol from Kamaelia.Chassis.ConnectedServer import SimpleServer from Kamaelia.Internet.TCPClient import TCPClient from Kamaelia.Util.Console import ConsoleEchoer from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.Util.Introspector import Introspector # Start the introspector and connect to a local visualiser Pipeline( Introspector(), TCPClient("127.0.0.1", 1500), ).activate() clientServerTestPort = random.randint(1501, 1599) SimpleServer(protocol=FortuneCookieProtocol, port=clientServerTestPort).activate() Pipeline(TCPClient("127.0.0.1", clientServerTestPort), ConsoleEchoer()).run()
# -*- coding: utf-8 -*- # Copyright 2010 British Broadcasting Corporation and Kamaelia Contributors(1) # # (1) Kamaelia Contributors are listed in the AUTHORS file and at # http://www.kamaelia.org/AUTHORS - please extend this file, # not this notice. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.Util.Console import ConsoleReader from Kamaelia.Protocol.HTTP.HTTPClient import SimpleHTTPClient from Kamaelia.File.Writing import SimpleFileWriter Pipeline( ConsoleReader(">>> ", ""), SimpleHTTPClient(), SimpleFileWriter("downloadedfile.txt"), ).run()
def handleCloseWindowRequest(self): self.send(shutdownMicroprocess(self), "signal") self.window.destroy() def getname(self, fname): return fname.split(':')[1].lstrip() def click_addComponent(self): node, name = self.argPanel.getDef() self.send(("ADD", node, name), "outbox") def click_addInline(self): node, name = self.argPanel.getInlineDef() self.send(("ADD", node, name), "outbox") def click_menuChoice(self, fname, fcode): if self.argPanel != None: self.argPanel.destroy() self.argPanel = ImportShardPanel(self.argCanvas, fname, fcode) self.argPanel.update_idletasks() self.argCanvas.itemconfigure(self.argCanvasWID, window=self.argPanel) self.argCanvas['scrollregion'] = self.argCanvas.bbox("all") if __name__ == "__main__": from Kamaelia.Chassis.Pipeline import Pipeline Pipeline(ImportShardsGUI('/usr/lib/python2.5/site-packages/Kamaelia/Util'), ).run()
# not this notice. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from Kamaelia.Util.DataSource import DataSource from Kamaelia.Protocol.HTTP.HTTPClient import SingleShotHTTPClient, SimpleHTTPClient from HTTPClient import SingleShotHTTPClient, SimpleHTTPClient from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.Util.Console import ConsoleEchoer from Kamaelia.XML.SimpleXMLParser import SimpleXMLParser from HTTPDataParser import HTTPDataParser Pipeline( DataSource(["http://jibbering.com/foaf.rdf"]), SimpleHTTPClient(), #SingleShotHTTPClient("http://www.w3.org/2007/08/pyRdfa/extract?uri=http://apassant.net/about/#alex"), #SimpleXMLParser(), HTTPDataParser(), ConsoleEchoer() ).run()
# limitations under the License. # ------------------------------------------------------------------------- from Audio.PyMedia.Output import Output from Audio.Codec.PyMedia.Decoder import Decoder test = 1 if test == 1: from Kamaelia.File.Reading import RateControlledFileReader from Kamaelia.Chassis.Pipeline import Pipeline Pipeline( RateControlledFileReader("/home/matteh/music/Radiohead - Creep.mp3", readmode="bytes", rate=8 * 44100 * 2 * 2, chunksize=1024), Decoder("MP3"), Output(sample_rate=4 * 22050, channels=2, format="S16_LE"), ).run() elif test == 2: from Kamaelia.Chassis.Graphline import Graphline from Kamaelia.File.Reading import PromptedFileReader Graphline( READER=PromptedFileReader("/home/matteh/music/Radiohead - Creep.mp3", readmode="bytes"), DECODE=Decoder("MP3"), OUTPUT=Output(sample_rate=2 * 22050, channels=2, format="S16_LE"), linkages={ ("READER", "outbox"): ("DECODE", "inbox"),
Backplane("AXONEVENTS").activate() bgcolour = (255, 255, 180) node_add_template = \ """ADD NODE %(nodeid)s non_config randompos component ADD NODE %(nodeid)s.o.outbox "outbox" randompos outbox ADD NODE %(nodeid)s.o.signal "signal" randompos outbox ADD NODE %(nodeid)s.i.inbox "inbox" randompos inbox ADD NODE %(nodeid)s.i.control "control" randompos inbox ADD LINK %(nodeid)s %(nodeid)s.o.outbox ADD LINK %(nodeid)s %(nodeid)s.o.signal ADD LINK %(nodeid)s %(nodeid)s.i.inbox ADD LINK %(nodeid)s %(nodeid)s.i.control """ Pipeline( ConsoleReader(), PublishTo("AXONVIS"), ).activate() Pipeline( SubscribeTo("AXONVIS"), text_to_token_lists(), AxonVisualiser(caption="Axon / Kamaelia Visualiser", screensize=(1024, 500), position=(0, 0), transparency=(255, 255, 255)), PublishTo("AXONEVENTS"), ).activate() class NodeAdder(Axon.Component.component): Outboxes = {
from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.Chassis.Graphline import Graphline from Kamaelia.Util.Console import ConsoleEchoer import os # test="rate limit output" # test="rate limited input" # test="reached end of output" # test="outpipes" test="inpipes" if test=="rate limit output": Pipeline( UnixProcess("cat /dev/zero",32*1024*1024), LineSplit(), Chunk(10), RateLimiter(10), CumulateSize(), ConsoleEchoer(forwarder=True) ).run() elif test=="rate limited input": ratelimiter=RateLimiter(10) ratelimiter.inboxes['inbox'].setSize(None) Pipeline( ChargenComponent(), ratelimiter, UnixProcess("cat -",32), ConsoleEchoer(forwarder=True) ).run() elif test=="reached end of output":
self.link((self, "inbox"), (self.chatter, "talk"), passthrough=1) self.link((self.chatter, "outbox"), (self.oscar, "inbox")) self.link((self.oscar, "outbox"), (self.chatter, "inbox")) self.link((self, "internal outbox"), (self.chatter, "inbox")) while len(queued): self.send(queued[0], "internal outbox") del(queued[0]) assert self.debugger.note("AIMHarness.main", 5, "Everything linked up and initialized, starting normal operation") while True: #FIXME: Why do we keep running instead of dying? self.pause() yield 1 __kamaelia_components__ = (AIMHarness, ) if __name__ == '__main__': from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.Util.Console import ConsoleEchoer, ConsoleReader from Kamaelia.Util.PureTransformer import PureTransformer def tuplefy(data): data = data.split() if len(data) > 1: data = ("message", data[0], " ".join(data[1:])) return data Pipeline(ConsoleReader(), PureTransformer(tuplefy), AIMHarness("kamaelia1", "abc123"), ConsoleEchoer() ).run()
while True: l = f.readline() if not l: # no data time.sleep(.1) else: yield l @TransformerGenComponent def grep(lines, pattern): "To stop this generator, you need to call it's .stop() method. The wrapper could do this" regex = re.compile(pattern) while 1: for l in lines(): if regex.search(l): yield l yield @TransformerGenComponent def printer(lines): "To stop this generator, you need to call it's .stop() method. The wrapper could do this" while 1: for line in lines(): sys.stdout.write(line) sys.stdout.flush() yield Pipeline(follow("somefile.txt"), grep(None, "o"), printer(None)).run()
#!/usr/bin/python # -*- coding: utf-8 -*- from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.Util.Console import * # ------- START OF CODE FRAGMENT NEEDED TO CONNECT TO INTROSPECTOR ---- # Remember to start Kamaelia/Tools/AxonVisualiser before doing this. # cd Kamaelia/Tools # ./AxonVisualiser.py --port=1600 from Kamaelia.Util.Introspector import Introspector from Kamaelia.Internet.TCPClient import TCPClient Pipeline( Introspector(), TCPClient("127.0.0.1", 1600), ).activate() # ------- END OF CODE FRAGMENT NEEDED TO CONNECT TO INTROSPECTOR ---- Pipeline( ConsoleReader(), ConsoleEchoer(), ).run()
self.pause() yield 1 # self.send(Axon.Ipc.producerFinished(message=self.display), "displayctrl") self.send(None, "yuvdata") # print "OK, we're done" __kamaelia_components__ = (VideoOverlay, ) if __name__ == "__main__": from Kamaelia.Codec.Dirac import DiracDecoder from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.File.ReadFileAdaptor import ReadFileAdaptor from Kamaelia.Codec.RawYUVFramer import RawYUVFramer # Pipeline( ReadFileAdaptor("/data/dirac-video/snowboard-jum-352x288x75.yuv", readmode="bitrate", bitrate = 2280960*8), Pipeline( ReadFileAdaptor("/data/dirac-video/snowboard-jum-352x288x75.dirac.drc", readmode="bitrate", bitrate=2280960 * 8), # Pipeline( ReadFileAdaptor("test.yuv", readmode="bitrate", bitrate = 2280960*8), DiracDecoder(), # RawYUVFramer(size=(352,288), pixformat = "YUV420_planar" ), # Pipeline( ReadFileAdaptor("/data/dirac-video/snowboard-jum-720x576x50.yuv", readmode="bitrate", bitrate = 2280960*8*4), # RawYUVFramer(size=(720,576), pixformat = pygame.IYUV_OVERLAY), VideoOverlay(), ).run()
class Test_Pipeline(unittest.TestCase): def setup_test(self, *children, **otherargs): self.setup_initialise(*children,**otherargs) self.setup_activate() def setup_initialise(self,*children,**otherargs): self.children=children[:] self.scheduler = scheduler() scheduler.run = self.scheduler self.pipeline = Pipeline(*children, **otherargs) self.inSrc = Dummy() self.inSrc.link((self.inSrc,"outbox"), (self.pipeline,"inbox")) self.inSrc.link((self.inSrc,"signal"), (self.pipeline,"control")) self.outDest = Dummy() self.outDest.link((self.pipeline,"outbox"), (self.outDest,"inbox")) self.outDest.link((self.pipeline,"signal"), (self.outDest,"control")) self.run = self.scheduler.main() def setup_activate(self): self.pipeline.activate(Scheduler=self.scheduler) self.inSrc.activate(Scheduler=self.scheduler) self.outDest.activate(Scheduler=self.scheduler) def sendToInbox(self,data): self.inSrc.send(data,"outbox") def sendToControl(self,data): self.inSrc.send(data,"signal") def dataReadyOutbox(self): return self.outDest.dataReady("inbox") def dataReadySignal(self): return self.outDest.dataReady("control") def recvOutbox(self): return self.outDest.recv("inbox") def recvSignal(self): return self.outDest.recv("control") def collectOutbox(self): out=[] while self.dataReadyOutbox(): out.append(self.recvOutbox()) return out def collectSignal(self): out=[] while self.dataReadySignal(): out.append(self.recvSignal()) return out def runFor(self, cycles): numcycles=cycles*(3+len(self.children)) # approx this many components in the system for i in range(0,numcycles): self.run.next() def test_PipelineActivatesChildrenOnlyWhenActivated(self): """Children are activated as soon as the Pipeline itself is activated, but no sooner.""" self.setup_initialise(MockChild(), MockChild(), MockChild()) for child in self.children: self.assert_(not child.wasActivated) self.setup_activate() self.runFor(cycles=1) self.runFor(cycles=3) for child in self.children: self.assert_(child.wasActivated) def test_PipelineTerminatesOnlyWhenAllChildrenHaveTerminated(self): self.setup_test(MockChild(), MockChild(), MockChild()) self.runFor(cycles=100) self.assert_(not self.pipeline._isStopped()) for child in self.children: self.assert_(not self.pipeline._isStopped()) # stop each child one at a time, and check that it is the only thing to # have stopped for child in self.children: # check the pipeline is still running self.assert_(not self.pipeline._isStopped()) child.stopNow() self.runFor(cycles=100) # by now the pipeline should have stopped too self.assert_(self.pipeline._isStopped()) def test_PipelineChildrenWiredOutboxInbox(self): """Pipeline wires up children so one child's "outbox" outbox feeds to the next's "inbox" inbox.""" self.setup_test(MockChild(), MockChild(), MockChild(), MockChild()) self.runFor(cycles=100) MSG = object() self.children[0].send(MSG, "outbox") for child in self.children[1:-1]: # all except first and last # expect to have received: self.assert_(child.recv("inbox") == MSG) # now send MSG = object() child.send(MSG, "outbox") self.assert_(self.children[-1].recv("inbox") == MSG) def test_PipelineChildrenWiredSignalControl(self): """Pipeline wires up children so one child's "signal" outbox feeds to the next's "control" inbox.""" self.setup_test(MockChild(), MockChild(), MockChild(), MockChild()) self.runFor(cycles=100) MSG = object() self.children[0].send(MSG, "signal") for child in self.children[1:-1]: # all except first and last # expect to have received: self.assert_(child.recv("control") == MSG) # now send MSG = object() child.send(MSG, "signal") self.assert_(self.children[-1].recv("control") == MSG) def test_PipelineFirstChildWiredToParentInboxes(self): """Pipeline wires up the first child's "inbox" and "control" inboxes to receive from the pipeline's "inbox" and "control" inboxes.""" self.setup_test(MockChild(), MockChild(), MockChild(), MockChild()) self.runFor(cycles=100) MSG = object() self.sendToInbox(MSG) self.assert_(self.children[0].recv("inbox")==MSG) MSG = object() self.sendToControl(MSG) self.assert_(self.children[0].recv("control")==MSG) def test_PipelineLastChildWiredToParentOutboxes(self): """Pipeline wires up the last child's "outbox" and "signal" outboxes to send out of the pipeline's "outbox" and "signal" outboxes.""" self.setup_test(MockChild(), MockChild(), MockChild(), MockChild()) self.runFor(cycles=100) MSG = object() self.children[-1].send(MSG,"outbox") self.assert_(self.recvOutbox()==MSG) MSG = object() self.children[-1].send(MSG,"signal") self.assert_(self.recvSignal()==MSG)