コード例 #1
0
ファイル: scanctrl.py プロジェクト: deloittem/irma-frontend
def check_probe(scan, probelist, session):
    """ check_probe specified scan

    :param scanid: id returned by scan_new
    :rtype: dict of 'code': int, 'msg': str [, optional 'probe_list':list]
    :return:
        on success 'probe_list' is the list of probes used for the scan
        on error 'msg' gives reason message
    :raise: IrmaDataBaseError, IrmaValueError
    """
    IrmaScanStatus.filter_status(scan.status, IrmaScanStatus.ready,
                                 IrmaScanStatus.ready)
    all_probe_list = celery_brain.probe_list()

    if probelist is not None:
        unknown_probes = []
        for p in probelist:
            if p not in all_probe_list:
                unknown_probes.append(p)
        if len(unknown_probes) != 0:
            reason = "probe {0} unknown".format(", ".join(unknown_probes))
            raise IrmaValueError(reason)
    else:
        probelist = all_probe_list
    log.debug("scanid: %s probelist: %s", scan.external_id, probelist)
    scan.set_probelist(probelist)
    session.commit()
コード例 #2
0
ファイル: scanctrl.py プロジェクト: deloittem/irma-frontend
def cancel(scan, session):
    """ cancel all remaining jobs for specified scan

    :param scanid: id returned by scan_new
    :rtype: dict of 'cancel_details': total':int, 'finished':int,
        'cancelled':int
    :return:
        informations about number of cancelled jobs by irma-brain
    :raise: IrmaDatabaseError, IrmaTaskError
    """
    log.debug("scanid: %s", scan.external_id)
    if scan.status < IrmaScanStatus.uploaded:
        # If not launched answer directly
        scan.set_status(IrmaScanStatus.cancelled)
        session.commit()
        return None

    if scan.status != IrmaScanStatus.launched:
        # If too late answer directly
        status_str = IrmaScanStatus.label[scan.status]
        if IrmaScanStatus.is_error(scan.status):
            # let the cancel finish and keep the error status
            return None
        else:
            reason = "can not cancel scan in {0} status".format(status_str)
            raise IrmaValueError(reason)

    # Else ask brain for job cancel
    (retcode, res) = celery_brain.scan_cancel(scan.external_id)
    if retcode == IrmaReturnCode.success:
        s_processed = IrmaScanStatus.label[IrmaScanStatus.processed]
        if 'cancel_details' in res:
            scan.set_status(IrmaScanStatus.cancelled)
            session.commit()
            return res['cancel_details']
        elif res['status'] == s_processed:
            # if scan is finished for the brain
            # it means we are just waiting for results
            scan.set_status(IrmaScanStatus.processed)
            session.commit()
        reason = "can not cancel scan in {0} status".format(res['status'])
        raise IrmaValueError(reason)
    else:
        raise IrmaTaskError(res)
コード例 #3
0
ファイル: services.py プロジェクト: vaginessa/irma
def check_probe(probelist):
    """ check_probe specified scan

    :param probelist: list of probes asked
    :return:
        on success return list of probes
        on error 'msg' gives reason message
    :raise: IrmaValueError
    """
    all_probe_list = celery_brain.probe_list()

    if probelist is not None:
        unknown_probes = []
        for p in probelist:
            if p not in all_probe_list:
                unknown_probes.append(p)
        if len(unknown_probes) != 0:
            reason = "probe {0} unknown".format(", ".join(unknown_probes))
            raise IrmaValueError(reason)
    else:
        probelist = all_probe_list
    return probelist
コード例 #4
0
ファイル: utils.py プロジェクト: vaginessa/irma
def build_sha256_path(sha256):
    """Builds a file path from its sha256. Creates directory if needed.
    :param sha256: the sha256 to create path
    :rtype: string
    :return: the path build from the sha256
    :raise: IrmaValueError, IrmaFileSystemError
        """
    PREFIX_NB = 3
    PREFIX_LEN = 2
    base_path = config.get_samples_storage_path()
    if (PREFIX_NB * PREFIX_LEN) > len(sha256):
        raise IrmaValueError("too much prefix for file storage")
    path = base_path
    for i in range(0, PREFIX_NB):
        prefix = sha256[i * PREFIX_LEN:(i + 1) * PREFIX_LEN]
        path = os.path.join(path, prefix)
    if not os.path.exists(path):
        os.makedirs(path)
    if not os.path.isdir(path):
        reason = "storage path is not a directory"
        raise IrmaFileSystemError(reason)
    return os.path.join(path, sha256)