Os Command shorcuts¶
Collection of function related to os and sys operations.
-
os_command_py.os_command.
check_directory_exist
(directory)¶ Check is a directory exist.
Parameters: directory (str) – directory path Returns: if the file exist Return type: bool Example: >>> test_exist = check_directory_exist(TEST_PATH) >>> print("Directory {} exist: {}".format(TEST_PATH, test_exist)) #doctest: +ELLIPSIS Directory ...input exist: True >>> test_exist = check_directory_exist(os.path.join(TEST_PATH,'no_way')) >>> print("Directory {} exist: {}".format( ... TEST_PATH+'/no_way', test_exist)) #doctest: +ELLIPSIS Directory ...no_way exist: False
-
os_command_py.os_command.
check_file_and_create_path
(file)¶ Check if file exist and create path if not available
Parameters: file (str) – file path Returns: File existance Return type: bool
-
os_command_py.os_command.
check_file_exist
(file)¶ Check is a file exist.
Parameters: file (str) – file path Returns: if the file exist Return type: bool Example: >>> test_exist = check_file_exist(os.path.join(TEST_PATH, "1y0m.pdb")) >>> print("1y0m.pdb exist: {}".format(test_exist)) 1y0m.pdb exist: True
-
os_command_py.os_command.
create_and_go_dir
(dir_name)¶ Create the path to a directory and change path in it.
Parameters: dir_name – directorie name Example: >>> TEST_OUT = str(getfixture('tmpdir')) >>> start_dir = os.getcwd() >>> create_and_go_dir(os.path.join(TEST_OUT, "tmp")) >>> print("Path: {}".format(os.getcwd())) #doctest: +ELLIPSIS Path: ...tmp >>> os.chdir(start_dir)
-
os_command_py.os_command.
create_dir
(dir_name)¶ Create the path to a directory.
Parameters: dir_name – directorie name
-
os_command_py.os_command.
delete_directory
(directory)¶ Delete a file.
Parameters: directory (str) – directory path Returns: operation sucess Return type: bool
-
os_command_py.os_command.
delete_file
(file)¶ Delete a file.
Parameters: file (str) – file path Returns: operation sucess Return type: bool
-
os_command_py.os_command.
full_path_and_check
(file)¶ Return the full path of a file
Parameters: file (str) – file path Returns: File path Return type: str
-
os_command_py.os_command.
get_directory
(file)¶ Return the path of a file directory
Parameters: file (str) – file path Returns: File path Return type: str
-
os_command_py.os_command.
get_gmx_version
()¶ Get gromacs version of mdrun.
Example: print('Version is {}'.format(get_gmx_version())) Version is 2016.4
-
os_command_py.os_command.
is_exe
(fpath)¶ Check is a file path exist and if user has access to it
Parameters: fpath (str) – file path Returns: if the file is an executable Return type: bool Example: >>> ls_path = which('ls') >>> print(is_exe(ls_path)) True
-
os_command_py.os_command.
which
(*program_list)¶ find and return the first path of a program if find. Look for all combination within the $PATH env variable
Parameters: program_list (list of str) – list of program name Returns: path of the program Return type: str Example: >>> ls_path = which('dontexist', 'ls') >>> print(ls_path.find('ls') != -1) #doctest: +ELLIPSIS True
..note:
Consider using shutil.which(program) for windows.