Update requirements.txt for refreshing JSON templates via a git fetch
The following code allows for templates to be refreshed by a NICOS script, which will be useful for instruments and so on with minimum interference:
from git import Repo
try:
from general_inst import get_nicos_inst as gnl
except ImportError:
import re
class Gnl:
"""In case we cannot import nicos-scripts"""
def __init__(self):
pass
def get_nicos_inst(self):
"""Method to fetch name from nicos.conf"""
with open("nicos.conf", encoding="utf-8") as f:
for line in f:
r = re.search(r'^instrument = "(.*)"', line)
if r is not None:
return r.group(1)
return "NONE"
gnl = Gnl()
repo = Repo("nexus-json-templates")
while True:
for inst, struct, sample in instruments:
repo.remotes.origin.fetch()
diff = repo.git.diff("origin/main", name_only=True)
if inst in diff:
repo.git.pull()
printwarning(
f"Updated JSON files: {diff}, on NICOS instance: {gnl.get_nicos_inst()}"
)
But for this to work the git module in python needs to be available from deployment.