Esempio n. 1
0
                if command == "undo\n":
                    self.send(self.loadMessage(current), "outbox")

            if not self.anyReady():
                yield 1


if __name__ == "__main__":
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

    def loadMessage(current):
        return [["LOAD", "slide.%d.png" % (current, )]]

    def saveMessage(current):
        return [["SAVE", "slide.%d.png" % (current, )]]


    #pipeline(
    #ConsoleReader(),
    #CheckpointSequencer(loadMessage,
    #saveMessage),
    #ConsoleEchoer(),
    #).run()
    pipeline(
        ConsoleReader(),
        CheckpointSequencer(lambda X: [["LOAD", "slide.%d.png" % (X, )]],
                            lambda X: [["SAVE", "slide.%d.png" % (X, )]]),
        ConsoleEchoer(),
    ).run()
Esempio n. 2
0
                self.forwardqueue.push(msg)

            # while there is enough data to send another chunk
            while len(self.forwardqueue) >= self.chunksize:
                self.sendChunk()

            # if nodelay then send any data not yet sent rather than waiting for more
            if self.nodelay:
                self.sendPartialChunk()

            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, producerFinished):
                    self.sendPartialChunk()
                    self.send(producerFinished(self), "signal")
                    return
                elif isinstance(msg, shutdown):
                    self.send(producerFinished(self), "signal")
                    return
            self.pause()


__kamaelia_components__ = (Chunkifier, )

if __name__ == '__main__':
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleEchoer, ConsoleReader

    # Example - spit out text entered by the user in chunks of 10 characters
    pipeline(ConsoleReader(eol=""), Chunkifier(10), ConsoleEchoer()).run()
Esempio n. 3
0
                if readsomething:
                    self.selectorWait(self.fd)
                    waiting = True

            if not self.done:
                self.pause()

        self.send(removeReader(self, self.fd), '_selectorask')
        os.close(self.fd)

        self.send(producerFinished(self), "signal")
        self.debug("IntelligentFileReader terminated")


__kamaelia_components__ = (IntelligentFileReader, )

if __name__ == "__main__":

    class DebugOutput(component):
        def main(self):
            while 1:
                yield 1
                self.pause()

    pipeline(
        ConsoleReader(),  # send arbitrary messages to wake it
        IntelligentFileReader("/dev/urandom", 1024, 5),
        DebugOutput(),  # component that doesn't check its inbox
    ).run()
Esempio n. 4
0
#     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.
# -------------------------------------------------------------------------
"""\
=================
Single-Shot HTTP Client
=================

This component is for downloading a single file from an HTTP server.
Pick up data received from the server on its "outbox" outbox.

Example Usage
-------------
Generally you should use SimpleHTTPClient in preference to this.
If you want to use it directly, note that it doesn't output strings
but ParsedHTTPHeader, ParsedHTTPBodyChunk and ParsedHTTPEnd like
HTTPParser.

pipeline(
Esempio n. 5
0

def BasicTorrentExplainer():
    """BasicTorrentExplainer is component useful for debugging
    TorrentClient/TorrentPatron. It converts each torrent IPC
    messages it receives into human readable lines of text."""
    
    return PureTransformer(lambda x : str(x) + "\n")


if __name__ == '__main__':
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

    from Kamaelia.Community.RJL.Kamaelia.File.TriggeredFileReader import TriggeredFileReader

    # download a linux distro or whatever
    # NOTE: Do not follow this example. It is used to illustrate/test the use of a TorrentClient component
    # alone. TorrentPatron can and should be used in place of TorrentClient for user applications
    # as it supports multiple instances (create two TorrentClients and see it all come falling down).
    pipeline(
        ConsoleReader(">>> ", ""),
        TriggeredFileReader(),
        TorrentClient(),
        BasicTorrentExplainer(),
        ConsoleEchoer(),    
    ).run()

            
__kamaelia_components__  = ( TorrentClient, BasicTorrentExplainer, )
Esempio n. 6
0
#
# 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.
# -------------------------------------------------------------------------
# Licensed to the BBC under a Contributor Agreement: RJL

"""\
=========================
Chunk Namer
=========================

A component that labels each message with a unique filename for that message.
e.g. "A" ... "B" ... --> ["chunk1", "A"] ... ["chunk2", "B"] ...

Example Usage
-------------
Save each line entered to the console to a separate file:

