Skip to content
Snippets Groups Projects
Commit 4dbf27ef authored by Jeremy Whiting's avatar Jeremy Whiting
Browse files

Implement find_hook from utils.c and use to run identify hook.

If unable to run devkit-1-identify just get hostname from OS.
parent 2a259454
No related branches found
No related tags found
1 merge request!1Rewrite devkit service in python.
......@@ -24,14 +24,74 @@
#SOFTWARE.
from http.server import BaseHTTPRequestHandler
import configparser
import json
import os
import platform
import socketserver
import subprocess
import urllib.parse
SERVICE_PORT = 32000
PACKAGE = "steamos-devkit-service"
DEVKIT_HOOKS_DIR = "/usr/share/steamos-devkit/hooks"
# root until config is loaded and told otherwise, etc.
entry_point_user = "root"
properties = {"key": "value"}
properties = {}
machine_name = ''
hook_dirs = []
use_default_hooks = True
global_config = configparser.ConfigParser()
global_config.read(["/etc/steamos-devkit/steamos-devkit.conf", "/usr/share/steamos-devkit/steamos-devkit.conf"])
def find_hook(hook_dirs, use_default_hooks, name):
# First see if it exists in the given paths.
for path in hook_dirs:
test_path = os.path.join(path, name)
if (os.path.exists(test_path) and os.access(test_path, os.X_OK)):
return test_path
if (not use_default_hooks):
print("Error: Unable to find hook for {} in hook directories\n".format(name))
return None
test_path = "/etc/{}/hooks/{}".format(PACKAGE, name)
if (os.path.exists(test_path) and os.access(test_path, os.X_OK)):
return test_path
test_path = "{}/{}".format(DEVKIT_HOOKS_DIR, name)
if (os.path.exists(test_path) and os.access(test_path, os.X_OK)):
return test_path
test_path = "{}/{}.sample".format(DEVKIT_HOOKS_DIR, name)
if (os.path.exists(test_path) and os.access(test_path, os.X_OK)):
return test_path
test_path = "{}/../hooks/{}".format(os.path.dirname(os.path.realpath(__file__)), name)
if (os.path.exists(test_path) and os.access(test_path, os.X_OK)):
return test_path
print("Error:: Unable to find hook for {} in /etc/{}/hooks or {}".format(name, PACKAGE, DEVKIT_HOOKS_DIR))
return None
# Run devkit-1-identify hook to get hostname, otherwise use default platform.node()
identify_hook = find_hook(hook_dirs, use_default_hooks, "devkit-1-identify")
if (identify_hook):
# Run hook and parse machine_name out
p = subprocess.Popen(identify_hook, shell=False, stdout=subprocess.PIPE)
output = ''
for line in p.stdout:
textline = line.decode(encoding='utf-8', errors="ignore")
output += textline
p.wait()
output_object = json.loads(output)
if ('machine_name' in output_object):
machine_name = output_object["machine_name"]
if not machine_name:
machine_name = platform.node()
class DevkitHandler(BaseHTTPRequestHandler):
def _send_headers(self, code, type):
......@@ -84,6 +144,7 @@ class DevkitService:
self.httpd = socketserver.TCPServer(("", self.port), DevkitHandler, bind_and_activate=False)
print("serving at port: {}".format(self.port))
print("machine name: {}".format(machine_name))
self.httpd.allow_reuse_address = True
self.httpd.server_bind()
self.httpd.server_activate()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment