Skip to content

Commit

Permalink
Add update_scripts method to automatically update scripts re-loading …
Browse files Browse the repository at this point in the history
…from its area
  • Loading branch information
vkuznet committed Nov 23, 2014
1 parent 5a3a008 commit ed88195
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/python/WMCore/ReqMgr/Web/ReqMgrService.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,10 @@ def __init__(self, app, config, mount):
yuidir = os.environ.get('YUI_ROOT', os.getcwd()+'/yui')
self.yuidir = web_config.get('yuidir', yuidir)
# read scripts area and initialize data-ops scripts
sdir = os.environ.get('RM_SCRIPTS', os.getcwd()+'/scripts')
self.sdict = {} # placeholder for data-ops scripts
for item in os.listdir(sdir):
with open(os.path.join(sdir, item), 'r') as istream:
self.sdict[item.split('.')[0]] = istream.read()
self.sdir = os.environ.get('RM_SCRIPTS', os.getcwd()+'/scripts')
self.sdict_thr = web_config.get('sdict_thr', 60) # put reasonable 10 min interval
self.sdict = {'ts':time.time()} # placeholder for data-ops scripts
self.update_scripts(force=True)

# To be filled at run time
self.cssmap = {}
Expand Down Expand Up @@ -269,6 +268,14 @@ def user_dn(self):
"""
return '/CN/bla/foo/'

def update_scripts(self, force=False):
"Update scripts dict"
if force or abs(time.time()-self.sdict['ts']) > self.sdict_thr:
for item in os.listdir(self.sdir):
with open(os.path.join(self.sdir, item), 'r') as istream:
self.sdict[item.split('.')[0]] = istream.read()
self.sdict['ts'] = time.time()

def abs_page(self, tmpl, content):
"""generate abstract page"""
menu = self.templatepage('menu', menus=menus(tmpl))
Expand Down Expand Up @@ -441,9 +448,10 @@ def create(self, **kwds):
return self.error(msg)

# create templatized page out of provided forms
self.update_scripts()
content = self.templatepage('create', table=json2table(jsondata, web_ui_names()),
jsondata=json.dumps(jsondata, indent=2), name=req_form,
scripts=self.sdict.keys())
scripts=[s for s in self.sdict.keys() if s!='ts'])
return self.abs_page('generic', content)

@expose
Expand All @@ -459,6 +467,7 @@ def genobjs(jsondict):
mydict.update({'myfield': item})
yield mydict
"""
self.update_scripts()
value = self.sdict.get(name, default)
return value

Expand Down

0 comments on commit ed88195

Please sign in to comment.