pipeline(
    ConsoleReader(),
    ChunkNamer("test", ".txt"),
    WholeFileWriter()
Esempio n. 7
0
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleEchoer, ConsoleReader

    if 0:
        class dictSender(Axon.Component.component):
            def main(self):
                while 1:
                    while self.dataReady("inbox"):
                        data = self.recv("inbox")
                        self.send({"data": data }, "outbox")
                    if not self.anyReady():
                        self.pause()
                    yield 1

        pipeline(SingleService(Name="Echo"),
                 ResourceRequestHandler()
        ).activate()

        pipeline(ConsoleReader(),
                 dictSender(),
                 SingleServiceUser(Name="Echo"),
        ).run()

    if 0:
        pipeline(SingleService(Name="Echo"),
                 RequestHandler()
        ).activate()

        pipeline(ConsoleReader(),
                 SingleServiceUser(Name="Echo"),
        ).run()
Esempio n. 8
0
#     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.
# -------------------------------------------------------------------------
"""\
=================
Single-Shot HTTP Client
=================

This component is for downloading a single file from an HTTP server.
Pick up data received from the server on its "outbox" outbox.

Example Usage
-------------
Generally you should use SimpleHTTPClient in preference to this.
If you want to use it directly, note that it doesn't output strings
but ParsedHTTPHeader, ParsedHTTPBodyChunk and ParsedHTTPEnd like
HTTPParser.

pipeline(
Esempio n. 9
0
#!/usr/bin/env python

# The contents of this file are subject to the BitTorrent Open Source License
# Version 1.1 (the License).  You may not copy or use this file, in either
# source code or executable form, except in compliance with the License.  You
# may obtain a copy of the License at http://www.bittorrent.com/license/.
#
# Software distributed under the License is distributed on an AS IS basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
# for the specific language governing rights and limitations under the
# License.

"""\
=================
.torrent Maker
=================

This component accepts filenames, one per message, in "inbox" and outputs the metadata (contents of the .torrent file) for that file to outbox.

Example Usage
-------------

This setup accepts filenames, one per line, and then seeds them using the given
tracker.

pipeline(
    ConsoleReader(eol=""),
    TorrentMaker(defaulttracker="http://sometracker.example.com:6969/announce"),
    TorrentPatron()
).run()
    
Esempio n. 10
0
def P2PStreamer(torrentsfolder):
    """\
    Arguments:
    - torrentsfolder, e.g. "http://my.server.example.org/radioFoo/"
    """
    
    # Create a pipeline of components whose net result is to output the contents of a certain URL
    # (torrentsfolder  + metafilename) every 60 seconds (the contents at the time of output, i.e.
    # it fetches the page every 60 seconds).
    
    poller = pipeline(
        # This generates a message every 60 seconds to wake TriggeredSource
         # allowing us to poll the meta file without busy-waiting.
        CheapAndCheerfulClock(60.0),
        
         # This sends the string (torrentsfolder  + "meta.txt") every time it receives a message
         # This string will be the URL of the meta file on the torrent hosting website
         # e.g. "http://my.server.example.org/radioFoo/meta.txt"
        TriggeredSource(torrentsfolder + "meta.txt"),
        
        # SimpleHTTPClient retrieves the resource specified by the message it receives,
        # which will be URL string. 
        # i.e. It fetches the page whose URL is (torrentsfolder + "meta.txt) (the string
        # produced by TriggeredSource) and forwards on the contents of that page.
        
        # The contents of that particular page will always be a number
        # (in the form of a decimal ASCII string) which represents the number of
        # 'chunks' of the stream that exist
        SimpleHTTPClient()
    )
    
    # As a whole, streamer acts like a normal streaming client, outputting the contents of
    # a stream to its outbox, although in much larger chunks with longer in between chunks
    # than for a typical stream.
    streamer = pipeline(
        # fetch the P2P-stream meta file every 60 seconds and send its contents on
        poller,
        
        # PartsFilenameGenerator uses the number retrived by poller
        # i.e. the number of chunks/torrents in the stream
        # to generate the URLs of all the .torrent files
        # (torrent metadata files) that make up the stream.
        # (They will have been named 1.torrent,
        # 2.torrent, 3.torrent ... etc. on the server).
        
        PartsFilenameGenerator(torrentsfolder, ".torrent"),        
        
        # Download these .torrent files (each message received by resourcefetcher
        # will be the URL of one .torrent file it should download). The
        # contents of the page downloaded it forwarded on to the next component.
        # NOTE: this downloads the .torrent file (metadata about part of the
        # stream) not the stream itself
        SimpleHTTPClient(),
        
        # now use BitTorrent to download the stream itself using the
        # metadata retrieved from .torrent files (each has information about a
        # section of the stream - a section itself is typically a few MB of data)
        # (TorrentPatron is a BitTorrent client component)
        TorrentPatron(),
        
        # output the names of the chunks of the stream as soon as they and
        # all previous chunks have been downloaded 
        StreamReconstructor(),
        
        # read the contents of these chunks (files)
        TriggeredFileReader(),
    )
    return streamer
Esempio n. 11
0
        return data

    def main(self):
        """Main loop"""
        while 1:
            yield 1

            while self.dataReady("inbox"):
                command = self.recv("inbox")
                self.send(self.readFile(command), "outbox")

            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, producerFinished) or isinstance(
                        msg, shutdown):
                    self.send(producerFinished(self), "signal")
                    return

            self.pause()


