def __init__(self): self.credentials = None self.client = None self.config = find_config(self.CONFIG) if not self.config_exists: print('Could not find {} file.'.format(self.CONFIG)) print('You need Amazon section in it to interact with S3') print('(Check config.ini.example if you need a reference.)') return settings = configparser.RawConfigParser() settings.read(self.config) self.settings = partial(settings.get, 'Amazon') try: self.credentials = { 'aws_access_key_id': self.settings('AccessKey'), 'aws_secret_access_key': self.settings('SecretKey'), 'region_name': self.settings('Region') } # friendly user message warning about old config.ini version region = self.credentials.get('region_name', '') if region and region.startswith('s3-'): msg = ( 'It looks like you have an old version of the config.ini ' 'file. We do not need anymore the service (s3) appended ' 'to the region (sa-east-1). Please update your config.ini ' 'replacing regions like `s3-sa-east-1` by `sa-east-1`.' ) print(msg) except configparser.NoSectionError: msg = ( 'You need an Amazon section in {} to interact with S3 ' '(Check config.ini.example if you need a reference.)' ) print(msg.format(self.CONFIG))
def test_find_config_a_file(self): os.chdir(self.root_not_a_file) self.assertEqual(helpers.find_config(), 'config.ini')
def test_find_config(self): os.chdir(self.subfolder) self.assertEqual(helpers.find_config(), self.config_file)