Changeset b20014b for python


Ignore:
Timestamp:
2015-05-09T12:17:54Z (10 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
17aa9a2
Parents:
199d51c
Message:

Store the hex_version coming from BitlBee as a tuple instead of raw, that's
a little nicer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/implugin.py

    r199d51c rb20014b  
    2525]
    2626
     27def make_version_tuple(hex):
     28        """Convert the BitlBee binary-encoded version number into something
     29        more "Pythonic". Could use distutils.version instead but its main
     30        benefit appears to be string parsing which here is not that useful."""
     31
     32        return (hex >> 16, (hex >> 8) & 0xff, hex & 0xff)
     33
    2734class RpcForwarder(object):
    2835        """Tiny object that forwards RPCs from local Python code to BitlBee
     
    5057       
    5158        # Filled in during initialisation:
    52         # Version code in hex. So if you need to do comparisions, for example
    53         # check "self.bitlbee_version >= 0x030202" for versions 3.2.2+
     59        # Version number as a three-tuple, so 3.2 becomes (3, 2, 0).
    5460        bitlbee_version = None
    5561        # Full version string
     
    7581        def init(self, bee):
    7682                self.bee = RpcForwarder(bee["method_list"], self._conn.call)
    77                 self.bitlbee_version = bee["version"]
     83                self.bitlbee_version = make_version_tuple(bee["version"])
    7884                self.bitlbee_version_str = bee["version_str"]
    7985
     
    104110                creds = {"username": account["user"], "password": account["pass"]}
    105111                r = self.ua.post(self.url("/api/login"), creds)
     112                self.bee.log("You're running BitlBee %d.%d.%d" % self.bitlbee_version)
    106113                if r.status_code != 200:
    107114                        self.bee.error("HTTP error %d" % r.status_code)
Note: See TracChangeset for help on using the changeset viewer.