Merge lp:~clicompanion-devs/clicompanion/fix-638243 into lp:clicompanion

Proposed by Duane Hinnen
Status: Merged
Merge reported by: Duane Hinnen
Merged at revision: not available
Proposed branch: lp:~clicompanion-devs/clicompanion/fix-638243
Merge into: lp:clicompanion
Diff against target: 237 lines (+87/-32)
2 files modified
.clicompanion (+23/-23)
clicompanion.py (+64/-9)
To merge this branch: bzr merge lp:~clicompanion-devs/clicompanion/fix-638243
Reviewer Review Type Date Requested Status
Duane Hinnen Approve
Review via email: mp+35688@code.launchpad.net

Description of the change

I have made it where the user can put the symbol @ where user arguments are required.
EX:
cat @ @ | sort | uniq > @
Then the code replaces those with the appropriate {0[0]} {0[1]} {0[2]} etc.
EX
cat {0[0]} {0[1]} | sort | uniq > {0[2]}

 I did this because I thought typing the actual {0[0]} would be confusing to users. I picked @ because I thought it would be the least likely to appear in a command. Anyone have a better suggestion?

To post a comment you must log in.
Revision history for this message
Duane Hinnen (duanedesign) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.clicompanion'
2--- .clicompanion 2010-09-04 02:44:07 +0000
3+++ .clicompanion 2010-09-16 16:39:54 +0000
4@@ -1,7 +1,7 @@
5-dpkg -l: package : Find version of a package
6+dpkg -l @: package : Find version of a package
7 df -h: : file system disk space usage
8 free -m: : show RAM usage
9-ps auxww | grep: process : displays information about the active process
10+ps auxww | grep @: process : displays information about the active process
11 iwconfig: : Display wireless network information
12 ifconfig -a: : displays the status of the currently active interfaces
13 sudo iwlist: : scan Scan Wireless networks
14@@ -11,38 +11,38 @@
15 sudo apt-get update && sudo apt-get upgrade: : Refresh update info and update all packages
16 sudo apt-get clean: : clear out all packages in /var/cache/apt/archives
17 sudo apt-get autoclean : : clear out obsolete packages(packages with a newer release)
18-apt-cache search :package : Find information on a package (not installed)
19+apt-cache search @ :package : Find information on a package (not installed)
20 sudo lshw : : List hardware
21 lspci : : list all PCI devices
22 aplay -l : : List all soundcards and digital audio devices
23-cat :path: Read File & Print to Standard Output
24-ls :path : List Folders Contents
25-ls -lSr :path : Show files by size, biggest last
26-mv :path : Move (Rename) Files
27-cp :path : Copy Files
28+cat @ :path: Read File & Print to Standard Output
29+ls @ :path : List Folders Contents
30+ls -lSr @ :path : Show files by size, biggest last
31+mv @ :path : Move (Rename) Files
32+cp @ :path : Copy Files
33 sudo lspci : : attached PCI devices
34-chmod : permissions file : Change access permissions, change mode
35-chown: owner:group file : Change the owner and/or group of each given file
36+chmod @ @ : permissions, file : Change access permissions, change mode
37+chown @ @: owner:group, file : Change the owner and/or group of each given file
38 dmesg : : Print kernel & driver messages
39 history : : Command History
40-locate : file : Find files (updatedb to update DB)
41+locate @ : file : Find files (updatedb to update DB)
42 sudo updatedb : : update the database for locate
43-which :command : Show full path name of command
44-find -maxdepth 1 -type f | xargs grep -F :string : Search all regular files for 'string' in this dir
45-gpg -c :file : Encypt a file
46-gpg :file.gpg : Decrypt a file
47-tar -xjf :archive.tar : Extract all files from archive.tar
48-tar -czf :Destination.tar.gz Source : Create Destination from Source
49+which @ :command : Show full path name of command
50+find -maxdepth 1 -type f | xargs grep -F @ :string : Search all regular files for 'string' in this dir
51+gpg -c @ :file : Encypt a file
52+gpg @ :file.gpg : Decrypt a file
53+tar -xjf @ :archive.tar : Extract all files from archive.tar
54+tar -czf @ :Destination.tar.gz Source : Create Destination from Source
55 iostat : : cpu and I/O statistics
56 netstat : : Print network connections and interface statistics
57-sudo fdisk -l :disk : List partition tables for specified devices
58+sudo fdisk -l @ :disk : List partition tables for specified devices
59 sudo ufw enable : : Enable netfilter firewall
60-sudo ufw allow :port : Open a port in netfilter firewall
61-sudo ufw deny :port : Close a port in netfilter firewall
62+sudo ufw allow @ :port : Open a port in netfilter firewall
63+sudo ufw deny @ :port : Close a port in netfilter firewall
64 sudo ufw disable : : Disable netfilter firewall
65-cat file1 file2 | sort | uniq > file3 : file1 file2 file3 : combine, sort and remove duplicates from 2 files
66-mkisofs -V LABEL -r dir | gzip > cdrom.iso.gz :isoname.iso.gz : Create cdrom image from contents of directory
67+cat @ @ | sort | uniq > @ : file1, file2, file3 : combine, sort and remove duplicates from 2 files
68+mkisofs -V LABEL -r dir | gzip > @ :isoname.iso.gz : Create cdrom image from contents of directory
69 cdrecord -v dev=/dev/cdrom -audio -pad *.wav : : Make audio CD from all wavs in current dir
70 dpkg-query -W -f='${Installed-Size;10}\t${Package}\n' | sort -k1,1n : : List all installed packages by size
71 tail -f /var/log/messages : : Monitor messages log file
72-apropos :command/package : search the manual page names and descriptions
73+apropos @ :command/package : search the manual page names and descriptions
74
75=== modified file 'clicompanion.py'
76--- clicompanion.py 2010-09-13 11:53:55 +0000
77+++ clicompanion.py 2010-09-16 16:39:54 +0000
78@@ -19,6 +19,7 @@
79 #
80 #
81
82+import re
83 import sys
84 import pygtk
85 pygtk.require('2.0')
86@@ -142,11 +143,14 @@
87 dialog.run()
88
89 ## user text assigned to a variable
90+
91 text = entry.get_text()
92+ user_input = text.split(' ')
93+
94 ## The destroy method must be called otherwise the 'Close' button will
95 ## not work.
96 dialog.destroy()
97- return text
98+ return user_input
99
100 def responseToDialog(self, text, dialog, response):
101 dialog.response(response)
102@@ -326,7 +330,6 @@
103
104 def _filter_commands(self, widget, data=None):
105 """Show commands matching a given search term.
106-
107 The user should enter a term in the search box and the treeview should
108 only display the rows which contain the search term.
109 Pretty straight-forward.
110@@ -364,16 +367,55 @@
111 widget = self.notebook.get_nth_page(pagenum)
112 page_widget = widget.get_child()
113
114- cmnd = CMNDS[row_int] ## CMNDS is where commands are stored
115+ ## CMNDS is where commands are stored
116+ cmnd = CMNDS[row_int]
117+ ## find how many @(user arguments) are in command
118+ match = re.findall('@', cmnd)
119+ #print match ## debug
120+ #match_group = match.group()
121+
122+ '''
123+ Make sure user arguments were found. Replace @ with something
124+ .format can read. This is done so the user can just enter @, when
125+ adding a command where arguments are needed, instead
126+ of {0[1]}, {0[1]}, {0[2]}
127+ '''
128+ if match == False:
129+ pass
130+ else:
131+ num = len(match)
132+ ran = 0
133+ new_cmnd = self.replace(cmnd, num, ran)
134+ print new_cmnd ## debug
135+
136 if not self.liststore[row_int][1] == " ": # command with user input
137 text = Companion.get_info(self, text)
138- page_widget.feed_child(cmnd+" "+text+"\n") #send command w/ input
139+ #print text ## debug
140+ print new_cmnd
141+ c = new_cmnd.format(text)
142+ print c ## debug
143+ page_widget.feed_child(c+"\n") #send command w/ input
144 page_widget.show()
145 else: ## command that has no user input
146 page_widget.feed_child(cmnd+"\n") #send command
147 page_widget.show()
148 page_widget.grab_focus()
149+
150+ ## replace @ with {0[n]}
151+ def replace(self, cmnd, num, ran):
152+ replace_cmnd=re.sub('@', '{0['+str(ran)+']}', cmnd, count=1)
153+ cmnd = replace_cmnd
154+ ran += 1
155+ if ran < num:
156+ return self.replace(cmnd, num, ran)
157+ else:
158+ pass
159+ return cmnd
160
161+
162+
163+
164+
165 ## open the man page for selected command
166 def man_page(self, widget, data=None):
167 row_int = int(ROW[0][0]) # removes everything but number from EX: [5,]
168@@ -463,9 +505,9 @@
169 closebtn.connect("clicked", self.close_tab, vte_tab) # signal handler for tab
170 self.window.show_all()
171
172-
173 return vte_tab
174
175+
176 ## Remove a page from the notebook
177 def close_tab(self, sender, widget):
178 ## get the page number of the tab we wanted to close
179@@ -519,8 +561,9 @@
180 self.treeview.columns[1] = gtk.TreeViewColumn(_('User Argument'))
181 self.treeview.columns[2] = gtk.TreeViewColumn(_('Description'))
182
183- ## right click menu event captur
184- bar = menus_buttons.FileMenu()
185+ ## right click menu event capture
186+ #bar = clicompanion.menus_buttons.FileMenu() ##### packaged version
187+ bar = menus_buttons.FileMenu() ################### local version
188 self.treeview.connect ("button_press_event", bar.right_click, self)
189
190 for n in range(3):
191@@ -608,6 +651,8 @@
192 self.search_label.set_alignment(xalign=-1, yalign=0)
193 self.search_box = gtk.Entry()
194 self.search_box.connect("changed", self._filter_commands)
195+ ## search box tooltip
196+ self.search_box.set_tooltip_text("Search your list of commands")
197 # Set the search box sensitive at program start, because expander is not
198 # unfolded by default
199 self.search_box.set_sensitive(False)
200@@ -618,8 +663,11 @@
201 menu_search_hbox.pack_start(menu_bar, True)
202
203
204+
205+ ## TODO Do we want to start with the command list open or closed?
206+ ## This code opens the app with it open
207+ ## We would also need to change the search field disable code
208 ## start program with expander open
209- ## TODO Do we want to start with the command list open or closed?
210 #expander.set_expanded(True)
211 #self.expanded_cb(expander, None)
212
213@@ -631,10 +679,15 @@
214 image = gtk.Image()
215 image.set_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
216 label = gtk.Label(' Command List')
217+ ## tooltip for the label of the expander
218+ expander_hbox.set_tooltip_text("Click to show/hide command list")
219+
220+
221 ## hbox to hold expander widget
222 expander_hbox.pack_start(image, False, False)
223- expander_hbox.pack_start(label, False, False)
224+ expander_hbox.pack_start(label, True, False)
225 expander.set_label_widget(expander_hbox)
226+
227
228
229 ## Add the first tab with the Terminal
230@@ -644,6 +697,8 @@
231
232 ## The "Add Tab" tab
233 add_tab_button = gtk.Button("+")
234+ ## tooltip for "Add Tab" tab
235+ add_tab_button.set_tooltip_text("Click to add another Tab")
236 add_tab_button.connect("clicked", self.add_tab)
237 self.notebook.append_page(gtk.Label(""), add_tab_button)
238

Subscribers

People subscribed via source and target branches