From 87a02442a983267932f56a311ebb8d7fe10b2bbf Mon Sep 17 00:00:00 2001 From: imliubo Date: Sat, 11 Jul 2020 15:51:20 +0800 Subject: [PATCH] cli_claim: Support python3.5. Fix "'PosixPath' object has no attribute 'startswith'" bug. --- cli/rmaker_tools/rmaker_claim/claim.py | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cli/rmaker_tools/rmaker_claim/claim.py b/cli/rmaker_tools/rmaker_claim/claim.py index 96ccae40..57a021b2 100644 --- a/cli/rmaker_tools/rmaker_claim/claim.py +++ b/cli/rmaker_tools/rmaker_claim/claim.py @@ -240,27 +240,27 @@ def save_claim_data(dest_filedir, node_id, private_key, node_cert, endpointinfo, 'node.info') # Create files for each claim data - node info, node key, # node cert, endpoint info - with open(dest_filedir+'node.info', 'w+') as info_file: + with open(str(dest_filedir+'node.info'), 'w+') as info_file: info_file.write(node_id) log.debug("Writing node info at location: " + dest_filedir + 'node.key') - with open(dest_filedir+'node.key', 'wb+') as info_file: + with open(str(dest_filedir+'node.key'), 'wb+') as info_file: info_file.write(private_key) log.debug("Writing node info at location: " + dest_filedir + 'node.crt') - with open(dest_filedir+'node.crt', 'w+') as info_file: + with open(str(dest_filedir+'node.crt'), 'w+') as info_file: info_file.write(node_cert) log.debug("Writing node info at location: " + dest_filedir + 'endpoint.info') - with open(dest_filedir+'endpoint.info', 'w+') as info_file: + with open(str(dest_filedir+'endpoint.info'), 'w+') as info_file: info_file.write(endpointinfo) log.debug("Writing node info at location: " + dest_filedir + 'node_info.csv') - with open(dest_filedir+'node_info.csv', 'w+') as info_file: + with open(str(dest_filedir+'node_info.csv'), 'w+') as info_file: for input_line in node_info_csv: info_file.write(input_line) info_file.write("\n") @@ -457,19 +457,19 @@ def verify_secret_key_exists(secret_key): return True def verify_mac_dir_exists(creds_dir, mac_addr): - mac_dir = Path(path.expanduser(str(creds_dir) + '/' + mac_addr)) + mac_dir = Path(path.expanduser(str(creds_dir) + '/' + str(mac_addr))) if mac_dir.exists(): dest_filedir = str(mac_dir) + '/' - output_bin_filename = mac_addr + '.bin' + output_bin_filename = str(mac_addr) + '.bin' return dest_filedir, output_bin_filename return False, False def create_mac_dir(creds_dir, mac_addr): # Create MAC directory - mac_dir = Path(path.expanduser(str(creds_dir) + '/' + mac_addr)) - os.makedirs(path.expanduser(mac_dir)) + mac_dir = Path(path.expanduser(str(creds_dir) + '/' + str(mac_addr))) + os.makedirs(path.expanduser(str(mac_dir))) log.debug("Creating new directory " + str(mac_dir)) - output_bin_filename = mac_addr + '.bin' + output_bin_filename = str(mac_addr) + '.bin' dest_filedir = str(mac_dir) + '/' return dest_filedir, output_bin_filename @@ -483,10 +483,10 @@ def create_config_dir(): str(Path(path.expanduser( configmanager.CONFIG_DIRECTORY))) + '/claim_data/' + - userid + str(userid) )) if not creds_dir.exists(): - os.makedirs(path.expanduser(creds_dir)) + os.makedirs(path.expanduser(str(creds_dir))) log.debug("Creating new directory " + str(creds_dir)) return userid, creds_dir @@ -503,10 +503,10 @@ def verify_claim_data_binary_exists(userid, mac_addr, dest_filedir, output_bin_f # Set config mac addr path mac_addr_config_path = str(Path(path.expanduser( configmanager.CONFIG_DIRECTORY))) + '/claim_data/' +\ - userid +\ + str(userid) +\ '/' +\ - mac_addr +\ - '/' + output_bin_filename + str(mac_addr) +\ + '/' + str(output_bin_filename) # Check if claim data for node exists in CONFIG directory log.debug("Checking if claim data for node exists in directory: " + configmanager.HOME_DIRECTORY +