def _create_archival_files(dmfilestat): logger.debug("Function: %s()" % sys._getframe().f_code.co_name) try: makePDF.makePDF(dmfilestat.result_id) csaFullPath = makeCSA.makeCSA(dmfilestat.result.get_report_dir(), dmfilestat.result.experiment.expDir) except: logger.error("Could not create Report PDF or CSA") raise
def archiveReport(pkR, dest, comment, _logger): logger = _logger result = shortcuts.get_object_or_404(models.Results, pk=pkR) oldDir = result.get_report_dir() reportFolder = os.path.basename(oldDir) rawDataDir = result.experiment.expDir # This is the directory for the result. Exported reports will create subdirs in it newReportDir = os.path.join(dest, reportFolder) if not os.path.isdir(newReportDir): old_umask = os.umask(0000) os.makedirs(newReportDir) os.umask(old_umask) logger.debug("Created dir: %s" % newReportDir) # make the Report PDF file now. backupPDF.pdf try: logger.debug("Making PDF of the report") makePDF.makePDF(pkR) logger.debug("Made PDF of the report") except: # TODO: Do we continue? OR do we abort? logger.exception(traceback.format_exc()) raise # make a customer support archive file try: logger.debug("Making CSA") csaFullPath = makeCSA.makeCSA(oldDir, rawDataDir) logger.debug("Made CSA") except: # TODO: Do we continue? OR do we abort? logger.exception(traceback.format_exc()) raise dt = datetime.datetime.now() dtForm = '%d_%02d_%02d_%02d_%02d_%02d' % (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second) newDir = os.path.join(dest, reportFolder, dtForm) if getSize(oldDir) >= getSpace(newReportDir): raise Exception("Not enough space to archive report '%s' at %s" % (result.resultsName, newReportDir)) result.updateMetaData(ARCHIVING, "Archiving report '%s' to %s" % (result.resultsName, newDir), 0, comment, logger=logger) # copy the entire directory from oldDir to the archive destination. try: # We desire to copy all files pointed to by symlinks; do not want just symlinks in the archive location shutil.copytree(oldDir, newDir, symlinks=False) result.updateMetaData(ARCHIVING, "Directory copy successful", 0, comment, logger=logger) except: logger.exception(traceback.format_exc()) raise ##check the sizes of the old directory and the destination. total_size1 = getSize(oldDir) #total_size2 = getSize(newDir) #logger.debug('size old dir: %d size new dir: %d'%(total_size1, total_size2)) ##if the sizes are identical, that means that all of the files were copied. If so, delete the old directory. #logger.debug('sizecheck complete, preparing to delete if sizes match') #if total_size1 == total_size2: try: # Remove the contents of the results directory # N.B. Execute as celery task for the sole reason of getting it executed with root permissions dir_del = removeDirContents.delay(oldDir) dir_del.get() except: logger.exception(traceback.format_exc()) raise Exception("Archive created but there was an error in cleaning up source data. See /var/log/ion/reportsLog.log.") for pdffile in ['backupPDF.pdf','report.pdf','plugins.pdf']: try: # Copy any pdf files shutil.copyfile(os.path.join(newDir, pdffile), os.path.join(oldDir, pdffile)) os.chmod(os.path.join(oldDir, pdffile), 0777) except: logger.exception(traceback.format_exc()) try: # Copy the customer support archive file from the archive location back to results directory shutil.copyfile(os.path.join(newDir, os.path.basename(csaFullPath)), csaFullPath) os.chmod(csaFullPath, 0777) result.updateMetaData(ARCHIVED, "Finished archiving.", total_size1, comment, logger=logger) except: logger.exception(traceback.format_exc())
def archiveReport(pkR, dest, comment, _logger): logger = _logger result = shortcuts.get_object_or_404(models.Results, pk=pkR) oldDir = result.get_report_dir() reportFolder = os.path.basename(oldDir) rawDataDir = result.experiment.expDir # This is the directory for the result. Exported reports will create subdirs in it newReportDir = os.path.join(dest, reportFolder) if not os.path.isdir(newReportDir): old_umask = os.umask(0000) os.makedirs(newReportDir) os.umask(old_umask) logger.debug("Created dir: %s" % newReportDir) # make the Report PDF file now. backupPDF.pdf try: logger.debug("Making PDF of the report") makePDF.makePDF(pkR) logger.debug("Made PDF of the report") except: # TODO: Do we continue? OR do we abort? logger.exception(traceback.format_exc()) raise # make a customer support archive file try: logger.debug("Making CSA") csaFullPath = makeCSA.makeCSA(oldDir, rawDataDir) logger.debug("Made CSA") except: # TODO: Do we continue? OR do we abort? logger.exception(traceback.format_exc()) raise dt = datetime.datetime.now() dtForm = '%d_%02d_%02d_%02d_%02d_%02d' % (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second) newDir = os.path.join(dest, reportFolder, dtForm) if getSize(oldDir) >= getSpace(newReportDir): raise Exception("Not enough space to archive report '%s' at %s" % (result.resultsName, newReportDir)) result.updateMetaData(ARCHIVING, "Archiving report '%s' to %s" % (result.resultsName, newDir), 0, comment, logger=logger) # copy the entire directory from oldDir to the archive destination. try: # We desire to copy all files pointed to by symlinks; do not want just symlinks in the archive location shutil.copytree(oldDir, newDir, symlinks=False) result.updateMetaData(ARCHIVING, "Directory copy successful", 0, comment, logger=logger) except: logger.exception(traceback.format_exc()) raise ##check the sizes of the old directory and the destination. total_size1 = getSize(oldDir) #total_size2 = getSize(newDir) #logger.debug('size old dir: %d size new dir: %d'%(total_size1, total_size2)) ##if the sizes are identical, that means that all of the files were copied. If so, delete the old directory. #logger.debug('sizecheck complete, preparing to delete if sizes match') #if total_size1 == total_size2: try: # Remove the contents of the results directory # N.B. Execute as celery task for the sole reason of getting it executed with root permissions dir_del = removeDirContents.delay(oldDir) dir_del.get() except: logger.exception(traceback.format_exc()) raise Exception( "Archive created but there was an error in cleaning up source data. See /var/log/ion/reportsLog.log." ) for pdffile in ['backupPDF.pdf', 'report.pdf', 'plugins.pdf']: try: # Copy any pdf files shutil.copyfile(os.path.join(newDir, pdffile), os.path.join(oldDir, pdffile)) os.chmod(os.path.join(oldDir, pdffile), 0777) except: logger.exception(traceback.format_exc()) try: # Copy the customer support archive file from the archive location back to results directory shutil.copyfile(os.path.join(newDir, os.path.basename(csaFullPath)), csaFullPath) os.chmod(csaFullPath, 0777) result.updateMetaData(ARCHIVED, "Finished archiving.", total_size1, comment, logger=logger) except: logger.exception(traceback.format_exc())