Salome HOME
compatibility python 2.6 and bug fix in sat log -t
[tools/sat.git] / src / system.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2013  CEA/DEN
4 #
5 #  This library is free software; you can redistribute it and/or
6 #  modify it under the terms of the GNU Lesser General Public
7 #  License as published by the Free Software Foundation; either
8 #  version 2.1 of the License.
9 #
10 #  This library is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #  Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public
16 #  License along with this library; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
19 '''
20 In this file : all functions that do a system call, like open a browser or an editor, or call a git command
21 '''
22
23 import subprocess
24
25 from . import printcolors
26
27 def show_in_editor(editor, filePath, logger):
28     '''open filePath using editor.
29     
30     :param editor str: The editor to use.
31     :param filePath str: The path to the file to open.
32     '''
33     # default editor is vi
34     if editor is None or len(editor) == 0:
35         editor = 'vi'
36     
37     if '%s' not in editor:
38         editor += ' %s'
39
40     try:
41         # launch cmd using subprocess.Popen
42         cmd = editor % filePath
43         logger.write('Launched command:\n' + cmd + '\n', 5)
44         p = subprocess.Popen(cmd, shell=True)
45         p.communicate()
46     except:
47         logger.write(printcolors.printcError(_("Unable to edit file %s\n") % filePath), 1)
48