11def read_info_file (info_file_path ):
22 tag_mapping = {
3- ' Name:' : ' name' ,
4- ' Abbreviation:' : ' abb' ,
5- ' Tags:' : ' tags' ,
6- ' Series Number:' : ' series' ,
7- ' Publication Date:' : ' publication_date' ,
8- ' Description:' : ' description' ,
9- ' Required Citations:' : ' citations' ,
10- ' Selected Studies:' : ' studies'
3+ " Name:" : " name" ,
4+ " Abbreviation:" : " abb" ,
5+ " Tags:" : " tags" ,
6+ " Series Number:" : " series" ,
7+ " Publication Date:" : " publication_date" ,
8+ " Description:" : " description" ,
9+ " Required Citations:" : " citations" ,
10+ " Selected Studies:" : " studies" ,
1111 }
1212
13- infos = {' files' : {}}
13+ infos = {" files" : {}}
1414
15- with open (info_file_path , 'r' , encoding = "utf-8" ) as file :
15+ with open (info_file_path , "r" , encoding = "utf-8" ) as file :
1616 line_cnt = 0
1717 lines = file .readlines ()
1818 for line in lines :
@@ -22,22 +22,24 @@ def read_info_file(info_file_path):
2222
2323 for tag , key in tag_mapping .items ():
2424 if line .startswith (tag ):
25- value = line [len (tag ):].strip ()
26- if key == ' tags' :
27- infos [key ] = [tag .strip () for tag in value .split (',' )]
25+ value = line [len (tag ) :].strip ()
26+ if key == " tags" :
27+ infos [key ] = [tag .strip () for tag in value .split ("," )]
2828 else :
2929 infos [key ] = value
3030 break
3131
32- if line .startswith ('file_name, modification_type, relates_to, title, description, publication_date' ):
32+ if line .startswith (
33+ "file_name, modification_type, relates_to, title, description, publication_date"
34+ ):
3335 break
3436
3537 for line in lines [line_cnt :]:
3638 line = line .strip ()
3739 if line :
38- split_line = [part .strip () for part in line .split (',' )]
40+ split_line = [part .strip () for part in line .split ("," )]
3941 new_split_line = []
40- tmp_split = ''
42+ tmp_split = ""
4143 inside_quotes = False
4244
4345 for split in split_line :
@@ -47,7 +49,7 @@ def read_info_file(info_file_path):
4749 new_split_line .append (tmp_split [:- 3 ])
4850 inside_quotes = False
4951 else :
50- tmp_split += ', '
52+ tmp_split += ", "
5153 else :
5254 if split .startswith ('"""' ) and len (split ) > 3 :
5355 if split .endswith ('"""' ):
@@ -58,16 +60,18 @@ def read_info_file(info_file_path):
5860 else :
5961 new_split_line .append (split )
6062 new_file_info = {
61- ' file_name' : new_split_line [0 ],
62- ' modification_type' : new_split_line [1 ],
63- ' relates_to' : new_split_line [2 ],
64- ' title' : new_split_line [3 ],
65- ' description' : new_split_line [4 ],
66- ' publication_date' : new_split_line [5 ]
63+ " file_name" : new_split_line [0 ],
64+ " modification_type" : new_split_line [1 ],
65+ " relates_to" : new_split_line [2 ],
66+ " title" : new_split_line [3 ],
67+ " description" : new_split_line [4 ],
68+ " publication_date" : new_split_line [5 ],
6769 }
6870
6971 file_name = new_split_line [0 ].strip ()
70- infos ['files' ][file_name ] = {key : value .strip () for key , value in new_file_info .items ()}
72+ infos ["files" ][file_name ] = {
73+ key : value .strip () for key , value in new_file_info .items ()
74+ }
7175
7276 return infos
7377
@@ -76,10 +80,10 @@ def file_description_line(file_dict, headers):
7680 values = []
7781 for h in headers :
7882 value = str (file_dict [h ])
79- if ',' in value :
83+ if "," in value :
8084 value = f'"""{ value } """'
8185 values .append (value )
82- return ', ' .join (values )
86+ return ", " .join (values )
8387
8488
8589def write_info_file (file_path , info_dict ):
@@ -94,8 +98,14 @@ def write_info_file(file_path, info_dict):
9498 f .write (f"Selected Studies: { info_dict ['studies' ]} \n \n " )
9599
96100 if info_dict ["files" ]:
97- headers = ["file_name" , "modification_type" , "relates_to" , "title" , "description" , "publication_date" ]
98- f .write (', ' .join (headers ) + "\n " )
101+ headers = [
102+ "file_name" ,
103+ "modification_type" ,
104+ "relates_to" ,
105+ "title" ,
106+ "description" ,
107+ "publication_date" ,
108+ ]
109+ f .write (", " .join (headers ) + "\n " )
99110 for file_descr in sorted (info_dict ["files" ], key = lambda x : x ["file_name" ]):
100111 f .write (file_description_line (file_descr , headers ) + "\n " )
101-
0 commit comments