__kamaelia_components__ = (TriggeredFileReader, )

if __name__ == "__main__":
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

    # Example - display the contents of files whose names are entered
    pipeline(ConsoleReader(eol=""), TriggeredFileReader(),
             ConsoleEchoer()).run()
Esempio n. 12
0
        SimpleHTTPClient(),
        
        # now use BitTorrent to download the stream itself using the
        # metadata retrieved from .torrent files (each has information about a
        # section of the stream - a section itself is typically a few MB of data)
        # (TorrentPatron is a BitTorrent client component)
        TorrentPatron(),
        
        # output the names of the chunks of the stream as soon as they and
        # all previous chunks have been downloaded 
        StreamReconstructor(),
        
        # read the contents of these chunks (files)
        TriggeredFileReader(),
    )
    return streamer
    
if __name__ == '__main__':
    # ask the user from which website we should get the stream's metadata
    # e.g. "http://my.server.example.org/radioFoo/"
    torrentsfolder = raw_input("P2P-stream meta folder (URL): ")
    
    pipeline(
        # fetch the stream using BitTorrent and HTTP - see above for details
        streamer = P2PStreamer(torrentsfolder),
        
        # write the stream to a file on disk
        SimpleFileWriter("myreconstructedstream.mp3")
    ).run()
    
Esempio n. 13
0
    def processMessage(self, msg):
        pass

    def main(self):
        while 1:
            yield 1
            while self.dataReady("inbox"):
                returnval = self.processMessage(self.recv("inbox"))
                if returnval != None:
                    self.send(returnval, "outbox")
            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, producerFinished) or isinstance(
                        msg, shutdown):
                    self.send(producerFinished(self), "signal")
                    return
            self.pause()


__kamaelia_components__ = (PureTransformer, )

if __name__ == "__main__":
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

    # Example - prepend "foo" and append "bar" to lines entered.
    pipeline(ConsoleReader(eol=""),
             PureTransformer(lambda x: "foo" + x + "bar!\n"),
             ConsoleEchoer()).run()
Esempio n. 14
0
            if not self.anyReady():
                self.pause()
                yield 1

if __name__ == "__main__":
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

    def loadMessage(current): return [["LOAD", "slide.%d.png" % (current,)]]
    def saveMessage(current): return [["SAVE", "slide.%d.png" % (current,)]]

    pipeline(
        ConsoleReader(">>>", ""),
        CheckpointSequencer(lambda X: [["LOAD", "slide.%d.png" % (X,)]],
                            lambda X: [["SAVE", "slide.%d.png" % (X,)]],
                            initial=0,
                            highest=0,
                           ),
        ConsoleEchoer(),
    ).run()



if __name__ == "__OLDmain__":
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

    def loadMessage(current): return [["LOAD", "slide.%d.png" % (current,)]]
    def saveMessage(current): return [["SAVE", "slide.%d.png" % (current,)]]

    pipeline(
Esempio n. 15
0
            while len(self.forwardqueue) >= self.chunksize:
                self.sendChunk()
            
            # if nodelay then send any data not yet sent rather than waiting for more
            if self.nodelay:
                self.sendPartialChunk()
                
            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, producerFinished):
                    self.sendPartialChunk()
                    self.send(producerFinished(self), "signal")
                    return
                elif isinstance(msg, shutdown):
                    self.send(producerFinished(self), "signal")
                    return
            self.pause()

