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():
import os
import sys
import time
from subprocess import check_output
from subprocess import check_output, call
if hasattr(sys.modules["mpcdf_common"], "checked_for_updates"):
return
......@@ -60,25 +60,41 @@ def check_for_update():
plugin_dir = os.path.dirname(os.path.realpath(__file__))
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
rev_file = os.path.join(plugin_dir, ".remote_head_rev")
try:
mtime = os.stat(rev_file).st_mtime
except FileNotFoundError:
except EnvironmentError:
mtime = 0
url = "https://gitlab.mpcdf.mpg.de/mpcdf/osc-plugins.git"
if time.time() - mtime > 86400:
server_rev, _ = check_output(["git", "ls-remote", url, "master"]).split(maxsplit=1)
with open(rev_file, "wb") as fd:
fd.write(server_rev)
update_server_rev()
with open(rev_file, "rb") as fd:
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:
# 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("Your plugin directory is out-of-date, new commits available on", url, 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