-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
77 lines (60 loc) · 2.06 KB
/
run.py
File metadata and controls
77 lines (60 loc) · 2.06 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import yaml
import urllib.request
from waitress import serve
from os import mkdir
from os.path import exists
from sys import argv
no_update = [ "-o", "--no-updates"]
path_flag = ["-f", "--folder"]
def update():
with urllib.request.urlopen('https://raw.githubusercontent.com/medowic/filelink/master/version/version.data') as response:
version_main = response.read().decode('utf-8')
version_main = version_main.strip()
with open(f"version/version.data", "r", encoding="utf-8") as file:
version_main_local = file.read()
version_main_local = version_main_local.strip()
if not version_main_local == version_main:
print(f"\nNew version of Filelink available ({version_main}) [current: {version_main_local}]")
print("You can download it from https://github.com/medowic/filelink")
with open("config/config.yaml", "r", encoding="utf-8") as file:
cfg = yaml.load(file, Loader=yaml.SafeLoader)
host = str(cfg["server"]["address"])
port = int(cfg["server"]["port"])
if not exists("tmp"):
mkdir("tmp")
for flag in path_flag:
if flag in argv:
path_index = argv.index(flag) + 1
try:
path = str(argv[path_index])
except IndexError:
path_set = False
else:
path_set = True
break
else: path_set = False
if not path_set:
try:
path = str(cfg["custom"]["path"])
except (KeyError, TypeError):
path = "files"
with open("tmp/path.tmp", "w", encoding="utf-8") as file:
file.write(path)
for flag in no_update:
if flag in argv:
is_update = False
break
else: is_update = True
if is_update:
update()
print("\nFilelink Server\n")
print("Debug:")
if host == "0.0.0.0":
print(f" * Running on all addresses ({host})")
print(f" * Running on http://127.0.0.1:{port}")
else:
print(f" * Running on http://{host}:{port}")
print("\nConfiguration:")
print(f" * Folder: {path}")
from main import app
serve(app, host=host, port=port)