-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get stok by login to luci and provide needed files by a local file se…
…rver (#113)
- Loading branch information
1 parent
d3a37d0
commit 95afeba
Showing
4 changed files
with
131 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
build/* | ||
build/* | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import socketserver | ||
import threading | ||
import time | ||
import sys | ||
|
||
class RequestHandler(socketserver.StreamRequestHandler): | ||
def handle(self): | ||
filename = self.rfile.readline().strip().decode('UTF-8') | ||
print("local file server is getting '{}' for {}.".format(filename, self.client_address[0])) | ||
with open("{}/{}".format(self.server.root_dir, filename), "rb") as f: | ||
self.wfile.write(f.read()) | ||
self.wfile.close() | ||
|
||
class TcpFileServer: | ||
def __init__(self, root_dir='.'): | ||
HOST, PORT = '', 0 | ||
self.server = socketserver.TCPServer((HOST, PORT), RequestHandler) | ||
self.server.root_dir = root_dir | ||
self.ip, self.port = self.server.server_address | ||
|
||
def __enter__(self): | ||
self.run() | ||
return self | ||
|
||
def run(self): | ||
self.server_thread = threading.Thread(target=self.server.serve_forever) | ||
self.server_thread.daemon = True | ||
self.server_thread.start() | ||
print("local file server is runing on {}:{}. root='{}'".format(self.ip, self.port, self.server.root_dir)) | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
self.server.shutdown() | ||
self.server.server_close() | ||
|
||
|
||
if __name__ == "__main__": | ||
root_dir = '.' if len(sys.argv) <= 1 else sys.argv[1] | ||
with TcpFileServer(root_dir): | ||
while True: | ||
time.sleep(10) |