forked from kivy/buildozer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |