def fromBinary(binaryPath): binaryConfig = "%s.fuzzmanagerconf" % binaryPath if not os.path.exists(binaryConfig): print("Warning: No binary configuration found at %s" % binaryConfig, file=sys.stderr) return None config = ConfigurationFiles([binaryConfig]) mainConfig = config.mainConfig for field in ["product", "platform", "os"]: if field not in mainConfig: raise RuntimeError( 'Missing "%s" in binary configuration file %s' % (field, binaryConfig)) # Version field is optional version = None if "product_version" in mainConfig: version = mainConfig["product_version"] return ProgramConfiguration(mainConfig["product"], mainConfig["platform"], mainConfig["os"], version=version, metadata=config.metadataConfig)
def __init__(self, serverHost=None, serverPort=None, serverProtocol=None, serverAuthToken=None, clientId=None): ''' Initialize the Reporter. This constructor will also attempt to read a configuration file to populate any missing properties that have not been passed to this constructor. @type serverHost: string @param serverHost: Server host to contact for refreshing signatures @type serverPort: int @param serverPort: Server port to use when contacting server @type serverAuthToken: string @param serverAuthToken: Token for server authentication @type clientId: string @param clientId: Client ID stored in the server when submitting issues ''' self.serverHost = serverHost self.serverPort = serverPort self.serverProtocol = serverProtocol self.serverAuthToken = serverAuthToken self.clientId = clientId # Now search for the global configuration file. If it exists, read its contents # and set all Collector settings that haven't been explicitely set by the user. globalConfigFile = os.path.join(os.path.expanduser("~"), ".fuzzmanagerconf") if os.path.exists(globalConfigFile): configInstance = ConfigurationFiles([globalConfigFile]) globalConfig = configInstance.mainConfig if self.serverHost is None and "serverhost" in globalConfig: self.serverHost = globalConfig["serverhost"] if self.serverPort is None and "serverport" in globalConfig: self.serverPort = globalConfig["serverport"] if self.serverProtocol is None and "serverproto" in globalConfig: self.serverProtocol = globalConfig["serverproto"] if self.serverAuthToken is None: if "serverauthtoken" in globalConfig: self.serverAuthToken = globalConfig["serverauthtoken"] elif "serverauthtokenfile" in globalConfig: with open(globalConfig["serverauthtokenfile"]) as f: self.serverAuthToken = f.read().rstrip() if self.clientId is None and "clientid" in globalConfig: self.clientId = globalConfig["clientid"] # Set some defaults that we can't set through default arguments, otherwise # they would overwrite configuration file settings if self.serverProtocol is None: self.serverProtocol = "https" # Try to be somewhat intelligent about the default port, depending on protocol if self.serverPort is None: if self.serverProtocol == "https": self.serverPort = 433 else: self.serverPort = 80 if self.serverHost is not None and self.clientId is None: self.clientId = platform.node()