__kamaelia_components__  = ( Chunkifier, )

if __name__ == '__main__':
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleEchoer, ConsoleReader

    # Example - spit out text entered by the user in chunks of 10 characters
    pipeline(
        ConsoleReader(eol=""),
        Chunkifier(10),
        ConsoleEchoer()
    ).run()
Esempio n. 16
0
        
        # does the seeding (uploading) of the file
        torrentpatron = TorrentPatron(),
        
        # puts a name to the .torrent file
        torrentnamer = TwoSourceListifier(),
        
        # send the .torrent file data to both the seeder and the saver
        torrentmetasplitter = fanout(["toTorrentPatron", "toNamer"]),

        # appends ".torrent" to the filename to give the .torrent filename
        suffixtorrent = PureTransformer(lambda x : x + ".torrent"),
        
        # output debugging messages, e.g. download progress
        explainer = pipeline(
            BasicTorrentExplainer(),
            ConsoleEchoer()
        ),
        
        linkages = {
            ("filenamereader", "outbox") : ("filenamesplitter", "inbox"),
            ("filenamesplitter", "toNamer") : ("suffixtorrent", "inbox"),
            ("suffixtorrent", "outbox")  :("torrentnamer", "a"),
            ("filenamesplitter", "toTorrentMaker") : ("torrentmaker", "inbox"),
            ("torrentmaker", "outbox") : ("torrentmetasplitter", "inbox"),
            ("torrentmetasplitter", "toTorrentPatron") : ("torrentpatron", "inbox"),
            ("torrentmetasplitter", "toNamer") : ("torrentnamer", "b"),            
            ("torrentnamer", "outbox") : ("filewriter", "inbox"),
            ("torrentpatron", "outbox") : ("explainer", "inbox"),
        }
    ).run()
Esempio n. 17
0
 def __init__(self, **args):
     super(LoggerService, self).__init__(**args)
     pipeline(
         self.LoggerSource(Name=self.Name),
         self.FileWriter(self.Logfile),
     ).activate()
Esempio n. 18
0
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

    def loadMessage(current): return [["LOAD", "slide.%d.png" % (current,)]]
    def saveMessage(current): return [["SAVE", "slide.%d.png" % (current,)]]

    #pipeline(
        #ConsoleReader(),
        #CheckpointSequencer(loadMessage, 
                            #saveMessage),
        #ConsoleEchoer(),
    #).run()
    pipeline(
        ConsoleReader(),
        CheckpointSequencer(lambda X: [["LOAD", "slide.%d.png" % (X,)]],
                            lambda X: [["SAVE", "slide.%d.png" % (X,)]]
                           ),
        ConsoleEchoer(),
    ).run()











Esempio n. 19
0
import time

from Axon.ThreadedComponent import threadedcomponent

# threadedcomponent so we can sleep without pausing other components
class CheapAndCheerfulClock(threadedcomponent):
    """Outputs the message True every interval seconds"""
    def __init__(self, interval):
        super(CheapAndCheerfulClock, self).__init__()
        self.interval = interval

    def main(self):
        while 1:
            self.send(True, "outbox")
            time.sleep(self.interval) # wait self.interval seconds
            
__kamaelia_components__  = ( CheapAndCheerfulClock, )

if __name__ == "__main__":
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.DataSource import TriggeredSource
    from Kamaelia.Util.Console import ConsoleEchoer
    
    # Example - print "fish" every 3 seconds.
    pipeline(
        CheapAndCheerfulClock(3.0),
        TriggeredSource("Fish\n"),
        ConsoleEchoer()
    ).run()
Esempio n. 20
0
class DataSource(component):
    def __init__(self, messages):
        super(DataSource, self).__init__()
        self.messages = messages

    def main(self):
        while len(self.messages) > 0:
            yield 1
            self.send(self.messages.pop(0), "outbox")
        yield 1
        self.send(producerFinished(self), "signal")
        return


def TriggeredSource(msg):
    return PureTransformer(lambda r: msg)


__kamaelia_components__ = (DataSource, )
__kamaelia_prefabs__ = (TriggeredSource, )

