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
1=== modified file 'bin/acire'
2--- bin/acire 2010-02-05 06:38:43 +0000
3+++ bin/acire 2010-02-07 11:14:11 +0000
4@@ -25,6 +25,7 @@
5 import gtksourceview
6 import gnome.vfs
7 import pango
8+import tempfile #Used in run_snippet to run user-modded snippet
9
10 # Check if we are working in the source tree or from the installed
11 # package and mangle the python path accordingly
12@@ -217,6 +218,7 @@
13 self.editor_buffer.set_text(all_the_text)
14 self.editor_buffer.set_data('filename', self.current_filename)
15 self.editor_view.show()
16+ self.editor_buffer.set_modified(False) #Reqd for check in run_snippet()
17
18 self.location_label.set_text(self.current_filename)
19 self.description_label.set_text(self.current_description)
20@@ -225,10 +227,27 @@
21 """Run the currently selected snippet"""
22
23 cmd = "/usr/bin/python"
24- argv = [cmd, self.current_filename]
25- directory = os.path.split(self.current_filename)[0]
26+ #If user has changed code in the editor, save as a temp file and exec that instead.
27+ tmp_sn_filename = self.current_filename
28+ #Check for mods needs set_modified(False) in snippet_selected()
29+ if self.editor_buffer.get_modified() == True:
30+ (tmp_sn_fd, tmp_sn_filename) = tempfile.mkstemp(
31+ prefix = os.path.basename(self.current_filename).split(".")[0] + '-',
32+ suffix = ".py") #get_snippets_file_list() also mandates '.py' extn
33+ e = self.editor_buffer
34+ #mkstemp returns fd NUMBER, not Py file object - so used os.* below
35+ os.write(tmp_sn_fd, e.get_text(e.get_start_iter(), e.get_end_iter()))
36+ os.fdatasync(tmp_sn_fd)
37+ os.close(tmp_sn_fd)
38+
39+ argv = [cmd, tmp_sn_filename]
40+ directory = os.path.split(tmp_sn_filename)[0]
41 self.terminal.fork_command(command=cmd, argv=argv, envv=None, directory=directory)
42 self.terminal_expander.set_expanded(True)
43+ ###if self.editor_buffer.get_modified() == True:
44+ #TO-DO: rm'ing the temp file here deletes it before it is exec'd in vte terminal :-(
45+ #For now, leaving the file(s) there; need ideas for cleanup - on app shutdown?
46+ ###os.unlink(tmp_sn_filename)
47
48 def get_snippets_file_list(self):
49 """Read in the snippets directory and put all Python files into a list."""

Subscribers

People subscribed via source and target branches

to all changes: