@@ -253,11 +253,45 @@ def _download_file_to(file_url, destination_folder, new_file_name=None):
253253
254254
255255def _save_data_as (data , destination_folder , file_name ):
256- out_file = codecs .open (
257- destination_folder + "/" + file_name , "w+" , encoding = "utf-8"
256+ download_file_lock = fasteners .InterProcessLock (
257+ constants .MultiBrowser .DOWNLOAD_FILE_LOCK
258+ )
259+ with download_file_lock :
260+ out_file = codecs .open (
261+ os .path .join (destination_folder , file_name ), "w+" , encoding = "utf-8"
262+ )
263+ out_file .writelines (data )
264+ out_file .close ()
265+
266+
267+ def _append_data_to_file (data , destination_folder , file_name ):
268+ download_file_lock = fasteners .InterProcessLock (
269+ constants .MultiBrowser .DOWNLOAD_FILE_LOCK
258270 )
259- out_file .writelines (data )
260- out_file .close ()
271+ with download_file_lock :
272+ existing_data = ""
273+ if os .path .exists (os .path .join (destination_folder , file_name )):
274+ with open (os .path .join (destination_folder , file_name ), "r" ) as f :
275+ existing_data = f .read ()
276+ if not existing_data .split ("\n " )[- 1 ] == "" :
277+ existing_data += "\n "
278+ out_file = codecs .open (
279+ os .path .join (destination_folder , file_name ), "w+" , encoding = "utf-8"
280+ )
281+ out_file .writelines ("%s%s" % (existing_data , data ))
282+ out_file .close ()
283+
284+
285+ def _get_file_data (folder , file_name ):
286+ download_file_lock = fasteners .InterProcessLock (
287+ constants .MultiBrowser .DOWNLOAD_FILE_LOCK
288+ )
289+ with download_file_lock :
290+ if not os .path .exists (os .path .join (folder , file_name )):
291+ raise Exception ("File not found!" )
292+ with open (os .path .join (folder , file_name ), "r" ) as f :
293+ data = f .read ()
294+ return data
261295
262296
263297def make_css_match_first_element_only (selector ):
0 commit comments