Exemple #1
0
def make_cat(cat_location, screensize, border):
    # Get the cat again!
    files = list()
    for x in os.listdir("pictures"):
        if x not in ("README", "CVS", ".svn"):
            files.append(x)

    image_location = files[random.randint(0, len(files) - 1)]

    cat_surface = pygame.image.load("pictures/" + image_location)
    cat = cat_surface.convert()
    cat.set_colorkey((255, 255, 255), pygame.RLEACCEL)

    rotation_speed = randomFromRangeExcludingZero(-2, 2)
    scale_speed = float(randomFromRangeExcludingZero(-1, 1))
    position = list((random.randint(border, screensize[0] - border),
                     random.randint(border, screensize[1] - border)))

    newCat = BasicSprite(image=cat)

    X = Graphline(newCat=newCat,
                  rotator=loopingCounter(rotation_speed),
                  translation=cartesianPingPong(position, screensize[0],
                                                screensize[1], border),
                  scaler=bouncingFloat(scale_speed),
                  imaging=continuousIdentity(cat),
                  shutdown_fanout=Fanout([
                      "rotator", "translation", "scaler", "imaging",
                      "self_shutdown"
                  ]),
                  linkages={
                      ("rotator", "outbox"): ("newCat", "rotator"),
                      ("translation", "outbox"): ("newCat", "translation"),
                      ("scaler", "outbox"): ("newCat", "scaler"),
                      ("imaging", "outbox"): ("newCat", "imaging"),
                      ("newCat", "signal"): ("shutdown_fanout", "inbox"),
                      ("shutdown_fanout", "rotator"): ("rotator", "control"),
                      ("shutdown_fanout", "translation"):
                      ("translation", "control"),
                      ("shutdown_fanout", "scaler"): ("scaler", "control"),
                      ("shutdown_fanout", "imaging"): ("imaging", "control"),
                      ("shutdown_fanout", "self_shutdown"):
                      ("shutdown_fanout", "control"),
                  }).activate()

    return newCat
Exemple #2
0
def ComplexIRCClientPrefab(host="127.0.0.1",
                           port=6667,
                           nick="kamaeliabot",
                           nickinfo="Kamaelia",
                           defaultChannel="#kamaeliatest",
                           IRC_Handler=IRC_Client):
    return Graphline(
        CLIENT=TCPClient(host, port),
        PROTO=IRC_Handler(nick, nickinfo, defaultChannel),
        SPLIT=Fanout(["toGraphline", "toTCP"]),
        linkages={
            ("CLIENT", "outbox"): ("PROTO", "inbox"),
            ("PROTO", "outbox"): ("SPLIT", "inbox"),
            ("PROTO", "heard"): ("SELF", "outbox"),  #passthrough
            ("SELF", "inbox"): ("PROTO", "talk"),  #passthrough
            ("SELF", "control"): ("PROTO", "control"),  #passthrough
            ("PROTO", "signal"): ("CLIENT", "control"),
            ("CLIENT", "signal"): ("SELF", "signal"),  #passthrough
            ("SPLIT", "toGraphline"): ("SELF", "sendCopy"),  #passthrough
            ("SPLIT", "toTCP"): ("CLIENT", "inbox")
        })
Exemple #3
0
            # 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
        # to peers (users that want to download the stream)
        split=Fanout(["toHTTP-POSTer", "toTorrentPatron"]),

        # fileupload uploads each message it receives to a script on a webserver.
        fileupload=Pipeline(
            # convert messages received to HTTP POST requests
            # for the URL trackerpostuploader
            # (with the contents of the message as the payload/request body)
            HTTPMakePostRequest(trackerpostuploader),

            # SimpleHTTPClient then makes these requests
            # (connecting to the server given in the URL and sending the
            # POST request in an HTTP request format)
            # the result of which is (assuming a suitable upload script on the
            # webserver) .torrent files sent to this pipeline as messages
            # are uploaded to the webserver
            SimpleHTTPClient()),
