Skip to content

Commit e9c4c64

Browse files
appstore: add unzip
1 parent 848420f commit e9c4c64

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

internal_filesystem/apps/com.example.appstore/assets/appstore.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,52 @@ def load_icon(url):
3434
print("Failed to download image: Status code", response.status_code)
3535
return None
3636

37+
import os
38+
try:
39+
import zipfile
40+
except ImportError:
41+
zipfile = None
42+
43+
def download_and_unzip(zip_url, dest_folder="/apps"):
44+
try:
45+
# Step 1: Download the .zip file
46+
print("Downloading .zip file from:", zip_url)
47+
response = urequests.get(zip_url, timeout=10)
48+
if response.status_code != 200:
49+
print("Download failed: Status code", response.status_code)
50+
response.close()
51+
return False
52+
# Save the .zip file to a temporary location
53+
temp_zip_path = f"{dest_folder}/temp.zip"
54+
print(f"Writing to temporary zip path: {temp_zip_path}")
55+
#if os.stat(temp_zip_path):
56+
# os.remove(temp_zip_path) # make sure it's gone
57+
with open(temp_zip_path, "wb") as f:
58+
f.write(response.content)
59+
response.close()
60+
print("Downloaded .zip file, size:", os.stat(temp_zip_path)[6], "bytes")
61+
# Step 2: Unzip the file
62+
if zipfile is None:
63+
print("Error: zipfile module not available in this MicroPython build")
64+
return False
65+
print("Unzipping it to:", dest_folder)
66+
os.stat(temp_zip_path)
67+
print(f"Stat says: {os.stat(temp_zip_path)}")
68+
with zipfile.ZipFile(temp_zip_path, "r") as zip_ref:
69+
zip_ref.extractall(dest_folder)
70+
print("Unzipped successfully")
71+
# Step 3: Clean up
72+
#if os.stat(temp_zip_path):
73+
os.remove(temp_zip_path) # make sure it's gone
74+
print("Removed temporary .zip file")
75+
return True
76+
except Exception as e:
77+
print("Operation failed:", str(e))
78+
return False
79+
finally:
80+
if 'response' in locals():
81+
response.close()
82+
3783

3884
def download_apps(json_url):
3985
global apps
@@ -121,7 +167,7 @@ def show_app_detail(app):
121167
detail_cont = lv.obj(headercont)
122168
detail_cont.set_style_pad_all(0, 0)
123169
detail_cont.set_flex_flow(lv.FLEX_FLOW.COLUMN)
124-
detail_cont.set_size(lv.pct(80), lv.SIZE_CONTENT)
170+
detail_cont.set_size(lv.pct(75), lv.SIZE_CONTENT)
125171
name_label = lv.label(detail_cont)
126172
name_label.set_text(app.name)
127173
name_label.set_style_text_font(lv.font_montserrat_24, 0)
@@ -131,7 +177,6 @@ def show_app_detail(app):
131177
#
132178
progress_bar = lv.bar(cont)
133179
progress_bar.set_width(lv.pct(100))
134-
#progress_bar.align(lv.ALIGN.BOTTOM_MID, 0, -50)
135180
progress_bar.set_range(0, 100)
136181
progress_bar.set_value(50, lv.ANIM.OFF)
137182
install_button = lv.button(cont)

internal_filesystem/lib/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ This /lib folder contains:
22
- https://github.com/echo-lalia/qmi8658-micropython/blob/main/qmi8685.py but given the correct name "qmi8658.py"
33
- traceback.mpy from https://github.com/micropython/micropython-lib
44
- https://github.com/glenn20/micropython-esp32-ota/ installed with import mip; mip.install('github:glenn20/micropython-esp32-ota/mip/ota')
5+
- mip.install('github:jonnor/micropython-zipfile')
56

0 commit comments

Comments
 (0)