-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate.py
More file actions
executable file
·53 lines (39 loc) · 1.2 KB
/
update.py
File metadata and controls
executable file
·53 lines (39 loc) · 1.2 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
import os
import subprocess
import daemon
import locale
import config as global_config
def invoke_git(command, *args):
process = subprocess.Popen(["git", command] + list(args), stdout=subprocess.PIPE, stderr=None)
process.wait()
return process.communicate()[0].decode(locale.getpreferredencoding(False))
def git_latest_version():
all_tags = invoke_git("tag", "-l").split("\n")
version_tags = [tag for tag in all_tags if len(tag) > 0 and tag[0] == "v"]
version_tags.sort(reverse=True)
return version_tags[0]
def git_checkout(ref):
invoke_git("checkout", ref)
def git_stash(command="save"):
invoke_git("stash", command)
def git_fetch():
invoke_git("fetch", "--all", "--tags")
def compile(config):
subprocess.call([global_config.DM_INSTALL_PATH, config.dme])
def update_daemon(config):
original_dir = os.getcwd()
os.chdir(config.path)
config.run_hook("pre_update")
git_stash()
git_fetch()
try:
version = git_latest_version()
except IndexError:
print("Unable to locate latest version, aborting.")
return
print("Checking out version " + version)
git_checkout(version)
git_stash("pop")
config.run_hook("post_update")
compile(config)
os.chdir(original_dir)