Skip to content

Commit

Permalink
Optimized Code
Browse files Browse the repository at this point in the history
  • Loading branch information
elibroftw committed Aug 9, 2019
1 parent 3842a96 commit 5d262ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 40 deletions.
27 changes: 3 additions & 24 deletions music_caster.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,9 @@ def change_settings(name, value):
def download_and_extract(link, infile, outfile=None):
r = requests.get(link, stream=True)
z = zipfile.ZipFile(io.BytesIO(r.content))
# NOTE: I'm unsure weather I need to delete the file before extracting. Test the exe
if outfile is None: z.extract(infile)
else:
new_file = z.open(infile)
# f'music-caster-{latest_version}/music_caster.py'
target = open(outfile, 'wb')
with new_file, target: copyfileobj(new_file, target)

Expand All @@ -147,32 +145,13 @@ def download_and_extract(link, infile, outfile=None):
os.chdir(starting_dir)
if settings.get('DEBUG'): Popen('python updater.py')
elif os.path.exists('updater.py'):
# download_and_extract(source_download_link, f'music-caster-{latest_version}/updater.py', 'updater.py')
r = requests.get(source_download_link, stream=True)
z = zipfile.ZipFile(io.BytesIO(r.content))
z.extract(f'music-caster-{latest_version}/updater.py')
z.close()
if os.path.exists('updater.py'): os.remove('updater.py')
os.rename(f'music-caster-{latest_version}/updater.py', 'updater.py')
os.rmdir(f'music-caster-{latest_version}')
download_and_extract(source_download_link, f'music-caster-{latest_version}/updater.py', 'updater.py')
Popen('pythonw updater.py')
elif os.path.exists('Updater.exe'):
# download_and_extract(bundle_download_link, 'Updater.exe')
r = requests.get(bundle_download_link, stream=True)
z = zipfile.ZipFile(io.BytesIO(r.content))
os.remove('Updater.exe')
z.extract('Updater.exe')
z.close()
download_and_extract(bundle_download_link, 'Updater.exe')
os.startfile('Updater.exe')
elif os.path.exists('updater.pyw'):
# download_and_extract(source_download_link, f'music-caster-{latest_version}/updater.py', 'updater.pyw')
r = requests.get(source_download_link, stream=True)
z = zipfile.ZipFile(io.BytesIO(r.content))
z.extract(f'music-caster-{latest_version}/updater.py')
z.close()
if os.path.exists('updater.pyw'): os.remove('updater.pyw')
os.rename(f'music-caster-{latest_version}/updater.py', 'updater.pyw')
os.rmdir(f'music-caster-{latest_version}')
download_and_extract(source_download_link, f'music-caster-{latest_version}/updater.py', 'updater.pyw')
Popen('pythonw updater.pyw')
sys.exit()

Expand Down
21 changes: 5 additions & 16 deletions updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,12 @@ def download_and_extract(link, infile, outfile=None):
print(bundle_download_link)
print(source_download_link)
Popen('python music_caster.py')
# add .py case

elif os.path.exists('music_caster.py'):
download_and_extract(source_download_link, f'music-caster-{latest_version}/music_caster.py', 'music_caster.py')
Popen('pythonw music_caster.py')
elif os.path.exists('music_caster.pyw'): # Update python file
# download_and_extract(source_download_link, f'music-caster-{latest_version}/music_caster.py', 'music_caster.pyw')
r = requests.get(source_download_link, stream=True)
z = zipfile.ZipFile(io.BytesIO(r.content))
z.extract(f'music-caster-{latest_version}/music_caster.py')
z.close()
if os.path.exists('music_caster.pyw'): os.remove('music_caster.pyw')
os.rename(f'music-caster-{latest_version}/music_caster.py', 'music_caster.pyw')
os.rmdir(f'music-caster-{latest_version}')
download_and_extract(source_download_link, f'music-caster-{latest_version}/music_caster.py', 'music_caster.pyw')
Popen('pythonw music_caster.pyw')
else: # Update Music Caster.exe; Change if statements so that .pyw is last
# download_and_extract(bundle_download_link, 'Music Caster.exe')
r = requests.get(bundle_download_link, stream=True)
z = zipfile.ZipFile(io.BytesIO(r.content))
if os.path.exists('Music Caster.exe'): os.remove('Music Caster.exe')
z.extract('Music Caster.exe')
z.close()
download_and_extract(bundle_download_link, 'Music Caster.exe')
os.startfile('Music Caster.exe')

0 comments on commit 5d262ff

Please sign in to comment.