Package pipe_control :: Module system
[hide private]
[frames] | no frames]

Source Code for Module pipe_control.system

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2016 Troels Schwarz-Linnet                                    # 
 4  #                                                                             # 
 5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
 6  #                                                                             # 
 7  # This program is free software: you can redistribute it and/or modify        # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation, either version 3 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # This program is distributed in the hope that it will be useful,             # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
19  #                                                                             # 
20  ############################################################################### 
21   
22  # Module docstring. 
23  """Module for various os and sys python module purposes.""" 
24   
25  # Python module imports. 
26  from os import chdir, getcwd 
27   
28  # relax module imports. 
29  import lib.arg_check 
30  from status import Status; status = Status() 
31   
32   
33 -def cd(path, verbose=False):
34 """The equivalent of python module os.chdir(path). Change the current working directory to the specified path. 35 36 @keyword verbose: A flag which if True will cause the previous directory to be printed. 37 @type verbose: bool 38 @param path: The path to the directory for the current working directory. 39 @type path: str 40 """ 41 42 # Check that the path is a string. 43 lib.arg_check.is_str(path, name="path", can_be_none=False, raise_error=True) 44 45 # Replace any remains of " and ' 46 path = path.replace('"', '').replace("'", "") 47 48 # Print previous current working directory. 49 if verbose: 50 print("The current working directory was: %s"%getcwd()) 51 52 # Change the current working directory. 53 chdir(path) 54 55 # Print current working directory. 56 print("The current working directory is now changed to: %s"%getcwd()) 57 58 # Notify observers that the current working directory has changed. 59 status.observers.system_cwd_path.notify()
60 61
62 -def pwd(verbose=True):
63 """Print and return string of the current working directory. Equivalent of python module os.getcwd(). 64 65 @keyword verbose: A flag which if True will cause the current directory to be printed. 66 @type verbose: bool 67 @return: Path to the current working directory. 68 @rtype: str 69 """ 70 71 # Get the current working directory. 72 cwd = getcwd() 73 74 # Print previous current working directory. 75 if verbose: 76 print("The current working directory is: %s"%cwd) 77 78 return cwd
79