Skip to content

Commit 1adc418

Browse files
authored
Merge pull request #944 from kurim/master
Fix for Expired Certificate #938
2 parents 1179ec3 + aae5124 commit 1adc418

7 files changed

Lines changed: 25 additions & 20 deletions

File tree

psa_car_controller/common/mylogger.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ def _log(self, level, # pylint: disable=too-many-arguments,unused-argument
1414
exc_info=None,
1515
extra=None,
1616
stack_info=False,
17+
stacklevel=1,
1718
exc_info_debug=False,
1819
**kwargs):
1920
if exc_info_debug and self.isEnabledFor(logging.DEBUG):
2021
exc_info = True
21-
super()._log(level, msg, args, exc_info, extra, stack_info)
22+
super()._log(level, msg, args, exc_info, extra, stack_info, stacklevel)
2223

2324
def __new_style_log(self, level, msg, args, exc_info=None, extra=None, # pylint: disable=too-many-arguments
2425
stack_info=False, **kwargs):

psa_car_controller/psa/setup/apk_parser.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import json
2-
import logging
32
import os
3+
import sys
44

5-
from androguard.core.bytecodes.apk import APK
5+
from androguard.core.apk import APK
66
from cryptography.hazmat.backends import default_backend
77
from cryptography.hazmat.primitives import serialization
88
from cryptography.hazmat.primitives.serialization import pkcs12
99

1010
from psa_car_controller.psa.constants import BRAND
1111

12-
logging.getLogger("androguard").setLevel(logging.ERROR)
12+
from androguard.core.axml import logger as androguard_logger
13+
androguard_logger.remove()
14+
androguard_logger.add(sys.stderr, level="ERROR")
1315

1416

1517
class ApkParser:

psa_car_controller/psa/setup/app_decoder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414

1515
logger = logging.getLogger(__name__)
1616

17-
APP_VERSION = "1.33.0"
17+
APP_VERSION = "1.48.2"
1818
GITHUB_USER = "flobz"
1919
GITHUB_REPO = "psa_apk"
2020
TIMEOUT_IN_S = 10
2121
app = PSACarController()
2222

2323

2424
def get_content_from_apk(filename: str, country_code: str) -> ApkParser:
25+
urlretrieve_from_github(GITHUB_USER, GITHUB_REPO, "", filename)
2526
apk_parser = ApkParser(filename, country_code)
26-
urlretrieve_from_github(GITHUB_USER, GITHUB_REPO, "", apk_parser.filename)
2727
apk_parser.retrieve_content_from_apk()
2828
return apk_parser
2929

psa_car_controller/psa/setup/github.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import bz2
12
import logging
23
from hashlib import sha1
4+
from os import path
35

46
import requests
57

@@ -36,9 +38,10 @@ def github_file_need_to_be_downloaded(user, repo, directory, filename):
3638

3739

3840
def urlretrieve_from_github(user, repo, directory, filename, branch="main"):
39-
if github_file_need_to_be_downloaded(user, repo, directory, filename):
40-
with open(filename, 'wb') as f:
41-
url = "https://github.com/{}/{}/raw/{}/{}{}".format(user, repo, branch, directory, filename)
41+
archive_name = filename + ".bz2"
42+
if github_file_need_to_be_downloaded(user, repo, directory, archive_name) or not path.isfile(filename):
43+
with open(archive_name, 'wb') as f:
44+
url = "https://github.com/{}/{}/raw/{}/{}{}".format(user, repo, branch, directory, archive_name)
4245
r = requests.get(url,
4346
headers={
4447
"Accept": "application/vnd.github.VERSION.raw"
@@ -50,3 +53,5 @@ def urlretrieve_from_github(user, repo, directory, filename, branch="main"):
5053
r.raise_for_status()
5154
for chunk in r.iter_content(1024):
5255
f.write(chunk)
56+
with bz2.BZ2File(archive_name, 'rb') as file, open(filename, 'wb') as out_file:
57+
out_file.write(file.read())

psa_car_controller/psacc/repository/trips.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def get_speed_average(distance, duration):
4949
speed_average = 0
5050
return speed_average
5151

52-
@staticmethod # noqa: MC0001
53-
def get_trips(vehicles_list: Cars) -> Dict[str, "Trips"]:
52+
@staticmethod
53+
def get_trips(vehicles_list: Cars) -> Dict[str, "Trips"]: # noqa: MC0001
5454
# pylint: disable=too-many-locals,too-many-statements,too-many-nested-blocks,too-many-branches
5555
conn = Database.get_db()
5656
vehicles = conn.execute("SELECT DISTINCT vin FROM position;").fetchall()

pyproject.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ include = [
1111
]
1212

1313
[tool.poetry.dependencies]
14-
python = ">=3.7.2, <4.0.0"
14+
python = ">=3.9, <4.0.0"
1515
paho-mqtt = ">=1.5.0, <2.0.0"
1616
dash = ">=2.9.0, <3.0.0"
1717
dash-daq = "^0.5.0"
@@ -27,7 +27,7 @@ pytz = "^2021.0"
2727
argparse = "^1.4.0"
2828
geojson = "^2.5.0"
2929
reverse-geocode = "^1.4.1"
30-
androguard = "^3.3.5"
30+
androguard = "^4.1.2"
3131
pycryptodomex = "^3.9.0"
3232
pydantic = "^1.9.0"
3333
"ruamel.yaml" = ">=0.15.0"
@@ -37,9 +37,7 @@ python-dateutil = ">=2.5.3"
3737
urllib3 = ">=1.15.1 <2.0.0"
3838
importlib-metadata = {version = ">=1.7.0", python = "<3.8"}
3939
pandas = "^1.1.5"
40-
numpy = [{version = ">=1.24.0", python = ">=3.11"},
41-
{version = "<1.26.0", python = "<3.9"},
42-
{version = "<1.22.0", python = "<3.8"}]
40+
numpy = "^1.24.0"
4341
scipy = [{version = ">=1.9.2", python = ">=3.11"},
4442
{version = "<1.11.0", python = "<3.8"},
4543
{version = "<1.8.0", python = "<3.8"}]
@@ -65,4 +63,4 @@ max_line_length = 120
6563
in-place = true
6664
recursive = true
6765
aggressive = 3
68-
exclude = "psa_car_controller/__main__.py,psa_car_controller/psa/connected_car_api"
66+
exclude = "psa_car_controller/__main__.py,psa_car_controller/psa/connected_car_api"

tests/test_unit.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from datetime import datetime, timedelta
66
from unittest.mock import MagicMock, patch
77

8-
import pytz
98
import reverse_geocode
109
from dateutil.tz import tzutc
1110
from greenery.lego import parse, charclass
@@ -337,10 +336,10 @@ def test_parse_apk(self):
337336
except FileNotFoundError:
338337
pass
339338
assert get_content_from_apk(filename, "FR")
340-
assert github_file_need_to_be_downloaded(GITHUB_USER, GITHUB_REPO, "", filename) is False
339+
assert github_file_need_to_be_downloaded(GITHUB_USER, GITHUB_REPO, "", filename + ".bz2") is False
341340

342341
def test_file_need_to_be_updated(self):
343-
filename = "mypeugeot.apk"
342+
filename = "mypeugeot.apk.bz2"
344343
with open(filename, "w") as f:
345344
f.write(" ")
346345
assert github_file_need_to_be_downloaded(GITHUB_USER, GITHUB_REPO, "", filename) is True

0 commit comments

Comments
 (0)