コード例 #1
0
ファイル: result_export.py プロジェクト: aidjek/TS
def exportReport(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)
    newReportDir = os.path.join(dest, reportFolder)
    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(newReportDir, dtForm)

    if getSize(oldDir) >= getSpace(dest):
        raise Exception("Not enough space to export report '%s' at %s" % (result.resultsName, dest))

    # This is the directory for the result.  Exported reports will create subdirs in it
    if not os.path.isdir(newReportDir):
        old_umask = os.umask(0000)
        os.makedirs(newReportDir)
        os.umask(old_umask)
        logger.debug("Created dir: %s" % newReportDir)

    result.updateMetaData("Exporting", "Exporting from %s to %s." % (oldDir, newDir), 0, comment, logger=logger)

    files.test_sigproc_infinite_regression(oldDir)

    try:
        # We desire to copy all files pointed to by symlinks; do not want just symlinks in the archive location
        #TODO: Change UMASK to get 775 permissions (default gets us 755)
        shutil.copytree(oldDir, newDir, symlinks=False)
        result.updateMetaData("Exported", "Export successful.", 0, comment, logger=logger)
    except Exception as inst:
        raise Exception("shutil module failed to copy. Error type: %s" % inst)
コード例 #2
0
ファイル: result_archive.py プロジェクト: GerritvanNiekerk/TS
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

    dt = datetime.datetime.now()
    dtForm = '%d_%02d_%02d_%02d_%02d_%02d' % (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second)
    newReportDir = os.path.join(dest, reportFolder)
    newDir = os.path.join(newReportDir, dtForm)

    if getSize(oldDir) >= getSpace(dest):
        raise Exception("Not enough space to archive report '%s' at %s" % (result.resultsName, dest))

    # This is the directory for the result.  Exported reports will create subdirs in it
    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

    result.updateMetaData(ARCHIVING, "Archiving report '%s' to %s" % (result.resultsName, newDir), 0, comment, logger=logger)

    files.test_sigproc_infinite_regression(oldDir)

    # 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)
        # I think this is a superfluous entry to the log
        #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/data_management.log.")

    for pdffile in ['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 IOError as e:
            logger.warn("I/O error(%d): %s - %s" % (e.errno, e.strerror, os.path.join(newDir, pdffile)))
        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())
コード例 #3
0
ファイル: result_archive.py プロジェクト: aidjek/TS
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

    dt = datetime.datetime.now()
    dtForm = '%d_%02d_%02d_%02d_%02d_%02d' % (dt.year, dt.month, dt.day,
                                              dt.hour, dt.minute, dt.second)
    newReportDir = os.path.join(dest, reportFolder)
    newDir = os.path.join(newReportDir, dtForm)

    if getSize(oldDir) >= getSpace(dest):
        raise Exception("Not enough space to archive report '%s' at %s" %
                        (result.resultsName, dest))

    # This is the directory for the result.  Exported reports will create subdirs in it
    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

    result.updateMetaData(ARCHIVING,
                          "Archiving report '%s' to %s" %
                          (result.resultsName, newDir),
                          0,
                          comment,
                          logger=logger)

    files.test_sigproc_infinite_regression(oldDir)

    # 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)
        # I think this is a superfluous entry to the log
        #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/data_management.log."
        )

    for pdffile in ['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 IOError as e:
            logger.warn("I/O error(%d): %s - %s" %
                        (e.errno, e.strerror, os.path.join(newDir, pdffile)))
        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())