if __name__ == "__main__":
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

    pipeline(
        DataSource([
            "hello", " ", "there", " ", "how", " ", "are", " ", "you", " ",
            "today\r\n", "?", "!"
        ]), ConsoleEchoer()).run()
Esempio n. 21
0
                if isinstance(msg, shutdown):
                    loop = False

            else:
                self.pause()

        #unregister with the service
        self.send(TIPCServiceRemove(replyService=(self, "torrent-inbox")),
                  "torrent-outbox")
        self.send(producerFinished(self), "signal")


__kamaelia_components__ = (TorrentPatron, )

if __name__ == '__main__':
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

    from Kamaelia.File.TriggeredFileReader import TriggeredFileReader
    from Kamaelia.Protocol.Torrent.TorrentClient import BasicTorrentExplainer

    # Download a .torrent file with your web browser then enter its file path
    # to the console to have TorrentPatron download it for you
    pipeline(
        ConsoleReader(">>> ", ""),
        TriggeredFileReader(),
        TorrentPatron(),
        BasicTorrentExplainer(),
        ConsoleEchoer(),
    ).run()
Esempio n. 22
0
    }
    target = "_tosubpipeline"
    SingleServiceComponent = SingleServiceUser
    Name = "logger"
    Prefix = "(any) "

    def transform(self, x):
        return self.Prefix + x

    def __init__(self, **args):
        super(Logger, self).__init__(**args)
        X = self.SingleServiceComponent(Name=self.Name).activate()
        self.link((self, "_tosubpipeline"), (X, "inbox"))


import time


class TimeSource(Axon.Component.component):
    def main(self):
        while 1:
            self.send(str(time.time()) + "\n", "outbox")
            yield 1


LoggerService(Logfile="/tmp/TestingTesting123.log")

pipeline(TimeSource(), Logger(Prefix="pipeline1 : ")).activate()

pipeline(TimeSource(), Logger(Prefix="pipeline2 : ")).run()
Esempio n. 23
0
 # to disk, creates a .torrent (BitTorrent metadata) file for
 # each chunk and then shares the chunks with clients using
 # the BitTorrent protocol (it 'seeds' each chunk)
 streamin = pipeline(
     # Icecast client that connects to a stream and outputs the raw stream data
     IcecastClient(streamurl),
     
     # Split the raw data into audio/visual data and stream metadata
     # example of such metadata would be song title and artist name
     IcecastDemux(),
     
     # Strip the metadata from the stream outputting only the a/v data
     IcecastStreamRemoveMetadata(),
     
     # Split the data stream into discrete chunks of a fixed size
     Chunkifier(chunksize),
     
     # Give each chunk a distinct filename to save it under
     # in the current directory ("./" means this directory)
     # (e.g. the first chunk's filename would be "./chunk1"
     # and the second "./chunk2" etc.)
     ChunkNamer("./"),
     
     # Write each chunk to disc under this name
     WholeFileWriter(),
     
     # Make a .torrent (BitTorrent metadata) file from each chunk file
     TorrentMaker(trackerannounceurl),
 ),
 
 # send the .torrent file to the website that will host them and to
 # a TorrentPatron which will then upload the associated chunks
Esempio n. 24
0
 def __init__(self, **args):
     super(LoggerService, self).__init__(**args)
     pipeline(
         self.LoggerSource(Name=self.Name),
         self.FileWriter(self.Logfile),
     ).activate()
Esempio n. 25
0
    def main(self):
        """Main loop"""
        while 1:
            yield 1

            while self.dataReady("inbox"):
                command = self.recv("inbox")
                self.send(self.readFile(command), "outbox")				
            
            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, producerFinished) or isinstance(msg, shutdown):
                    self.send(producerFinished(self), "signal")
                    return
            
            self.pause()

__kamaelia_components__  = ( TriggeredFileReader, )

if __name__ == "__main__":
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

    # Example - display the contents of files whose names are entered
    pipeline(
        ConsoleReader(eol=""),
        TriggeredFileReader(),
        ConsoleEchoer()
    ).run()
Esempio n. 26
0
#!/usr/bin/env python

# The contents of this file are subject to the BitTorrent Open Source License
# Version 1.1 (the License).  You may not copy or use this file, in either
# source code or executable form, except in compliance with the License.  You
# may obtain a copy of the License at http://www.bittorrent.com/license/.
#
# Software distributed under the License is distributed on an AS IS basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
# for the specific language governing rights and limitations under the
# License.

