Skip to content

Commit

Permalink
very important update to the updater, it now works better, but it'll …
Browse files Browse the repository at this point in the history
…still update to this version from the previous version
  • Loading branch information
scoofy committed Oct 15, 2016
1 parent f353f3f commit 5e57dc6
Showing 1 changed file with 69 additions and 15 deletions.
84 changes: 69 additions & 15 deletions update_wxstocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,98 @@
print "In the case of a change to the updating process, please check the wxStocks readme file in your new folder."
sys.exit()

# get new directory split name
new_split_folder_name = (newly_downloaded_path + "\\wxStocks.py").split("\\")[-2]

# get current directory split name
for root, dirs, files in os.walk(current_dir):
for filename in files:
if filename.endswith("wxStocks.py"):
new_path = os.path.join(root, filename)
path_list = new_path.split("\\")
key_split_folder_name = path_list[-2]
current_path = os.path.join(root, filename)
path_list = current_path.split("\\")
old_split_folder_name = path_list[-2]
break


for root, dirs, files in os.walk(current_dir):
# add new files
for root, dirs, files in os.walk(newly_downloaded_path):
for filename in files:
if root.split("\\")[-1] in ["DO_NOT_COPY", "user_data", "wxStocks_data"]:
continue
if filename.endswith(".py"):
existing_path = os.path.join(root, filename)
#print root
newly_downloaded_file_path = os.path.join(root, filename)

split_root_path = root.split("\\" + key_split_folder_name +"\\")
split_root_path = root.split("\\" + new_split_folder_name +"\\")
try:
full_extention = split_root_path[1]
except:
full_extention = None

#print split_root
#print split_root_path
if full_extention:
newly_downloaded_file_path = "\\".join([newly_downloaded_path, full_extention]) + "\\" + filename
existing_file_path = "\\".join([current_dir, full_extention]) + "\\" + filename
else:
newly_downloaded_file_path = "\\".join([newly_downloaded_path, filename])
existing_file_path = "\\".join([current_dir, filename])
#print existing_file_path

try:
checksum_new = hashlib.md5(open(str(newly_downloaded_file_path)).read()).hexdigest()
except:
checksum_new = None
try:
checksum_old = hashlib.md5(open(str(existing_path)).read()).hexdigest()
checksum_old = hashlib.md5(open(str(existing_file_path)).read()).hexdigest()
except:
checksum_old = None
if checksum_new != checksum_old:
print "UPDATING:", existing_path
shutil.copy(newly_downloaded_file_path, existing_path)
print '"' + filename + '"', "was successfully updated"

if checksum_new:
if checksum_new != checksum_old:
print "UPDATING:", existing_file_path
shutil.copy(newly_downloaded_file_path, existing_file_path)
# remove existing .pyc file
pyc_path = os.path.splitext(existing_file_path)[0] + ".pyc"
try:
os.remove(pyc_path)
except:
pass
print '"' + filename + '"', "was successfully updated"

# delete nonexistant file from current directory
for root, dirs, files in os.walk(current_dir):
for filename in files:
if root.split("\\")[-1] in ["DO_NOT_COPY", "user_data", "wxStocks_data"]:
continue
if filename.endswith(".py"):
#print root
existing_file_path = os.path.join(root, filename)

split_root_path = root.split("\\" + old_split_folder_name +"\\")
try:
full_extention = split_root_path[1]
except:
full_extention = None

#print split_root_path
if full_extention:
potential_new_file_path = "\\".join([newly_downloaded_path, full_extention]) + "\\" + filename
else:
potential_new_file_path = "\\".join([newly_downloaded_path, filename])
if not os.path.isfile(potential_new_file_path): # file no longer exists
print "Deleting:", existing_file_path
print "It apparently no longer exists"
try:
os.remove(existing_file_path)
print '"' + filename + '"', "was successfully removed"
except:
pass
# remove existing .pyc file
pyc_path = os.path.splitext(existing_file_path)[0] + ".pyc"
try:
os.remove(pyc_path)
except:
pass
# delete directory if it is empty
if not os.listdir(root):
print "Removing empty directory:", root
os.rmdir(root)

print "Update complete"

0 comments on commit 5e57dc6

Please sign in to comment.