Skip to content

Commit

Permalink
Merge pull request #944 from kurim/master
Browse files Browse the repository at this point in the history
Fix for Expired Certificate #938
  • Loading branch information
flobz authored Aug 31, 2024
2 parents 1179ec3 + aae5124 commit 1adc418
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 20 deletions.
3 changes: 2 additions & 1 deletion psa_car_controller/common/mylogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ def _log(self, level, # pylint: disable=too-many-arguments,unused-argument
exc_info=None,
extra=None,
stack_info=False,
stacklevel=1,
exc_info_debug=False,
**kwargs):
if exc_info_debug and self.isEnabledFor(logging.DEBUG):
exc_info = True
super()._log(level, msg, args, exc_info, extra, stack_info)
super()._log(level, msg, args, exc_info, extra, stack_info, stacklevel)

def __new_style_log(self, level, msg, args, exc_info=None, extra=None, # pylint: disable=too-many-arguments
stack_info=False, **kwargs):
Expand Down
8 changes: 5 additions & 3 deletions psa_car_controller/psa/setup/apk_parser.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import json
import logging
import os
import sys

from androguard.core.bytecodes.apk import APK
from androguard.core.apk import APK
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
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:
Expand Down
4 changes: 2 additions & 2 deletions psa_car_controller/psa/setup/app_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

logger = logging.getLogger(__name__)

APP_VERSION = "1.33.0"
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

Expand Down
11 changes: 8 additions & 3 deletions psa_car_controller/psa/setup/github.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import bz2
import logging
from hashlib import sha1
from os import path

import requests

Expand Down Expand Up @@ -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"
Expand All @@ -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())
4 changes: 2 additions & 2 deletions psa_car_controller/psacc/repository/trips.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def get_speed_average(distance, duration):
speed_average = 0
return speed_average

@staticmethod # noqa: MC0001
def get_trips(vehicles_list: Cars) -> Dict[str, "Trips"]:
@staticmethod
def get_trips(vehicles_list: Cars) -> Dict[str, "Trips"]: # noqa: MC0001
# pylint: disable=too-many-locals,too-many-statements,too-many-nested-blocks,too-many-branches
conn = Database.get_db()
vehicles = conn.execute("SELECT DISTINCT vin FROM position;").fetchall()
Expand Down
10 changes: 4 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include = [
]

[tool.poetry.dependencies]
python = ">=3.7.2, <4.0.0"
python = ">=3.9, <4.0.0"
paho-mqtt = ">=1.5.0, <2.0.0"
dash = ">=2.9.0, <3.0.0"
dash-daq = "^0.5.0"
Expand All @@ -27,7 +27,7 @@ pytz = "^2021.0"
argparse = "^1.4.0"
geojson = "^2.5.0"
reverse-geocode = "^1.4.1"
androguard = "^3.3.5"
androguard = "^4.1.2"
pycryptodomex = "^3.9.0"
pydantic = "^1.9.0"
"ruamel.yaml" = ">=0.15.0"
Expand All @@ -37,9 +37,7 @@ python-dateutil = ">=2.5.3"
urllib3 = ">=1.15.1 <2.0.0"
importlib-metadata = {version = ">=1.7.0", python = "<3.8"}
pandas = "^1.1.5"
numpy = [{version = ">=1.24.0", python = ">=3.11"},
{version = "<1.26.0", python = "<3.9"},
{version = "<1.22.0", python = "<3.8"}]
numpy = "^1.24.0"
scipy = [{version = ">=1.9.2", python = ">=3.11"},
{version = "<1.11.0", python = "<3.8"},
{version = "<1.8.0", python = "<3.8"}]
Expand All @@ -65,4 +63,4 @@ max_line_length = 120
in-place = true
recursive = true
aggressive = 3
exclude = "psa_car_controller/__main__.py,psa_car_controller/psa/connected_car_api"
exclude = "psa_car_controller/__main__.py,psa_car_controller/psa/connected_car_api"
5 changes: 2 additions & 3 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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
Expand Down Expand Up @@ -337,10 +336,10 @@ def test_parse_apk(self):
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
Expand Down

0 comments on commit 1adc418

Please sign in to comment.