diff --git a/plugins/TorrentFiles/tab_files.py b/plugins/TorrentFiles/tab_files.py index 634779f4d..3832f52b9 100644 --- a/plugins/TorrentFiles/tab_files.py +++ b/plugins/TorrentFiles/tab_files.py @@ -51,6 +51,8 @@ class FilesTabManager(FilesBaseManager): def open_file(self, widget=None): import os + from deluge.common import exec_command + save_dir = self.manager.unique_IDs[self.file_unique_id].save_dir selected_paths = self.file_view.get_selection().get_selected_rows()[1] try: @@ -59,8 +61,8 @@ class FilesTabManager(FilesBaseManager): convert_path_to_child_path(path) file_name = self.file_store.get_value( self.file_store.get_iter(child_path), 0) - os.popen2('%s "%s"' % (self.file_viewer, - os.path.join(save_dir, file_name))) + exec_command(self.file_viewer, + os.path.join(save_dir, file_name)) except KeyError: pass diff --git a/src/common.py b/src/common.py index b0065f781..d2d72c4df 100644 --- a/src/common.py +++ b/src/common.py @@ -129,11 +129,7 @@ def open_url_in_browser(link): import webbrowser webbrowser.open(link) else: - import os, sys - py_version = sys.version[:3] - file = os.path.join(INSTALL_PREFIX, 'lib', 'python' \ - + py_version, 'site-packages', 'deluge', 'browser.py') - os.spawnlp(os.P_NOWAIT, 'python', 'python', file, link) + exec_deluge_command('browser.py', link) def is_url(url): import re @@ -156,6 +152,24 @@ def fetch_url(url): return None +def exec_command(executable, *parameters): + from subprocess import Popen + + command = [executable] + command.extend(parameters) + Popen(command) + + +def exec_deluge_command(script, *parameters): + """Execute deluge's command like browser.py, update.py and others""" + + import sys + + py_version = sys.version[:3] + full_path = os.path.join(INSTALL_PREFIX, 'lib', 'python' + py_version, + 'site-packages', 'deluge', script) + exec_command('python', full_path, *parameters) + # Encryption States class EncState: forced, enabled, disabled = range(3) diff --git a/src/interface.py b/src/interface.py index ff5dba514..f4ba7cd50 100644 --- a/src/interface.py +++ b/src/interface.py @@ -115,25 +115,13 @@ class DelugeGTK: self.update_interface = True def new_release_check(): - import sys - py_version = sys.version[:3] - file = os.path.join(common.INSTALL_PREFIX, 'lib', 'python' \ - + py_version, 'site-packages', 'deluge', 'update.py') - os.spawnlp(os.P_NOWAIT, 'python', 'python', file, - common.PROGRAM_VERSION) + common.exec_deluge_command('update.py', common.PROGRAM_VERSION) def send_info(): import time def _run_script(): - import sys - - py_version = sys.version[:3] - - file = os.path.join(common.INSTALL_PREFIX, 'lib', 'python' \ - + py_version, 'site-packages', 'deluge', 'info.py') - os.spawnlp(os.P_NOWAIT, 'python', 'python', file, - common.PROGRAM_VERSION) + common.exec_deluge_command('info.py', common.PROGRAM_VERSION) info_file = os.path.join(common.CONFIG_DIR, 'infosent') @@ -657,7 +645,7 @@ class DelugeGTK: torrent_path = os.path.join(torrent_path, file["path"].split("/", 1)[0]) - os.popen2('%s "%s"' % (file_manager, torrent_path)) + common.exec_command(file_manager, torrent_path) except KeyError: pass