Merge lp:~quickly-committers/quickly/ide into lp:quickly

Proposed by Tony Byrne
Status: Needs review
Proposed branch: lp:~quickly-committers/quickly/ide
Merge into: lp:quickly
Diff against target: 271 lines (+117/-56)
6 files modified
data/templates/ubuntu-application/configure.py (+2/-3)
data/templates/ubuntu-application/edit.py (+2/-1)
data/templates/ubuntu-application/internal/quicklyutils.py (+0/-38)
data/templates/ubuntu-flash-game/internal/quicklyutils.py (+0/-13)
quickly/builtincommands.py (+32/-1)
quickly/templatetools.py (+81/-0)
To merge this branch: bzr merge lp:~quickly-committers/quickly/ide
Reviewer Review Type Date Requested Status
Quickly Developers Pending
Review via email: mp+61326@code.launchpad.net

Description of the change

Quickly uses the same editor for editing project (many files open) and for read_input (open a single file and react to editor close down). In order to do both tasks quickly uses a particular property of gedit which allows both usages simultaneously. It would be nice to use a different program for editing files (an IDE) and for reading input. Also different IDEs for different languages.

Proposal: quickly reads a preference file e.g. ~.config/quickly/preferences containing something like

[vala-ubuntu-application]
ide = valide

[ubuntu-application]
ide = geany

[java-ubuntu-application]
ide = eclipse

[kubuntu-application]
ide = kdevelop

and uses the ide for quickly edit. Automatically creates ~.config/quickly/preferences and adds a command $ quickly preferences to allow editing this file

The bad news: running trunk/quickly$ test/run.sh doesn't work for me still so I cannot test it :(

To post a comment you must log in.
lp:~quickly-committers/quickly/ide updated
621. By Tony Byrne <email address hidden>

removed some junk

Revision history for this message
Michael Terry (mterry) wrote :

I dig moving the functions to templatetools to be shared. But why create a preference system for the ide issue? Isn't that already handled via environment variables?

Revision history for this message
Tony Byrne (tony-badwolf) wrote :

Having an environment variable for each template would be unwieldy.
Also the environment variables are effectively
export PARAMETER=value in the ~/.bashrc file
while
parameter=value in the ~/.config/quickly/preferences file allows a
$quickly preferences command to edit them and apply instantly without
requiring a terminal restart.

Actually moving get_quickly_editors() was a side effect of searching
for get_quickly_editors() so I could be sure to consider every call,
then noticing the almost duplicate code and that it is not specific to
a template anyway. But the location of get_quickly_editors() inside
the template also hints that different editors for each template is a
good idea anyway.

I'm also working on enhancing the add command so that you could call,
for instance,
$quickly add company_logo where company_logo would reside in a
directory and .bashrc (or preferences) would contain
plugins=/my/plugin/directory.

In effect the more choices we give to the developer the more
parameters=value statements, with sensible defaults, are needed.

There is a gap in configuration
projects have .quickly
quickly has .bashrc
templates have nothing

quickly can edit part of .quickly ($quickly dependencies)
but does not provide editing .bashrc, neither does .bashrc have sections.

On 18/05/2011, Michael Terry <email address hidden> wrote:
> I dig moving the functions to templatetools to be shared. But why create a
> preference system for the ide issue? Isn't that already handled via
> environment variables?
> --
> https://code.launchpad.net/~tony-badwolf/quickly/ide/+merge/61326
> You are the owner of lp:~tony-badwolf/quickly/ide.
>

Unmerged revisions

621. By Tony Byrne <email address hidden>

removed some junk

620. By Tony Byrne <email address hidden>

allow preferences to be edited outside project
removed quickly configure preferences
added quickly preferences
moved read_input from templates/ubuntu-application/quicklyutils.py
to quickly/templatetools.py

619. By Tony Byrne <email address hidden>

added command configure preferences

618. By Tony Byrne <email address hidden>

