def main(): gclient.create_dir_if_not_exist("/galaxy/aa-d/test_from_python") print(gclient.list_dirs_in_dir("/galaxy/aa-d/")) print(gclient.list_dirs_in_dir("/home/pslx/Downloads")) print(gclient.get_attr("/home/pslx/Downloads")) print(gclient.get_attr("/galaxy/aa-d/test_from_python")) gclient.create_file_if_not_exist("/galaxy/aa-d/test_from_python/test.txt") gclient_ext.cp_file("/galaxy/aa-d/test_from_python/test.txt", "/galaxy/aa-d/test_from_python/test1.txt") gclient_ext.mv_file("/galaxy/aa-d/test_from_python/test.txt", "/galaxy/aa-d/test_from_python/test3.txt") print(gclient.list_dirs_in_dir_recursive("/galaxy/aa-d/test_from_python")) print(gclient.list_files_in_dir_recursive("/galaxy/aa-d/test_from_python")) t = time.time() gclient.read("/galaxy/aa-d/large_test.txt") print(time.time() - t) data = gclient.read_multiple( ["/galaxy/aa-d/test_from_python/test1.txt", "/galaxy/aa-d/test3.txt"]) for key, val in data.items(): print(key, val) data = gclient_ext.read_txts( ["/galaxy/aa-d/test_from_python/test1.txt", "/galaxy/aa-d/test3.txt"]) for key, val in data.items(): print(key, val) print(gclient.list_cells()) print(gclient.read('/galaxy/aa-d/test.pb')) print(gclient_ext.read_txt('/galaxy/aa-d/test.pb')) message = TestMessage() message.name = "test" gclient_ext.write_proto_message('/galaxy/aa-d/test1.pb', message) print(gclient_ext.read_proto_message('/galaxy/aa-d/test1.pb', TestMessage)) print(gclient.check_health("aa")) gclient.write_multiple(path_data_map={ '/galaxy/aa-d/test_from_python/test2.txt': '123', '/galaxy/aa-d/test_from_python/test4.txt': '234', }, mode='a') gclient_ext.write_proto_messages( path_data_map={ '/galaxy/aa-d/test_from_python/test2.pb': message, '/galaxy/aa-d/test_from_python/test4.pb': message, }) print( gclient_ext.read_proto_messages(paths=[ '/galaxy/aa-d/test_from_python/test2.pb', '/galaxy/aa-d/test_from_python/test4.pb' ], message_type=TestMessage)) print(gclient.create_file_if_not_exist("/LOCAL/test/test.txt")) print(gclient.create_file_if_not_exist("/galaxy/aa-d/test/test.txt"))
def write(self, data, params=None): if not isinstance(data, str): if not params: params = {'delimiter': ','} else: assert isinstance(params, dict) and 'delimiter' in params if params: for param in params: if not isinstance(data, str) and param == 'delimiter': continue self._logger.warning( param + " will be omitted since it is not useful as an input argument in this function." ) self._SYS_LOGGER.warning( param + " will be omitted since it is not useful as an input argument in this function." ) if not isinstance(data, str): self._SYS_LOGGER.info( "Data is not str instance, joining them with preset delimiter." ) data_to_write = params['delimiter'].join( [str(val) for val in data]) else: data_to_write = data try: self.increment_rpc_count_by(n=1) if self._config['write_rule_type'] == WriteRuleType.WRITE_FROM_END: gclient.write(path=self._file_name, data=data_to_write + '\n', mode='a') else: existing_data = gclient_ext.read_txt(path=self._file_name) if existing_data is None: existing_data = '' gclient.write(path=self._file_name, data=data_to_write + '\n' + existing_data, mode='w') except Exception as err: self._SYS_LOGGER.info("Write to file [" + self._file_name + "] got exception: " + str(err) + '.') self._logger.error("Write to file [" + self._file_name + "] got exception: " + str(err) + '.') raise StorageWriteException("Write to file [" + self._file_name + "] got exception: " + str(err) + '.')
def _query_file_to_str(query_file): query_str = gclient_ext.read_txt(path=query_file) return query_str
def read_lined_txt_from_file(cls, file_name): data = gclient_ext.read_txt(file_name) return [item.strip() for item in data.rstrip().split('\n')]
def read_json_from_file(cls, file_name): data = gclient_ext.read_txt(path=file_name) if data: return json.loads(data) else: return {}