import os
os.environ["LANG"] = "en_GB.UTF-8"

"""\
=================
.torrent Maker
=================

This component accepts filenames, one per message, in "inbox" and outputs the metadata (contents of the .torrent file) for that file to outbox.

Example Usage
-------------

This setup accepts filenames, one per line, and then seeds them using the given
tracker.

pipeline(
    ConsoleReader(eol=""),
    TorrentMaker(defaulttracker="http://sometracker.example.com:6969/announce"),
Esempio n. 27
0
#     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.
# -------------------------------------------------------------------------
# Licensed to the BBC under a Contributor Agreement: RJL
"""\
=========================
Chunk Namer
=========================

A component that labels each message with a unique filename for that message.
e.g. "A" ... "B" ... --> ["chunk1", "A"] ... ["chunk2", "B"] ...

Example Usage
-------------
Save each line entered to the console to a separate file:

pipeline(
    ConsoleReader(),
    ChunkNamer("test", ".txt"),
    WholeFileWriter()
Esempio n. 28
0
if __name__ == "__main__":
    from Kamaelia.File.Reading import RateControlledFileReader
    from Kamaelia.Chassis.Pipeline import pipeline

    filename="/home/matteh/music/Philip Glass/Solo Piano/01 - Metamorphosis One.mp3"
    #filename="/home/matteh/music/Muse/Absolution/01 - Intro.mp3"
    #filename="/home/matteh/music/Rodeohead.mp3"
    
    extension = filename.split(".")[-1]
        
    test = 3
    
    if test == 1:
        pipeline( RateControlledFileReader(filename,readmode="bytes",rate=999999,chunksize=1024),
                  AudioDecoder(extension),
                  SoundOutput(),
                ).run()
                
    elif test == 2:
        pipeline( RateControlledFileReader(filename,readmode="bytes",rate=999999,chunksize=1024),
                  AudioDecoder(extension),
                  ExtractData(),
                  RawSoundOutput(),
                ).run()
                
    elif test == 3:
        pipeline( SoundInput(),
                  AudioEncoder(codec="mp3", bitrate=128000, sample_rate=44100, channels=2),
                  AudioDecoder("mp3"),
#                  SimpleDelay(),
                  SoundOutput(),
Esempio n. 29
0
if __name__ == "__main__":
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

    def loadMessage(current):
        return [["LOAD", "slide.%d.png" % (current, )]]

    def saveMessage(current):
        return [["SAVE", "slide.%d.png" % (current, )]]

    pipeline(
        ConsoleReader(">>>", ""),
        CheckpointSequencer(
            lambda X: [["LOAD", "slide.%d.png" % (X, )]],
            lambda X: [["SAVE", "slide.%d.png" % (X, )]],
            initial=0,
            highest=0,
        ),
        ConsoleEchoer(),
    ).run()

if __name__ == "__OLDmain__":
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

    def loadMessage(current):
        return [["LOAD", "slide.%d.png" % (current, )]]

    def saveMessage(current):
        return [["SAVE", "slide.%d.png" % (current, )]]
Esempio n. 30
0
"""

import time

from Axon.ThreadedComponent import threadedcomponent


# threadedcomponent so we can sleep without pausing other components
class CheapAndCheerfulClock(threadedcomponent):
    """Outputs the message True every interval seconds"""
    def __init__(self, interval):
        super(CheapAndCheerfulClock, self).__init__()
        self.interval = interval

    def main(self):
        while 1:
            self.send(True, "outbox")
            time.sleep(self.interval)  # wait self.interval seconds


__kamaelia_components__ = (CheapAndCheerfulClock, )

if __name__ == "__main__":
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Community.RJL.Kamaelia.Util.DataSource import TriggeredSource
    from Kamaelia.Util.Console import ConsoleEchoer

    # Example - print "fish" every 3 seconds.
    pipeline(CheapAndCheerfulClock(3.0), TriggeredSource("Fish\n"),
             ConsoleEchoer()).run()
Esempio n. 31
0
        
    def processMessage(self, msg):
        pass
        
    def main(self):
        while 1:
            yield 1
            while self.dataReady("inbox"):
                returnval = self.processMessage(self.recv("inbox"))
                if returnval != None:
                    self.send(returnval, "outbox")
            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, producerFinished) or isinstance(msg, shutdown):
                    self.send(producerFinished(self), "signal")
                    return
            self.pause()

__kamaelia_components__  = ( PureTransformer, )

if __name__ == "__main__":
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

    # Example - prepend "foo" and append "bar" to lines entered.
    pipeline(
        ConsoleReader(eol=""),
        PureTransformer(lambda x : "foo" + x + "bar!\n"),
        ConsoleEchoer()
    ).run()
Esempio n. 32
0
        self.uploadurl = uploadurl
        
    def main(self):
        while 1:
            yield 1
            while self.dataReady("inbox"):
                msg = self.recv("inbox")
                msg = { "url" : self.uploadurl, "postbody" : msg }
                self.send(msg, "outbox")
            
            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, producerFinished) or isinstance(msg, shutdown):
                    self.send(producerFinished(self), "signal")
                    return

            self.pause()

if __name__ == "__main__":
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Community.RJL.Kamaelia.Protocol.HTTP.HTTPClient import SimpleHTTPClient
    
    postscript = raw_input("Post Script URL: ") # e.g. "http://www.example.com/upload.php"
    
    pipeline(
        ConsoleReader(eol=""),
        HTTPMakePostRequest(postscript),
        SimpleHTTPClient()
    ).run()
Esempio n. 33
0
       super(Logger, self).__init__(**args)
       X = self.SingleServiceComponent(Name = self.Name).activate()
       self.link((self,"_tosubpipeline"), (X,"inbox"))

import time

class TimeSource(Axon.Component.component):
    def main(self):
        while 1:
            self.send(str(time.time())+"\n", "outbox")
            yield 1

LoggerService(Logfile="/tmp/TestingTesting123.log")

pipeline(
    TimeSource(),
    Logger(Prefix="pipeline1 : ")
).activate()

pipeline(
    TimeSource(),
    Logger(Prefix="pipeline2 : ")
).run()








Esempio n. 34
0
            if not waiting:                                    
                readsomething = False
                while len(self.outboxes["outbox"]) < self.maxqueue and self.tryReadChunk(self.fd):
                    readsomething = True
                    pass
                    
                if readsomething:
                    self.selectorWait(self.fd)
                    waiting = True
                    
            if not self.done:
                self.pause()
        
        self.send(producerFinished(self), "signal")
        self.debug("IntelligentFileReader terminated")

__kamaelia_components__  = ( IntelligentFileReader, )

if __name__ == "__main__":
    class DebugOutput(component):
        def main(self):
            while 1:
                yield 1
                self.pause()
            
    pipeline(
        ConsoleReader(), # send arbitrary messages to wake it
        IntelligentFileReader("/dev/urandom", 1024, 5),
        DebugOutput(), # component that doesn't check its inbox
    ).run()
Esempio n. 35
0
    }

    def __init__(self, filename):
        super(IcecastStreamWriter, self).__init__()
        self.filename = filename
    def main(self):
        f = open(self.filename, "wb")
        while 1:
            yield 1
            while self.dataReady("inbox"):
                msg = self.recv("inbox")
                if isinstance(msg, IceIPCDataChunk):
                    f.write(msg.data)

            self.pause()

__kamaelia_components__  = ( IcecastDemux, IcecastClient, IcecastStreamWriter )
__kamaelia_prefabs__  = ( IcecastStreamRemoveMetadata, )

if __name__ == '__main__':
    from Kamaelia.Chassis.Pipeline import pipeline

    # Save a SHOUTcast/Icecast stream to disk
    # (you can then use an MP3 player program to listen to it while it downloads).
    streamurl = raw_input("Stream URL: ") # e.g. "http://a.stream.url.example.com:1234/"
    pipeline(
        IcecastClient(streamurl),
        IcecastDemux(),
        IcecastStreamWriter("stream.mp3"),
    ).run()
Esempio n. 36
0
#     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.
# -------------------------------------------------------------------------
"""\
=================
Data Source component
=================

This component outputs messages specified at its creation one after another.

Example Usage
-------------

To output "hello" then "world":
pipeline(
    DataSource(["hello", "world"]),
    ConsoleEchoer()
).run()
Esempio n. 37
0
        # to disk, creates a .torrent (BitTorrent metadata) file for
        # each chunk and then shares the chunks with clients using
        # the BitTorrent protocol (it 'seeds' each chunk)
        streamin=pipeline(
            # Icecast client that connects to a stream and outputs the raw stream data
            IcecastClient(streamurl),

            # Split the raw data into audio/visual data and stream metadata
            # example of such metadata would be song title and artist name
            IcecastDemux(),

            # Strip the metadata from the stream outputting only the a/v data
            IcecastStreamRemoveMetadata(),

            # Split the data stream into discrete chunks of a fixed size
            Chunkifier(chunksize),

            # Give each chunk a distinct filename to save it under
            # in the current directory ("./" means this directory)
            # (e.g. the first chunk's filename would be "./chunk1"
            # and the second "./chunk2" etc.)
            ChunkNamer("./"),

            # Write each chunk to disc under this name
            WholeFileWriter(),

            # Make a .torrent (BitTorrent metadata) file from each chunk file
            TorrentMaker(trackerannounceurl),
        ),

        # send the .torrent file to the website that will host them and to
        # a TorrentPatron which will then upload the associated chunks
Esempio n. 38
0
    from Kamaelia.File.Reading import RateControlledFileReader
    from Kamaelia.Chassis.Pipeline import pipeline

    filename = "/home/matteh/music/Philip Glass/Solo Piano/01 - Metamorphosis One.mp3"
    #filename="/home/matteh/music/Muse/Absolution/01 - Intro.mp3"
    #filename="/home/matteh/music/Rodeohead.mp3"

    extension = filename.split(".")[-1]

    test = 3

    if test == 1:
        pipeline(
            RateControlledFileReader(filename,
                                     readmode="bytes",
                                     rate=999999,
                                     chunksize=1024),
            AudioDecoder(extension),
            SoundOutput(),
        ).run()

    elif test == 2:
        pipeline(
            RateControlledFileReader(filename,
                                     readmode="bytes",
                                     rate=999999,
                                     chunksize=1024),
            AudioDecoder(extension),
            ExtractData(),
            RawSoundOutput(),
        ).run()
Esempio n. 39
0
        self.uploadurl = uploadurl
        
    def main(self):
        while 1:
            yield 1
            while self.dataReady("inbox"):
                msg = self.recv("inbox")
                msg = { "url" : self.uploadurl, "postbody" : msg }
                self.send(msg, "outbox")
            
            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, producerFinished) or isinstance(msg, shutdown):
                    self.send(producerFinished(self), "signal")
                    return

            self.pause()

if __name__ == "__main__":
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer
    from Kamaelia.Chassis.Pipeline import pipeline
    from Kamaelia.Community.RJL.Kamaelia.Protocol.HTTP.HTTPClient import SimpleHTTPClient
    
    postscript = raw_input("Post Script URL: ") # e.g. "http://www.example.com/upload.php"
    
    pipeline(
        ConsoleReader(eol=""),
        HTTPMakePostRequest(postscript),
        SimpleHTTPClient()
    ).run()
Esempio n. 40
0
        # saves the .torrent file
        filewriter=WholeFileWriter(),

        # does the seeding (uploading) of the file
        torrentpatron=TorrentPatron(),

        # puts a name to the .torrent file
        torrentnamer=TwoSourceListifier(),

        # send the .torrent file data to both the seeder and the saver
        torrentmetasplitter=fanout(["toTorrentPatron", "toNamer"]),

        # appends ".torrent" to the filename to give the .torrent filename
        suffixtorrent=PureTransformer(lambda x: x + ".torrent"),

        # output debugging messages, e.g. download progress
        explainer=pipeline(BasicTorrentExplainer(), ConsoleEchoer()),
        linkages={
            ("filenamereader", "outbox"): ("filenamesplitter", "inbox"),
            ("filenamesplitter", "toNamer"): ("suffixtorrent", "inbox"),
            ("suffixtorrent", "outbox"): ("torrentnamer", "a"),
            ("filenamesplitter", "toTorrentMaker"): ("torrentmaker", "inbox"),
            ("torrentmaker", "outbox"): ("torrentmetasplitter", "inbox"),
            ("torrentmetasplitter", "toTorrentPatron"):
            ("torrentpatron", "inbox"),
            ("torrentmetasplitter", "toNamer"): ("torrentnamer", "b"),
            ("torrentnamer", "outbox"): ("filewriter", "inbox"),
            ("torrentpatron", "outbox"): ("explainer", "inbox"),
        }).run()