mirror of
https://github.com/flobz/psa_car_controller.git
synced 2026-08-21 08:56:29 +00:00
feat: compress apk to be under github file size limit
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from androguard.core.apk import APK
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
@@ -9,7 +9,9 @@ from cryptography.hazmat.primitives.serialization import pkcs12
|
||||
|
||||
from psa_car_controller.psa.constants import BRAND
|
||||
|
||||
logging.getLogger("androguard").setLevel(logging.ERROR)
|
||||
from androguard.core.axml import logger as androguard_logger
|
||||
androguard_logger.remove()
|
||||
androguard_logger.add(sys.stderr, level="ERROR")
|
||||
|
||||
|
||||
class ApkParser:
|
||||
|
||||
@@ -14,16 +14,16 @@ from psa_car_controller.psacc.application.charge_control import ChargeControl, C
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
APP_VERSION = "1.48.1"
|
||||
GITHUB_USER = "HansUweRempler" #"flobz" temporary replaced till flobz updated his own
|
||||
APP_VERSION = "1.48.2"
|
||||
GITHUB_USER = "flobz"
|
||||
GITHUB_REPO = "psa_apk"
|
||||
TIMEOUT_IN_S = 10
|
||||
app = PSACarController()
|
||||
|
||||
|
||||
def get_content_from_apk(filename: str, country_code: str) -> ApkParser:
|
||||
urlretrieve_from_github(GITHUB_USER, GITHUB_REPO, "", filename)
|
||||
apk_parser = ApkParser(filename, country_code)
|
||||
urlretrieve_from_github(GITHUB_USER, GITHUB_REPO, "", apk_parser.filename)
|
||||
apk_parser.retrieve_content_from_apk()
|
||||
return apk_parser
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import bz2
|
||||
import logging
|
||||
from hashlib import sha1
|
||||
from os import path
|
||||
|
||||
import requests
|
||||
|
||||
@@ -36,9 +38,10 @@ def github_file_need_to_be_downloaded(user, repo, directory, filename):
|
||||
|
||||
|
||||
def urlretrieve_from_github(user, repo, directory, filename, branch="main"):
|
||||
if github_file_need_to_be_downloaded(user, repo, directory, filename):
|
||||
with open(filename, 'wb') as f:
|
||||
url = "https://github.com/{}/{}/raw/{}/{}{}".format(user, repo, branch, directory, filename)
|
||||
archive_name = filename + ".bz2"
|
||||
if github_file_need_to_be_downloaded(user, repo, directory, archive_name) or not path.isfile(filename):
|
||||
with open(archive_name, 'wb') as f:
|
||||
url = "https://github.com/{}/{}/raw/{}/{}{}".format(user, repo, branch, directory, archive_name)
|
||||
r = requests.get(url,
|
||||
headers={
|
||||
"Accept": "application/vnd.github.VERSION.raw"
|
||||
@@ -50,3 +53,5 @@ def urlretrieve_from_github(user, repo, directory, filename, branch="main"):
|
||||
r.raise_for_status()
|
||||
for chunk in r.iter_content(1024):
|
||||
f.write(chunk)
|
||||
with bz2.BZ2File(archive_name, 'rb') as file, open(filename, 'wb') as out_file:
|
||||
out_file.write(file.read())
|
||||
|
||||
+2
-3
@@ -5,7 +5,6 @@ import unittest
|
||||
from datetime import datetime, timedelta
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytz
|
||||
import reverse_geocode
|
||||
from dateutil.tz import tzutc
|
||||
from greenery.lego import parse, charclass
|
||||
@@ -337,10 +336,10 @@ class TestUnit(unittest.TestCase):
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
assert get_content_from_apk(filename, "FR")
|
||||
assert github_file_need_to_be_downloaded(GITHUB_USER, GITHUB_REPO, "", filename) is False
|
||||
assert github_file_need_to_be_downloaded(GITHUB_USER, GITHUB_REPO, "", filename + ".bz2") is False
|
||||
|
||||
def test_file_need_to_be_updated(self):
|
||||
filename = "mypeugeot.apk"
|
||||
filename = "mypeugeot.apk.bz2"
|
||||
with open(filename, "w") as f:
|
||||
f.write(" ")
|
||||
assert github_file_need_to_be_downloaded(GITHUB_USER, GITHUB_REPO, "", filename) is True
|
||||
|
||||
Reference in New Issue
Block a user