def init_app(self, obj, test=False): """Sets up client with config values from obj Args: obj (instance): config object """ # ToDo: Remove once code is v1.0 # Updated how client is initialized. Can still be # used the old way but the new way is way more efficient # Just pass in the config object and the client takes care # of the rest. No need to initialize NotSoTuf object first! if hasattr(obj, 'config'): config = obj.config.copy() else: config = Config() config.from_object(obj) # Grabbing config information update_url = config.get(u'UPDATE_URL', None) update_urls = config.get(u'UPDATE_URLS', None) self.update_urls = self._sanatize_update_url(update_url, update_urls) self.app_name = config.get(u'APP_NAME', u'PyiUpdater') self.company_name = config.get(u'COMPANY_NAME', u'Digital Sapphire') if test: self.data_dir = 'cache' self.platform = 'mac' else: self.data_dir = user_cache_dir(self.app_name, self.company_name) self.platform = get_system() self.update_folder = os.path.join(self.data_dir, u'update') self.public_key = config.get(u'PUBLIC_KEY', None) self.debug = config.get(u'DEBUG', False) self.verify = config.get(u'VERIFY_SERVER_CERT', True) if self.verify is True: self.http_pool = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where()) else: self.http_pool = urllib3.PoolManager() self.version_file = u'version.json' self.current_app_dir = os.path.dirname(sys.argv[0]) self._setup() self.refresh()
def init_app(self, obj, test=False): """Sets up client with config values from obj Args: obj (instance): config object """ # ToDo: Remove once code is v1.0 # Updated how client is initialized. Can still be # used the old way but the new way is way more efficient # Just pass in the config object and the client takes care # of the rest. No need to initialize NotSoTuf object first! if hasattr(obj, 'config'): config = obj.config.copy() else: config = Config() config.from_object(obj) # Grabbing config information update_url = config.get(u'UPDATE_URL', None) update_urls = config.get(u'UPDATE_URLS', None) self.update_urls = self._sanatize_update_url(update_url, update_urls) self.app_name = config.get(u'APP_NAME', u'PyiUpdater') self.company_name = config.get(u'COMPANY_NAME', u'Digital Sapphire') if test: self.data_dir = 'cache' self.platform = 'mac' else: self.data_dir = user_cache_dir(self.app_name, self.company_name) self.platform = get_system() self.update_folder = os.path.join(self.data_dir, u'update') self.public_key = config.get(u'PUBLIC_KEY', None) self.debug = config.get(u'DEBUG', False) self.verify = config.get(u'VERIFY_SERVER_CERT', True) if self.verify is True: self.http_pool = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where()) else: self.http_pool = urllib3.PoolManager() self.version_file = u'version.json' self.current_app_dir = os.path.dirname(sys.argv[0]) self._setup() self.refresh()
class PyiUpdater(object): """There are 2 ways to load config. The first was is during object initialization. The second way is later with :meth:`update_config` Examples are shown below:: Config(object): APP_NAME = "NST" APP_DATA_DIR = None UPDATE_URL = http://www.test-nst.com/updates app = NotSoTuf(__name__, Config()) app = NotSoTuf(__name__) app.update_config(Config()) Kwargs: import_name (str): used to get current directory cfg_obj (instance): object with config attributes """ def __init__(self, cfg_obj=None): if pyi_version < (2, 1, 1): raise PyiUpdaterError("Must have at least PyInstaller v2.1.1", expected=True) self.config = Config() if cfg_obj: self.update_config(cfg_obj) def update_config(self, obj): """Proxy method to update internal config dict Args: obj (instance): config object """ self.config.from_object(obj) if self.config.get(u"APP_NAME", None) is None: self.config[u"APP_NAME"] = u"PyiUpdater App"
class PyiUpdater(object): """There are 2 ways to load config. The first was is during object initialization. The second way is later with :meth:`update_config` Examples are shown below:: Config(object): APP_NAME = "NST" APP_DATA_DIR = None UPDATE_URL = http://www.test-nst.com/updates app = NotSoTuf(__name__, Config()) app = NotSoTuf(__name__) app.update_config(Config()) Kwargs: import_name (str): used to get current directory cfg_obj (instance): object with config attributes """ def __init__(self, cfg_obj=None): if pyi_version < (2, 1, 1): raise PyiUpdaterError('Must have at least PyInstaller v2.1.1', expected=True) self.config = Config() if cfg_obj: self.update_config(cfg_obj) def update_config(self, obj): """Proxy method to update internal config dict Args: obj (instance): config object """ self.config.from_object(obj) if self.config.get(u'APP_NAME', None) is None: self.config[u'APP_NAME'] = u'PyiUpdater App'
def test_prod_bad_atter(): test_prod_config() config = Config() prod_config = ProdConfig() config.from_object(prod_config) assert config.get(u'DEBUG', None) is not None
def test_dev_config_bad_attr(): config = Config() test_config = DevConfig() config.from_object(test_config) assert config.get(u'BAD_ATTR', None) is None