chg: Add ERROR while exiting to help with logging

This commit is contained in:
Sayantan Santra 2023-08-11 14:21:57 -05:00
parent a80d769567
commit 64d0a7f184
Signed by: SinTan1729
GPG key ID: EB3E68BFBA25C85F
5 changed files with 39 additions and 31 deletions

View file

@ -11,14 +11,14 @@ from packaging.version import Version
import requests as req import requests as req
from bs4 import BeautifulSoup as bs from bs4 import BeautifulSoup as bs
from ReVancedBuilder.Cleanup import clean_exit from ReVancedBuilder.Cleanup import err_exit
# Determine the best version available to download # Determine the best version available to download
def apkpure_best_match(version, soup): def apkpure_best_match(version, soup):
try: try:
vers_list = [Version(x['data-dt-version']) for x in soup.css.select(f"a[data-dt-apkid^=\"b/APK/\"]")] vers_list = [Version(x['data-dt-version']) for x in soup.css.select(f"a[data-dt-apkid^=\"b/APK/\"]")]
except: except:
clean_exit(f" There was some error getting list of versions of {apk}...", appstate) err_exit(f" There was some error getting list of versions of {apk}...", appstate)
if version != '0': if version != '0':
vers_list = filter(lambda x: x <= Version(version), vers_list) vers_list = filter(lambda x: x <= Version(version), vers_list)
@ -50,7 +50,7 @@ def apkpure_dl(apk, appname, version, hard_version, session, present_vers, flag)
try: try:
ver_code = soup.css.select(f"a[data-dt-version=\"{version}\"][data-dt-apkid^=\"b/APK/\"]")[0]['data-dt-versioncode'] ver_code = soup.css.select(f"a[data-dt-version=\"{version}\"][data-dt-apkid^=\"b/APK/\"]")[0]['data-dt-versioncode']
except: except:
clean_exit(f" There was some error while downloading {apk}...", appstate) err_exit(f" There was some error while downloading {apk}...", appstate)
res = session.get(f"https://d.apkpure.com/b/APK/{apk}?versionCode={ver_code}", stream=True) res = session.get(f"https://d.apkpure.com/b/APK/{apk}?versionCode={ver_code}", stream=True)
res.raise_for_status() res.raise_for_status()
@ -73,7 +73,7 @@ def get_apks(appstate):
try: try:
patches = req.get('https://releases.revanced.app/patches').json() patches = req.get('https://releases.revanced.app/patches').json()
except req.exceptions.RequestException as e: except req.exceptions.RequestException as e:
clean_exit(e, appstate) err_exit(e, appstate)
session = req.Session() session = req.Session()
session.headers.update({'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0'}) session.headers.update({'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0'})
@ -88,7 +88,7 @@ def get_apks(appstate):
pretty_name = build_config[app]['pretty_name'] pretty_name = build_config[app]['pretty_name']
apkpure_appname = build_config[app]['apkpure_appname'] apkpure_appname = build_config[app]['apkpure_appname']
except: except:
clean_exit(f"Invalid config for {app} in build_config!", appstate) err_exit(f"Invalid config for {app} in build_config!", appstate)
print(f"Checking {pretty_name}...") print(f"Checking {pretty_name}...")
try: try:

View file

@ -10,6 +10,8 @@ import time
from ReVancedBuilder.Notifications import send_notif from ReVancedBuilder.Notifications import send_notif
# Move apps to proper location # Move apps to proper location
def move_apps(appstate): def move_apps(appstate):
build_config = appstate['build_config'] build_config = appstate['build_config']
print = appstate['logger'].info print = appstate['logger'].info
@ -50,7 +52,8 @@ def move_apps(appstate):
if f.stat().st_ctime < now - 7 * 86400: if f.stat().st_ctime < now - 7 * 86400:
os.remove(f) os.remove(f)
def clean_exit(msg, appstate, code=1):
def err_exit(msg, appstate, code=1):
print = appstate['logger'].info print = appstate['logger'].info
try: try:
@ -60,7 +63,7 @@ def clean_exit(msg, appstate, code=1):
pass pass
if msg: if msg:
print(msg) print(f"ERROR: {msg}")
# Delete the lockfile # Delete the lockfile
os.remove('lockfile') os.remove('lockfile')

View file

@ -9,9 +9,11 @@ import configparser as cp
import json import json
import subprocess import subprocess
from ReVancedBuilder.Cleanup import clean_exit from ReVancedBuilder.Cleanup import err_exit
# Build the revanced apps # Build the revanced apps
def build_apps(appstate): def build_apps(appstate):
build_config = appstate['build_config'] build_config = appstate['build_config']
flag = appstate['flag'] flag = appstate['flag']
@ -66,7 +68,7 @@ def build_apps(appstate):
apkpure_appname = build_config[app]['apkpure_appname'] apkpure_appname = build_config[app]['apkpure_appname']
output_name = build_config[app]['output_name'] output_name = build_config[app]['output_name']
except: except:
clean_exit(f"Invalid config for {app} in build_config!", appstate) err_exit(f"Invalid config for {app} in build_config!", appstate)
cmd += f" -a {apk}.apk -o {output_name}.apk" cmd += f" -a {apk}.apk -o {output_name}.apk"
@ -82,10 +84,11 @@ def build_apps(appstate):
if line_utf: if line_utf:
print(line_utf) print(line_utf)
except Exception as e: except Exception as e:
clean_exit(f"There was an error while building {pretty_name}!\n{e}", appstate) err_exit(
f"There was an error while building {pretty_name}!\n{e}", appstate)
try: try:
os.rename(output_name+'.apk', output_name+'.apk') os.rename(output_name+'.apk', output_name+'.apk')
except FileNotFoundError: except FileNotFoundError:
clean_exit(f"There was an error while building {pretty_name}!", appstate) err_exit(
f"There was an error while building {pretty_name}!", appstate)

