This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCERNdCacheTapeinfo.py
107 lines (76 loc) · 3.83 KB
/
CERNdCacheTapeinfo.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import hf
from sqlalchemy import INT, FLOAT, Column
from datetime import datetime, timedelta
class CERNdCacheTapeinfo(hf.module.ModuleBase):
config_keys = {
'used_tape': ('URL of the used tape input txt file', ''),
'total_tape': ('URL of the total tape input txt file', ''),
'used_disk': ('URL of the used disk input txt file', ''),
'total_disk': ('URL of the total disk input txt file', ''),
}
config_hint = ''
table_columns = [
Column('used_tape_size', FLOAT),
Column('used_tape_timestamp', INT),
Column('total_tape_size', FLOAT),
Column('used_disk_size', FLOAT),
Column('total_disk_size', FLOAT),
], []
def prepareAcquisition(self):
if 'used_tape' not in self.config: raise hf.exceptions.ConfigError('used_tape option not set')
self.used_tape = hf.downloadService.addDownload(self.config['used_tape'])
if 'total_tape' not in self.config: raise hf.exceptions.ConfigError('total_tape option not set')
self.total_tape = hf.downloadService.addDownload(self.config['total_tape'])
if 'used_disk' not in self.config: raise hf.exceptions.ConfigError('used_disk option not set')
self.used_disk = hf.downloadService.addDownload(self.config['used_disk'])
if 'total_disk' not in self.config: raise hf.exceptions.ConfigError('total_disk option not set')
self.total_disk = hf.downloadService.addDownload(self.config['total_disk'])
self.source_url = list(set((self.used_tape.getSourceUrl(),
self.total_tape.getSourceUrl(),
self.used_disk.getSourceUrl(),
self.total_disk.getSourceUrl())))
def extractData(self):
data = {'used_tape_size': 0.0,
'used_tape_timestamp': 0,
'total_tape_size': 0.0,
'used_disk_size': 0.0,
'total_disk_size': 0.0,
'status': 1.0}
used_tape_f=-99.0
for line in open(self.used_tape.getTmpPath()).readlines():
if "T1_DE_KIT" not in line:
continue
used_tape_f=float(line.split()[3])
data['used_tape_size'] = used_tape_f
total_tape_f=-99.0
used_tape_time=0
all_lines=open(self.total_tape.getTmpPath()).read()
for line in open(self.total_tape.getTmpPath()).readlines():
if "<td>cms </td><td>" not in line:
continue
total_tape_f=round(float(line.split()[2]),3)
#used_tape_time=datetime.strptime(line.split()[0]+" "+line.split()[1],'%Y-%m-%d %H:%M:%S')
end_str= all_lines.find("Update once per day at midnight")
start_str = all_lines.find("Data on Grid SEs as of")
date_string=all_lines[start_str:end_str].splitlines()[2]
used_tape_time=datetime.strptime(date_string,'%a %b %d %H:%M:%S %Z %Y')
# used_tape_time is given in CET, datetime(1970,1,1) in UTC. Therefore, 1 hour is substracted
total_seconds = int((used_tape_time - datetime(1970,1,1) - timedelta(hours=1)).total_seconds())
data['total_tape_size'] = total_tape_f
data['used_tape_timestamp'] = total_seconds
used_disk_f=-99.0
for line in open(self.used_disk.getTmpPath()).readlines():
if "T1_DE_KIT" not in line:
continue
used_disk_f=float(line.split()[3])
data['used_disk_size'] = used_disk_f
total_disk_f=-99.0
for line in open(self.total_disk.getTmpPath()).readlines():
if "T1_DE_KIT" not in line:
continue
total_disk_f=float(line.split()[3])
data['total_disk_size'] = total_disk_f
return data
def getTemplateData(self):
data = hf.module.ModuleBase.getTemplateData(self)
return data