Mercurial > codedump
annotate qbittorrent_update.py @ 62:8be9281d7ade
Add `qbittorrent_update.py`
yes, there is a long ass line. no, i don't want to shrink it
committer: GitHub <noreply@github.com>
| author | Paper <37962225+mrpapersonic@users.noreply.github.com> | 
|---|---|
| date | Sun, 30 Jan 2022 20:31:44 -0500 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 62 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 1 """ | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 2 qBittorrent Updater for Windows (x64) | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 3 by Paper | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 4 | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 5 This could be easily ported to macOS/Linux, but for the former it | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 6 would just be easier to do it in AppleScript, and for the latter | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 7 you should already be using a package manager to do this for you. | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 8 """ | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 9 import urllib.request | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 10 import re | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 11 import psutil | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 12 import os | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 13 import platform | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 14 import time | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 15 | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 16 | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 17 def _check_running(exename): | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 18 for proc in psutil.process_iter(): | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 19 try: | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 20 if proc.name() == exename: | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 21 return True | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 22 except psutil.NoSuchProcess as err: | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 23 return False | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 24 except psutil.AccessDenied: | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 25 return False | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 26 | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 27 | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 28 QBITTORRENT_DIRECTORY = "C:\\Program Files\\qBittorrent" | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 29 TEMP_DIRECTORY = os.getenv("TEMP") | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 30 BIT_STR = "_x64" if platform.machine().endswith('64') else "" | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 31 | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 32 if _check_running("qbittorrent.exe"): | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 33 print("qBittorrent is currently running! Please exit it and try again.") | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 34 quit(1) | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 35 | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 36 # Get the link for the latest version, courtesy of SourceForge | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 37 urllib.request.urlretrieve(re.search("\<a href=\"(https:\/\/sourceforge\.net\/projects\/qbittorrent\/files\/qbittorrent-win32\/qbittorrent-[0-9\.]+\/qbittorrent_[0-9\.]+" + BIT_STR + "_setup\.exe\/download)\"\>", urllib.request.urlopen("https://www.qbittorrent.org/download.php").read().decode("utf-8")).group(1), os.path.join(TEMP_DIRECTORY, "qbittorrent_setup.exe")) | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 38 | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 39 # Run the installer and wait for it to finish | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 40 os.system(os.path.join(TEMP_DIRECTORY, "qbittorrent_setup.exe") + " /S") | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 41 while _check_running("qbittorrent_setup.exe"): | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 42 time.sleep(5) | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 43 | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 44 # Cleanup | 
| 
8be9281d7ade
Add `qbittorrent_update.py`
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 45 os.remove(os.path.join(TEMP_DIRECTORY, "qbittorrent_setup.exe")) | 
