@@ -78,12 +78,8 @@ def init_app(self):
7878
7979 def _init_app_internal (self , raw_icon , raw_menu_name , version = None ):
8080 # do the {version} replacement if needed
81- if version is None :
82- icon = raw_icon
83- menu_name = raw_menu_name
84- else :
85- icon = self ._translate_version_tokens (raw_icon , version )
86- menu_name = self ._translate_version_tokens (raw_menu_name , version )
81+ icon = self ._apply_version_to_setting (raw_icon , version )
82+ menu_name = self ._apply_version_to_setting (raw_menu_name , version )
8783
8884 # the command name mustn't contain spaces and funny chars, so sanitize it.
8985 # Also, should be nice for the shell engine.
@@ -224,22 +220,47 @@ def _translate_version_tokens(self, raw_string, version):
224220 string = string .replace ("{v%d}" % i , token )
225221 return string
226222
227- def _get_app_path (self , version = None ):
228- """ Return the platform specific app path, performing version substitution. """
229- platform_name = {"linux2" : "linux" , "darwin" : "mac" , "win32" : "windows" }[sys .platform ]
230- raw_app_path = self .get_setting ("%s_path" % platform_name , "" )
223+ def _apply_version_to_setting (self , raw_string , version = None ):
224+ """
225+ Replace any version tokens contained in the raw_string with the appropriate version value from
226+ the app settings.
227+
228+ If version is None, then no version has been specified and we will return the first version
229+ from the versions list in the settings. If no versions have been defined in the settings, then
230+ we return the raw_string since there's no replacement to do.
231+
232+ :param raw_string: the raw string potentially containing the version tokens (eg. {version},
233+ {v0}, ...) we will be replacing. This string could represent a number of
234+ things including a path, an args string, etc.
235+ :param version: version string to use for the token replacement.
236+ :returns: string with version tokens replaced with their appropriate values
237+ """
231238 if version is None :
232239 # there are two reasons version could be None
233- # the first is if versions have not been configured, in which case the raw path is valid
234- # if versions has been configured, then we should expand with the first element in the
235- # list, which will be treated as the default
240+ # 1. if versions have not been configured, the raw string is assumed valid
241+ # 2. if versions has been configured, but no specific version was requested, then we
242+ # expand with the first element in the versions list, and use it as the default
236243 versions = self .get_setting ("versions" )
237244 if versions :
238- return self ._translate_version_tokens (raw_app_path , versions [0 ])
245+ return self ._translate_version_tokens (raw_string , versions [0 ])
239246 else :
240- return raw_app_path
247+ return raw_string
241248 else :
242- return self ._translate_version_tokens (raw_app_path , version )
249+ return self ._translate_version_tokens (raw_string , version )
250+
251+ def _get_app_path (self , version = None ):
252+ """ Return the platform specific app path, performing version substitution. """
253+ platform_name = {"linux2" : "linux" , "darwin" : "mac" , "win32" : "windows" }[sys .platform ]
254+ raw_app_path = self .get_setting ("%s_path" % platform_name , "" )
255+
256+ return self ._apply_version_to_setting (raw_app_path )
257+
258+ def _get_app_args (self , version = None ):
259+ """ Return the platform specific app path, performing version substitution. """
260+ platform_name = {"linux2" : "linux" , "darwin" : "mac" , "win32" : "windows" }[sys .platform ]
261+ raw_app_args = self .get_setting ("%s_args" % platform_name , "" )
262+
263+ return self ._apply_version_to_setting (raw_app_args )
243264
244265 def _launch_app (self , context , file_to_open = None , version = None ):
245266 """
@@ -273,10 +294,8 @@ def _launch_app_internal(self, context, file_to_open=None, version=None):
273294 """
274295 # get the executable path
275296 app_path = self ._get_app_path (version )
276-
277297 # get the app args:
278- platform_name = {"linux2" : "linux" , "darwin" : "mac" , "win32" : "windows" }[sys .platform ]
279- app_args = self .get_setting ("%s_args" % platform_name , "" )
298+ app_args = self ._get_app_args (version )
280299
281300 engine_name = self .get_setting ("engine" )
282301 if engine_name :
0 commit comments