-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
59 lines (49 loc) · 1.55 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import http.server
import uploadserver
import shutil
working_dir = 'working'
inputs_dir = os.path.join(working_dir, 'inputs')
outputs_dir = os.path.join(working_dir, 'outputs')
os.makedirs(working_dir, exist_ok=True)
os.makedirs(inputs_dir, exist_ok=True)
os.makedirs(outputs_dir, exist_ok=True)
def handle_uploads():
import subprocess
result = subprocess.run(['python', 'pixelization.py', '--input', working_dir, '--output', outputs_dir])
if result.returncode != 0:
print('Error processing images')
return
else:
print('Images processed')
# debug
# for file in os.listdir(unprocessed_dir):
# old_file = os.path.join(unprocessed_dir, file)
# new_file = os.path.join(outputs_dir, file)
# shutil.copy(old_file, new_file)
for file in os.listdir(working_dir):
old_file = os.path.join(working_dir, file)
if not os.path.isfile(old_file):
continue
new_file = os.path.join(inputs_dir, file)
os.rename(old_file, new_file)
class Args:
port = 8000
cgi = False
allow_replace = False
bind = None
directory = working_dir
theme = 'dark'
server_certificate = None
client_certificate = None
basic_auth = None
basic_auth_upload = None
uploadserver.args = Args()
old_receive_upload = uploadserver.receive_upload
def new_receive_upload(handler: http.server.BaseHTTPRequestHandler):
status, message = old_receive_upload(handler)
if status != http.HTTPStatus.BAD_REQUEST:
handle_uploads()
return status, message
uploadserver.receive_upload = new_receive_upload
uploadserver.serve_forever()