View file

@ -8,6 +8,7 @@ import re
import requests as req import requests as req
import subprocess import subprocess
def send_notif(appstate, error=False): def send_notif(appstate, error=False):
print = appstate['logger'].info print = appstate['logger'].info
timestamp = appstate['timestamp'] timestamp = appstate['timestamp']
@ -32,7 +33,8 @@ def send_notif(appstate, error=False):
for app in build_config: for app in build_config:
if not build_config[app].getboolean('build'): if not build_config[app].getboolean('build'):
continue continue
msg = msg.replace(build_config[app]['apk'], build_config[app]['pretty_name']) msg = msg.replace(
build_config[app]['apk'], build_config[app]['pretty_name'])
msg += '\nTimestamp: ' + timestamp msg += '\nTimestamp: ' + timestamp
if appstate['microg_updated']: if appstate['microg_updated']:
@ -89,7 +91,7 @@ def send_notif(appstate, error=False):
if line_utf: if line_utf:
print(line_utf) print(line_utf)
except Exception as e: except Exception as e:
clean_exit(f"Failed!\n{e}", appstate) err_exit(f"Failed!\n{e}", appstate)
else: else:
print('Don\'t know how to send notifications to ' + entry) print('Don\'t know how to send notifications to ' + entry)

View file

@ -17,7 +17,7 @@ from datetime import datetime
from ReVancedBuilder.APKPure_dl import apkpure_best_match, apkpure_dl, get_apks from ReVancedBuilder.APKPure_dl import apkpure_best_match, apkpure_dl, get_apks
from ReVancedBuilder.JAVABuilder import build_apps from ReVancedBuilder.JAVABuilder import build_apps
from ReVancedBuilder.Notifications import send_notif from ReVancedBuilder.Notifications import send_notif
from ReVancedBuilder.Cleanup import move_apps, clean_exit from ReVancedBuilder.Cleanup import move_apps, err_exit
# Update the ReVanced tools, if needed # Update the ReVanced tools, if needed
def update_tools(appstate): def update_tools(appstate):
@ -52,7 +52,7 @@ def update_microg(appstate):
data = req.get('https://api.github.com/repos/inotia00/VancedMicroG/releases/latest').json()['tag_name'] data = req.get('https://api.github.com/repos/inotia00/VancedMicroG/releases/latest').json()['tag_name']
latest_ver = Version(data) latest_ver = Version(data)
except req.exceptions.RequestException as e: except req.exceptions.RequestException as e:
clean_exit(e, appstate) err_exit(e, appstate)
try: try:
present_ver = Version(appstate['present_vers']['VancedMicroG']) present_ver = Version(appstate['present_vers']['VancedMicroG'])
@ -124,7 +124,7 @@ except:
flag = None flag = None
if flag not in ['buildonly', 'checkonly', 'force', 'experimental', None]: if flag not in ['buildonly', 'checkonly', 'force', 'experimental', None]:
clean_exit(f"Unknown flag: {flag}", appstate) err_exit(f"Unknown flag: {flag}", appstate)
appstate['flag'] = flag appstate['flag'] = flag
appstate['microg_updated'] = False appstate['microg_updated'] = False
@ -137,7 +137,7 @@ try:
appstate['build_config']=cp.ConfigParser() appstate['build_config']=cp.ConfigParser()
appstate['build_config'].read_file(open('build_config', 'r')) appstate['build_config'].read_file(open('build_config', 'r'))
except FileNotFoundError: except FileNotFoundError:
clean_exit('No build config provided, exiting. Please look at the GitHub page for more information:\n https://github.com/SinTan1729/ReVancedBuilder', appstate) err_exit('No build config provided, exiting. Please look at the GitHub page for more information:\n https://github.com/SinTan1729/ReVancedBuilder', appstate)
appstate['notification_config'] = cp.ConfigParser() appstate['notification_config'] = cp.ConfigParser()
appstate['notification_config'].read('notification_config') appstate['notification_config'].read('notification_config')
@ -146,7 +146,7 @@ appstate['notification_config'].read('notification_config')
try: try:
tools = req.get('https://releases.revanced.app/tools').json()['tools'] tools = req.get('https://releases.revanced.app/tools').json()['tools']
except req.exceptions.RequestException as e: except req.exceptions.RequestException as e:
clean_exit(e, appstate) err_exit(e, appstate)
try: try:
with open('versions.json', 'r') as f: with open('versions.json', 'r') as f: