Commit d5f0620d authored by Lorenz Huedepohl's avatar Lorenz Huedepohl
Browse files

Fix update notifications

* Python 2 incompatibility
* Handle actual update, .remote_head_rev needs to be updated
  in that case
parent 5cb4cd33
Pipeline #67010 passed with stage
in 13 seconds
...@@ -51,7 +51,7 @@ def check_for_update(): ...@@ -51,7 +51,7 @@ def check_for_update():
import os import os
import sys import sys
import time import time
from subprocess import check_output from subprocess import check_output, call
if hasattr(sys.modules["mpcdf_common"], "checked_for_updates"): if hasattr(sys.modules["mpcdf_common"], "checked_for_updates"):
return return
...@@ -60,25 +60,41 @@ def check_for_update(): ...@@ -60,25 +60,41 @@ def check_for_update():
plugin_dir = os.path.dirname(os.path.realpath(__file__)) plugin_dir = os.path.dirname(os.path.realpath(__file__))
git_dir = os.path.join(plugin_dir, ".git") git_dir = os.path.join(plugin_dir, ".git")
local_rev = check_output(["git", "--git-dir", git_dir, "rev-parse", "HEAD"]).strip() local_rev = check_output(["git", "--git-dir", git_dir, "rev-parse", "HEAD"], encoding="utf-8").strip()
url = "https://gitlab.mpcdf.mpg.de/mpcdf/osc-plugins.git"
def update_server_rev():
server_rev, _ = check_output(["git", "ls-remote", url, "master"], encoding="utf-8").split(maxsplit=1)
with open(rev_file, "w") as fd:
fd.write(server_rev)
# Check for update on server just once a day # Check for update on server just once a day
rev_file = os.path.join(plugin_dir, ".remote_head_rev") rev_file = os.path.join(plugin_dir, ".remote_head_rev")
try: try:
mtime = os.stat(rev_file).st_mtime mtime = os.stat(rev_file).st_mtime
except FileNotFoundError: except EnvironmentError:
mtime = 0 mtime = 0
url = "https://gitlab.mpcdf.mpg.de/mpcdf/osc-plugins.git"
if time.time() - mtime > 86400: if time.time() - mtime > 86400:
server_rev, _ = check_output(["git", "ls-remote", url, "master"]).split(maxsplit=1) update_server_rev()
with open(rev_file, "wb") as fd:
fd.write(server_rev)
with open(rev_file, "rb") as fd: with open(rev_file, "r") as fd:
server_rev = fd.read().strip() server_rev = fd.read().strip()
if server_rev != local_rev:
if call(["git", "--git-dir", git_dir, "merge-base", "--is-ancestor", server_rev, "HEAD"]) == 0:
# Server rev is older than ours. Check again
update_server_rev()
with open(rev_file, "r") as fd:
server_rev = fd.read().strip()
if server_rev != local_rev:
if call(["git", "--git-dir", git_dir, "merge-base", "--is-ancestor", server_rev, "HEAD"]) == 0:
print(file=sys.stderr)
print("You have unpushed commits in", plugin_dir, "- consider pushing them", file=sys.stderr)
print(file=sys.stderr)
else:
print(file=sys.stderr) print(file=sys.stderr)
print("Your plugin directory is out-of-date, new commits available on", url, file=sys.stderr) print("Your plugin directory is out-of-date, new commits available on", url, file=sys.stderr)
print(file=sys.stderr) print(file=sys.stderr)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment