Skip to content

Commit

Permalink
Make auto-updater work on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
MalloyDelacroix committed Feb 10, 2017
1 parent f405bea commit 74e2930
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
19 changes: 14 additions & 5 deletions DFR_Updater/Updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import tempfile
import zipfile
import tarfile
from PyQt5.QtCore import QObject, pyqtSignal


Expand Down Expand Up @@ -97,9 +98,14 @@ def replace_with_new_version(self):
try:
if self.run:
self.update_label.emit('Installing new update...')
zip_ref = zipfile.ZipFile(self.file_name, 'r')
zip_ref.extractall(self.temp_directory)
zip_ref.close()
if sys.platform == 'win32':
zip_ref = zipfile.ZipFile(self.file_name, 'r')
zip_ref.extractall(self.temp_directory)
zip_ref.close()
else:
tar = tarfile.open(self.file_name)
tar.extractall(path=self.temp_directory)
tar.close()

unpacked_directory = None
for x in os.listdir(self.temp_directory):
Expand All @@ -112,13 +118,16 @@ def replace_with_new_version(self):
for file in file_list:
shutil.move(os.path.join(unpacked_directory, file), self.program_files_location)
self.update_progress_bar.emit(1)

except:
self.run = False
self.error_signal.emit((2, self.temp_directory))

def clean_up_temporary(self):
"""Deletes any temporary files that where created"""
self.update_label.emit('Cleaning up temp folder...')
shutil.rmtree(self.temp_directory)
if self.run:
self.update_label.emit('Cleaning up temp folder...')
shutil.rmtree(self.temp_directory)

def stop(self):
self.run = False
Expand Down
3 changes: 2 additions & 1 deletion DFR_Updater/UpdaterGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def launch_program(self):
if sys.platform == 'win32':
os.startfile(os.path.join(self.program_files_location, 'DownloaderForReddit.exe'))
elif sys.platform == 'linux':
subprocess.call(['xdg-open', os.path.join(self.program_files_location, 'DownloaderForReddit')])
subprocess.Popen([os.path.join(self.program_files_location, 'DownloaderForReddit'),
os.path.join(self.program_files_location, 'DownloaderForReddit')])

"""
The methods below are to alert the user to any type of error that may arise during the update process and provide
Expand Down
3 changes: 1 addition & 2 deletions DownloaderForReddit/RedditDownloaderGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,6 @@ def save_state(self):
self.settings.setValue('list_sort_method', self.list_sort_method)

def check_for_updates(self, from_menu):
print('checking for updates')
self.update_thread = QtCore.QThread()
self.update_checker = UpdateChecker(self.version)
self.update_checker.moveToThread(self.update_thread)
Expand Down Expand Up @@ -1250,6 +1249,6 @@ def run_updater(self):
if platform == 'win32':
os.startfile(updater)
else:
subprocess.call(['xdg-open', updater])
subprocess.Popen([updater, updater])
except:
self.update_output(updater)

0 comments on commit 74e2930

Please sign in to comment.