Hong Minhee avatar Hong Minhee committed e9c82a8

Show log size

Comments (0)

Files changed (3)

irclog/archive.py

 """
 import re
 import glob
+import os.path
 import functools
 import datetime
 try:
         """The tomorrow log of the same channel."""
         return self.channel[self.date + datetime.timedelta(days=1)]
 
+    @property
+    def filename(self):
+        """The filename of the log.  If not exists, it could be ``None``."""
+        replacers = dict(self.channel.pattern_replacers)
+        replacers["date"] = self.channel.encode_element_key(self.date)
+        files = self.pattern.glob(**replacers)
+        if files:
+            return files[0]
+
+    @property
+    def file_size(self):
+        """The size of the log file in bytes."""
+        filename = self.filename
+        if filename:
+            return os.path.getsize(filename)
+        return 0
+
     def is_logged(self):
         """Returns ``True`` if the channel of the day has logged.
 
         :returns: ``True`` or ``False``
 
         """
-        replacers = dict(self.channel.pattern_replacers)
-        replacers["date"] = self.channel.encode_element_key(self.date)
-        files = self.pattern.glob(**replacers)
-        return bool(files)
+        return bool(self.filename)
 
     def __eq__(self, other):
         return self.channel == other.channel and self.date == other.date
         return not (self == other)
 
     def __iter__(self):
-        replacers = dict(self.channel.pattern_replacers)
-        replacers["date"] = self.channel.encode_element_key(self.date)
-        files = self.pattern.glob(**replacers)
-        if not files:
+        filename = self.filename
+        if not filename:
             return
-        with open(files[0]) as file:
+        with open(filename) as file:
             for msg in irclog.parser.parse(file, self.date):
                 yield msg
 

irclog/web/templates/basic/log.html

       <ul>
         {% for channel in log.server %}
           {% if channel == log.channel %}
-            <li><strong>{{ channel }}</strong></li>
+            {% set this_log = log %}
           {% elif channel[log.date].is_logged() %}
-            <li><a href="{{ channel[log.date]|url }}">{{ channel }}</a></li>
+            {% set this_log = channel[log.date] %}
+          {% else %}
+            {% set this_log = None %}
+          {% endif %}
+          {% if this_log %}
+            <li>
+              {% if channel == log.channel %}
+                <strong>{{ channel }}</strong>
+              {% else %}
+                <a href="{{ this_log|url }}">{{ channel }}</a>
+              {% endif %}
+              <span style="background-color: rgba(0, 0, 0, 
+                {% if not this_log.is_logged() %}
+                  0
+                {%- elif this_log.file_size + 102400 > 524288-%}
+                  1.0
+                {%- else -%}
+                  {{ ((this_log.file_size + 102400) / 524288)|round(2) -}}
+                {%- endif -%}
+                );"
+                class="size">{{- this_log.file_size|filesizeformat -}}
+              <span>
+            </li>
           {% endif %}
         {% endfor %}
       </ul>

irclog/web/templates/basic/style.css

 aside div li { display: block; margin: 0; padding: 8px 8px 8px 25px;
                border-top: 1px #eee solid; color: gray; }
 aside div a { color: gray; text-decoration: none; }
+aside .channels .size { color: white; background-color: rgba(0, 0, 0, 0.3);
+                        font-family: Verdana, Tahoma, sans-serif;
+                        font-size: xx-small; border-radius: 5em;
+                        padding: 3px; display: block; float: right;
+                        text-align: center; }
 article { margin-left: 180px; line-height: 130%;
           border-left: 1px solid #ccc; display: block; }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.