OSDN Git Service

Some translation.
[karesansui/karesansui.git] / karesansui / lib / rrd / users.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # This file is part of Karesansui Core.
5 #
6 # Copyright (C) 2010 HDE, Inc.
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13
14 import re
15 import datetime
16 import rrdtool
17 import karesansui
18 from karesansui.lib.const import GRAPH_COMMON_PARAM, DEFAULT_LANGS
19 from karesansui.lib.utils import is_readable, generate_phrase
20
21 def create_users_graph(_, lang, graph_dir, rrd_dir, start, end, dev=None, type=None):
22     graph_filename = "%s.png" % (generate_phrase(12,'abcdefghijklmnopqrstuvwxyz'))
23     graph_filepath = "%s/%s" % (graph_dir, graph_filename)
24
25     rrd_filepath = ("%s/users/users.rrd" % (rrd_dir),
26                     )
27
28     for filepath in rrd_filepath:
29         if is_readable(filepath) is False:
30             return ""
31
32     legend_header_label = {"min":_('Min'),
33                            "max":_('Max'),
34                            "ave":_('Ave'),
35                            "last":_('Last'),
36                            }
37
38     for key in legend_header_label.keys():
39         if re.search(u"[^a-zA-Z0-9]", legend_header_label[key]):
40             legend_header_label[key] = "</tt>%s<tt>" % (legend_header_label[key].encode("utf-8"))
41         else:
42             legend_header_label[key] = "%s" % (legend_header_label[key].encode("utf-8"))
43
44     legend_header = "<tt>                 %s       %s       %s       %s</tt>" % (legend_header_label['min'],
45                                                                                 legend_header_label['max'],
46                                                                                 legend_header_label['ave'],
47                                                                                 legend_header_label['last']
48                                                                                 )
49     # TRANSLATORS:
50     #  ユーザ数のグラフのタイトル
51     title = _('Users Logged In')
52     if re.search(u"[^a-zA-Z0-9_\-\.]", title):
53         title = "%s" % (title.encode("utf-8"))
54     else:
55         title = "<tt>%s</tt>" % (title.encode("utf-8"))
56
57     created_label = _('Graph created')
58     if re.search(u"[^a-zA-Z0-9 ]", created_label):
59         created_label = "</tt>%s<tt>" % (created_label.encode("utf-8"))
60     else:
61         created_label = "%s" % (created_label.encode("utf-8"))
62
63     created_time = "%s" % (datetime.datetime.today().strftime(DEFAULT_LANGS[lang]['DATE_FORMAT'][1]))
64     created_time = re.sub(r':', '\:', created_time)
65
66     legend_footer = "<tt>%s \: %s</tt>" % (created_label, created_time)
67
68     data = rrdtool.graph(graph_filepath,
69                          GRAPH_COMMON_PARAM,
70                          "--title", title,
71                          # TRANSLATORS:
72                          #   ユーザ数のグラフの縦軸のラベル
73                          "--vertical-label", _('Users ').encode("utf-8"),
74                          "--start", start,
75                          "--end",  end,
76                          "--legend-direction", "bottomup",
77                          "DEF:users=%s:users:AVERAGE" % (rrd_filepath[0]),
78                          "COMMENT:%s\\r" % legend_footer,
79                          "COMMENT:<tt>---------------------------------------------------------------------------</tt>\\n",
80                          # TRANSLATORS:
81                          #   ユーザ数のグラフの凡例
82                          "AREA:users#80AA00:<tt>%s    </tt>" % (_('Users').encode("utf-8")),
83                          "GPRINT:users:MIN:<tt>%8.2lf</tt>",
84                          "GPRINT:users:MAX:<tt>%8.2lf</tt>",
85                          "GPRINT:users:AVERAGE:<tt>%8.2lf</tt>",
86                          "GPRINT:users:LAST:<tt>%8.2lf</tt>\\n",
87                          "COMMENT:%s\\n" % (legend_header),
88                          "COMMENT: \\n",
89                          )
90
91     return graph_filepath