-
Notifications
You must be signed in to change notification settings - Fork 44
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
11 changed files
with
499 additions
and
2 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
Empty file.
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,37 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
function build_start() | ||
{ | ||
# test_script $1 | ||
# if [ $? -ne 0 ]; then | ||
# echo "Error: $1 failed to execute." | ||
# exit 1 | ||
# fi | ||
cd $1 | ||
if [[ -f main.py ]]; then | ||
rm -rf dist | ||
maixtool release | ||
else | ||
maixcdk distclean | ||
maixcdk release -p maixcam | ||
fi | ||
mkdir -p ../apps | ||
cp -r dist/pack/* ../apps | ||
cd .. | ||
} | ||
|
||
rm -rf apps/ | ||
|
||
for dir in */; do | ||
if [ -d "$dir" ]; then | ||
if [[ "${dir}x" != "apps/x" ]]; then | ||
echo "----- build ${dir} -----" | ||
build_start "${dir%/}" | ||
echo "----- build ${dir} done -----" | ||
fi | ||
fi | ||
done | ||
|
||
|
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 @@ | ||
20240709 |
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,71 @@ | ||
import os | ||
import sys | ||
import requests | ||
import subprocess | ||
|
||
curr_dir = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
def get_release_image_url(tag_name): | ||
owner = "sipeed" | ||
repo = "LicheeRV-Nano-Build" | ||
url = f"https://api.github.com/repos/{owner}/{repo}/releases" | ||
|
||
# Make the request to the GitHub API | ||
response = requests.get(url) | ||
|
||
# Check if the request was successful | ||
if response.status_code == 200: | ||
releases = response.json() | ||
# Print the release information | ||
for release in releases: | ||
if release['tag_name'] == tag_name: | ||
for asset in release['assets']: | ||
if asset['name'].endswith(".img.xz"): | ||
return asset['browser_download_url'], asset['name'] | ||
else: | ||
raise Exception(f"Failed to retrieve releases: {response.status_code}") | ||
return None, None | ||
|
||
def download_file(url, output_path, force=False): | ||
save_dir = os.path.dirname(output_path) | ||
# Ensure the save directory exists | ||
if not os.path.exists(save_dir): | ||
os.makedirs(save_dir) | ||
if os.path.exists(output_path) and not force: | ||
print(f"-- file {os.path.basename(output_path)} already exists, skip download") | ||
return | ||
try: | ||
# Use subprocess to call wget | ||
subprocess.run( | ||
["wget", "--progress=dot:giga", "-O", output_path, url], | ||
check=True | ||
) | ||
print(f"Download completed: {output_path}") | ||
except subprocess.CalledProcessError as e: | ||
print(f"An error occurred: {e}") | ||
|
||
def get_base_image(file_path = ""): | ||
version_txt = os.path.join(curr_dir, "base_system_version.txt") | ||
with open(version_txt, "r") as f: | ||
version = f.readline().strip() | ||
url, filename = get_release_image_url(version) | ||
if not url: | ||
raise Exception("get base system image download url failed") | ||
print(f"-- download base system {filename} from url: {url}") | ||
if not file_path: | ||
file_path = os.path.join(curr_dir, "tmp", filename) | ||
download_file(url, file_path) | ||
return file_path | ||
|
||
|
||
if __name__ == "__main__": | ||
import argparse | ||
args_parser = argparse.ArgumentParser() | ||
args_parser.add_argument( | ||
"-o", "--out", help="download file path, default will save to tmp/***.img.xz", default="" | ||
) | ||
args = args_parser.parse_args() | ||
|
||
base_system_path = get_base_image(args.out) | ||
print(f"\n-- got base system: {base_system_path}") | ||
|
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,97 @@ | ||
import os | ||
import sys | ||
import requests | ||
import subprocess | ||
import tarfile | ||
import zipfile | ||
|
||
curr_dir = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
def get_release_builtin_files_url(): | ||
owner = "sipeed" | ||
repo = "MaixPy" | ||
url = f"https://api.github.com/repos/{owner}/{repo}/releases" | ||
|
||
# Make the request to the GitHub API | ||
response = requests.get(url) | ||
|
||
# Check if the request was successful | ||
if response.status_code == 200: | ||
releases = response.json() | ||
releases = sorted(releases, key=lambda x: x['created_at'], reverse=True) | ||
release = releases[0] | ||
for asset in release['assets']: | ||
if "builtin_files" in asset['name']: | ||
if (not asset['name'].endswith(".zip")) and ((not asset['name'].endswith(".tar.xz"))) and (not asset['name'].endswith(".xz")): | ||
raise Exception(f"bultin_files only support .zip, .tar.xz, .xz format, but found {asset['name']}") | ||
return asset['browser_download_url'], asset['name'] | ||
else: | ||
raise Exception(f"Failed to retrieve releases: {response.status_code}") | ||
return None, None | ||
|
||
def download_file(url, output_path, force=False): | ||
save_dir = os.path.dirname(output_path) | ||
# Ensure the save directory exists | ||
if not os.path.exists(save_dir): | ||
os.makedirs(save_dir) | ||
if os.path.exists(output_path) and not force: | ||
print(f"-- file {os.path.basename(output_path)} already exists, skip download") | ||
return | ||
try: | ||
# Use subprocess to call wget | ||
subprocess.run( | ||
["wget", "--progress=dot:giga", "-O", output_path, url], | ||
check=True | ||
) | ||
print(f"Download completed: {output_path}") | ||
except subprocess.CalledProcessError as e: | ||
print(f"An error occurred: {e}") | ||
|
||
def unzip(file_path, unzip_path): | ||
""" | ||
解压文件 | ||
支持 .xz .tar.xz .zip 格式 | ||
""" | ||
ext = os.path.splitext(file_path)[1] | ||
if ext not in [".xz", ".tar.xz", ".zip"]: | ||
raise Exception("file format not support unzip") | ||
if not os.path.exists(unzip_path): | ||
os.makedirs(unzip_path) | ||
|
||
if file_path.endswith('.tar.xz') or file_path.endswith('.xz'): | ||
with tarfile.open(file_path, 'r:xz') as tar: | ||
tar.extractall(path=unzip_path, filter='data') | ||
elif file_path.endswith('.zip'): | ||
with zipfile.ZipFile(file_path, 'r') as zip_ref: | ||
zip_ref.extractall(unzip_path) | ||
else: | ||
raise ValueError("Unsupported file format") | ||
|
||
def get_builtin_files(file_path = "", unzip_path=""): | ||
url, filename = get_release_builtin_files_url() | ||
if not url: | ||
raise Exception("get base system image download url failed") | ||
print(f"-- download os builtin files {filename} from url: {url}") | ||
if not file_path: | ||
file_path = os.path.join(curr_dir, "tmp", filename) | ||
download_file(url, file_path) | ||
if unzip_path: | ||
unzip(file_path, unzip_path) | ||
return unzip_path | ||
return file_path | ||
|
||
|
||
if __name__ == "__main__": | ||
import argparse | ||
args_parser = argparse.ArgumentParser() | ||
args_parser.add_argument( | ||
"-o", "--out", help="download file path, default will save to tmp/***.img.xz", default="", | ||
) | ||
args_parser.add_argument( | ||
"--unzip", help="directly unzip files to --out dir", type=str, default="", | ||
) | ||
args = args_parser.parse_args() | ||
|
||
os_builtin_files = get_builtin_files(args.out, args.unzip) | ||
print(f"\n-- got builtin files: {os_builtin_files}") | ||
|
Binary file not shown.
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,70 @@ | ||
''' | ||
Usage: python gen_app_info.py apps_dir | ||
''' | ||
import os | ||
import yaml | ||
import sys | ||
|
||
app_info_content = ''' | ||
[basic] | ||
version=1 | ||
''' | ||
|
||
if len(sys.argv) > 1: | ||
apps_dir = sys.argv[1] | ||
else: | ||
apps_dir = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
app_info_path = os.path.join(apps_dir, "app.info") | ||
|
||
high_priority_apps = [ | ||
"app_store", | ||
"settings" | ||
] | ||
|
||
apps_info = {} | ||
for name in os.listdir(apps_dir): | ||
app_info_str = "" | ||
app_dir = os.path.join(apps_dir, name) | ||
if not os.path.isdir(app_dir): | ||
continue | ||
app_yaml_path = os.path.join(app_dir, "app.yaml") | ||
with open(app_yaml_path, "r") as f: | ||
app_info = yaml.safe_load(f) | ||
if app_info["id"] == "launcher": | ||
continue | ||
app_info_str += f'[{app_info["id"]}]\n' | ||
valid_keys = ["name", "version", "icon", "author", "desc"] | ||
for k, v in app_info.items(): | ||
valid = False | ||
for valid_k in valid_keys: | ||
if k.startswith(valid_k): | ||
valid = True | ||
break | ||
if not valid: | ||
continue | ||
app_info_str += f'{k}={v}\n' | ||
if "main.py" in os.listdir(app_dir): | ||
exec_path = "main.py" | ||
else: | ||
exec_path = app_info["id"] | ||
app_info_str += f"exec={exec_path}\n" | ||
app_info_str += "\n" | ||
apps_info[app_info["id"]] = app_info_str | ||
|
||
for id in high_priority_apps: | ||
if id in apps_info: | ||
app_info_content += apps_info[id] | ||
|
||
li = [] | ||
for id, content in apps_info.items(): | ||
if id in high_priority_apps: | ||
continue | ||
li.append((id, content)) | ||
li = sorted(li, key=lambda x:x[0]) | ||
for id, content in li: | ||
app_info_content += content | ||
|
||
with open(app_info_path, "w", encoding="utf-8") as f: | ||
f.write(app_info_content) |
Oops, something went wrong.