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
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
def apkpure_best_match(version, soup):
try:
vers_list = [Version(x['data-dt-version']) for x in soup.css.select(f"a[data-dt-apkid^=\"b/APK/\"]")]
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':
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:
ver_code = soup.css.select(f"a[data-dt-version=\"{version}\"][data-dt-apkid^=\"b/APK/\"]")[0]['data-dt-versioncode']
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.raise_for_status()
@ -73,7 +73,7 @@ def get_apks(appstate):
try:
patches = req.get('https://releases.revanced.app/patches').json()
except req.exceptions.RequestException as e:
clean_exit(e, appstate)
err_exit(e, appstate)
session = req.Session()
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']
apkpure_appname = build_config[app]['apkpure_appname']
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}...")
try:

View file

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

View file

@ -9,9 +9,11 @@ import configparser as cp
import json
import subprocess
from ReVancedBuilder.Cleanup import clean_exit
from ReVancedBuilder.Cleanup import err_exit
# Build the revanced apps
def build_apps(appstate):
build_config = appstate['build_config']
flag = appstate['flag']
@ -66,7 +68,7 @@ def build_apps(appstate):
apkpure_appname = build_config[app]['apkpure_appname']
output_name = build_config[app]['output_name']
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"
@ -82,10 +84,11 @@ def build_apps(appstate):
if line_utf:
print(line_utf)
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:
os.rename(output_name+'.apk', output_name+'.apk')
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 subprocess
def send_notif(appstate, error=False):
print = appstate['logger'].info
timestamp = appstate['timestamp']
@ -32,7 +33,8 @@ def send_notif(appstate, error=False):
for app in build_config:
if not build_config[app].getboolean('build'):
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
if appstate['microg_updated']:
@ -53,7 +55,7 @@ def send_notif(appstate, error=False):
print('URL or TOPIC not provided!')
continue
headers = {'Icon': 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Revanced-logo-round.svg/240px-Revanced-logo-round.svg.png',
'Title': encoded_title}
'Title': encoded_title}
try:
req.post(f"{url}/{topic}", msg, headers=headers)
except Exception as e:
@ -89,7 +91,7 @@ def send_notif(appstate, error=False):
if line_utf:
print(line_utf)
except Exception as e:
clean_exit(f"Failed!\n{e}", appstate)
err_exit(f"Failed!\n{e}", appstate)
else:
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.JAVABuilder import build_apps
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
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']
latest_ver = Version(data)
except req.exceptions.RequestException as e:
clean_exit(e, appstate)
err_exit(e, appstate)
try:
present_ver = Version(appstate['present_vers']['VancedMicroG'])
@ -124,7 +124,7 @@ except:
flag = 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['microg_updated'] = False
@ -137,7 +137,7 @@ try:
appstate['build_config']=cp.ConfigParser()
appstate['build_config'].read_file(open('build_config', 'r'))
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'].read('notification_config')
@ -146,7 +146,7 @@ appstate['notification_config'].read('notification_config')
try:
tools = req.get('https://releases.revanced.app/tools').json()['tools']
except req.exceptions.RequestException as e:
clean_exit(e, appstate)
err_exit(e, appstate)
try:
with open('versions.json', 'r') as f: