Salome HOME
max lenght of lines is now 80
[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, 
21 like open a browser or an editor, or call a git command
22 '''
23
24 import subprocess
25
26 from . import printcolors
27
28 def show_in_editor(editor, filePath, logger):
29     '''open filePath using editor.
30     
31     :param editor str: The editor to use.
32     :param filePath str: The path to the file to open.
33     '''
34     # default editor is vi
35     if editor is None or len(editor) == 0:
36         editor = 'vi'
37     
38     if '%s' not in editor:
39         editor += ' %s'
40
41     try:
42         # launch cmd using subprocess.Popen
43         cmd = editor % filePath
44         logger.write('Launched command:\n' + cmd + '\n', 5)
45         p = subprocess.Popen(cmd, shell=True)
46         p.communicate()
47     except:
48         logger.write(printcolors.printcError(_("Unable to edit file %s\n") 
49                                              % filePath), 1)
50