Skip to content

Commit

Permalink
Unzip test
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian-O committed Aug 31, 2023
1 parent ca206d5 commit 49d50a8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ jobs:
run: |
brew install automake
sudo ln -sfn /usr/local/opt/openssl /usr/local/ssl
- name: Unzip Test
run: |
ls -la
python3 scripts/unziptest.py
ls -la
- name: buildozer android debug
run: |
touch main.py
Expand Down
64 changes: 64 additions & 0 deletions buildozer/scripts/unziptest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import os
from os.path import join

from zipfile import ZipFile

from buildozer.buildops import download, cmd


def bash_cmd_case():
os.mkdir("test_bash_cmd")
os.chdir("test_bash_cmd")
download(
"https://dl.google.com/android/repository/android-ndk-r25b-linux.zip",
"test.zip",
)
cmd("unzip test.zip", show_output=True, env=os.environ)
os.chdir("..")


def python_library_case():
os.mkdir("test_pylib")
os.chdir("test_pylib")
download(
"https://dl.google.com/android/repository/android-ndk-r25b-linux.zip",
"test.zip",
)
with ZipFile("test.zip", "r") as compressed_file:
for file_info in compressed_file.infolist():
_extract_one_file_from_zip(
compressed_file,
file_info.filename,
file_info.external_attr,
os.getcwd(),
)
os.chdir("..")


def _extract_one_file_from_zip(
compressed_file, filename, external_attr, destination_dir
):
"""
Python's zipfile library does not preserve Unix file permissions
on extraction, so this function extracts one file and chmods it
appropriately.
On Windows platforms, the extra work has no effect.
"""
compressed_file.extract(filename, path=destination_dir)

# First 2 bytes of 4-byte value represent Unix permissions
permission = external_attr >> 16
os.chmod(join(destination_dir, filename), permission)


def compare():
bash_cmd_case()
python_library_case()
cmd(
["diff", "-r", "test_bash_cmd/", "test_pylib/"],
show_output=True,
env=os.environ,
)

compare()

0 comments on commit 49d50a8

Please sign in to comment.