~clicompanion-devs/clicompanion/clicomp-glade

« back to all changes in this revision

Viewing changes to comps.drafts.builds/clicompanion-0.0.4.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
import os
 
4
import curses
 
5
import subprocess
 
6
 
 
7
 
 
8
def get_param(screen,y,x, prompt_string):
 
9
 
 
10
    screen.addstr(y, x, prompt_string)
 
11
    screen.refresh()
 
12
    input = screen.getstr(21, 4, 60)
 
13
    return input
 
14
 
 
15
def execute_cmd(screen,args):
 
16
 
 
17
### subprocess.Popen(args,
 
18
###                        stdout=subprocess.PIPE,
 
19
###                        stderr=subprocess.PIPE )
 
20
 
 
21
    p = os.system(args)
 
22
    o = str(p)
 
23
#    output,errors = p.communicate()
 
24
#    output = output.split('\n')
 
25
 
 
26
    showdata(screen,o)
 
27
 
 
28
    
 
29
def getmax(lines): return max([len(str(l)) for l in lines])
 
30
 
 
31
def user_input(screen):
 
32
 
 
33
 
 
34
    win_user_input = curses.newwin(5,50,20,5)
 
35
    win_user_input.border(0)
 
36
    win_user_input.addstr(2, 2, 'Please enter a number then hit Enter',curses.A_BOLD)
 
37
 
 
38
    win_user_input.refresh()
 
39
 
 
40
 
 
41
 
 
42
def showdata(screen,data):
 
43
    wy,wx=screen.getmaxyx()
 
44
    wy-=2
 
45
    wx-=2
 
46
    if type(data)==str:
 
47
        data = data.split('\n')
 
48
 
 
49
    padx = max(getmax(data),wx)
 
50
    pady = max(len(data)+1,wy)
 
51
    max_x = padx-wx
 
52
    max_y = pady-wy
 
53
    
 
54
        
 
55
    pad = curses.newpad(pady,padx)
 
56
        
 
57
    for i,line in enumerate(data):
 
58
        pad.addstr(i,0,str(line))
 
59
    
 
60
    x=0
 
61
    y=0
 
62
    
 
63
    inkey=0
 
64
    
 
65
    while inkey != 'q':
 
66
        pad.refresh(y,x,1,1,wy,wx)
 
67
        inkey = screen.getkey()
 
68
        
 
69
                
 
70
        if inkey=='KEY_UP':y=max(y-1,0)
 
71
        elif inkey=='KEY_DOWN':y=min(y+1,max_y)
 
72
        elif inkey=='KEY_LEFT':x=max(x-1,0)
 
73
        elif inkey=='KEY_RIGHT':x=min(x+1,max_x)
 
74
        elif inkey=='KEY_NPAGE':y=min(y+wy,max_y)
 
75
        elif inkey=='KEY_PPAGE':y=max(y-wy,0)
 
76
        elif inkey=='KEY_HOME':y=0
 
77
        elif inkey=='KEY_END':y=max_y
 
78
        
 
79
 
 
80
 
 
81
 
 
82
 
 
83
 
 
84
def main(screen):
 
85
 
 
86
    pad = curses.newpad(110, 60)
 
87
    
 
88
    if curses.has_colors():
 
89
 
 
90
        bg = curses.COLOR_WHITE
 
91
        curses.init_pair(1, curses.COLOR_BLUE, bg)
 
92
        curses.init_pair(2, curses.COLOR_RED, bg)
 
93
 
 
94
 
 
95
    x = "0"
 
96
    bye = "20"
 
97
 
 
98
    while x != "20":
 
99
 
 
100
 
 
101
 
 
102
        pad.clear()
 
103
        pad.border()
 
104
 
 
105
        pad.addstr(4, 4, "1 - Find version of an installed package", curses.color_pair(1))
 
106
        pad.addstr(5, 4, "2 - List installed packages", curses.color_pair(1))
 
107
        pad.addstr(6, 4, "3 - Show disk space", curses.color_pair(1))
 
108
        pad.addstr(7, 4, "4 - Show RAM usage", curses.color_pair(1))
 
