diff --git a/.gitignore b/.gitignore index 0d20b6487c61e7d1bde93acf4a14b7a89083a16d..9923a656a7a2336dc839d6825f6b2919e01cf0f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +.remote_head_rev *.pyc diff --git a/mpcdf_common.py b/mpcdf_common.py index 79d4294fac63fdcfce4b7a09eb74ff08290c548d..8c52cf03a3fd07b82d660efc86c07e0fdd97252b 100644 --- a/mpcdf_common.py +++ b/mpcdf_common.py @@ -47,6 +47,46 @@ prjconf_start_marker = "# Autogenerated by osc mpcdf_setup_repos, do not edit ti prjconf_end_marker = "# End of autogenerated section\n" +def check_for_update(): + import os + import sys + import time + from subprocess import check_output + + if hasattr(sys.modules["mpcdf_common"], "checked_for_updates"): + return + else: + setattr(sys.modules["mpcdf_common"], "checked_for_updates", 1) + + 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() + + # 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: + 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) + + with open(rev_file, "rb") as fd: + server_rev = fd.read().strip() + if server_rev != local_rev: + print(file=sys.stderr) + print("Your plugin directory is out-of-date, new commits available on", url, file=sys.stderr) + print(file=sys.stderr) + + +check_for_update() + + def compiler_module(compiler_repo): return compiler_repo.replace("_", "/", 1).replace("_", ".")