Beispiel #1
0
 def __init__(self, **kwargs):
     access = kwargs.get('accesskey', None)
     secret = kwargs.get('secret', None)
     bucket = kwargs.get('bucket', '')
     configpath = kwargs.get('configpath', None)
     omd = OMD()
     omd.update({'accesskey': access, 'secret': secret, 'bucket': bucket})
     if configpath is not None and exists(configpath):
         with open(configpath, 'r') as f:
             omd.update_extend(yaml.safe_load(f))
     self.access = omd.get('accesskey', access)
     self.secret = omd.get('secret', secret)
     bucket_name = omd.get('bucket', bucket)
     cd = None
     try:
         self.s3 = boto3.client('s3',
                                aws_access_key_id=self.access,
                                aws_secret_access_key=self.secret)
         self.bucket = boto3.resource(
             's3',
             aws_access_key_id=self.access,
             aws_secret_access_key=self.secret).Bucket(bucket_name)
         cd = self.bucket.creation_date
         # make sure you actually have a bucket
     except ClientError as e:
         raise ValueError(e.response['Error']['Message'])
     if cd is None:
         raise ValueError("This bucket [" + self.bucket.name +
                          "] does not exist")
     logging.getLogger("connectionpool.py").setLevel(logging.WARNING)
     logging.getLogger("connectionpool").setLevel(logging.WARNING)
def get_details():
    '''looks for values in pdf_store.yml '''
    yaml_path = "pdf_store.yml"
    omd = OMD()
    # Fallback to defaults for local devserver
    omd.update({'s3_yaml': 's3.yml', 'tmpdir': './tmp/', 'instance': 'dev'})
    if exists(yaml_path):
        with open(yaml_path, 'r') as f:
            omd.update_extend(yaml.safe_load(f))
    return omd
Beispiel #3
0
def test_update_extend():
    for first, second in zip(_ITEMSETS, _ITEMSETS[1:] + [[]]):
        omd1 = OMD(first)
        omd2 = OMD(second)
        ref = dict(first)
        orig_keys = set(omd1)

        ref.update(second)
        omd1.update_extend(omd2)
        for k in omd2:
            assert len(omd1.getlist(k)) >= len(omd2.getlist(k))

        assert omd1.todict() == ref
        assert orig_keys <= set(omd1)
Beispiel #4
0
def test_update_extend():
    for first, second in zip(_ITEMSETS, _ITEMSETS[1:] + [[]]):
        omd1 = OMD(first)
        omd2 = OMD(second)
        ref = dict(first)
        orig_keys = set(omd1)

        ref.update(second)
        omd1.update_extend(omd2)
        for k in omd2:
            assert len(omd1.getlist(k)) >= len(omd2.getlist(k))

        assert omd1.todict() == ref
        assert orig_keys <= set(omd1)
def ConfigSources(yaml_path):
    '''Helper method returning an :py:class:`boltons.dictutils.OrderedMultiDict` representing configuration sources (defaults, yaml)'''

    omd = OMD()
    # Fallback to defaults for local devserver
    omd.update({
        'baseurl': 'http://localhost:4567',
        'username': '******',
        'password': '******'
    })

    if exists(yaml_path):
        with open(yaml_path, 'r') as f:
            omd.update_extend(yaml.safe_load(f))
            log.debug("loaded yaml config", source=yaml_path)
    return omd