Salome HOME
add options edit, list, and copy to config command
[tools/sat.git] / src / common / fileSystem.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 sys
24 import subprocess
25
26
27 def show_in_editor(editor, filePath):
28     '''open filePath using editor.
29     :param editor str: The editor to use.
30     :param filePath str: The path to the file to open.
31     '''
32     # default editor is vi
33     if editor is None or len(editor) == 0:
34         editor = 'vi'
35     
36     if '%s' not in editor:
37         editor += ' %s'
38
39     try:
40         # launch cmd using subprocess.Popen
41         cmd = editor % filePath
42         p = subprocess.Popen(cmd, shell=True)
43         p.communicate()
44     except:
45         sys.stderr.write("Unable to edit file %s\n" % filePath)
46