def get_app_versions(app_id, page):
_, response = app.test_client.get('/apps/{}/versions/page/{}?t={}'.format(app_id, page, time.time()))
response_normal_check(response)
return response
python类app()的实例源码
def put_app_detail(app_id, name, short_chain, detail):
_, response = app.test_client.put('/apps/{}'.format(app_id),
data=ujson.dumps(dict(name=name, short_chain=short_chain, detail=detail)))
response_normal_check(response)
return response
def del_app_version(app_id, package_id):
_, response = app.test_client.delete('/apps/{}/versions/{}'.format(app_id, package_id))
response_normal_check(response)
return response
def make_shell_context():
return dict(app=app)
def client():
return testing.TestClient(app.app)
def main_menu():
while True:
clear()
menu_items = [
{"title": "Browse app library", "function": store},
{"title": "Update apps and libs", "function": update},
{"title": "Remove app", "function": remove}
]
option = dialogs.prompt_option(menu_items, none_text="Exit", text="What do you want to do?", title="TiLDA App Library")
if option:
option["function"]()
else:
return
def update():
clear()
connect()
with dialogs.WaitingMessage(text="Downloading full list of library files", title="TiLDA App Library") as message:
message.text="Downloading full list of library files"
master = http_client.get("http://api.badge.emfcamp.org/firmware/master-lib.json").raise_for_status().json()
libs_to_update = []
for lib, expected_hash in master.items():
if expected_hash != filesystem.calculate_hash("lib/" + lib):
libs_to_update.append({
"url": "http://api.badge.emfcamp.org/firmware/master/lib/" + lib,
"target": "lib/" + lib,
"expected_hash": expected_hash,
"title": lib
})
download_list(libs_to_update, message)
apps = get_local_apps()
for i, app in enumerate(apps):
message.text = "Updating app %s" % app
if app.fetch_api_information():
download_app(app, message)
dialogs.notice("Everything is up-to-date")
def store():
global apps_by_category
while True:
empty_local_app_cache()
clear()
connect()
with dialogs.WaitingMessage(text="Fetching app library...", title="TiLDA App Library"):
categories = get_public_app_categories()
category = dialogs.prompt_option(categories, text="Please select a category", select_text="Browse", none_text="Back")
if category:
store_category(category)
else:
return
def __init__(self, ip, port, agent_port, username, password, pub_key_auth, tools):
# Setup params
self._ip = ip
self._port = port
self._agent_port = agent_port
self._username = username
self._password = password
self._pub_key_auth = bool(pub_key_auth)
self._tools_local = tools
# Init related objects
self.app = App(self)
self.local_op = LocalOperations()
self.remote_op = RemoteOperations(self)
self.printer = Printer()
self.agent = NeedleAgent(self)
# ==================================================================================================================
# UTILS - USB
# ==================================================================================================================
def connect():
wifi.connect(
wait=True,
show_wait_message=True,
prompt_on_fail=True,
dialog_title='TiLDA App Library'
)
### VIEWS ###
def store_details(category, app):
clear()
empty_local_app_cache()
with dialogs.WaitingMessage(text="Fetching app information...", title="TiLDA App Library"):
app.fetch_api_information()
clear()
if dialogs.prompt_boolean(app.description, title = str(app), true_text = "Install", false_text="Back"):
install(app)
dialogs.notice("%s has been successfully installed" % app)
def remove():
clear()
app = dialogs.prompt_option(get_local_apps(), title="TiLDA App Library", text="Please select an app to remove", select_text="Remove", none_text="Back")
if app:
clear()
with dialogs.WaitingMessage(text="Removing %s\nPlease wait..." % app, title="TiLDA App Library"):
for file in os.listdir(app.folder_path):
os.remove(app.folder_path + "/" + file)
os.remove(app.folder_path)
remove()
def __init__(self, app):
self.app = App(app)
def initializeGL(self):
self.app = App()