moved get_quickly_editors() into templatetools: same code for all templates
use a config file to allow developer use an ide for editing project keeping gedit for read_input()

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/templates/ubuntu-application/configure.py'
2--- data/templates/ubuntu-application/configure.py 2010-10-18 18:39:04 +0000
3+++ data/templates/ubuntu-application/configure.py 2011-05-17 22:51:41 +0000
4@@ -82,7 +82,7 @@
5 if len(argv) > 2:
6 project_name = argv[2]
7 else:
8- project_name = quicklyutils.read_input()
9+ project_name = templatetools.read_input()
10 # need to try and get the original project name if it exists. We'll need this
11 # to replace any existing settings
12 if not configurationhandler.project_config:
13@@ -158,7 +158,7 @@
14 dependencies = [elem.strip() for elem in configurationhandler.project_config['dependencies'].split(',') if elem]
15 except KeyError:
16 dependencies = []
17- userinput = quicklyutils.read_input('\n'.join(dependencies))
18+ userinput = templatetools.read_input('\n'.join(dependencies))
19 dependencies = []
20 for depends in userinput.split('\n'):
21 dependencies.extend([elem.strip() for elem in depends.split(',') if elem])
22@@ -174,4 +174,3 @@
23 configurationhandler.loadConfig()
24 configurationhandler.project_config["target_distribution"] = argv[2]
25 configurationhandler.saveConfig()
26-
27
28=== modified file 'data/templates/ubuntu-application/edit.py'
29--- data/templates/ubuntu-application/edit.py 2011-04-27 15:02:41 +0000
30+++ data/templates/ubuntu-application/edit.py 2011-05-17 22:51:41 +0000
31@@ -65,7 +65,8 @@
32 # add helpfile sources
33 filelist.extend(glob.glob('help/C/*.page'))
34
35-editor = quicklyutils.get_quickly_editors()
36+editor = templatetools.get_ide(configurationhandler.project_config['template'])
37+
38 if templatetools.in_verbose_mode():
39 instance = subprocess.Popen([editor] + filelist)
40 else:
41
42=== modified file 'data/templates/ubuntu-application/internal/quicklyutils.py'
43--- data/templates/ubuntu-application/internal/quicklyutils.py 2011-03-02 15:04:44 +0000
44+++ data/templates/ubuntu-application/internal/quicklyutils.py 2011-05-17 22:51:41 +0000
45@@ -229,44 +229,6 @@
46 buffered_message +=' %s' % line
47 return(changelog)
48
49-
50-def get_quickly_editors():
51- '''Return prefered editor for ubuntu-application template'''
52-
53- default_editor = os.environ.get("QUICKLY_EDITOR")
54- if not default_editor:
55- default_editor = os.environ.get("EDITOR")
56- if not default_editor:
57- default_editor = os.environ.get("SELECTED_EDITOR")
58- if default_editor:
59- editor = default_editor
60- elif templatetools.is_X_display():
61- editor = "gedit"
62- else:
63- editor = "nano"
64- return editor
65-
66-def read_input(start=''):
67- depfile_name = tempfile.mkstemp()[1]
68- open(depfile_name,'w').write(start)
69-
70- # Run the editor with a new tmpdir. This is because gedit uses tmpdir
71- # to find other instances of gedit, and we don't want that. If we allowed
72- # that, gedit would return immediately and open a new tab in the other
73- # gedit. This makes it difficult to tell when user is done editing (how
74- # to detect that vs nano opening and closing without the user saving it?).
75- editor = get_quickly_editors()
76- subenv = dict(os.environ)
77- subenv['TMPDIR'] = tempfile.mkdtemp()
78- subprocess.call([editor, depfile_name], stdout=subprocess.PIPE, env=subenv)
79- os.rmdir(subenv['TMPDIR'])
80-
81- # Grab file contents
82- rv = file(depfile_name, 'r').read().strip()
83- os.remove(depfile_name)
84-
85- return rv
86-
87 def take_email_from_string(value):
88 '''Try to take an email from a string'''
89
90
91=== modified file 'data/templates/ubuntu-flash-game/internal/quicklyutils.py'
92--- data/templates/ubuntu-flash-game/internal/quicklyutils.py 2011-01-03 15:07:28 +0000
93+++ data/templates/ubuntu-flash-game/internal/quicklyutils.py 2011-05-17 22:51:41 +0000
94@@ -209,19 +209,6 @@
95 buffered_message +=' %s' % line
96 return(changelog)
97
98-
99-def get_quickly_editors():
100- '''Return prefered editor for ubuntu-application template'''
101-
102- editor = "gedit"
103- default_editor = os.environ.get("EDITOR")
104- if not default_editor:
105- default_editor = os.environ.get("SELECTED_EDITOR")
106- if default_editor:
107- editor = default_editor
108- return editor
109-
110-
111 def take_email_from_string(value):
112 '''Try to take an email from a string'''
113
114
115=== modified file 'quickly/builtincommands.py'
116--- quickly/builtincommands.py 2010-11-29 15:18:46 +0000
117+++ quickly/builtincommands.py 2011-05-17 22:51:41 +0000
118@@ -15,8 +15,10 @@
119 #You should have received a copy of the GNU General Public License along
120 #with this program. If not, see <http://www.gnu.org/licenses/>.
121
122+import ConfigParser
123 import os
124 import shutil
125+import StringIO
126 import sys
127
128 import configurationhandler
129@@ -211,7 +213,36 @@
130 os.rename(filedest.name, commandsconfig_path)
131 return 0
132
133-
134+help_preferences = _("Edit developers preferences")
135+usage_preferences = _("Usage: quickly preferences")
136+def preferences(project_template, project_dir, command_args, shell_completion=False):
137+ """Configure preferences"""
138+
139+ # We have nothing for this
140+ if shell_completion:
141+ return("")
142+
143+ preferences = templatetools.get_preferences()
144+
145+ #convert preferences into editable contents
146+ fp_current = StringIO.StringIO()
147+ preferences.write(fp_current)
148+ contents = fp_current.getvalue()
149+ fp_current.close()
150+
151+ # ask developer to edit the contents
152+ newcontents = templatetools.read_input(contents)
153+
154+ # convert the contents back into a ConfigParser object
155+ newIO = StringIO.StringIO(newcontents)
156+ new_preferences = ConfigParser.SafeConfigParser()
157+ # an exception here reject bad edits
158+ new_preferences.readfp(newIO)
159+
160+ templatetools.set_preferences(new_preferences)
161+
162+
163+ return 0
164
165 # here, special builtin commands properties (if nothing specified, commands can be launched inside and outside projects)
166 launched_inside_project_only = []
167
168=== modified file 'quickly/templatetools.py'
169--- quickly/templatetools.py 2010-12-20 20:33:12 +0000
170+++ quickly/templatetools.py 2011-05-17 22:51:41 +0000
171@@ -15,15 +15,20 @@
172 #You should have received a copy of the GNU General Public License along
173 #with this program. If not, see <http://www.gnu.org/licenses/>.
174
175+import ConfigParser
176 import os
177 import stat
178 import string
179+import subprocess
180 import sys
181 import re
182+import tempfile
183
184 import gettext
185 from gettext import gettext as _
186
187+import glib
188+
189 import configurationhandler
190 import tools
191 import quicklyconfig
192@@ -256,3 +261,79 @@
193 print_command_candidates(template)
194 sys.exit(4)
195
196+def get_preferences():
197+ 'parse ~/.config/quickly/preferences for configuration'
198+ template_names = commands.get_all_templates()
199+ preferences = ConfigParser.SafeConfigParser()
200+
201+ for template_name in template_names:
202+ preferences.add_section(template_name)
203+
204+ config_dir = os.path.join(glib.get_user_config_dir(), 'quickly')
205+ config_file = os.path.join(config_dir, 'preferences')
206+ preferences.read(config_file)
207+
208+ return preferences
209+
210+def set_preferences(new_preferences):
211+ 'write ~/.config/quickly/preferences'
212+
213+ config_dir = os.path.join(glib.get_user_config_dir(), 'quickly')
214+ config_file = os.path.join(config_dir, 'preferences')
215+
216+ # ensure config_dir exists
217+ if not os.path.isdir(config_dir):
218+ os.makedirs(config_dir)
219+
220+ # write the preferences file
221+ with open(config_file, 'w') as fp:
222+ new_preferences.write(fp)
223+
224+def get_quickly_editors():
225+ '''Return prefered editor for any template'''
226+
227+ default_editor = os.environ.get("QUICKLY_EDITOR")
228+ if not default_editor:
229+ default_editor = os.environ.get("EDITOR")
230+ if not default_editor:
231+ default_editor = os.environ.get("SELECTED_EDITOR")
232+ if default_editor:
233+ editor = default_editor
234+ elif is_X_display():
235+ editor = "gedit"
236+ else:
237+ editor = "nano"
238+ return editor
239+
240+def read_input(start=''):
241+ depfile_name = tempfile.mkstemp()[1]
242+ open(depfile_name,'w').write(start)
243+
244+ # Run the editor with a new tmpdir. This is because gedit uses tmpdir
245+ # to find other instances of gedit, and we don't want that. If we allowed
246+ # that, gedit would return immediately and open a new tab in the other
247+ # gedit. This makes it difficult to tell when user is done editing (how
248+ # to detect that vs nano opening and closing without the user saving it?).
249+ editor = get_quickly_editors()
250+ subenv = dict(os.environ)
251+ subenv['TMPDIR'] = tempfile.mkdtemp()
252+ subprocess.call([editor, depfile_name], stdout=subprocess.PIPE, env=subenv)
253+ os.rmdir(subenv['TMPDIR'])
254+
255+ # Grab file contents
256+ rv = file(depfile_name, 'r').read().strip()
257+ os.remove(depfile_name)
258+
259+ return rv
260+
261+def get_ide(template):
262+ '''Return prefered editor for specified template'''
263+ preferences = get_preferences()
264+
265+ if preferences.has_option(template, 'ide'):
266+ return preferences.get(template, 'ide')
267+ else:
268+ return get_quickly_editors()
269+
270+
271+

Subscribers

People subscribed via source and target branches