示例#1
0
 def attribute_bgimage(self, value):
     # If http fetch and store image bytes,
     # otherwise store resource location string.
     if value.startswith('http'):
         log.debug('Opening URL: %s', value)
         response = urllib.request.urlopen(value)
         value = response.read()
     # Exit out if image hasnt changed
     if value == self.bgimage:
         return
     # Fade out (if self.bgfade set)
     if self.bgfade:
         framerate = self.bgfade / 40.0
         if self.bgimage:
             for i in range(100, -1, -5):
                 self.bgopacity = i * 0.01
                 self.update()
                 time.sleep(framerate)
         else:
             self.bgopacity = 0
             #self.update()
     # Set the new bgimage
     self.bgimage = value
     self.update()
     # Fade in (if self.bgfade set)
     if self.bgfade:
         for i in range(5, 101, 5):
             time.sleep(framerate)
             self.bgopacity = i * 0.01
             self.update()
示例#2
0
 def attribute_bgimage(self, value):
     # If http fetch and store image bytes,
     # otherwise store resource location string.
     if value.startswith('http'):
         log.debug('Opening URL: %s', value)
         response = urllib.request.urlopen(value)
         value = response.read()
     # Exit out if image hasnt changed
     if value == self.bgimage:
         return
     # Fade out (if self.bgfade set)
     if self.bgfade:
         framerate = self.bgfade / 40.0
         if self.bgimage:
             for i in range(100, -1, -5):
                 self.bgopacity = i * 0.01
                 self.update()
                 time.sleep(framerate)
         else:
             self.bgopacity = 0
             #self.update()
     # Set the new bgimage
     self.bgimage = value
     self.update()
     # Fade in (if self.bgfade set)
     if self.bgfade:
         for i in range(5, 101, 5):
             time.sleep(framerate)
             self.bgopacity = i * 0.01
             self.update()
示例#3
0
def http_request(url, data=None, timeout=10):
    log.debug("Requesting URL: %s" % url)
    data = urlencode(data).encode('utf8') if data else None
    try:
        response = urlopen(url, data=data, timeout=timeout)
        return {'success':True, 'response':response, 'url':url}
    except (URLError, socket.timeout) as err:
        log.error("Error requesting URL: %s; %s" % (url, err))
        return {'success':False, 'error':err, 'url':url}
示例#4
0
def get_stdout(command):
    log.debug('Running command: %s' % command)
    result = subprocess.check_output(shlex.split(command))
    return result.decode('utf8')