forked from htj/lrmsurgen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlrms-ur-generator
executable file
·78 lines (57 loc) · 2.3 KB
/
lrms-ur-generator
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
#!/usr/bin/env python
#
# LRMS UR Generator executable.
#
# Module for the LRMS UR Generator module.
#
# Author: Henrik Thostrup Jensen <htj@ndgf.org>
# Copyright: Nordic Data Grid Facility (2009)
import os
import sys
import logging
from lrmsurgen import config
LOG_FORMAT = "%(asctime)s [%(levelname)s] %(message)s"
def main():
# start with command line parsing and various setups
parser = config.getParser()
options, args = parser.parse_args()
if not os.path.exists(options.config):
# we don't have logging yet
print 'Configuration file %s does not exist' % options.config
sys.exit(1)
cfg = config.getConfig(options.config)
logfile = options.logfile
if logfile is None:
logfile = config.getConfigValue(cfg, config.SECTION_COMMON, config.LOGFILE, config.DEFAULT_LOG_FILE)
logging.basicConfig(filename=logfile, format=LOG_FORMAT, level=logging.DEBUG)
hostname = config.getConfigValue(cfg, config.SECTION_COMMON, config.HOSTNAME)
if hostname is None:
import socket
hostname = socket.getfqdn()
user_map_file = config.getConfigValue(cfg, config.SECTION_COMMON, config.USERMAP, config.DEFAULT_USERMAP_FILE)
project_map_file = config.getConfigValue(cfg, config.SECTION_COMMON, config.PROJECTMAP, config.DEFAULT_PROJECTMAP_FILE)
# basic configuration done, read usermap+projectmap and start lrms ur module
try:
user_map = config.getUserMap(user_map_file)
except IOError:
logging.error('IOError while attempting to read user map at %s (missing file?)' % user_map_file)
user_map = {}
try:
project_map = config.getProjectMap(project_map_file)
except IOError:
logging.error('IOError while attempting to read project map at %s (missing file?)' % user_map_file)
project_map = {}
sections = cfg.sections()
if config.SECTION_MAUI in sections:
from lrmsurgen import maui as lrms
elif config.SECTION_TORQUE in sections:
from lrmsurgen import torque as lrms
# more LRMSes to come...
try:
lrms.generateUsageRecords(cfg, hostname, user_map, project_map)
except Exception, e:
logging.error('Got exception while generating usage records:')
logging.exception(e)
sys.exit(3)
if __name__ == '__main__':
main()