Commit 3fad46e5 authored by Sébastien Luttringer's avatar Sébastien Luttringer
Browse files

Add pager to Printer class

Attachements now use this
parent 320d902f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1293,6 +1293,8 @@ file where alias are stored
\fBCC_DEBUG\fP
.TP
\fBCC_PROFILE\fP
.TP
\fBCC_PAGER\fP

.SH AUTHOR
SmartJog IT
+3 −6
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
#coding=utf8

'''
CloudControl script releated commands
CloudControl attachment command
'''

import os
@@ -16,8 +16,8 @@ class Command_attachment(TqlCommand):

    def __init__(self, cli, argv0):
        TqlCommand.__init__(self, cli, argv0)
        self.set_usage("%prog [options] <tql> attachment [attachment] ...")
        self.tql_filter += "&r=job"
        self.set_usage("%prog <tql> <attachment>")

    def __call__(self, argv):
        # Parse argline
@@ -26,13 +26,10 @@ class Command_attachment(TqlCommand):
        if len(self.args) != 2:
            raise cmdBadArgument()
        # ask server
        pager = os.environ.get('PAGER', '/bin/more')
        objs = self.rpc.call("attachment", self.args[0], self.args[1])
        for out in objs['objects']:
            if out['status'] == 'success':
                page = '# %s:\n\n%s\n' % (out['id'], out['output'])
                p = subprocess.Popen([pager], stdin=subprocess.PIPE)
                p.communicate(page)
                self.printer.pager(f_output)
            else:
                self.printer.warn('%s: %s' % (out['id'], out['message']))

+15 −4
Original line number Diff line number Diff line
@@ -8,12 +8,13 @@ CloudControl CLI Printer module
import cccli
from cccli.exception import *

import sys
import os
import termios
import fcntl
import struct
import os
import signal
import struct
import subprocess
import sys
import termios

color = {
    # regular
@@ -176,6 +177,16 @@ class Printer(object):
            return
        self.out("\033[H\033[2J", nl="")

    def pager(self, data):
        '''Page data using PAGER'''
        binary = os.environ.get("CC_PAGER", os.environ.get("PAGER", "more"))
        if isinstance(data, basestring):
            p = subprocess.Popen(binary, stdin=subprocess.PIPE, shell=True)
            p.communicate(data)
        else:
            p = subprocess.Popen(binary, stdin=data, shell=True)
            p.wait()


class History(object):
    '''History class'''