Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
SteamOS Devkit Service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
devkit
SteamOS Devkit Service
Commits
4dbf27ef
Commit
4dbf27ef
authored
3 years ago
by
Jeremy Whiting
Browse files
Options
Downloads
Patches
Plain Diff
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
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1
Rewrite devkit service in python.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/steamos-devkit-service.py
+62
-1
62 additions, 1 deletion
src/steamos-devkit-service.py
with
62 additions
and
1 deletion
src/steamos-devkit-service.py
+
62
−
1
View file @
4dbf27ef
...
@@ -24,14 +24,74 @@
...
@@ -24,14 +24,74 @@
#SOFTWARE.
#SOFTWARE.
from
http.server
import
BaseHTTPRequestHandler
from
http.server
import
BaseHTTPRequestHandler
import
configparser
import
json
import
json
import
os
import
platform
import
socketserver
import
socketserver
import
subprocess
import
urllib.parse
import
urllib.parse
SERVICE_PORT
=
32000
SERVICE_PORT
=
32000
PACKAGE
=
"
steamos-devkit-service
"
DEVKIT_HOOKS_DIR
=
"
/usr/share/steamos-devkit/hooks
"
# root until config is loaded and told otherwise, etc.
# root until config is loaded and told otherwise, etc.
entry_point_user
=
"
root
"
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
):
class
DevkitHandler
(
BaseHTTPRequestHandler
):
def
_send_headers
(
self
,
code
,
type
):
def
_send_headers
(
self
,
code
,
type
):
...
@@ -84,6 +144,7 @@ class DevkitService:
...
@@ -84,6 +144,7 @@ class DevkitService:
self
.
httpd
=
socketserver
.
TCPServer
((
""
,
self
.
port
),
DevkitHandler
,
bind_and_activate
=
False
)
self
.
httpd
=
socketserver
.
TCPServer
((
""
,
self
.
port
),
DevkitHandler
,
bind_and_activate
=
False
)
print
(
"
serving at port: {}
"
.
format
(
self
.
port
))
print
(
"
serving at port: {}
"
.
format
(
self
.
port
))
print
(
"
machine name: {}
"
.
format
(
machine_name
))
self
.
httpd
.
allow_reuse_address
=
True
self
.
httpd
.
allow_reuse_address
=
True
self
.
httpd
.
server_bind
()
self
.
httpd
.
server_bind
()
self
.
httpd
.
server_activate
()
self
.
httpd
.
server_activate
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment