Ejemplo n.º 1
0
def _page(output, pager_command=None):
    """Conditionally pipes the supplied output through a pager.

    :param output:
    :type output: object
    :param pager_command:
    :type pager_command: str
    """

    output = six.text_type(output)

    if not sys.stdout.isatty() or util.is_windows_platform():
        print(output)
        sys.stdout.flush()
        return

    num_lines = output.count('\n')
    exceeds_tty_height = pager.getheight() - 1 < num_lines

    if pager_command is None:
        pager_command = 'less -R'

    try:
        paginate = config.get_config_val("core.pagination")
    except Exception:
        paginate = True
    if exceeds_tty_height and paginate and \
            spawn.find_executable(pager_command.split(' ')[0]) is not None:
        pydoc.pipepager(output, cmd=pager_command)
    else:
        print(output)
Ejemplo n.º 2
0
def _page(output, pager_command=None):
    """Conditionally pipes the supplied output through a pager.

    :param output:
    :type output: object
    :param pager_command:
    :type pager_command: str
    """

    output = six.text_type(output)

    if not sys.stdout.isatty() or util.is_windows_platform():
        print(output)
        return

    num_lines = output.count('\n')
    exceeds_tty_height = pager.getheight() - 1 < num_lines

    if pager_command is None:
        pager_command = 'less -R'

    paginate = config.get_config_val("core.pagination") or True
    if exceeds_tty_height and paginate and \
            spawn.find_executable(pager_command.split(' ')[0]) is not None:
        pydoc.pipepager(output, cmd=pager_command)
    else:
        print(output)
Ejemplo n.º 3
0
def _page(output, pager_command=None):
    """Conditionally pipes the supplied output through a pager.

    :param output:
    :type output: object
    :param pager_command:
    :type pager_command: str
    """

    output = six.text_type(output)

    if pager_command is None:
        pager_command = 'less -R'

    if not sys.stdout.isatty() or util.is_windows_platform():
        print(output)
        return

    num_lines = output.count('\n')
    exceeds_tty_height = pager.getheight() - 1 < num_lines

    paginate = util.get_config().get("core.pagination", True)
    if exceeds_tty_height and paginate:
        pydoc.pipepager(output, cmd=pager_command)
    else:
        print(output)
Ejemplo n.º 4
0
def _page(output, pager_command=None):
    """Conditionally pipes the supplied output through a pager.

    :param output:
    :type output: object
    :param pager_command:
    :type pager_command: str
    """

    output = str(output)

    if pager_command is None:
        pager_command = 'less -R'

    if not sys.stdout.isatty() or util.is_windows_platform():
        print(output)
        return

    num_lines = output.count('\n')
    exceeds_tty_height = pager.getheight() - 1 < num_lines

    if exceeds_tty_height:
        pydoc.pipepager(output, cmd=pager_command)
    else:
        print(output)
Ejemplo n.º 5
0
def page(content, pagecallback=None):
    """
    Output `content`, call `pagecallback` after every page with page
    number as a parameter. `pagecallback` may return False to terminate
    pagination.

    Default callback shows prompt, waits for keypress and aborts on
    'q', ESC or Ctrl-C.
    """
    width = pager.getwidth()
    height = pager.getheight()
    pagenum = 1
    print content.next()
    try:
        try:
            line = content.next().rstrip("\r\n")
        except AttributeError:
            # Python 3 compatibility
            line = content.__next__().rstrip("\r\n")
    except StopIteration:
        pagecallback(pagenum, height-1)
        return

    while True:     # page cycle
        linesleft = height-1 # leave the last line for the prompt callback
        while linesleft:
            linelist = [line[i:i+width] for i in range(0, len(line), width)]
            if not linelist:
                linelist = ['']
            lines2print = min(len(linelist), linesleft)
            for i in range(lines2print):
                print(linelist[i])
            linesleft -= lines2print
            linelist = linelist[lines2print:]

            if linelist: # prepare symbols left on the line for the next iteration
                line = ''.join(linelist)
                continue
            else:
                try:
                    try:
                        line = content.next().rstrip("\r\n")
                    except AttributeError:
                        # Python 3 compatibility
                        line = content.__next__().rstrip("\r\n")
                except StopIteration:
                    pagecallback(pagenum, linesleft)
                    return

        if pagecallback(pagenum, linesleft) == False:
            return
        pagenum += 1
Ejemplo n.º 6
0
    def page(self, content, pagecallback=None, always_page=False):
        rows = pager.getheight()

        if always_page is False:
            if len(content) < rows:
                for line in content:
                    print(line)
                return

        if pagecallback is None:
            pagecallback = OptionsPrompt()

        pager.page(iter(content), pagecallback=pagecallback)
Ejemplo n.º 7
0
    def page(self, content, pagecallback=None, always_page=False):
        rows = pager.getheight()

        if always_page is False:
            if len(content) < rows:
                for line in content:
                    print(line)
                return

        if pagecallback is None:
            pagecallback = OptionsPrompt()

        pager.page(iter(content), pagecallback=pagecallback)
Ejemplo n.º 8
0
    def get_map(self):
        width, height = pager.getwidth() * self.scaling, pager.getheight(
        ) * self.scaling
        minx, miny, maxx, maxy = (
            self.center[0] - (width / float(2) + self.gutter) * self.res,
            self.center[1] - (height / float(2) + self.gutter) * self.res,
            self.center[0] + (width / float(2) + self.gutter) * self.res,
            self.center[1] + (height / float(2) + self.gutter) * self.res)
        bbox = (miny, minx, maxy, maxx) if self.invert_axis else (minx, miny,
                                                                  maxx, maxy)
        params = {
            "width": int(width + self.gutter * 2),
            "height": int(height + self.gutter * 2),
            "bbox": ",".join(str(x) for x in bbox),
            "layers": self.layer,
            "format": self.format,
            "request": "GetMap",
            "version": ".".join(str(x) for x in self.version),
            "service": "WMS"
        }

        if self.version >= (1, 3, 0):
            params["crs"] = self.srs
        else:
            params["srs"] = self.srs

        if self.style:
            params["style"] = self.style

        r = self.session.get(self.url, params=params)

        self.last_error = None

        if r.status_code != 200 or not r.headers.get(
                "Content-Type").startswith("image/"):
            self.last_error = r.text
            return None

        try:
            img = Image.open(io.BytesIO(r.content))
            img = process_image(img, self.gutter, self.scaling)
            return img
        except IOError as e:
            self.last_error = str(e)
            return None
Ejemplo n.º 9
0
 def pan_down(self):
     self.center = self.center[0], \
                   self.center[1] - int(self.res * pager.getheight() * self.pan_factor * self.scaling)