This new method will be a common helper for the proto-* commands. It will
also be more generally useful. Here is the first draft:
def runExternalCommands(c, commands,
base_dir = None,
path_setting = None,
warning = None,
):
'''
A helper for prototype commands or any other code that
runs programs in a separate process.
base_dir: Base directory to use if no config path given.
commands: A string or list of commands, for
g.execute_shell_commands.
path_setting: Name of @string setting for the base directory.
warning: A warning to be printed before executing the commands.
'''
if not base_dir and not path_setting:
return g.es_print('Please use base_dir, path_setting or both')
if path_setting and not c:
return g.es_print('path_setting requires valid c arg')
if path_setting:
base_dir = c.config.getString(path_setting)
if base_dir:
base_dir = base_dir.replace('\\','/')
if not g.os_path_exists(base_dir):
return g.es_print('@string path-setting not found: %r' %
base_dir)
else:
return g.es_print('setting not found: @string %s' % path_setting
)
else:
base_dir = base_dir.replace('\\','/')
if not g.os_path_exists(base_dir):
return g.es_print('base_dir not found: %r' % base_dir)
if warning:
g.es_print(warning)
os.chdir(base_dir) # Can't do this in the commands list.
g.execute_shell_commands(commands)
It could be called a thin wrapper for g.execute_shell_commands. Its main
feature is to allow users to specify either a base directory, or an @string
setting giving the base directory. It then checks the resulting directory
and gives a warning if it doesn't exist.
This method is the easy way to run any desired program in an external
process.
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.