コード例 #1
0
ファイル: dropBox.py プロジェクト: RREYESAL/RPC_HVScan
def uploadFile(fileHash, fileContent, username, backend, fileName):
    '''Uploads a file to the dropbox for online.
    '''

    logging.debug('dropBox::uploadFile(%s, %s [len], %s, %s, %s)', fileHash, len(fileContent), username, backend, fileName)

    logging.info('uploadFile(): Checking whether the hash is valid...')
    checkHash(fileHash)

    logging.info('uploadFile(): %s: Checking the file content hash...', fileHash)
    fileContentHash = getHash(fileContent)
    if fileHash != fileContentHash:
        raise DropBoxError('The given file hash %s does not match with the file content hash %s.' % (fileHash, fileContentHash))

    logging.info('uploadFile(): %s: Checking whether the file already exists...', fileHash)
    state = dataAccess.getFileState(fileHash)

    if state == 'Uploaded':
        raise DropBoxError('The uploaded file with hash %s already exists in the Uploaded files (i.e. not yet processed). This probably means that you sent the same request twice in a short time.' % fileHash)

    if state == 'Pending':
        raise DropBoxError('The uploaded file with hash %s already exists in the Pending files (i.e. files that are waiting to be pulled by online that were already checked). This probably means that you sent the same request twice in a short time.' % fileHash)

    if state == 'Acknowledged':
        raise DropBoxError('The uploaded file with hash %s already exists in the Acknowledged files (i.e. files that were already pulled by online not too long ago -- we do not keep all of them forever). This probably means that you sent the same request twice after some time.' % fileHash)

    if state == 'Bad':
        raise DropBoxError('The uploaded file with hash %s already exists in the Bad files (i.e. files that were wrong for some reason). Therefore this file will be skipped since the results of the checks should be the same again (i.e. wrong).' % fileHash)

    logging.info('uploadFile(): %s: Saving the uploaded file in the database...', fileHash)
    dataAccess.insertFile(fileHash, 'Uploaded', backend, username, fileName, fileContent)

    logging.info('uploadFile(): %s: Checking the contents of the file...', fileHash)
    try:
        metadata = check.checkFile(fileHash, fileContent, backend)
    except DropBoxError as e:
        failUpload(fileHash)
        raise e
    except Exception as e:
        # Other kind of exception: this is a bug :(
        alarm.alarm('Non-DropBoxError exception raised in check.py: %s' % e)
        failUpload(fileHash)
        raise DropBoxError('Oops, something went wrong while checking your file. This is most likely a bug in the DropBox. %s' % config.notifiedErrorMessage)

    # Divide the metadata in the userText and the real metadata
    userText = metadata['userText']
    metadata['userText'] = ''

    logging.info('uploadFile(): %s: Inserting entry in the fileLog...', fileHash)
    try:
        dataAccess.insertFileLog(fileHash, Constants.WAITING_FOR_START, dumpJson(metadata), dumpJson(userText))
    except cx_Oracle.IntegrityError:
        failUpload(fileHash)
        raise DropBoxError('The uploaded file %s was already requested in the database.' % fileHash)

    logging.info('uploadFile(): %s: Updating state of the file to Pending...', fileHash)
    dataAccess.updateFileState(fileHash, 'Pending')

    logging.info('uploadFile(): %s: The upload was successful.', fileHash)
コード例 #2
0
ファイル: dropBox.py プロジェクト: RREYESAL/RPC_HVScan
def failUpload(fileHash):
    '''Fails an upload moving it to the bad folder.
    '''

    logging.info('uploadFile(): %s: Updating state of the file to Bad...', fileHash)
    dataAccess.updateFileState(fileHash, 'Bad')

    logging.info('uploadFile(): %s: The upload failed.', fileHash)
コード例 #3
0
ファイル: dropBox.py プロジェクト: RREYESAL/RPC_HVScan
def acknowledgeFile(fileHash):
    '''Acknowledges that a file was received in online.

    Called from online.
    '''

    logging.debug('dropBox::acknowledgeFile(%s)', fileHash)

    logging.info('acknowledgeFile(): Checking whether the hash is valid...')
    checkHash(fileHash)

    logging.info('acknowledgeFile(): %s: Checking whether the pending file exists...', fileHash)
    checkPendingFile(fileHash)

    logging.info('acknowledgeFile(): %s: Updating state of the file to Acknowledged...', fileHash)
    dataAccess.updateFileState(fileHash, 'Acknowledged')