Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env micropython
- import urequests
- import sys
- import os
- ARCHITECTURE_MAP = {
- "armv6l": "armv6",
- "armv7l": "armv7",
- "aarch64": "aarch64",
- "i686": "x86",
- "x86_64": "x86_64" if "ld-linux-x86-64.so.2" in os.listdir("/lib") else "x86"
- }
- bytes_to_mb = lambda size_in_bytes: size_in_bytes / (1024 * 1024)
- def GetRemoteTextFile(filename):
- response = urequests.get(f"{BuildMirror()}/tcz/{filename}")
- if response.status_code == 200:
- return response.text
- else:
- print(f"Error downloading file {filename}. Status code: {response.status_code}")
- sys.exit(1)
- def GetLocalTextFile(filename):
- try:
- with open(filename, "r") as f:
- content = f.read().strip()
- if not content:
- print(f"File {filename} is empty")
- sys.exit(1)
- return content
- except Exception as e:
- print(f"Error: {e}")
- sys.exit(1)
- def BuildMirror():
- mirror = GetLocalTextFile("/opt/tcemirror")
- version = GetLocalTextFile("/etc/os-release")
- version_lines = version.splitlines()
- for line in version_lines:
- if line.startswith("VERSION_ID="):
- version = line.split("=")[1].strip().split(".")[0] + ".x"
- break
- architecture = GetLocalTextFile("/proc/sys/kernel/arch")
- architecture = ARCHITECTURE_MAP.get(architecture)
- return f"{mirror}{version}/{architecture}"
- if len(sys.argv) < 2:
- print("Please enter the package name.")
- sys.exit(1)
- package = sys.argv[1]
- if not package.endswith(".tcz"):
- package += ".tcz"
- sizelist = GetRemoteTextFile("sizelist")
- packageTree = GetRemoteTextFile(f"{package}.tree")
- print(" Filename Size (bytes) Size (MB)")
- print("------------------------------------------------------------------")
- # Create a dictionary mapping the file name to its size in bytes
- size_dict = {line.split()[0]: int(line.split()[1]) for line in sizelist.splitlines()}
- # Print the results directly from the list comprehension
- print("\n".join(f"{filename:<40} {size_in_bytes:<13} {bytes_to_mb(size_in_bytes):<8.2f}" for filename, size_in_bytes in size_dict.items() if filename in packageTree))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement