Skip to content

Commit

Permalink
fixes in script that upload packages to web server following code review
Browse files Browse the repository at this point in the history
Signed-off-by: oreiss <[email protected]>
  • Loading branch information
orenreiss committed Dec 28, 2022
1 parent 8c47a70 commit c21a38f
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions scripts/populate_file_web_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python3
#!/usr/bin/env python3

import sys
import os
Expand Down Expand Up @@ -74,7 +74,7 @@ def __str__(self):

# Helper functions

def print_msg(print_level, msg, print_in_place):
def print_msg(print_level, msg, print_in_place=False):
if PRINT_LEVEL_LUT[g_current_print_level] >= PRINT_LEVEL_LUT[print_level]:
if True == print_in_place:
print(msg, end='\r')
Expand All @@ -86,15 +86,15 @@ def create_dir_if_not_exist(dir):
try:
os.mkdir(dir)
except:
print_msg(PRINT_LEVEL_WARN, "Cannot create directory " + dir, False)
print_msg(PRINT_LEVEL_WARN, "Cannot create directory " + dir)

def delete_file_if_exist(file):

if os.path.exists(file):
try:
os.remove(file)
except:
print_msg(PRINT_LEVEL_WARN, "Cannot delete " + file, False)
print_msg(PRINT_LEVEL_WARN, "Cannot delete " + file)

# Logic functions

Expand All @@ -113,7 +113,7 @@ def generate_output_file(resources, dest_url_valid, dest_url, output_file_name):
line += resource.name + "==" + resource.hash
f.write(line + '\n')
except:
print_msg(PRINT_LEVEL_WARN, output_file_name + " cannot be created", False)
print_msg(PRINT_LEVEL_WARN, output_file_name + " cannot be created")
return RET_CODE_CANNOT_CREATE_FILE

f.close()
Expand Down Expand Up @@ -147,7 +147,7 @@ def upload_resource_to_server(resource_path, resource_name, user, key, server_ur
# Check if server reports checksum, if so compare reported sum and the one
# specified in filename
if reported_md5 != None and reported_md5 != file_md5:
print_msg(PRINT_LEVEL_WARN, f"Server reported file's chsum {reported_md5}, expected {file_md5}", False)
print_msg(PRINT_LEVEL_WARN, f"Server reported file's chsum {reported_md5}, expected {file_md5}")


return RET_CODE_SUCCESS
Expand All @@ -163,7 +163,7 @@ def download_external_resouce(resource, cache_path):
f.write(r.content)
f.close()
except:
print_msg(PRINT_LEVEL_ERROR, "Cannot write " + resource_path_in_cache + " to cache", False)
print_msg(PRINT_LEVEL_ERROR, "Cannot write " + resource_path_in_cache + " to cache")
resource_path_in_cache = "" #report error

return resource_path_in_cache
Expand All @@ -178,7 +178,7 @@ def get_resources_list(resource_files_list):
for line in f:
resource_list.append(Resource(line, file_name))
except:
print_msg(PRINT_LEVEL_WARN, file_name + " cannot be opened", False)
print_msg(PRINT_LEVEL_WARN, file_name + " cannot be opened")

return resource_list

Expand All @@ -199,7 +199,7 @@ def get_resource_files_list(serach_path):
for file in files:
if False == filter_out_dir(subdir) and RESOURCES_FILE_NAME == file:
file_full_path = os.path.join(subdir, file)
print_msg(PRINT_LEVEL_VERBOSE, "Found resource file :" + file_full_path, False)
print_msg(PRINT_LEVEL_VERBOSE, "Found resource file :" + file_full_path)
resource_files_list.append(file_full_path)

return resource_files_list
Expand Down Expand Up @@ -253,14 +253,14 @@ def main():
if not unique_name in resource_dict.keys():
resource_dict[unique_name] = resource

print_msg(PRINT_LEVEL_INFO, "Found " + str(len(resource_files_list)) + " version files and " + str(len(resource_dict.keys())) + " unique resources", False)
print_msg(PRINT_LEVEL_INFO, "Found " + str(len(resource_files_list)) + " version files and " + str(len(resource_dict.keys())) + " unique resources")

if args.dest != DEFAULT_INVALID_INPUT:
upload_files_to_server = True
print_msg(PRINT_LEVEL_INFO, "Upload files to URL - " + args.dest, False)
print_msg(PRINT_LEVEL_INFO, "Upload files to URL - " + args.dest)
else:
upload_files_to_server = False
print_msg(PRINT_LEVEL_INFO, "Skipping files upload to server", False)
print_msg(PRINT_LEVEL_INFO, "Skipping files upload to server")

#create cache directory if not exist
create_dir_if_not_exist(args.cache)
Expand All @@ -270,7 +270,7 @@ def main():

resource = resource_dict[unique_name]

print_msg(PRINT_LEVEL_VERBOSE, resource, False)
print_msg(PRINT_LEVEL_VERBOSE, resource)

resource_counter += 1.0

Expand All @@ -294,7 +294,7 @@ def main():
# generate version output file as needed
if args.output != DEFAULT_INVALID_INPUT:
ret_val = generate_output_file(resource_dict, upload_files_to_server, args.dest, args.output)
print_msg(PRINT_LEVEL_INFO, "Generate output file " + args.output, False)
print_msg(PRINT_LEVEL_INFO, "Generate output file " + args.output)

return ret_val

Expand Down

0 comments on commit c21a38f

Please sign in to comment.