summaryrefslogtreecommitdiff
path: root/upgrade.py
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2017-07-25 06:18:18 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2017-07-25 06:18:18 +0200
commit832bc8c8e85c075edf559a32400d86183e985728 (patch)
tree80346180eb02de40c8342055bbd1f22055640d84 /upgrade.py
parent049849cac97ff5fa2e2b12503702fe52a115182c (diff)
parent77dd64c0757c0191b276e65c24ee9874959790c8 (diff)
Updated version 0.9.1 from 'upstream/0.9.1'
with Debian dir df52fe78cbe3481a4d64083df8ec468669b4bd47
Diffstat (limited to 'upgrade.py')
-rw-r--r--upgrade.py54
1 files changed, 52 insertions, 2 deletions
diff --git a/upgrade.py b/upgrade.py
index d952608..4085b98 100644
--- a/upgrade.py
+++ b/upgrade.py
@@ -35,6 +35,8 @@ import shlex
from subprocess import Popen, PIPE
from queue import Queue, Empty
import subprocess
+import platform
+from distutils.version import StrictVersion
from gettext import gettext as _
from PyQt5.QtCore import (pyqtSignal, pyqtSlot, Qt, QThread, QObject, QTimer)
@@ -61,9 +63,50 @@ class RPDUpgrade(QObject):
def make_pip_command(self, args: str) -> List[str]:
return shlex.split('{} -m pip {}'.format(sys.executable, args))
+ def pip_version(self) -> StrictVersion:
+ import pip
+
+ return StrictVersion(pip.__version__)
+
@pyqtSlot(str)
def start(self, installer: str) -> None:
+ # explicitly uninstall any previous version installed with pip
+ self.sendMessage("Uninstalling previous version installed with pip...\n")
+ l_command_line = 'list --user --disable-pip-version-check'
+ if self.pip_version() >= StrictVersion('9.0.0'):
+ l_command_line = '{} --format=columns'.format(l_command_line)
+ l_args = self.make_pip_command(l_command_line)
+
+ u_command_line = 'uninstall --disable-pip-version-check -y rapid-photo-downloader'
+ u_args = self.make_pip_command(u_command_line)
+ while True:
+ try:
+ output = subprocess.check_output(l_args, universal_newlines=True)
+ if 'rapid-photo-downloader' in output:
+ with Popen(
+ u_args, stdout=PIPE, stderr=PIPE, bufsize=1, universal_newlines=True
+ ) as p:
+ for line in p.stdout:
+ self.sendMessage(line, truncate=True)
+ cmd = self.checkForCmd()
+ if cmd is not None:
+ assert cmd == 'STOP'
+ self.failure('\nTermination requested')
+ return
+ p.wait()
+ i = p.returncode
+ if i != 0:
+ self.sendMessage(
+ "Encountered an error uninstalling previous version installed with "
+ "pip\n"
+ )
+ else:
+ break
+ except Exception:
+ break
+ self.sendMessage('...done uninstalling previous version.\n')
+
name = os.path.basename(installer)
name = name[:len('.tar.gz') * -1]
@@ -72,6 +115,9 @@ class RPDUpgrade(QObject):
with tarfile.open(installer) as tar:
with tar.extractfile(rpath) as requirements:
reqbytes = requirements.read()
+ if platform.machine() == 'x86_64' and platform.python_version_tuple()[1] in (
+ '5', '6'):
+ reqbytes = reqbytes.rstrip() + b'\nPyQt5'
with tempfile.NamedTemporaryFile(delete=False) as temp_requirements:
temp_requirements.write(reqbytes)
temp_requirements_name = temp_requirements.name
@@ -81,7 +127,9 @@ class RPDUpgrade(QObject):
self.sendMessage("Installing application requirements...\n")
try:
- cmd = self.make_pip_command('install --user -r {}'.format(temp_requirements.name))
+ cmd = self.make_pip_command(
+ 'install --user --disable-pip-version-check -r {}'.format(temp_requirements.name)
+ )
with Popen(cmd, stdout=PIPE, stderr=PIPE, bufsize=1, universal_newlines=True) as p:
for line in p.stdout:
self.sendMessage(line, truncate=True)
@@ -103,7 +151,9 @@ class RPDUpgrade(QObject):
self.sendMessage("\nInstalling application...\n")
try:
- cmd = self.make_pip_command('install --user --no-deps {}'.format(installer))
+ cmd = self.make_pip_command(
+ 'install --user --disable-pip-version-check --no-deps {}'.format(installer)
+ )
with Popen(cmd, stdout=PIPE, stderr=PIPE, bufsize=1, universal_newlines=True) as p:
for line in p.stdout:
self.sendMessage(line, truncate=True)