fluffychat: 1.22.1 -> 1.23.0 (#364091)
[NixPkgs.git] / pkgs / by-name / mi / microsoft-edge / update.py
blobe0d007c12f1793531815e1f8ff96df3eb21b1f5b
1 #! /usr/bin/env nix-shell
2 #! nix-shell -i python3 -p python3Packages.packaging python3Packages.python-debian common-updater-scripts
4 import base64
5 import textwrap
6 import os
7 from urllib import request
9 from collections import OrderedDict
10 from debian.deb822 import Packages
11 from debian.debian_support import Version
12 from os.path import abspath, dirname
14 PIN_PATH = dirname(abspath(__file__)) + '/default.nix'
16 def packages():
17 packages_url = 'https://packages.microsoft.com/repos/edge/dists/stable/main/binary-amd64/Packages'
18 handle = request.urlopen(packages_url)
19 return handle
22 def latest_packages(packages: bytes):
23 latest_packages: OrderedDict[str, Packages] = {}
24 for package in Packages.iter_paragraphs(packages, use_apt_pkg=False):
25 name: str = package['Package']
26 if not name.startswith('microsoft-edge-stable'):
27 continue
28 channel = name.replace('microsoft-edge-', '')
29 if channel not in latest_packages:
30 latest_packages[channel] = package
31 else:
32 old_package = latest_packages[channel]
33 if old_package.get_version() < package.get_version(): # type: ignore
34 latest_packages[channel] = package
35 return OrderedDict(sorted(latest_packages.items(), key=lambda x:x[0]))
38 def write_expression():
39 latest = latest_packages(packages())
40 version = Version.re_valid_version.match(latest['stable']['Version']).group('upstream_version')
41 os.system(f'update-source-version microsoft-edge "{version}"')
44 write_expression()