コード例 #1
0
def create_presigned_url_expanded(objName):
    """Generate a presigned URL to invoke an S3.Client method

    Not all the client methods provided in the AWS Python SDK are supported.

    :param client_method_name: Name of the S3.Client method, e.g., 'list_buckets'
    :param method_parameters: Dictionary of parameters to send to the method
    :param expiration: Time in seconds for the presigned URL to remain valid
    :param http_method: HTTP method to use (GET, etc.)
    :return: Presigned URL as string. If error, returns None.
    """

    # Generate a presigned URL for the S3 client method
    s3_client = boto3.client('s3')
    try:
        response = s3_client.generate_presigned_url('get_object',
                                                    Params={
                                                        'Bucket':
                                                        'ece516-bucket',
                                                        'Key': objName,
                                                    },
                                                    ExpiresIn=30)
    except ClientError as e:
        logging.error(e)
        return None

    # The response contains the presigned URL
    return response
コード例 #2
0
def api_camera_enabled(camera_id: int):

    if request.method == 'GET':
    
        camera, err = bvc_db.get_camera(camera_id)

        if camera is None:
            logging.error(err)
            return error_response(404, err)

        return flask.jsonify({'enabled' : camera.get('enabled', True) })

    if request.method == 'PUT':

        enabled = request.get_json()['enabled']

        if not isinstance(enabled,bool):
            return error_response(400, "invalid argument")

        res, err = bvc_db.set_camera_enabled(camera_id, enabled)

        if res is None:
            logging.error(err)
            return error_response(404, err)

        logging.info("camera [%d] enabled = %s", camera_id, enabled)

        app.dispatcher.on_cameras_update()

        return flask.jsonify(res)
コード例 #3
0
    def launch_all_krakens(cls):
        for (kraken_name, conf) in cls.data_sets.items():
            additional_args = conf.get('kraken_args', [])
            exe = os.path.join(krakens_dir, kraken_name)
            logging.debug("spawning " + exe)

            assert os.path.exists(exe), "cannot find the kraken {}".format(exe)

            args = [exe] + additional_args

            kraken = subprocess.Popen(args,
                                      stderr=None,
                                      stdout=None,
                                      close_fds=False)

            cls.krakens_pool[kraken_name] = kraken

        logging.debug("{} kraken spawned".format(len(cls.krakens_pool)))

        # we want to wait for all data to be loaded
        all_good = True
        for name, kraken_process in cls.krakens_pool.items():
            if not check_loaded(name):
                all_good = False
                logging.error(
                    "error while loading the kraken {}, stoping".format(name))
                break

        # a bit of cleaning
        if not all_good:
            cls.kill_all_krakens()

            cls.krakens_pool.clear()
            assert False, "problem while loading the kraken, no need to continue"
コード例 #4
0
    def __get_title(self, response):
        try:

            soup = BeautifulSoup(response.text, 'html.parser')
            return soup.title.string
        except requests.exceptions.ConnectionError:
            logging.error(traceback.extract_stack())
            return None
コード例 #5
0
def api_camera_get(camera_id: int):

    camera, err = bvc_db.get_camera(camera_id)

    if camera is None:
        logging.error(err)
        return error_response(404, err)#"camera {0} not found".format(camera_id))

    return flask.jsonify({'camera': camera })
コード例 #6
0
ファイル: tests_mechanism.py プロジェクト: eturck/navitia
 def kill_all_krakens(cls):
     for name, kraken_process in cls.krakens_pool.items():
         logging.debug("killing " + name)
         if cls.data_sets[name].get('check_killed', True):
             kraken_process.poll()
             if kraken_process.returncode is not None:
                 logging.error('kraken is dead, check errors, return code = %s', kraken_process.returncode)
                 assert False, 'kraken is dead, check errors, return code'
         kraken_process.kill()
コード例 #7
0
def store_file(file_name, file):
    """Upload a file to an S3 bucket

    :param file_name: File to upload
    :param bucket: Bucket to upload to
    :param object_name: S3 object name. If not specified then file_name is used
    :return: True if file was uploaded, else False
    """
    # Upload the file
    s3_client = boto3.resource('s3')
    try:
        response = s3_client.Bucket("ece516-bucket").put_object(Key=file_name,
                                                                Body=file)
    except ClientError as e:
        logging.error(e)
        return False
    return True
コード例 #8
0
def api_camera_alert_(camera_id:str, alert_id:str):

    if request.method == 'GET':

        alert, err = bvc_db.get_camera_alert(camera_id, alert_id)

        if alert is None:
            logging.error(err)
            return error_response(404, err)

        return flask.jsonify({'alert' : alert })

    if request.method == 'PUT':

        res, err = bvc_db.update_camera_alert(camera_id, alert_id, request.get_json())

        if res is None:
            logging.error(err)
            return error_response(404, err)

        return flask.jsonify(res)

    if request.method == 'DELETE':

        res, err = bvc_db.delete_camera_alert(camera_id, alert_id)

        if res is None:
            logging.error(err)
            return error_response(404, err)

        app.dispatcher.on_cameras_update()

        return flask.jsonify(res), 204
コード例 #9
0
def api_camera_alerts(camera_id:str):

    if request.method == 'GET':
        
        alerts, err = bvc_db.get_camera_alerts(camera_id)

        if alerts is None:
            logging.error(err)
            return error_response(404, err)

        return flask.jsonify({ 'alerts' : alerts })

    if request.method == 'POST':
        
        alert_id, err = bvc_db.append_camera_alert(camera_id, request.get_json())

        if alert_id is None:
            logging.error(err)
            return error_response(404, err)

        app.dispatcher.on_cameras_update()

        return flask.jsonify({ 'alert' : { 'id' : alert_id } }), 201, {'location': '/api/cameras/{0}/alerts/{1}'.format(camera_id,alert_id)}

    if request.method == 'DELETE':
        
        res, err = bvc_db.delete_camera_alerts(camera_id)

        if res is None:
            logging.error(err)
            return error_response(404, err)

        app.dispatcher.on_cameras_update()

        return flask.jsonify(res), 204
コード例 #10
0
def storage(data):
    """七牛云存储上传文件接口"""
    if not data:
        return None
    try:
        # 构建鉴权对象
        q = Auth(access_key, secret_key)

        # 生成上传 Token,可以指定过期时间等
        token = q.upload_token(bucket_name)

        # 上传文件
        ret, info = put_data(token, None, data)

    except Exception as e:
        logging.error(e)
        raise e

    if info and info.status_code != 200:
        raise Exception("上传文件到七牛失败")

    # 返回七牛中保存的图片名,这个图片名也是访问七牛获取图片的路径
    return ret["key"]