Beispiel #1
0
    def download_image(self, images, trace, headers=None):
        retry = Retry(retries=3,
                      exp_bkf=False,
                      final_exc=SourceError('could not get image from source'))

        while retry.left():
            try:
                image = images.select()

                if image.url is None:
                    continue

                temp_filepath = get(
                    image.url,
                    msg='getting image',
                    max_content_length=Config().get('image.max_size'),
                    save_to_temp_file=True,
                    headers=headers)

                im = Image.open(temp_filepath)
                image.type = im.format.lower()
                image.i_width, image.i_height = im.size
                im.close()

                if image.i_width < 1 or image.i_height < 1:
                    retry.retry()
                    continue

                if image.ext is None:
                    image.ext = image.url[image.url.rfind('.') + 1:]

                image.temp_filepath = temp_filepath

                retry.cancel()

            except (HttpError, IOError) as e:
                log.error(e)
                printer.printf('error', str(e))
                retry.retry()

        return image
Beispiel #2
0
    def get_image(self, params=None):
        params = BingParams()

        self._images = Images(params,
                              cache=True,
                              cache_timeout='1w',
                              trace=self._trace)
        self._images.add_select_filter(lambda i: exists(i.url),
                                       retry=Retry(retries=10),
                                       msg='checking urls')

        if not self._images.available():
            self.get_image_urls()

        return self._http.download_image(self._images, self._trace)
Beispiel #3
0
    def quit(self, condition, retry, fade):
        if condition is not None:
            r = Retry(retries=retry[0], delay=retry[1], exp_bkf=False)

            while r.left():
                rc, _ = sys_command(condition)
                if rc == 0:
                    r.cancel()
                else:
                    r.retry()

        if fade > 0:
            saved_volume = self.volume
            self.fade_volume(0, fade)
            self.stop()
            self.volume = saved_volume

        self._main.Quit()
Beispiel #4
0
	def parse(self, params):
		if params.page is not None:
			self.parse_page(params.page)
			return

		retry = Retry(retries=3, exp_bkf=False, delay=1, final_exc=SourceError('could not get unused images'))

		config = Config(group=self.name)
		page = config.pget('page', default=1)

		while retry.left():
			self.parse_page(page)

			if self._images.available():
				retry.cancel()
			else:
				page += 1
				config.pset('page', page)
				retry.retry()
Beispiel #5
0
    def get_dbus_interface(self, wait=False):
        retry_count = self.launch_wait if wait else 1
        retry = Retry(retries=retry_count,
                      delay=1,
                      exp_bkf=False,
                      final_exc=PlayerError('vlc is not running'))

        while retry.left():
            try:
                player_obj = dbus.SessionBus().get_object(
                    self.service_name, self.object_path)
                retry.cancel()
            except DBusException as e:
                retry.retry()

        self._player = dbus.Interface(player_obj,
                                      dbus_interface=self.player_interface)
        self._tracklist = dbus.Interface(
            player_obj, dbus_interface=self.tracklist_interface)
        self._prop = dbus.Interface(player_obj,
                                    dbus_interface=self.prop_interface)
        self._main = dbus.Interface(player_obj,
                                    dbus_interface=self.main_interface)