Skip to content

Commit

Permalink
Use pathlib instead of os.path
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard20181 committed Sep 17, 2022
1 parent 08fbb8d commit 9968805
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 17 deletions.
3 changes: 2 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ echo "Extract WSA"
if [ -f "$WSA_ZIP_PATH" ]; then
WSA_WORK_ENV="${WORK_DIR:?}"/ENV
if [ -f "$WSA_WORK_ENV" ]; then rm -f "${WSA_WORK_ENV:?}"; fi
touch "$WSA_WORK_ENV"
export WSA_WORK_ENV
if ! python3 extractWSA.py "$ARCH" "$WSA_ZIP_PATH" "$WORK_DIR"; then
echo "Unzip WSA failed, is the download incomplete?"
Expand All @@ -351,8 +352,8 @@ else
echo "The WSA zip package does not exist, is the download incomplete?"
exit 1
fi
echo "Extract Magisk"

echo "Extract Magisk"
if [ -f "$MAGISK_PATH" ]; then
if ! python3 extractMagisk.py "$ARCH" "$MAGISK_PATH" "$WORK_DIR"; then
echo "Unzip Magisk failed, is the download incomplete?"
Expand Down
7 changes: 3 additions & 4 deletions scripts/extractMagisk.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@
import sys

import zipfile
import os
from pathlib import Path
import platform

is_x86_64 = platform.machine() in ("AMD64", "x86_64")
host_abi = "x64" if is_x86_64 else "arm64"
arch = sys.argv[1]
magisk_zip = sys.argv[2]
if not os.path.exists(Path.cwd().parent / sys.argv[3] / "magisk"):
os.makedirs(Path.cwd().parent / sys.argv[3] / "magisk")
workdir = Path.cwd().parent / sys.argv[3] / "magisk"
workdir = Path(sys.argv[3]) / "magisk"
if not Path(workdir).is_dir():
workdir.mkdir()

abi_map = {"x64": ["x86_64", "x86"], "arm64": ["arm64-v8a", "armeabi-v7a"]}

Expand Down
10 changes: 5 additions & 5 deletions scripts/extractWSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@

zip_name = ""
wsa_zip_path= Path(sys.argv[2]).resolve()
workdir = Path.cwd().parent / sys.argv[3] / "wsa"
if not os.path.exists(workdir):
os.makedirs(workdir)
workdir = Path(sys.argv[3]) / "wsa"
if not Path(workdir).is_dir():
workdir.mkdir()
with zipfile.ZipFile(wsa_zip_path) as zip:
for f in zip.filelist:
if arch in f.filename.lower():
zip_name = f.filename
output_name = zip_name[11:-5]
if not os.path.isfile(workdir / zip_name):
if not Path(workdir / zip_name).is_file():
zip_path = workdir / zip_name
print(f"unzipping to {workdir}", flush=True)
zip.extract(f, workdir)
Expand Down Expand Up @@ -67,6 +67,6 @@
g.filename = f'{name}.xml'
l.extract(g, workdir / 'xml')
with zipfile.ZipFile(zip_path) as zip:
if not os.path.isdir(workdir / arch):
if not Path(workdir / arch).is_dir():
print(f"unzipping from {zip_path}", flush=True)
zip.extractall(workdir / arch)
4 changes: 2 additions & 2 deletions scripts/fixGappsProp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

from __future__ import annotations
from io import TextIOWrapper
from os import system, path
from typing import OrderedDict
from pathlib import Path
import sys
class Prop(OrderedDict):
def __init__(self, file: TextIOWrapper) -> None:
Expand Down Expand Up @@ -61,7 +61,7 @@ def fingerprint(sec: str, p: Prop) -> str:


def fix_prop(sec, prop):
if not path.exists(prop):
if not Path(prop).is_file():
return

print(f"fixing {prop}", flush=True)
Expand Down
1 change: 0 additions & 1 deletion scripts/generateGappsLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import sys

import requests
import os
import json
import re
from pathlib import Path
Expand Down
1 change: 0 additions & 1 deletion scripts/generateMagiskLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import sys

import os
import json
import requests
from pathlib import Path
Expand Down
5 changes: 2 additions & 3 deletions scripts/generateWSALinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import html
import warnings
import re
import os
from pathlib import Path

warnings.filterwarnings("ignore")
Expand Down Expand Up @@ -81,8 +80,8 @@
with open(Path.cwd().parent / "xml/FE3FileUrl.xml", "r") as f:
file_content = f.read()

if not os.path.exists(download_dir):
os.makedirs(download_dir)
if not download_dir.is_dir():
download_dir.mkdir()
tmpdownlist = open(download_dir/tempScript, 'a')
for i, v, f in identities:
if re.match(f"Microsoft\.UI\.Xaml\..*_{arch}_.*\.appx", f):
Expand Down

0 comments on commit 9968805

Please sign in to comment.