Mercurial > codedump
comparison updatechromium.py @ 39:a93c352af05e
Update updatechromium.py
committer: GitHub <noreply@github.com>
author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
---|---|
date | Mon, 21 Jun 2021 13:58:31 -0400 |
parents | 310a73329fa4 |
children | 2aa9614cb39a |
comparison
equal
deleted
inserted
replaced
38:310a73329fa4 | 39:a93c352af05e |
---|---|
1 #!/usr/bin/python | |
2 # Binaries from | |
1 # https://github.com/ungoogled-software/ungoogled-chromium-archlinux/ | 3 # https://github.com/ungoogled-software/ungoogled-chromium-archlinux/ |
2 import urllib.request | 4 import urllib.request |
3 import os | 5 import os |
4 import json | 6 import json |
5 import sys | 7 import sys |
6 import subprocess | 8 import subprocess |
7 from tqdm import tqdm | 9 from tqdm import tqdm |
8 | 10 |
11 | |
12 # Decodes subprocess stdouts, made into a function because why not | |
13 def decode_line(line): | |
14 decodeline = [] | |
15 for i in line: | |
16 decodeline.append(i.decode("utf-8").rstrip()) | |
17 return decodeline | |
18 | |
19 | |
20 # Checks current version against installed version | |
21 def check_version(version): | |
22 pacman = subprocess.Popen(["pacman", "-Qm"], stdout=subprocess.PIPE, | |
23 stderr=subprocess.STDOUT) | |
24 decodeline = decode_line(pacman.stdout.readlines()) | |
25 for i in decodeline: | |
26 if i.split(" ")[0] == "ungoogled-chromium": | |
27 if i.split(" ")[1] == version: | |
28 print("You are on the latest version!") | |
29 sys.exit(0) | |
30 | |
31 | |
32 # Checks for any Chromium processes currently running | |
9 # Returns 0 if running, 1 if not running, and 2 if it doesn't exist | 33 # Returns 0 if running, 1 if not running, and 2 if it doesn't exist |
10 def check_for_file(file): | 34 def check_for_file(files): |
11 process = subprocess.Popen(["which", file], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) | 35 process = subprocess.Popen(["which", files], stdout=subprocess.DEVNULL, |
36 stderr=subprocess.STDOUT) | |
12 process.wait() | 37 process.wait() |
13 | 38 |
14 if process.returncode == 0: | 39 if process.returncode == 0: |
15 try: | 40 pgrep = subprocess.Popen(["pidof", files], stdout=subprocess.PIPE, |
16 subprocess.check_output(["pidof", file]) | 41 stderr=subprocess.STDOUT) |
42 decodeline = decode_line(pgrep.stdout.readlines()) | |
43 if len(decodeline) > 0: | |
17 return 0 | 44 return 0 |
18 except: | 45 else: |
19 return 1 | 46 return 1 |
20 else: | 47 else: |
21 return 2 | 48 return 2 |
22 | 49 |
50 | |
51 # Progress bar, copied from stackoverflow :pngtroll: | |
23 class DownloadProgressBar(tqdm): | 52 class DownloadProgressBar(tqdm): |
24 def update_to(self, b=1, bsize=1, tsize=None): | 53 def update_to(self, b=1, bsize=1, tsize=None): |
25 if tsize is not None: | 54 if tsize is not None: |
26 self.total = tsize | 55 self.total = tsize |
27 self.update(b * bsize - self.n) | 56 self.update(b * bsize - self.n) |
28 | 57 |
29 | 58 |
30 def download_url(url, output_path): | 59 def download_url(url, output_path): |
31 with DownloadProgressBar(unit='B', unit_scale=True, | 60 with DownloadProgressBar(unit='B', unit_scale=True, |
32 miniters=1, desc=url.split('/')[-1]) as t: | 61 miniters=1, desc=url.split('/')[-1]) as t: |
33 urllib.request.urlretrieve(url, filename=output_path, reporthook=t.update_to) | 62 urllib.request.urlretrieve(url, filename=output_path, |
63 reporthook=t.update_to) | |
64 | |
34 | 65 |
35 if check_for_file("chromium") == 0: | 66 if check_for_file("chromium") == 0: |
36 print("Chromium is still running! Exiting...") | 67 print("Chromium is still running! Exiting...") |
37 sys.exit(1) | 68 sys.exit(1) |
38 OWNER = "ungoogled-software" | 69 owner = "ungoogled-software" |
39 REPO = "ungoogled-chromium-archlinux" | 70 repo = "ungoogled-chromium-archlinux" |
40 r = urllib.request.urlopen(f"https://api.github.com/repos/{OWNER}/{REPO}/releases") | 71 json = json.loads(urllib.request.urlopen(f"https://api.github.com/repos/{owner}/{repo}/releases").read()) |
41 json = json.loads(r.read()) | 72 check_version(json[0]["tag_name"]) |
42 for i in json[0]["assets"]: | 73 for i in json[0]["assets"]: |
43 if i["content_type"] == "application/octet-stream": | 74 if i["content_type"] == "application/octet-stream": |
44 download_url(f"{i['browser_download_url']}", "/tmp/chromium.tar.zst") | 75 download_url(f"{i['browser_download_url']}", "/tmp/chromium.tar.zst") |
45 os.system("sudo pacman -U /tmp/chromium.tar.zst") | 76 os.system("sudo pacman -U /tmp/chromium.tar.zst") |
46 os.remove("/tmp/chromium.tar.zst") | 77 os.remove("/tmp/chromium.tar.zst") |
47 |