def __init__(self, access_key=None, access_secret=None, config=None): ''' :param access_key: The app access key :param access_secret: The app access secret :param config: The FDS service's config ''' self._delimiter = "/" if access_key == None or access_secret == None: # Get keys from environment variables if "XIAOMI_ACCESS_KEY" in os.environ and "XIAOMI_SECRET_KEY" in os.environ: self._access_key = os.environ["XIAOMI_ACCESS_KEY"] self._secret_key = os.environ["XIAOMI_SECRET_KEY"] else: # Read keys from configuration file config_filename = os.path.join(os.path.expanduser('~'), ".config/xiaomi/config") if os.path.exists(config_filename): with open(config_filename) as f: data = json.load(f) self._access_key = data["access_key"] self._secret_key = data["secret_key"] else: self._access_key = access_key self._secret_key = access_secret self._auth = Signer(self._access_key, self._secret_key) if config == None: config = FDSClientConfiguration() if "FDS_ENDPOINT" in os.environ: config.set_endpoint(os.environ["FDS_ENDPOINT"]) self._config = config self._request = FDSRequest(config.timeout, config.max_retries)
def test_set_endpoint(self): httpConfig = FDSClientConfiguration(region_name, False, False, False) endpoint = region_name + ".api.xiaomi.net" httpConfig.set_endpoint(endpoint) httpUri = httpConfig.get_base_uri() self.assertEqual("http://" + endpoint + "/", httpUri) httpsConfig = FDSClientConfiguration(region_name, False, False, True) httpsConfig.set_endpoint(endpoint) httpsUri = httpsConfig.get_base_uri() self.assertEqual("https://" + endpoint + "/", httpsUri)
def test_set_endpoint(self): httpConfig = FDSClientConfiguration(region_name, False, False, False) endpoint = region_name + ".api.xiaomi.net" httpConfig.set_endpoint(endpoint) httpUri = httpConfig.get_base_uri() self.assertEqual("http://" + endpoint + "/", httpUri) httpsConfig = FDSClientConfiguration(region_name, False, False, True) httpsConfig.set_endpoint(endpoint) httpsUri = httpsConfig.get_base_uri() self.assertEqual("https://" + endpoint + "/", httpsUri)
def write_fds_file(object_content, name): bucket_name = "mlmodel" AK = "AKYX4NXAR6QJOK2RBW" SK = "MuS+R5nNehuCogsqtztD+HT0JTsmjHS88NW8J8Z+" ENDPOINT = "cnbj1-fds.api.xiaomi.net" config = FDSClientConfiguration() config.set_endpoint(ENDPOINT) client = GalaxyFDSClient(AK, SK, config) client.put_object(bucket_name, name, object_content)
def __init__(self, access_key=None, access_secret=None, config=None): ''' :param access_key: The app access key :param access_secret: The app access secret :param config: The FDS service's config ''' self._delimiter = "/" if access_key == None or access_secret == None: self._access_key = self.load_access_key() self._secret_key = self.load_secret_key() else: self._access_key = access_key self._secret_key = access_secret self._auth = Signer(self._access_key, self._secret_key) if config == None: config = FDSClientConfiguration() config.set_endpoint(self.load_endpoint()) self._config = config self._request = FDSRequest(config.timeout, config.max_retries)
def read_fds_file(paths): bucket_name = "mlmodel" AK = "" SK = "" ENDPOINT = "cnbj1-fds.api.xiaomi.net" config = FDSClientConfiguration() config.set_endpoint(ENDPOINT) client = GalaxyFDSClient(AK, SK, config) X = [] y = [] parts = [] for path in paths: print("read path:", path) try: obj = client.get_object(bucket_name, path) for chunk in obj.stream: parts.append(chunk) except GalaxyFDSClientException as e: print("reading fds something is wrong") print(e.message) whole_file = "".join(parts) del parts whole_lines = whole_file.split("\n") del whole_file gc.collect() whole_lines.pop() for i in range(len(whole_lines)): eles = whole_lines[i].strip().split(",") if len(eles) == 2: X.append(int(eles[0])) y.append([int(eles[1])]) del whole_lines gc.collect() return X, y