109
        pad.addstr(8, 4, "5 - Display network information", curses.color_pair(1))
 
110
        pad.addstr(9, 4, "6 - Display wireless information", curses.color_pair(1))
 
111
        pad.addstr(10, 4, "7 - Scan wireless networks", curses.color_pair(1))
 
112
        pad.addstr(11, 4, "8 - Reset the network", curses.color_pair(1))
 
113
        pad.addstr(12, 4, "9 - What version of Ubuntu do I have?", curses.color_pair(1))
 
114
        pad.addstr(13, 4, "10 - Kernel Information", curses.color_pair(1))
 
115
        pad.addstr(14, 4, "11 - Refresh update info and update all packages", curses.color_pair(1))
 
116
        pad.addstr(15, 4, "12 - Find information on a package (not installed)", curses.color_pair(1))
 
117
        pad.addstr(16, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
118
        pad.addstr(17, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
119
        pad.addstr(18, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
120
        pad.addstr(19, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
121
        pad.addstr(20, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
122
        pad.addstr(21, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
123
        pad.addstr(22, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
124
        pad.addstr(23, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
125
        pad.addstr(24, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
126
        pad.addstr(25, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
127
        pad.addstr(26, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
128
        pad.addstr(27, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
129
        pad.addstr(28, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
130
        pad.addstr(29, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
131
        pad.addstr(30, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
132
        pad.addstr(31, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
133
        pad.addstr(32, 4, "13 - Locate a file on your computer", curses.color_pair(1))
 
134
        pad.addstr(33, 4, "20 - Exit", curses.color_pair(2))
 
135
        yy=0
 
136
        xx=0
 
137
        pad.noutrefresh( yy,xx, 1,1, 20,60)
 
138
                
 
139
        #if x=='KEY_UP':y=y+1
 
140
        #elif x=='KEY_DOWN':x=x-1
 
141
        
 
142
        user_input(screen)
 
143
                        
 
144
 
 
145
        #for y in range(0, 60):
 
146
         #   for x in range(0, 60):
 
147
        #        try: pad.addch(y,x, ord('a') + (x*x+y*y) % 26 )
 
148
        #        except curses.error: pass
 
149
 
 
150
        x = pad.getstr(0,0, 2)
 
151
 
 
152
 
 
153
        if x == "1" :
 
154
            package = get_param(screen, 20, 4, "Enter the package name")
 
155
            execute_cmd(screen,"dpkg -s " + package)
 
156
 
 
157
        if x == "2" :
 
158
            execute_cmd(screen, "dpkg -l")
 
159
 
 
160
        if x == "3" :
 
161
            execute_cmd(screen, "df -h")
 
162
 
 
163
        if x == "4" :
 
164
            execute_cmd(screen, "free -m")
 
165
 
 
166
        if x == "5" :
 
167
            execute_cmd(screen, "ifconfig")
 
168
 
 
169
        if x == "6" :
 
170
            execute_cmd(screen, "iwconfig")
 
171
 
 
172
        if x == "7" :
 
173
            execute_cmd(screen, "sudo iwlist scan")
 
174
 
 
175
        if x == "8" :
 
176
            execute_cmd(screen, "sudo /etc/init.d/networking restart")
 
177
 
 
178
        if x == "9" :
 
179
            execute_cmd(screen, "lsb_release -a")
 
180
 
 
181
        if x == "10" :
 
182
            execute_cmd(screen, "uname -a")
 
183
 
 
184
        if x == "11" :
 
185
            execute_cmd(screen, "sudo apt-get update && sudo apt-get upgrade")
 
186
 
 
187
        if x == "12" :
 
188
            package = get_param(screen, 20, 4,"Enter the package name")
 
189
            execute_cmd(screen, "apt-cache search " + package)
 
190
 
 
191
        if x == "13" :
 
192
            package = get_param(screen, 20, 4,"Enter the file name")
 
193
            execute_cmd(screen, "locate " + package)
 
194
 
 
195
 
 
196
curses.wrapper(main)
 
197
curses.endwin()
 
198
 
 
199