Ejemplo n.º 1
0
def update_package_config():
    """ Every time sentinelhub package is installed entire config.json is overwritten. However this function
    will check if sentinelhub is already installed and try to copy those parameters from old config.json that are by
    default set to an empty value (i.e. instance_id, aws_access_key_id and aws_secret_access_key) into new config.json
    file.
    """
    try:
        import importlib
        import sys
        import json

        path = importlib.machinery.PathFinder().find_spec('sentinelhub', sys.path[1:]).submodule_search_locations[0]
        old_config_filename = os.path.join(path, 'config.json')

        with open(old_config_filename, 'r') as file:
            old_config = json.load(file)

        from sentinelhub.config import SHConfig

        config = SHConfig()
        for attr, value in old_config.items():
            if hasattr(config, attr) and not getattr(config, attr):
                setattr(config, attr, value)

        config.save()

    except BaseException:
        pass
Ejemplo n.º 2
0
def try_create_config_file():
    """ After the package is installed it will try to trigger saving a config.json file
    """
    try:
        from sentinelhub.config import SHConfig
        SHConfig()
    except BaseException:
        pass
Ejemplo n.º 3
0
    def test_configuration(self):
        SHConfig().save()

        config_file = '{}/../sentinelhub/config.json'.format(os.path.dirname(os.path.realpath(__file__)))

        if not os.path.isfile(config_file):
            self.fail(msg='Config file does not exist: {}'.format(os.path.abspath(config_file)))

        with open(config_file, 'r') as fp:
            config = json.load(fp)

            ogc_base_url = config['ogc_base_url']
            aws_base_url = config['aws_base_url']
            default_start_date = config['default_start_date']
            max_download_attempts = config['max_download_attempts']
            download_sleep_time = config['download_sleep_time']

            instance_id = config['instance_id']
            if not instance_id:
                instance_id = None

        self.assertEqual(SHConfig().ogc_base_url, ogc_base_url,
                         msg="Expected {}, got {}".format(ogc_base_url, SHConfig().ogc_base_url))
        self.assertEqual(SHConfig().aws_base_url, aws_base_url,
                         msg="Expected {}, got {}".format(aws_base_url, SHConfig().aws_base_url))
        self.assertEqual(SHConfig().instance_id, instance_id,
                         msg="Expected {}, got {}".format(instance_id, SHConfig().instance_id))
        self.assertEqual(SHConfig().default_start_date, default_start_date,
                         msg="Expected {}, got {}".format(default_start_date, SHConfig().default_start_date))
        self.assertEqual(SHConfig().max_download_attempts, max_download_attempts,
                         msg="Expected {}, got {}".format(max_download_attempts,
                                                          SHConfig().max_download_attempts))
        self.assertEqual(SHConfig().download_sleep_time, download_sleep_time,
                         msg="Expected {}, got {}".format(download_sleep_time,
                                                          SHConfig().download_sleep_time))