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 test_update_basic(): omd = OMD(_ITEMSETS[1]) omd2 = OMD({'a': 10}) omd.update(omd2) assert omd['a'] == 10 assert omd.getlist('a') == [10] omd2_c = omd2.copy() omd2_c.pop('a') assert omd2 != omd2_c
def test_update_basic(): omd = OMD(_ITEMSETS[1]) omd2 = OMD({"a": 10}) omd.update(omd2) assert omd["a"] == 10 assert omd.getlist("a") == [10] omd2_c = omd2.copy() omd2_c.pop("a") assert omd2 != omd2_c
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
def test_update(): for first, second in zip(_ITEMSETS, _ITEMSETS[1:]): omd1 = OMD(first) omd2 = OMD(second) ref1 = dict(first) ref2 = dict(second) omd1.update(omd2) ref1.update(ref2) assert omd1.todict() == ref1 omd1_repr = repr(omd1) omd1.update(omd1) assert omd1_repr == repr(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