Exemple #4
0
    def suffixMatchOnly(x):
        if x[:len(urlprefix)] == urlprefix:
            return x

    class ListSplit(component):
        def main(self):
            while 1:
                yield 1
                while self.dataReady("inbox"):
                    msg = self.recv("inbox")
                    for m in msg:
                        self.send(m, "outbox")
                self.pause()

    Graphline(usersuppliedurls=ConsoleReader(eol=""),
              splitter=Fanout(["toHTTPClient", "toCorrectRelativeLinks"]),
              splittertwo=Fanout(["toSplitterOne", "toEchoer"]),
              newlinesuffixadder=PureTransformer(lambda x: x + "\n"),
              httpclient=SimpleHTTPClient(),
              htmlprocessor=HTMLProcess(),
              linkextractor=ExtractLinks(),
              linkcorrector=CorrectRelativeLinks(),
              listsplitter=ListSplit(),
              prefixmatcher=PureTransformer(suffixMatchOnly),
              newurlechoer=ConsoleEchoer(),
              unseenonly=UnseenOnly(),
              linkages={
                  ("usersuppliedurls", "outbox"): ("unseenonly", "inbox"),
                  ("newurlechoer", "outbox"): ("splitter", "inbox"),
                  ("splitter", "toHTTPClient"): ("httpclient", "inbox"),
                  ("splitter", "toCorrectRelativeLinks"):
Exemple #5
0
    def initComponents(self): 
        fanout = Fanout(["features", "info"])
        self.link((self, 'inbox'), (fanout, 'inbox'), passthrough=1)
        self.addChildren(fanout)
        fanout.activate()
        
        subdisp = SubscriptionsDiscoveryDispatcher()
        self.link((self, 'subscription.inbox'), (subdisp, 'inbox'), passthrough=1)
        self.link((self, 'subscription.forward'), (subdisp, 'forward'), passthrough=1)
        self.link((self, 'in.subscription.get'), (subdisp, 'forward'), passthrough=1)
        self.link((self, 'in.subscription.set'), (subdisp, 'forward'), passthrough=1)
        self.link((self, 'in.subscription.result'), (subdisp, 'forward'), passthrough=1)
        self.link((self, 'in.subscription.error'), (subdisp, 'forward'), passthrough=1)
        self.link((subdisp, 'outbox'), (self, 'subscription.outbox'), passthrough=2)
        self.link((subdisp, 'xmpp.get'), (self, 'out.subscription.get'), passthrough=2)
        self.link((subdisp, 'xmpp.set'), (self, 'out.subscription.set'), passthrough=2)
        self.link((subdisp, 'xmpp.result'), (self, 'out.subscription.result'), passthrough=2)
        self.link((subdisp, 'xmpp.error'), (self, 'out.subscription.error'), passthrough=2)
        self.link((subdisp, 'unknown'), (self, 'unknown'), passthrough=2)
        self.link((subdisp, 'log'), (self, 'log'), passthrough=2)
        self.addChildren(subdisp)
        subdisp.activate()      

        affdisp = AffiliationsDiscoveryDispatcher()
        self.link((self, 'affiliation.inbox'), (affdisp, 'inbox'), passthrough=1)
        self.link((self, 'affiliation.forward'), (affdisp, 'forward'), passthrough=1)
        self.link((self, 'in.affiliation.get'), (affdisp, 'forward'), passthrough=1)
        self.link((self, 'in.affiliation.set'), (affdisp, 'forward'), passthrough=1)
        self.link((self, 'in.affiliation.result'), (affdisp, 'forward'), passthrough=1)
        self.link((self, 'in.affiliation.error'), (affdisp, 'forward'), passthrough=1)
        self.link((affdisp, 'outbox'), (self, 'affiliation.outbox'), passthrough=2)
        self.link((affdisp, 'xmpp.get'), (self, 'out.affiliation.get'), passthrough=2)
        self.link((affdisp, 'xmpp.set'), (self, 'out.affiliation.set'), passthrough=2)
        self.link((affdisp, 'xmpp.result'), (self, 'out.affiliation.result'), passthrough=2)
        self.link((affdisp, 'xmpp.error'), (self, 'out.affiliation.error'), passthrough=2)
        self.link((affdisp, 'unknown'), (self, 'unknown'), passthrough=2)
        self.link((affdisp, 'log'), (self, 'log'), passthrough=2)
        self.addChildren(affdisp)
        affdisp.activate()
    
        featdisp = FeaturesDiscoveryDispatcher()
        self.link((fanout, 'features'), (featdisp, 'inbox'))
        self.link((self, 'features.inbox'), (featdisp, 'inbox'), passthrough=1)
        self.link((self, 'features.forward'), (featdisp, 'forward'), passthrough=1)
        self.link((self, 'in.features.get'), (featdisp, 'forward'), passthrough=1)
        self.link((self, 'in.features.set'), (featdisp, 'forward'), passthrough=1)
        self.link((self, 'in.features.result'), (featdisp, 'forward'), passthrough=1)
        self.link((self, 'in.features.error'), (featdisp, 'forward'), passthrough=1)
        self.link((featdisp, 'outbox'), (self, 'outbox'), passthrough=2)
        self.link((featdisp, 'xmpp.get'), (self, 'out.features.get'), passthrough=2)
        self.link((featdisp, 'xmpp.set'), (self, 'out.features.set'), passthrough=2)
        self.link((featdisp, 'xmpp.result'), (self, 'out.features.result'), passthrough=2)
        self.link((featdisp, 'xmpp.error'), (self, 'out.features.error'), passthrough=2)
        self.link((featdisp, 'unknown'), (self, 'unknown'), passthrough=2)
        self.link((featdisp, 'log'), (self, 'log'), passthrough=2)
        self.addChildren(featdisp)
        featdisp.activate()

        itemsdisp = ItemsDiscoveryDispatcher()
        self.link((self, 'items.inbox'), (itemsdisp, 'inbox'), passthrough=1)
        self.link((self, 'items.forward'), (itemsdisp, 'forward'), passthrough=1)
        self.link((self, 'in.items.get'), (itemsdisp, 'forward'), passthrough=1)
        self.link((self, 'in.items.set'), (itemsdisp, 'forward'), passthrough=1)
        self.link((self, 'in.items.result'), (itemsdisp, 'forward'), passthrough=1)
        self.link((self, 'in.items.error'), (itemsdisp, 'forward'), passthrough=1)
        self.link((itemsdisp, 'outbox'), (self, 'outbox'), passthrough=2)
        self.link((itemsdisp, 'xmpp.get'), (self, 'out.items.get'), passthrough=2)
        self.link((itemsdisp, 'xmpp.set'), (self, 'out.items.set'), passthrough=2)
        self.link((itemsdisp, 'xmpp.result'), (self, 'out.items.result'), passthrough=2)
        self.link((itemsdisp, 'xmpp.error'), (self, 'out.items.error'), passthrough=2)
        self.link((itemsdisp, 'unknown'), (self, 'unknown'), passthrough=2)
        self.link((itemsdisp, 'log'), (self, 'log'), passthrough=2)
        self.addChildren(itemsdisp)
        itemsdisp.activate()

        infodisp = InformationDiscoveryDispatcher()
        self.link((fanout, 'info'), (infodisp, 'inbox'))
        self.link((self, 'info.inbox'), (infodisp, 'inbox'), passthrough=1)
        self.link((self, 'info.forward'), (infodisp, 'forward'), passthrough=1)
        self.link((self, 'in.info.get'), (infodisp, 'forward'), passthrough=1)
        self.link((self, 'in.info.set'), (infodisp, 'forward'), passthrough=1)
        self.link((self, 'in.info.result'), (infodisp, 'forward'), passthrough=1)
        self.link((self, 'in.info.error'), (infodisp, 'forward'), passthrough=1)
        self.link((infodisp, 'outbox'), (self, 'outbox'), passthrough=2)
        self.link((infodisp, 'xmpp.get'), (self, 'out.info.get'), passthrough=2)
        self.link((infodisp, 'xmpp.set'), (self, 'out.info.set'), passthrough=2)
        self.link((infodisp, 'xmpp.result'), (self, 'out.info.result'), passthrough=2)
        self.link((infodisp, 'xmpp.error'), (self, 'out.info.error'), passthrough=2)
        self.link((infodisp, 'unknown'), (self, 'unknown'), passthrough=2)
        self.link((infodisp, 'log'), (self, 'log'), passthrough=2)
        self.addChildren(infodisp)
        infodisp.activate()

        return 1
Exemple #6
0
            self.pause()


if __name__ == '__main__':
    # The 'announce' URL of the BitTorrent tracker to use
    # e.g. "http://192.168.1.5:6969/announce"
    trackerannounceurl = raw_input("Tracker Announce URL: ")

    Graphline(
        filenamereader=ConsoleReader(">>> ", ""),

        # send the filename entered by the user to both the .torrent
        # maker and to the file writer to use as part of the filename
        # (so that it knows what to save the metadata as)
        filenamesplitter=Fanout(["toNamer", "toTorrentMaker"]),

        # makes the .torrent file (BitTorrent metadata)
        torrentmaker=TorrentMaker(trackerannounceurl),

        # 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"]),