add basic backup alias
This commit is contained in:
parent
067ab48de0
commit
44555fc84e
1 changed files with 57 additions and 12 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import lib
|
||||||
source ~/xsh/functions.xsh
|
source ~/xsh/functions.xsh
|
||||||
|
|
||||||
def _debug():
|
def _debug():
|
||||||
|
@ -41,19 +42,60 @@ def _bwc(args: list):
|
||||||
else:
|
else:
|
||||||
print(f"copied {i}")
|
print(f"copied {i}")
|
||||||
|
|
||||||
def _mcrcon(args: list):
|
def _backup(args: list):
|
||||||
if p"~/.mcrcon".exists():
|
from pathlib import Path
|
||||||
source "~/.mcrcon"
|
target_path = Path(args[0])
|
||||||
else:
|
max_backup_count: int = 3
|
||||||
raise FileNotFoundError("~/.mcrcon")
|
if len(args) == 2 and isinstance(args[1], int):
|
||||||
$(mcrcon @(" ".join(args)))
|
max_backup_count = int(args[1])
|
||||||
|
bm = lib.BackupManager(target_path)
|
||||||
|
bm.create_backup()
|
||||||
|
bm.delete_excess_backups(max_backup_count)
|
||||||
|
|
||||||
def _mcterm():
|
def _mcrcon(args: list):
|
||||||
if p"~/.mcrcon".exists():
|
import json
|
||||||
source "~/.mcrcon"
|
try:
|
||||||
else:
|
with p"~/.mcrcon.json".open("r") as fp:
|
||||||
raise FileNotFoundError("~/.mcrcon")
|
servers_data = json.load(fp)
|
||||||
|
server_data = servers_data[args[0]]
|
||||||
|
$MCRCON_HOST = server_data["address"]
|
||||||
|
$MCRCON_PORT = server_data["port"]
|
||||||
|
$MCRCON_PASS = server_data["password"]
|
||||||
|
$(mcrcon @(" ".join(args[1:])))
|
||||||
|
except IndexError:
|
||||||
|
print("Please indicate which server to connect to.")
|
||||||
|
except KeyError:
|
||||||
|
print("Server configuration not found.")
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Server configuration file '.mcrcon.json' is not found.")
|
||||||
|
|
||||||
|
def _mcterm(args: list):
|
||||||
|
import json
|
||||||
|
try:
|
||||||
|
with p"~/.mcrcon.json".open("r") as fp:
|
||||||
|
servers_data = json.load(fp)
|
||||||
|
server_data = servers_data[args[0]]
|
||||||
|
$MCRCON_HOST = server_data["address"]
|
||||||
|
$MCRCON_PORT = server_data["port"]
|
||||||
|
$MCRCON_PASS = server_data["password"]
|
||||||
mcrcon -t
|
mcrcon -t
|
||||||
|
except IndexError:
|
||||||
|
print("Please indicate which server to connect to.")
|
||||||
|
except KeyError:
|
||||||
|
print("Server configuration not found.")
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Server configuration file '.mcrcon.json' is not found.")
|
||||||
|
|
||||||
|
def _mclist():
|
||||||
|
import json
|
||||||
|
try:
|
||||||
|
with p"~/.mcrcon.json".open("r") as fp:
|
||||||
|
servers_data = json.load(fp)
|
||||||
|
print("Servers:")
|
||||||
|
for key in servers_data:
|
||||||
|
print("\t-", key)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Server configuration file '.mcrcon.json' is not found.")
|
||||||
|
|
||||||
def _alias():
|
def _alias():
|
||||||
for alias in aliases:
|
for alias in aliases:
|
||||||
|
@ -91,12 +133,15 @@ def _ls():
|
||||||
|
|
||||||
def load_aliases():
|
def load_aliases():
|
||||||
aliases.update({
|
aliases.update({
|
||||||
|
'bu': _backup,
|
||||||
|
'backup': _backup,
|
||||||
'bwg': _bwc,
|
'bwg': _bwc,
|
||||||
'colortest': _colortest,
|
'colortest': _colortest,
|
||||||
'debug': _debug,
|
'debug': _debug,
|
||||||
'ls': 'ls -alhs --color=auto',
|
'ls': 'ls -alhs --color=auto',
|
||||||
'mc': _mcrcon,
|
'mc': _mcrcon,
|
||||||
'mct': _mcterm,
|
'mct': _mcterm,
|
||||||
|
'mcl': _mclist,
|
||||||
':q': 'exit',
|
':q': 'exit',
|
||||||
'ensure-tmux': _ensure_tmux,
|
'ensure-tmux': _ensure_tmux,
|
||||||
'aliases': _alias,
|
'aliases': _alias,
|
||||||
|
|
Loading…
Reference in a new issue