vaporizor commited on
Commit
6112997
·
1 Parent(s): c9407c0

Inital project

Browse files
Files changed (4) hide show
  1. .gitignore +4 -0
  2. Dockerfile +21 -0
  3. main.py +37 -0
  4. requirements.txt +0 -0
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ .DS_Store
2
+ minecraft-schematic-generator-linux
3
+ minecraft-schematic-generator-mac
4
+ minecraft-schematic-generator.exe
Dockerfile ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+ ENV PATH="/home/user/.local/bin:$PATH"
9
+
10
+ WORKDIR /app
11
+
12
+ # Kept for convenience if dependencies needed in the future
13
+ COPY --chown=user ./requirements.txt requirements.txt
14
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
15
+ COPY --chown=user . /app
16
+
17
+ USER root
18
+ RUN chown -R user /app && chmod -R 700 /app
19
+ USER user
20
+
21
+ CMD ["python", "main.py"]
main.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from os.path import exists
2
+ from platform import system
3
+ from subprocess import run, Popen, PIPE
4
+ from signal import signal, SIGINT
5
+ from urllib.request import urlretrieve
6
+
7
+
8
+ def download_server(file_name):
9
+ # Download server executable from mmmfrieddough's github releases
10
+ print("Downloading companion..")
11
+
12
+ # No error handling as we want program to halt if download fails
13
+ urlretrieve("https://github.com/mmmfrieddough/minecraft-schematic-generator/releases/latest/download/" + file_name, file_name)
14
+ if exists(file_name):
15
+ print(file_name + " downloaded succesfully!")
16
+ if system() != "Windows":
17
+ print("Setting executable permissions..")
18
+ run(["chmod", "+x", "./"+file_name])
19
+ else:
20
+ print("Failed to save companion to " + file_name)
21
+
22
+
23
+ file_name_map = {
24
+ "Linux": "-linux",
25
+ "Darwin": "-mac",
26
+ "Windows": ".exe"
27
+ }
28
+ file_name = "minecraft-schematic-generator" + file_name_map[system()]
29
+ if not exists(file_name):
30
+ download_server(file_name)
31
+
32
+ print("Starting companion..")
33
+ try:
34
+ backend = Popen(["./" + file_name, "--port", "7860"])
35
+ backend.wait()
36
+ except KeyboardInterrupt:
37
+ print("Exiting..")
requirements.txt ADDED
File without changes