def init_app(self, obj, refresh=False, test=False, data_dir=None): """Sets up client with config values from obj ######Args: obj (instance): config object ######Kwargs: refresh (bool): True - Refresh update manifest on object initialization. False - Don't refresh update manifest on object initialization """ # A super dict used to save config info & be dot accessed config = _Config() config.from_object(obj) # Boolean: If executing frozen self.FROZEN = FROZEN # Grabbing config information update_urls = config.get('UPDATE_URLS', []) # List of URL to check for update data self.update_urls = Client._sanitize_update_url(update_urls) # Name of the running application self.app_name = config.get('APP_NAME', 'PyUpdater') # Name of the app author self.company_name = config.get('COMPANY_NAME', 'Digital Sapphire') # Used in testing to force use of the mac archive if test: # Making platform deterministic for tests. self.data_dir = obj.DATA_DIR self.platform = 'mac' else: # pragma: no cover if data_dir is None: # Getting platform specific user data directory self.data_dir = appdirs.user_data_dir(self.app_name, self.company_name) else: self.data_dir = data_dir # Used when parsing the update manifest self.platform = _get_system() # Folder to house update archives self.update_folder = os.path.join(self.data_dir, settings.UPDATE_FOLDER) # The root public key to verify the app signing private key self.root_key = config.get('PUBLIC_KEY', '') # We'll get the app_key later in _get_signing_key # That's if we verify the keys manifest self.app_key = None # Used to disable TLS cert verification self.verify = config.get('VERIFY_SERVER_CERT', True) # Max number of download retries self.max_download_retries = config.get('MAX_DOWNLOAD_RETRIES') # The name of the version file to download self.version_file = settings.VERSION_FILE_FILENAME # The name of the key file to download self.key_file = settings.KEY_FILE_FILENAME # urllib3 headers self.urllib3_headers = obj.URLLIB3_HEADERS # Creating data & update directories self._setup() if refresh is True: self.refresh()
def __init__(self, obj, **kwargs): if obj is None: obj = DefaultClientConfig() refresh = kwargs.get("refresh", False) progress_hooks = kwargs.get("progress_hooks") test = kwargs.get("test", False) data_dir = kwargs.get("data_dir") headers = kwargs.get("headers") # 3rd Party downloader self.downloader = kwargs.get("downloader") if headers is not None: if not isinstance(headers, dict): raise ClientError("headers argument must be a dict", expected=True) # String: Name of binary to update self.name = None # String: Version of the binary to update self.version = None # String: Update manifest as json string - set in _get_update_manifest self.json_data = None # Boolean: Version file verification self.verified = False # Boolean: Json being loaded to dict self.ready = False # LIst: Progress hooks to be called self.progress_hooks = [] if progress_hooks is not None: if not isinstance(progress_hooks, list): raise SyntaxError("progress_hooks must be provided as a list.") self.progress_hooks += progress_hooks obj.URLLIB3_HEADERS = headers # A super dict used to save config info & be dot accessed config = _Config() config.from_object(obj) # Boolean: If executing frozen self.FROZEN = FROZEN # Grabbing config information update_urls = config.get("UPDATE_URLS", []) # List of URL to check for update data self.update_urls = Client._sanitize_update_url(update_urls) # Name of the running application self.app_name = config.get("APP_NAME", "PyUpdater") # Name of the app author self.company_name = config.get("COMPANY_NAME", "Digital Sapphire") # Used in testing to force use of the mac archive if test: # Making platform deterministic for tests. self.data_dir = obj.DATA_DIR self.platform = "mac" else: # pragma: no cover if data_dir is None: # Getting platform specific user data directory self.data_dir = appdirs.user_data_dir(self.app_name, self.company_name) else: self.data_dir = data_dir # Used when parsing the update manifest self.platform = _get_system() if six.PY2: self.data_dir = self.data_dir.decode("utf-8") # Folder to house update archives self.update_folder = os.path.join(self.data_dir, settings.UPDATE_FOLDER) # The root public key to verify the app signing private key self.root_key = config.get("PUBLIC_KEY", "") # We'll get the app_key later in _get_signing_key # That's if we verify the keys manifest self.app_key = None # Used to disable TLS cert verification self.verify = config.get("VERIFY_SERVER_CERT", True) # Max number of download retries self.max_download_retries = config.get("MAX_DOWNLOAD_RETRIES", 3) # HTTP Timeout self.http_timeout = config.get("HTTP_TIMEOUT", 30) # The name of the version file to download self.version_file = settings.VERSION_FILE_FILENAME # The name of the original version of the version file. # Basically the version.gz vs vesion-<platform>.gz self.version_file_compat = settings.VERSION_FILE_FILENAME_COMPAT # The name of the key file to download self.key_file = settings.KEY_FILE_FILENAME # urllib3 headers self.urllib3_headers = obj.URLLIB3_HEADERS # Creating data & update directories self._setup() if refresh is True: self.refresh()
def __init__(self, obj, **kwargs): if obj is None: obj = DefaultClientConfig() refresh = kwargs.get('refresh', False) progress_hooks = kwargs.get('progress_hooks') test = kwargs.get('test', False) data_dir = kwargs.get('data_dir') headers = kwargs.get('headers') if headers is not None: if not isinstance(headers, dict): raise ClientError('headers argument must be a dict', expected=True) # String: Name of binary to update self.name = None # String: Version of the binary to update self.version = None # String: Update manifest as json string - set in _get_update_manifest self.json_data = None # Boolean: Version file verification self.verified = False # Boolean: Json being loaded to dict self.ready = False # LIst: Progress hooks to be called self.progress_hooks = [] if progress_hooks is not None: if not isinstance(progress_hooks, list): raise SyntaxError('progress_hooks must be provided as a list.') self.progress_hooks += progress_hooks obj.URLLIB3_HEADERS = headers # A super dict used to save config info & be dot accessed config = _Config() config.from_object(obj) # Boolean: If executing frozen self.FROZEN = FROZEN # Grabbing config information update_urls = config.get('UPDATE_URLS', []) # List of URL to check for update data self.update_urls = Client._sanitize_update_url(update_urls) # Name of the running application self.app_name = config.get('APP_NAME', 'PyUpdater') # Name of the app author self.company_name = config.get('COMPANY_NAME', 'Digital Sapphire') # Used in testing to force use of the mac archive if test: # Making platform deterministic for tests. self.data_dir = obj.DATA_DIR self.platform = 'mac' else: # pragma: no cover if data_dir is None: # Getting platform specific user data directory self.data_dir = appdirs.user_data_dir(self.app_name, self.company_name) else: self.data_dir = data_dir # Used when parsing the update manifest self.platform = _get_system() # Folder to house update archives self.update_folder = os.path.join(self.data_dir, settings.UPDATE_FOLDER) # The root public key to verify the app signing private key self.root_key = config.get('PUBLIC_KEY', '') # We'll get the app_key later in _get_signing_key # That's if we verify the keys manifest self.app_key = None # Used to disable TLS cert verification self.verify = config.get('VERIFY_SERVER_CERT', True) # Max number of download retries self.max_download_retries = config.get('MAX_DOWNLOAD_RETRIES', 3) # The name of the version file to download self.version_file = settings.VERSION_FILE_FILENAME # The name of the key file to download self.key_file = settings.KEY_FILE_FILENAME # urllib3 headers self.urllib3_headers = obj.URLLIB3_HEADERS # Creating data & update directories self._setup() if refresh is True: self.refresh()