22
33
44import os
5+ import shutil
56import sys
67import traceback
78
89
10+
911from RMS .Formats .FFfile import validFFName
1012from RMS .Logger import getLogger
1113from RMS .Misc import archiveDir , tarWithProgress
1214from RMS .Routines import MaskImage
1315from Utils .GenerateThumbnails import generateThumbnails
1416from Utils .StackFFs import stackFFs
17+ from Utils .LogArchiver import makeLogArchives
1518
1619
1720# Get the logger from the main module
@@ -147,7 +150,13 @@ def archiveFieldsums(dir_path):
147150
148151
149152def archiveDetections (captured_path , archived_path , ff_detected , config , extra_files = None ):
150- """ Create thumbnails and compress all files with detections and the accompanying files in one archive.
153+ """ Create thumbnails and compress all files with detections and the accompanying files
154+ in one archive, suffix _detected
155+
156+ or
157+
158+ only the fr*.bin, ff*.fits and extra_files in one archive, suffix _imgdata,
159+ and everything apart from fr*.bin and ff*.fits in another archive, suffix _metadata
151160
152161 Arguments:
153162 captured_path: [str] Path where the captured files are located.
@@ -156,18 +165,19 @@ def archiveDetections(captured_path, archived_path, ff_detected, config, extra_f
156165 config: [conf object] Configuration.
157166
158167 Keyword arguments:
159- extra_files: [list] A list of extra files (with fill paths) which will be be saved to the night
168+ extra_files: [list] A list of extra files (with full paths) which will be saved to the night
160169 archive.
161170
162171 Return:
163172 archive_name: [str] Name of the archive where the files were compressed to.
173+ imgdata_archive_name: [str] Name of the archive where the images were compressed to.
174+ metadata_archive_name: [str] Name of the archive where the metadata was compressed to.
164175
165176 """
166177
167178 # Get the list of files to archive
168179 file_list = selectFiles (config , captured_path , ff_detected )
169180
170-
171181 log .info ('Generating thumbnails...' )
172182
173183 try :
@@ -249,21 +259,70 @@ def archiveDetections(captured_path, archived_path, ff_detected, config, extra_f
249259 log .error ('Generating stack failed with error:' + repr (e ))
250260 log .error ("" .join (traceback .format_exception (* sys .exc_info ())))
251261
262+ log .info ("Generating an archive file of most recent logs..." )
263+
264+ try :
265+
266+
267+ log_archive_path = makeLogArchives (config , captured_path )
268+ log .info (f"Log archive saved to: { log_archive_path } " )
269+ file_list .append (os .path .basename (log_archive_path ))
270+
271+ except Exception as e :
272+ log .error ('Generating log archives failed with error:' + repr (e ))
273+ log .error ("" .join (traceback .format_exception (* sys .exc_info ())))
274+
252275
253276
254277 if file_list :
255278
256279 # Create the archive ZIP in the parent directory of the archive directory
257- archive_name = os .path .join (os .path .abspath (os .path .join (archived_path , os .pardir )),
258- os .path .basename (captured_path ) + '_detected' )
280+ archive_base = os .path .join (os .path .abspath (os .path .join (archived_path , os .pardir )),
281+ os .path .basename (captured_path ))
259282
260- # Archive the files
261- archive_name = archiveDir (captured_path , file_list , archived_path , archive_name , \
262- extra_files = extra_files )
283+ # Create the imgdata set which is the union of the sets of FF files and FR files
284+ imgdata_set = (set ([item for item in file_list if item .startswith ("FF" ) and item .endswith (".fits" )]) |
285+ set ([item for item in file_list if item .startswith ("FR" ) and item .endswith (".bin" )]))
286+
287+ # Create the metadata set which is all the files from _detected excluding the files in imgdata_set,
288+ # (*.fits and *.bin)
289+
290+ metadata_set = set ([item for item in file_list if item not in imgdata_set ])
291+
292+ # Create all the required archive names and paths
293+ archive_name = f"{ archive_base } _detected"
294+ metadata_archived_path = f"{ archived_path } _metadata"
295+ metadata_archive_name = f"{ archive_base } _metadata"
296+ imgdata_archived_path = f"{ archived_path } _imgdata"
297+ imgdata_archive_name = f"{ archive_base } _imgdata"
298+
299+ # In all cases, generate the _detected directory and archive as a record for the station
300+
301+ # Make the archive directory and compress into _detected.tar.bz2 if config.upload_split is False.
302+
303+ create_detected_tar_bz2 = not config .upload_split
304+ archive_name = archiveDir (captured_path , file_list , archived_path , archive_name , extra_files = extra_files ,
305+ create_archive = create_detected_tar_bz2 )
306+
307+ if config .upload_split :
308+ # Create a directory to hold the metadata files, archive, then remove the directory
309+ metadata_archive_name = archiveDir (captured_path , metadata_set , metadata_archived_path ,
310+ metadata_archive_name , extra_files = extra_files , delete_dest_dir = True )
311+
312+ # Create a directory to hold the imgdata files, archive, then remove the directory
313+ imgdata_archive_name = archiveDir (captured_path , imgdata_set , imgdata_archived_path ,
314+ imgdata_archive_name , extra_files = extra_files , delete_dest_dir = True )
315+
316+ # Set to archive_name to None to prevent upload from this execution path
317+ archive_name = None
318+
319+ else :
320+ # Set to None, as these archives will not be generated in this path
321+ imgdata_archive_name , metadata_archive_name = None , None
263322
264- return archive_name
323+ return archive_name , imgdata_archive_name , metadata_archive_name
265324
266- return None
325+ return None , None , None
267326
268327
269328def archiveFrameTimelapse (frames_root ,
@@ -355,7 +414,7 @@ def archiveFrameTimelapse(frames_root,
355414
356415 ff_detected = ['FF_CA0001_20170905_094707_004_0000000.fits' , 'FF_CA0001_20170905_094716_491_0000256.fits' ]
357416
358- archive_name = archiveDetections (captured_path , archived_path , ff_detected , config )
417+ archive_name , metadata_name , imgdata_name = archiveDetections (captured_path , archived_path , ff_detected , config )
359418
360- print (archive_name )
419+ print (archive_name , metadata_name , imgdata_name )
361420
0 commit comments