mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Added backup command
This commit is contained in:
parent
c99ccd0586
commit
01bf88f83d
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,7 +5,6 @@
|
||||
*.note
|
||||
*.xcf
|
||||
nohup.out
|
||||
*.egg-info
|
||||
|
||||
# currently not using
|
||||
/screenshot*.png
|
||||
|
@ -21,7 +21,7 @@ Also neat: You can use your **custom artist or track images**.
|
||||
|
||||
## Requirements
|
||||
|
||||
* Python 3
|
||||
* Python 3.5 or higher
|
||||
* Several Pip packages (automatically downloaded)
|
||||
* If you'd like to display images, you will need API keys for [Last.fm](https://www.last.fm/api/account/create) and [Fanart.tv](https://fanart.tv/get-an-api-key/). These are free of charge!
|
||||
|
||||
|
@ -7,7 +7,7 @@ author = {
|
||||
"email":"maloja@krateng.dev",
|
||||
"github": "krateng"
|
||||
}
|
||||
version = 2,0,7
|
||||
version = 2,0,8
|
||||
versionstr = ".".join(str(n) for n in version)
|
||||
|
||||
|
||||
|
@ -161,16 +161,51 @@ def loadlastfm(filename):
|
||||
def direct():
|
||||
from . import server
|
||||
|
||||
def backup(level="full"):
|
||||
import tarfile
|
||||
from datetime import date
|
||||
import glob
|
||||
|
||||
|
||||
@mainfunction({},shield=True)
|
||||
|
||||
user_files = {
|
||||
"minimal":[
|
||||
"rules/*.tsv",
|
||||
"scrobbles"
|
||||
],
|
||||
"full":[
|
||||
"clients/authenticated_machines.tsv",
|
||||
"images/artists",
|
||||
"images/tracks",
|
||||
"settings/settings.ini"
|
||||
]
|
||||
}
|
||||
|
||||
user_files = user_files["minimal"] if level == "minimal" else user_files["minimal"] + user_files["full"]
|
||||
real_files = []
|
||||
for g in user_files:
|
||||
real_files += glob.glob(g)
|
||||
|
||||
today = date.today()
|
||||
datestr = "-".join((str(today.year),str(today.month),str(today.day)))
|
||||
filename = "maloja_backup_" + datestr + ".tar.gz"
|
||||
archivefile = os.path.join(origpath,filename)
|
||||
assert not os.path.exists(archivefile)
|
||||
with tarfile.open(name=archivefile,mode="x:gz") as archive:
|
||||
for f in real_files:
|
||||
archive.add(f)
|
||||
|
||||
|
||||
|
||||
@mainfunction({"l":"level"},shield=True)
|
||||
def main(action,*args,**kwargs):
|
||||
actions = {
|
||||
"start":restart,
|
||||
"restart":restart,
|
||||
"stop":stop,
|
||||
"import":loadlastfm,
|
||||
"debug":direct
|
||||
"debug":direct,
|
||||
"backup":backup
|
||||
}
|
||||
if action in actions: actions[action](*args,**kwargs)
|
||||
else: print("Valid commands: " + " ".join(a for a in actions))
|
||||
|
Loading…
Reference in New Issue
Block a user