forked from nonokangwei/Stable-Diffusion-on-GCP
/
user-watch.py
32 lines (26 loc) · 1.04 KB
/
user-watch.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
import json
import shutil
import requests
import time
import os
sdk_http_port = os.environ['AGONES_SDK_HTTP_PORT']
url = 'http://localhost:' + sdk_http_port + '/watch/gameserver'
time.sleep(30)
r = requests.get(url, stream=True)
if r.encoding is None:
r.encoding = 'utf-8'
for line in r.iter_lines(decode_unicode=True):
if line:
response = json.loads(line)
if "user" in response['result']['object_meta']['labels']:
print(response['result']['object_meta']['labels']['user'])
if os.path.isdir('/stable-diffusion-webui/outputs'):
shutil.rmtree('/stable-diffusion-webui/outputs')
src = '/result/' + response['result']['object_meta']['labels']['user'] + '/outputs'
if os.path.isdir(src):
os.symlink(src, '/stable-diffusion-webui/outputs', target_is_directory = True)
break
else :
os.makedirs(src)
os.symlink(src, '/stable-diffusion-webui/outputs', target_is_directory = True)
break