Merge lp:~edgar-b-dsouza/acire/run_modified_code into lp:acire

Proposed by Ed S
Status: Merged
Merged at revision: not available
Proposed branch: lp:~edgar-b-dsouza/acire/run_modified_code
Merge into: lp:acire
Diff against target: 49 lines (+21/-2)
1 file modified
bin/acire (+21/-2)
To merge this branch: bzr merge lp:~edgar-b-dsouza/acire/run_modified_code
Reviewer Review Type Date Requested Status
Jono Bacon Pending
Review via email: mp+18792@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ed S (edgar-b-dsouza) wrote :

Implemented run-modified-code-from-editor as in Bug #514124 by saving to temp file and execing.

Please review.

Thanks,
Ed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/acire'
--- bin/acire 2010-02-05 06:38:43 +0000
+++ bin/acire 2010-02-07 11:14:11 +0000
@@ -25,6 +25,7 @@
25import gtksourceview25import gtksourceview
26import gnome.vfs26import gnome.vfs
27import pango27import pango
28import tempfile #Used in run_snippet to run user-modded snippet
2829
29# Check if we are working in the source tree or from the installed 30# Check if we are working in the source tree or from the installed
30# package and mangle the python path accordingly31# package and mangle the python path accordingly
@@ -217,6 +218,7 @@
217 self.editor_buffer.set_text(all_the_text)218 self.editor_buffer.set_text(all_the_text)
218 self.editor_buffer.set_data('filename', self.current_filename)219 self.editor_buffer.set_data('filename', self.current_filename)
219 self.editor_view.show()220 self.editor_view.show()
221 self.editor_buffer.set_modified(False) #Reqd for check in run_snippet()
220 222
221 self.location_label.set_text(self.current_filename)223 self.location_label.set_text(self.current_filename)
222 self.description_label.set_text(self.current_description)224 self.description_label.set_text(self.current_description)
@@ -225,10 +227,27 @@
225 """Run the currently selected snippet"""227 """Run the currently selected snippet"""
226228
227 cmd = "/usr/bin/python"229 cmd = "/usr/bin/python"
228 argv = [cmd, self.current_filename]230 #If user has changed code in the editor, save as a temp file and exec that instead.
229 directory = os.path.split(self.current_filename)[0]231 tmp_sn_filename = self.current_filename
232 #Check for mods needs set_modified(False) in snippet_selected()
233 if self.editor_buffer.get_modified() == True:
234 (tmp_sn_fd, tmp_sn_filename) = tempfile.mkstemp(
235 prefix = os.path.basename(self.current_filename).split(".")[0] + '-',
236 suffix = ".py") #get_snippets_file_list() also mandates '.py' extn
237 e = self.editor_buffer
238 #mkstemp returns fd NUMBER, not Py file object - so used os.* below
239 os.write(tmp_sn_fd, e.get_text(e.get_start_iter(), e.get_end_iter()))
240 os.fdatasync(tmp_sn_fd)
241 os.close(tmp_sn_fd)
242
243 argv = [cmd, tmp_sn_filename]
244 directory = os.path.split(tmp_sn_filename)[0]
230 self.terminal.fork_command(command=cmd, argv=argv, envv=None, directory=directory)245 self.terminal.fork_command(command=cmd, argv=argv, envv=None, directory=directory)
231 self.terminal_expander.set_expanded(True)246 self.terminal_expander.set_expanded(True)
247 ###if self.editor_buffer.get_modified() == True:
248 #TO-DO: rm'ing the temp file here deletes it before it is exec'd in vte terminal :-(
249 #For now, leaving the file(s) there; need ideas for cleanup - on app shutdown?
250 ###os.unlink(tmp_sn_filename)
232 251
233 def get_snippets_file_list(self):252 def get_snippets_file_list(self):
234 """Read in the snippets directory and put all Python files into a list."""253 """Read in the snippets directory and put all Python files into a list."""

Subscribers

People subscribed via source and target branches

to all changes: