Example #1
0
 def poll(self):
     gotsome = False
     try:
         m = self.getMixer()
     except Exception, e:
         log.warn('Got no mixer: %s' % utils.e2str(e))
         return False
Example #2
0
 def poll(self):
     gotsome = False
     try:
         m = self.getMixer()
     except Exception, e:
         log.warn('Got no mixer: %s' % utils.e2str(e))
         return False
Example #3
0
    def open(self):
        print "def open(self):"

        self.api_version = spotify.api_version
        self.cache_location = "/tmp"
        self.settings_location = "/tmp"
        self.application_key = None
        self.appkey_file = "spotify_appkey.key"
        self.user_agent = "chains"

        if self.application_key is None:
            self.classdata = config.getServiceSharePath(self.config["main"]["class"]) + "/"
            self.application_key = open(self.classdata + self.appkey_file).read()
        self.awoken = threading.Event()  # used to block until awoken
        self.timer = None
        self.finished = False
        self.session = None

        self.username = "******"
        try:
            self.username = self.config["main"]["username"]
        except KeyError:
            log.warn('No "username" in %s service config, using %s' % (self.config["id"], self.username))
        self.password = "******"
        try:
            self.password = self.config["main"]["password"]
        except KeyError:
            log.warn('No "password" in %s service config, using %s' % (self.config["id"], self.password))
        self.audio = AlsaController()
        self.ctr = None
        self.playing = False
        self._queue = []
        print "Logging in, please wait..."
        self.connect()
        print "Finished connecting?"
Example #4
0
 def cmd_listSms(self, store=None):
     realStore = None
     if store:
         for s in self.smsStores:
             if s[0] == store:
                 realStore = s[1]
                 break
         if not realStore:
             raise Exception('Invalid sms store: %s' % store)
     else:
         realStore = 'ALL'
     res = self.cmd('AT+CMGL=%s' % realStore, bufsize=50, raw=True)
     log.warn('todo: not finished: cmd_listSms() !')
     return res
Example #5
0
 def cmd_listSms(self, store=None):
     realStore = None
     if store:
         for s in self.smsStores:
             if s[0] == store:
                 realStore = s[1]
                 break
         if not realStore:
             raise Exception('Invalid sms store: %s' % store)
     else:
         realStore = 'ALL'
     res = self.cmd('AT+CMGL=%s' % realStore, bufsize=50, raw=True)
     log.warn('todo: not finished: cmd_listSms() !')
     return res
Example #6
0
 def cmd_sendSms(self, number, message):
     log.info('sendSms: %s : %s' % (number, message))
     id = None
     res = self.cmd('at+cmgs="%s"' % number, raw=True)
     #log.info('sendSms result: %s' % res)
     if (type(res) in (type([]),type((1,))) and res[0] == '>') or res == '>':
         res = self.cmd('%s\x1A' % message, bufsize=5, raw=True)
         log.info('sendSms result2: %s' % res)
         if res and len(res) > 1:
             # id = res[1].split(":")[1].strip()
             id = res.split(":")[1].strip()
         else:
             log.warn("Unknown result2: %s" % res)
     else:
         log.warn("Unknown result1: %s" % res)
     return id
Example #7
0
 def cmd_sendSms(self, number, message):
     log.info('sendSms: %s : %s' % (number, message))
     id = None
     res = self.cmd('at+cmgs="%s"' % number, raw=True)
     #log.info('sendSms result: %s' % res)
     if (type(res) in (type([]), type(
         (1, ))) and res[0] == '>') or res == '>':
         res = self.cmd('%s\x1A' % message, bufsize=5, raw=True)
         log.info('sendSms result2: %s' % res)
         if res and len(res) > 1:
             # id = res[1].split(":")[1].strip()
             id = res.split(":")[1].strip()
         else:
             log.warn("Unknown result2: %s" % res)
     else:
         log.warn("Unknown result1: %s" % res)
     return id
Example #8
0
 def parseResult(self, data, cmd):
     # f.ex. an incoming sms may occur when we parse result of a command,
     # so do incoming check here also
     log.debug('Parseresult')
     log.debug('Parseresult data: %s' % data)
     log.debug('Parseresult cmd: %s' % cmd)
     for l in data:
         self.onIncoming(l, True)
     if len(data) == 1 or (len(data) == 3 and data[1] == '' and data[2] == 'OK'):
         res = self.parseResultLine(data[0], cmd)
         if res:
             return res
         else:
             return data[0]
     elif len(data) == 4 and data[0] == '' and data[2] == '' and data[3] == 'OK':
         return data[1]
     else:
         log.warn("Unknown result: %s" % data)
         return data
Example #9
0
 def parseResult(self, data, cmd):
     # f.ex. an incoming sms may occur when we parse result of a command,
     # so do incoming check here also
     log.debug('Parseresult')
     log.debug('Parseresult data: %s' % data)
     log.debug('Parseresult cmd: %s' % cmd)
     for l in data:
         self.onIncoming(l, True)
     if len(data) == 1 or (len(data) == 3 and data[1] == ''
                           and data[2] == 'OK'):
         res = self.parseResultLine(data[0], cmd)
         if res:
             return res
         else:
             return data[0]
     elif len(data) == 4 and data[0] == '' and data[2] == '' and data[
             3] == 'OK':
         return data[1]
     else:
         log.warn("Unknown result: %s" % data)
         return data
Example #10
0
class AlsaService(Service):
    def _getSoundsPath(self):
        return '/srv/chains/data/services/alsa'  # @todo: from config

    def getMixer(self):
        try:
            return alsaaudio.Mixer(self.config['main']['mixer'])
        except KeyError:
            return alsaaudio.Mixer()

    def open(self):
        self.polldata = {'vol': -1, 'mute': -1}
        if self.poll():
            try:
                interval = float(self.config['main']['pollinterval'])
            except:
                interval = 1
            log.info('Starting poller with interval: %s' % interval)
            while True:
                time.sleep(interval)
                self.poll()
        else:
            log.info('Not starting poller')

    def poll(self):
        gotsome = False
        try:
            m = self.getMixer()
        except Exception, e:
            log.warn('Got no mixer: %s' % utils.e2str(e))
            return False
        try:
            vol = m.getvolume()[0]
            if vol != self.polldata['vol']:
                self.onEvent({'key': 'volume', 'value': vol})
                self.polldata['vol'] = vol
            gotsome = True
        except Exception, e:
            log.warn(utils.e2str(e))