]> us-delaporte.pagekite.me Git - dotfiles.git/blob - invoke/luanti-local/tasks.py
Fix for 'git clone' echoing to stderr
[dotfiles.git] / invoke / luanti-local / tasks.py
1 from invoke import task
2
3 import datetime
4 import os
5
6 home = os.path.expanduser('~')
7 flat_pak_root = f"{home}/.var/app/net.minetest.Minetest"
8 root = f"{flat_pak_root}/.minetest"
9 mod_dir = f"{root}/mods"
10 easy_dir = f"{home}/minetest/"
11 run_mt = f"flatpak run net.minetest.Minetest"
12 world_dir = f"{root}/worlds"
13 scripts = f"{home}/ansible/luanti/remote"
14
15 # flatpak
16 link_to = f"{home}/.var/app/net.minetest.Minetest/.minetest"
17 # default
18 # link_to = f"{home}/.minetest/"
19
20 @task
21 def debug(c):
22 result = c.run('which minetest')
23 print(result.ok)
24
25 @task
26 def install(c):
27 print("Installing...")
28 # result = c.run('which minetest')
29 # if not(result.ok):
30 c.run("sudo apt install flatpak")
31 c.run("sudo apt install gnome-software-plugin-flatpak")
32 c.run("flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo")
33 c.run("flatpak install flathub net.minetest.Minetest -y")
34 result = c.run('which minetest')
35 print(f"MineTest installed at {result.stdout}")
36 print("To run: flatpak run net.minetest.Minetest")
37
38 @task
39 def restore_remote(c, dir):
40 if not os.path.isdir(dir):
41 print(f"No backups found at {dir}")
42 return
43 print(f"Will restore MineTest backup from {dir}")
44
45 world_folder = f"{home}/minetest/worlds"
46 c.run(f"mkdir -p {world_folder}")
47 print("Restoring backed up worlds...")
48 c.run(f"mv {dir}/* {world_folder}")
49 print("Finished")
50
51
52 @task
53 def status(c):
54 print(f"+ Minetest data assumed to be at {link_to}")
55 print(f"+ Easy folder assumed to be {easy_dir}")
56 print(f"+ ls ---")
57 c.run(f"ls -ald {link_to} | grep minetest")
58
59
60 @task
61 def games(c):
62 print(f"+ List Games ---")
63 cmd = f"{run_mt} --gameid list"
64 c.run(cmd)
65
66 @task
67 def play(c):
68 c.run(f"{run_mt}")
69
70 @task
71 def worlds(c):
72 print(f"+ List Worlds ---")
73 cmd = f"{run_mt} --gameid minetest --worldlist path"
74 c.run(cmd)
75
76
77 @task
78 def version(c):
79 cmd = f"{run_mt} --version"
80 c.run(cmd)
81
82 @task
83 def serve(c, world="SurfaceWorld"):
84 cmd = f"{run_mt} --gameid minetest --server --worldname {world}"
85 c.run(cmd)
86
87 @task
88 def bkmod(c, name=None):
89 '''Save the current set of mods and create an empty mod directory.'''
90 if not name:
91 name = datetime.datetime.now().strftime("%Y%h%d%H%M")
92 c.run(f"mv {mod_dir} {root}/mods_{name}")
93 c.run(f"mkdir -p {mod_dir}")
94 c.run(f"ls {root}")
95
96 @task
97 def rmod(c, name):
98 '''Restore a backed up set of mods.'''
99 if len(os.listdir(f"{mod_dir}")) != 0:
100 bk = datetime.datetime.now().strftime("%Y%h%d%H%M")
101 print(f"Backed up non-emtpy mod dir to mods_{bk}.")
102 c.run(f"mv {mod_dir} {root}/mods_{bk}")
103 else:
104 print("Removing empty mod dir.")
105 c.run(f"mkdir -p {mod_dir}")
106 c.run(f"mv {root}/mods_{name}/* {mod_dir}/")
107 print(f"mods_{name} restored to mods")
108 print("ls of root")
109 c.run(f"ls {root}")
110 print("ls of mods")
111 c.run(f"ls {root}/mods")
112
113 @task
114 def listmods(c):
115 print("ls of mods")
116 c.run(f"ls {root}/mods/")
117
118 @task
119 def logs(c, lines=20):
120 '''Output some logs'''
121 c.run(f"tail -n {lines} {root}/debug.txt")
122
123 @task
124 def backup_remote(c):
125 stopped = input("Is the server stopped?")
126 if(stopped != 'y'):
127 print("so go stop the server...")
128 exit()
129 print("okay...backing up.")
130 c.run(f"{scripts}/do_luanti.sh {scripts}/backup.sh")
131 c.run(f"{scripts}/check_db.sh")
132
133 def backup(c):
134 stopped = input("Is the server stopped?")
135 if(stopped != 'y'):
136 print("so go stop the server...")
137 exit()
138 print("okay...backing up.")
139 c.run(f"{scripts}/do_luanti.sh {scripts}/backup.sh")
140 c.run(f"{scripts}/check_db.sh")
141
142
143 @task
144 def checkdb(c):
145 c.run(f"{scripts}/check_db.sh")
146