Răsfoiți Sursa

Seperated PyServer from main repo

tobychui 4 ani în urmă
părinte
comite
e622c6fd28

+ 0 - 3
.gitignore

@@ -47,9 +47,6 @@ subservice/*
 !subservice/WsTTY/
 !subservice/WsTTY/*
 
-!subservice/PyServer
-!subservice/PyServer/*
-
 #Binary related
 build/*
 aroz_online.exe

+ 0 - 0
subservice/PyServer/.startscript


+ 0 - 14
subservice/PyServer/README.md

@@ -1,14 +0,0 @@
-# PyServer
-
-PyServer is a basic example showcasing the method for bridging Python written web application into ArozOS with a bash script and a few flag files.
-
-
-
-### Installation
-
-1. Create a new folder inside arozos/subservices named "PyServer"
-2. Drag and drop all the files into the newly created PyServer folder
-3. Restart arozos
-
-
-

+ 0 - 96
subservice/PyServer/main.py

@@ -1,96 +0,0 @@
-from http.server import BaseHTTPRequestHandler, HTTPServer
-import time
-import requests
-import sys
-import os
-
-arozRequestEndpoint = "http://localhost:8080/api/ajgi/interface"
-serverPort = 8000
-
-def getMime(filename):
-    ext = filename.split(".").pop()
-    if ext == "png" or ext == "jpg" or ext == "jpeg" or ext == "gif":
-        return "image/" + ext
-    elif ext == "html" or ext == "htm":
-        return "text/" + ext
-    
-    return "application/" + ext
-    
-def resolveVirtualPath(path, token):
-    # Create an AGI script to perform a specific operation on ArozOS
-    # For example, this script get the user's desktop path on host file system
-    script = ""
-    script += 'var abspath = decodeAbsoluteVirtualPath("' + path + '");'
-    script += 'sendResp(abspath);'
-    
-    # Put the script into the POST request payload
-    payload = {'script':script}
-    
-    # Post the script with the token to ArozOS
-    session = requests.Session()
-    resp = session.post(arozRequestEndpoint + "?token=" + token, data = payload)
-    print(resp.content.decode('UTF-8'))
-    
-    # Return as a simple JSON string (Replace \\ with / for Windows)
-    return '"' + str(resp.content.decode('UTF-8')).replace("\\", "/") + '"'
-
-class Router(BaseHTTPRequestHandler):
-    def do_GET(self):
-        # Get the request token and username from the request header
-        username = self.headers.get('aouser') # This is the username of the requesting user
-        token = self.headers.get('aotoken') # This is the token for requesting ArozOS for futher file operation / information
-        
-        print("Req: " + self.path + " by " + username)
-        if self.path == "/":
-            self.path = "/index.html"
-        if self.path == "/api":
-            # Demo for getting information from the ArozOS AGI gateway
-            resp = resolveVirtualPath("user:/Desktop", token);
-            self.send_response(200)
-            self.send_header('Content-type',"application/json")
-            self.end_headers()
-            self.wfile.write(bytes(str(resp), "utf-8"))
-            return
-        if os.path.exists("web" + self.path):
-            # Serve the file
-            self.send_response(200)
-            self.send_header('Content-type',getMime(self.path))
-            self.end_headers()
-            f = open("web" + self.path, 'rb')
-            self.wfile.write(f.read())
-            f.close()
-            return
-        else:
-            self.send_response(404)
-            self.send_header("Content-type", "text/html")
-            self.wfile.write(bytes("404 Not Found", "utf-8"))
-            return
-        return
-        self.send_response(200)
-        self.send_header("Content-type", "text/html")
-        self.end_headers()
-        self.wfile.write(bytes("<html><head><title>https://pythonbasics.org</title></head>", "utf-8"))
-        self.wfile.write(bytes("<p>Request: %s</p>" % self.path, "utf-8"))
-        self.wfile.write(bytes("<body>", "utf-8"))
-        self.wfile.write(bytes("<p>This is an example web server.</p>", "utf-8"))
-        self.wfile.write(bytes("</body></html>", "utf-8"))
-
-if __name__ == "__main__":
-    # Parse the input from ArozOS
-    # ArozOS will pass in port and parent calling endpoint and parsed by the start.sh / start.bat
-    # print(sys.argv)
-    if (len(sys.argv) > 1):
-        serverPort = int(sys.argv[1][1:])
-        arozRequestEndpoint = sys.argv[2]
-    
-    
-    webServer = HTTPServer(("localhost", serverPort), Router)
-    print("PyServer started http://%s:%s" % ("localhost", serverPort))
-
-    try:
-        webServer.serve_forever()
-    except KeyboardInterrupt:
-        pass
-
-    webServer.server_close()
-    print("PyServer stopped.")

+ 0 - 15
subservice/PyServer/moduleInfo.json

@@ -1,15 +0,0 @@
-{
-    "Name": "PyServer",
-	"Desc": "A basic example for showing how to bridge Python web server to ArozOS",
-	"Group": "Development",
-	"IconPath": "PyServer/img/small_icon.png",
-	"Version": "1.0",
-	"StartDir": "PyServer/index.html",
-	"SupportFW": true,
-	"LaunchFWDir": "PyServer/index.html",
-	"InitFWSize": [475, 550],
-	"SupportEmb": true,
-	"LaunchEmb": "PyServer/embedded.html",
-	"InitEmbSize": [360, 240],
-	"SupportedExt": [".py"]
-}

+ 0 - 1
subservice/PyServer/start.bat

@@ -1 +0,0 @@
-python3 main.py %2 %4

+ 0 - 2
subservice/PyServer/start.sh

@@ -1,2 +0,0 @@
-#!/bin/bash
-python3 main.py %2 %4

BIN
subservice/PyServer/web/img/desktop_icon.png


BIN
subservice/PyServer/web/img/desktop_icon.psd


BIN
subservice/PyServer/web/img/small_icon.png


+ 0 - 44
subservice/PyServer/web/index.html

@@ -1,44 +0,0 @@
-<!DOCTYPE html>
-<html>
-    <head>
-        <meta name="apple-mobile-web-app-capable" content="yes" />
-        <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
-        <meta charset="UTF-8">
-        <meta name="theme-color" content="#4b75ff">
-        <link rel="stylesheet" href="../script/semantic/semantic.min.css">
-        <script src="../script/jquery.min.js"></script>
-        <script src="../script/ao_module.js"></script>
-        <script src="../script/semantic/semantic.min.js"></script>
-        <title>PyServer</title>
-        <style>
-            body{
-                background-color:white;
-            }
-        </style>
-    </head>
-    <body>
-        <br><br>
-        <div class="ui container">
-            <h2>Hello World!</h2>
-            <p>This is a Python written web server running inside ArozOS</p>
-			<p>Your Desktop folder path on the disk is: <span id="desktopPath">Loading...</span></p>
-			<p>For CSS Examples, see <a href="https://semantic-ui.com/">https://semantic-ui.com/</a></p>
-			<button class="ui blue button" onclick="openDesktop()"><i class="folder open icon"></i> Open Desktop</button>
-        </div>
-		<script>
-			//See arozos/web/script/ao_module.js for more floatWindow APIs
-			ao_module_setWindowTitle("PyServer - Example");
-			
-			function openDesktop(){
-				ao_module_openPath("user:/Desktop/");
-			}
-			
-			//This will request the /api endpoint from the Python Server
-			setTimeout(function(){
-				$.get("./api", function(data){
-					$("#desktopPath").text(data);
-				})
-			}, 1000);
-		</script>
-    </body>
-</html>