Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
augustin_s
pier
Commits
37075b34
Commit
37075b34
authored
May 10, 2022
by
augustin_s
🐍
Browse files
added commandline args incl. script dir selection; handle ctrl+c
parent
f615daf2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
7 deletions
+36
-7
pier.py
pier.py
+36
-7
scripts/example1.py
scripts/example1.py
+0
-0
scripts/example2.py
scripts/example2.py
+0
-0
No files found.
pier.py
View file @
37075b34
#!/usr/bin/env python3
DIR
=
"."
HOST
=
"localhost"
PORT
=
9090
import
argparse
parser
=
argparse
.
ArgumentParser
(
description
=
"pier - Python Interpreter Executing Remotely"
,
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
parser
.
add_argument
(
"-d"
,
"--dir"
,
default
=
DIR
,
help
=
"directory containing python scripts"
)
parser
.
add_argument
(
"-H"
,
"--host"
,
default
=
HOST
,
help
=
"host name"
)
parser
.
add_argument
(
"-P"
,
"--port"
,
default
=
PORT
,
help
=
"port number"
,
type
=
int
)
clargs
=
parser
.
parse_args
()
from
contextlib
import
redirect_stdout
,
redirect_stderr
from
functools
import
lru_cache
from
glob
import
glob
from
io
import
StringIO
import
os
import
http.server
import
socketserver
HOST
=
"localhost"
PORT
=
9090
class
ScriptServer
(
http
.
server
.
SimpleHTTPRequestHandler
):
def
do_GET
(
self
):
...
...
@@ -71,10 +87,23 @@ def encode_html(*msg):
if
__name__
==
"__main__"
:
try
:
os
.
chdir
(
clargs
.
dir
)
except
Exception
as
e
:
tn
=
type
(
e
).
__name__
msg
=
f
"
{
tn
}
:
{
e
}
"
raise
SystemExit
(
msg
)
host
=
clargs
.
host
port
=
clargs
.
port
socketserver
.
TCPServer
.
allow_reuse_address
=
True
with
socketserver
.
ThreadingTCPServer
((
HOST
,
PORT
),
ScriptServer
)
as
httpd
:
print
(
f
"serving at
{
HOST
}
:
{
PORT
}
"
)
httpd
.
serve_forever
()
with
socketserver
.
ThreadingTCPServer
((
host
,
port
),
ScriptServer
)
as
httpd
:
print
(
f
"serving at
{
host
}
:
{
port
}
"
)
try
:
httpd
.
serve_forever
()
except
KeyboardInterrupt
:
print
()
example1.py
→
scripts/
example1.py
View file @
37075b34
File moved
example2.py
→
scripts/
example2.py
View file @
37075b34
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment