-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgrid_helper_tasks.py
More file actions
34 lines (28 loc) · 1.09 KB
/
grid_helper_tasks.py
File metadata and controls
34 lines (28 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import law
import luigi
import os
import re
from .run_tools import ps_call
from .grid_tools import get_voms_proxy_info
class CreateVomsProxy(law.Task):
time_limit = luigi.Parameter(default='24')
def __init__(self, *args, **kwargs):
super(CreateVomsProxy, self).__init__(*args, **kwargs)
self.proxy_path = os.getenv("X509_USER_PROXY")
if os.path.exists(self.proxy_path):
proxy_info = get_voms_proxy_info()
timeleft = proxy_info.get('timeleft', 0.)
if timeleft < float(self.time_limit):
self.publish_message(f"Removing old proxy which expires in a less than {timeleft:.1f} hours.")
self.output().remove()
def output(self):
return law.LocalFileTarget(self.proxy_path)
def create_proxy(self, proxy_file):
self.publish_message("Creating voms proxy...")
proxy_file.makedirs()
ps_call(['voms-proxy-init', '-voms', 'cms', '-rfc', '-valid', '192:00', '--out', proxy_file.path])
def run(self):
proxy_file = self.output()
self.create_proxy(proxy_file)
if not proxy_file.exists():
raise RuntimeError("Unable to create voms proxy")