Changeset 47be2684 in flex_extract.git for Source/Python/Mods/tools.py
- Timestamp:
- Oct 28, 2020, 10:28:24 AM (4 years ago)
- Branches:
- ctbto, dev
- Children:
- 75db9b0
- Parents:
- 697b8d0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Source/Python/Mods/tools.py
rf61e1df r47be2684 249 249 type=none_or_str, default=None, 250 250 help='The name of the ECMWF server name where the' 251 'job script is to be submitted ' 251 'job script is to be submitted ' 252 252 '(e.g. ecgate | cca | ccb)') 253 253 … … 624 624 '''Creates a directory. 625 625 626 If the directory already exists, an information is printed and the creation 626 If the directory already exists, an information is printed and the creation 627 627 skipped. The program stops only if there is another problem. 628 628 … … 856 856 ---------- 857 857 cmd_list : list of str 858 A list of the components for the command line execution. 859 They will be concatenated with blank space for the command 858 A list of the components for the command line execution. 859 They will be concatenated with blank space for the command 860 860 to be submitted, like ['mv', file1, file2] for mv file1 file2. 861 861 … … 910 910 911 911 return start_period, end_period 912 913 914 def check_for_string_in_file(filepath, search_string): 915 """ 916 Search for a specific string in a file and return True if 917 the string was found. 918 919 Parameters 920 ---------- 921 filepath : str 922 The full file path which is to be examined. 923 924 search_string : str 925 The string which is looked up for in the file. 926 927 Return 928 ------ 929 Boolean : 930 True : String was found 931 False : String was not found 932 """ 933 with open(filepath, 'r') as fio: 934 for line in fio: 935 if search_string in line: 936 return True 937 return False 938 939 940 def overwrite_lines_in_file(filepath, search_string, sub_string): 941 """ 942 Overwrites lines which contain the given search string with the 943 substitution string. 944 945 Parameters 946 ---------- 947 search_string : str 948 The string which is looked up for in the file. 949 950 sub_string : str 951 The string which overwrites the search string. 952 953 Return 954 ------ 955 """ 956 with open(filepath, 'r') as fio: 957 data = fio.readlines() 958 959 with open(filepath, 'w') as fio: 960 for line in data: 961 if search_string in line: 962 fio.write(sub_string) 963 else: 964 fio.write(line) 965 966 return 967
Note: See TracChangeset
for help on using the changeset viewer.