Changeset 35571fb for protocols


Ignore:
Timestamp:
2013-01-13T12:06:01Z (12 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
75bda8b
Parents:
4cb21b7 (diff), 650d2b4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from vmiklos.

Location:
protocols/skype
Files:
9 added
10 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • protocols/skype/HACKING

    r4cb21b7 r35571fb  
    1717
    18184) irssi
     19
     20== Tests
     21
     22The plugin is tested with a mocked IRC client and a mocked skyped. To add a new
     23test, the following steps are necessary:
     24
     251) Add a new -skyped.mock file: just do the test manually, copy&paste the
     26skyped output and clean it up, so Alice talks to Bob.  You can test the created
     27mock file by starting skyped with the -m option, and testing it from an IRC
     28client manually.
     29
     302) Add a new -bitlbee.mock file: do the test manually from irssi, and use:
     31
     32/connect -rawlog rawlog localhost
     33
     34Then clean up the rawlog: the input lines are parsed as matching patterns, so
     35boring prefix/suffix text can be left out, non-interesting lines can be
     36deleted. The output lines still have to be strict IRC commands, as usual.
     37
     383) Add the new test to test.py and run it!
     39
     40// vim: ft=asciidoc
  • protocols/skype/Makefile

    r4cb21b7 r35571fb  
    2424
    2525test: all
    26         $(MAKE) -C t/ all
     26        ./test.py
    2727
    2828doc: $(MANPAGES)
  • protocols/skype/skype.c

    r4cb21b7 r35571fb  
    22 *  skype.c - Skype plugin for BitlBee
    33 *
    4  *  Copyright (c) 2007-2013 by Miklos Vajna <vmiklos@frugalware.org>
     4 *  Copyright (c) 2007-2013 by Miklos Vajna <vmiklos@vmiklos.hu>
    55 *
    66 *  This program is free software; you can redistribute it and/or modify
  • protocols/skype/skyped.py

    r4cb21b7 r35571fb  
    33#   skyped.py
    44
    5 #   Copyright (c) 2007, 2008, 2009, 2010, 2011 by Miklos Vajna <vmiklos@frugalware.org>
     5#   Copyright (c) 2007-2013 by Miklos Vajna <vmiklos@vmiklos.hu>
    66#
    77#   This program is free software; you can redistribute it and/or modify
     
    276276                sock.close()
    277277
     278class MockedSkype:
     279        """Mock class for Skype4Py.Skype(), in case the -m option is used."""
     280        def __init__(self, mock):
     281                sock = open(mock)
     282                self.lines = sock.readlines()
     283       
     284        def SendCommand(self, c):
     285                pass
     286
     287        def Command(self, msg, Block):
     288                if msg == "PING":
     289                        return ["PONG"]
     290                line = self.lines[0].strip()
     291                if not line.startswith(">> "):
     292                        raise Exception("Corrupted mock input")
     293                line = line[3:]
     294                if line != msg:
     295                        raise Exception("'%s' != '%s'" % (line, msg))
     296                self.lines = self.lines[1:] # drop the expected incoming line
     297                ret = []
     298                while True:
     299                        # and now send back all the following lines, up to the next expected incoming line
     300                        if len(self.lines) == 0:
     301                                break
     302                        if self.lines[0].startswith(">> "):
     303                                break
     304                        if not self.lines[0].startswith("<< "):
     305                                raise Exception("Corrupted mock input")
     306                        ret.append(self.lines[0][3:].strip())
     307                        self.lines = self.lines[1:]
     308                return ret
     309
    278310class SkypeApi:
    279         def __init__(self):
    280                 self.skype = Skype4Py.Skype()
    281                 self.skype.OnNotify = self.recv
    282                 self.skype.Client.Start()
     311        def __init__(self, mock):
     312                if not mock:
     313                        self.skype = Skype4Py.Skype()
     314                        self.skype.OnNotify = self.recv
     315                        self.skype.Client.Start()
     316                else:
     317                        self.skype = MockedSkype(mock)
    283318
    284319        def recv(self, msg_text):
     
    335370                        c = self.skype.Command(e, Block=True)
    336371                        self.skype.SendCommand(c)
    337                         self.recv(c.Reply)
     372                        if hasattr(c, "Reply"):
     373                                self.recv(c.Reply) # Skype4Py answer
     374                        else:
     375                                for i in c: # mock may return multiple iterable answers
     376                                        self.recv(i)
    338377                except Skype4Py.SkypeError:
    339378                        pass
     
    360399                # this will be read first by the input handler
    361400                self.buf = None
     401                self.mock = None
    362402
    363403
     
    422462        options = Options()
    423463        try:
    424                 opts, args = getopt.getopt(sys.argv[1:], "c:dhH:l:np:v", ["config=", "debug", "help", "host=", "log=", "nofork", "port=", "version"])
     464                opts, args = getopt.getopt(sys.argv[1:], "c:dhH:l:m:np:v", ["config=", "debug", "help", "host=", "log=", "mock=", "nofork", "port=", "version"])
    425465        except getopt.GetoptError:
    426466                options.usage(1)
     
    436476                elif opt in ("-l", "--log"):
    437477                        options.log = arg
     478                elif opt in ("-m", "--mock"):
     479                        options.mock = arg
    438480                elif opt in ("-n", "--nofork"):
    439481                        options.daemon = False
     
    486528                server(options.host, options.port)
    487529        try:
    488                 skype = SkypeApi()
     530                skype = SkypeApi(options.mock)
    489531        except Skype4Py.SkypeAPIError, s:
    490532                sys.exit("%s. Are you sure you have started Skype?" % s)
  • protocols/skype/skyped.txt

    r4cb21b7 r35571fb  
    3939        Set the log file in background mode (default: none)
    4040
     41-m, --mock=<file>::
     42        Mock mode: replay session from file, instead of connecting to Skype.
     43
    4144-n, --nofork::
    4245        Don't run as daemon in the background
     
    5053== AUTHOR
    5154
    52 Written by Miklos Vajna <vmiklos@frugalware.org>
     55Written by Miklos Vajna <vmiklos@vmiklos.hu>
Note: See TracChangeset for help on using the changeset viewer.