~clicompanion-devs/clicompanion/clicomp-glade

« back to all changes in this revision

Viewing changes to comps.drafts.builds/cliForum.exp.py

  • Committer: duanedesign
  • Date: 2010-04-04 05:50:48 UTC
  • Revision ID: duanedesign@gmail.com-20100404055048-hqptxm1na56lawe6
"added scroling, 56 command capacity"

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
from os import system
 
4
import curses
 
5
 
 
6
'''
 
7
def get_param(screen, prompt_string):
 
8
     screen.clear()
 
9
     screen.border(0)
 
10
     screen.addstr(2, 2, prompt_string)
 
11
     screen.refresh()
 
12
     input = screen.getstr(10, 10, 60)
 
13
     return input
 
14
'''
 
15
 
 
16
def get_param_new(screen,y,x, prompt_string):
 
17
     screen.addstr(y, x, prompt_string)
 
18
     screen.refresh()
 
19
     curses.echo(); curses.nocbreak(); screen.keypad(0)
 
20
     
 
21
     input = screen.getstr()
 
22
     
 
23
     curses.noecho(); curses.cbreak(); screen.keypad(1)
 
24
     
 
25
     return input
 
26
 
 
27
'''
 
28
def execute_cmd(cmd_string):
 
29
     system("clear")
 
30
     a = system(cmd_string)
 
31
     print ""
 
32
     if a == 0:
 
33
          print "Command executed correctly"
 
34
     else:
 
35
          print "Command terminated with error"
 
36
     raw_input("Press enter")
 
37
     print ""
 
38
     
 
39
'''
 
40
 
 
41
def execute_cmd_new(screen,args):
 
42
    import subprocess
 
43
    p = subprocess.Popen(args,
 
44
                        stdout=subprocess.PIPE,
 
45
                        stderr=subprocess.PIPE )
 
46
    
 
47
    output,errors = p.communicate()
 
48
    output = output.split('\n')
 
49
 
 
50
    showdata(screen,output)
 
51
    
 
52
    
 
53
def showdata(screen,data):
 
54
    wy,wx=screen.getmaxyx()
 
55
    wy-=2
 
56
    wx-=2
 
57
    if type(data)==str:
 
58
        data = data.split('\n')
 
59
 
 
60
    padx = max(getmax(data),wx)
 
61
    pady = max(len(data)+1,wy)
 
62
    max_x = padx-wx
 
63
    max_y = pady-wy
 
64
    
 
65
        
 
66
    pad = curses.newpad(pady,padx)
 
67
        
 
68
    for i,line in enumerate(data):
 
69
        pad.addstr(i,0,str(line))
 
70
    
 
71
    x=0
 
72
    y=0
 
73
    
 
74
    inkey=0
 
75
    
 
76
    while inkey != 'q':
 
77
        pad.refresh(y,x,1,1,wy,wx)
 
78
        inkey = screen.getkey()
 
79
        
 
80
                
 
81
        if inkey=='KEY_UP':y=max(y-1,0)
 
82
        elif inkey=='KEY_DOWN':y=min(y+1,max_y)
 
83
        elif inkey=='KEY_LEFT':x=max(x-1,0)
 
84
        elif inkey=='KEY_RIGHT':x=min(x+1,max_x)
 
85
        elif inkey=='KEY_NPAGE':y=min(y+wy,max_y)
 
86
        elif inkey=='KEY_PPAGE':y=max(y-wy,0)
 
87
        elif inkey=='KEY_HOME':y=0
 
88
        elif inkey=='KEY_END':y=max_y
 
89
        
 
90
        
 
91
    
 
92
 
 
93
def getmax(lines): return max([len(str(l)) for l in lines])
 
94
 
 
95
 
 
96
def menu(screen):
 
97
    x = 0
 
98
  
 
99
    while x != ord('q'):
 
100
        curses.cbreak()
 
101
        curses.noecho()
 
102
        screen.keypad(1)
 
103
 
 
104
        screen.clear()
 
105
        screen.border(0)
 
106
        data = "Please enter a number... \n 1 - Find version of a package \
 
107
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
108
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
109
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
110
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
111
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
112
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
113
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
114
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
115
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
116
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
117
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
118
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
119
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
120
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
121
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
122
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
123
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
124
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
125
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
126
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
127
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
128
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
129
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
130
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
131
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
132
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
133
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
134
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
135
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
136
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
137
        \n 2 - List installed packages \n 3 - \   Show disk space \n q - Exit \
 
138
        "
 
139
        screen.refresh()
 
140
       
 
141
 
 
142
        x = screen.getch(10,4)
 
143
 
 
144
        if x == ord('1'):
 
145
            package = get_param_new(screen,10,4, "Enter the package name: ")
 
146
            execute_cmd_new(screen,["dpkg", "-s", package])
 
147
 
 
148
        elif x == ord('2'):
 
149
            execute_cmd_new(screen,["dpkg", "-l"])
 
150
 
 
151
        elif x == ord('3'):
 
152
            execute_cmd_new(screen,["df", "-h"])
 
153
 
 
154
        elif x == ord('s'):
 
155
            curses.nocbreak(); screen.keypad(0); curses.echo()
 
156
            wy,wx=screen.getmaxyx()
 
157
 
 
158
            screen.addstr(10,4,'Y:'+str(wy))
 
159
            screen.addstr(11,4,'X:'+str(wx))
 
160
 
 
161
            screen.refresh()
 
162
            curses.napms(1000)
 
163
 
 
164
        elif x == ord('t'):
 
165
 
 
166
            showdata(screen,data)
 
167
 
 
168
curses.wrapper(menu)