]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
replace TIME_FORMAT constant with format_time func 222/head
authorLeif Ryge <leif@synthesize.us>
Mon, 4 Jan 2016 16:00:59 +0000 (16:00 +0000)
committerLeif Ryge <leif@synthesize.us>
Mon, 4 Jan 2016 16:10:37 +0000 (16:10 +0000)
This is for #1077 but does not resolve it as this does (should) not actually
change any HTML output. It is just a cleanup.

src/allmydata/util/time_format.py
src/allmydata/web/common.py
src/allmydata/web/introweb.py
src/allmydata/web/root.py
src/allmydata/web/status.py

index 0f8f2f387dd89735e25ae208e8e6064851fd6878..f159ebec3e3c5963ef35dad3af3912356485f6b0 100644 (file)
@@ -3,6 +3,9 @@
 
 import calendar, datetime, re, time
 
+def format_time(t):
+    return time.strftime("%H:%M:%S %d-%b-%Y", t)
+
 def iso_utc_date(now=None, t=time.time):
     if now is None:
         now = t()
index 52fed6a04be4c0002a52acc7e546380b5abfe5d4..f4229bb24dad1632f07841ada78c97b79e70faba 100644 (file)
@@ -16,8 +16,6 @@ from allmydata.util import abbreviate
 from allmydata.util.encodingutil import to_str, quote_output
 
 
-TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
-
 def get_filenode_metadata(filenode):
     metadata = {'mutable': filenode.is_mutable()}
     if metadata['mutable']:
index 6287af63131351a15bcbf3ee1fd118c9b18aafd8..d8e420d019e5519cf4fda60fa864ef9d5744cff2 100644 (file)
@@ -7,7 +7,8 @@ import allmydata
 import simplejson
 from allmydata import get_package_versions_string
 from allmydata.util import idlib
-from allmydata.web.common import getxmlfile, get_arg, TIME_FORMAT
+from allmydata.util.time_format import format_time
+from allmydata.web.common import getxmlfile, get_arg
 
 
 class IntroducerRoot(rend.Page):
@@ -53,7 +54,7 @@ class IntroducerRoot(rend.Page):
 
     # FIXME: This code is duplicated in root.py and introweb.py.
     def data_rendered_at(self, ctx, data):
-        return time.strftime(TIME_FORMAT, time.localtime())
+        return format_time(time.localtime())
     def data_version(self, ctx, data):
         return get_package_versions_string()
     def data_import_path(self, ctx, data):
index 8a9969c610f43a18097a8e904a3a19e35afa99d2..06c6d5b409c1219854f442b1659938dd8567eade 100644 (file)
@@ -10,11 +10,12 @@ from nevow.util import resource_filename
 import allmydata # to display import path
 from allmydata import get_package_versions_string
 from allmydata.util import log
+from allmydata.util.time_format import format_time
 from allmydata.interfaces import IFileNode
 from allmydata.web import filenode, directory, unlinked, status, operations
 from allmydata.web import storage
 from allmydata.web.common import abbreviate_size, getxmlfile, WebError, \
-     get_arg, RenderMixin, get_format, get_mutable_type, TIME_FORMAT
+     get_arg, RenderMixin, get_format, get_mutable_type
 
 
 class URIHandler(RenderMixin, rend.Page):
@@ -171,7 +172,7 @@ class Root(rend.Page):
 
     # FIXME: This code is duplicated in root.py and introweb.py.
     def data_rendered_at(self, ctx, data):
-        return time.strftime(TIME_FORMAT, time.localtime())
+        return format_time(time.localtime())
     def data_version(self, ctx, data):
         return get_package_versions_string()
     def data_import_path(self, ctx, data):
@@ -309,10 +310,8 @@ class Root(rend.Page):
         ctx.fillSlots("connected", connected)
         ctx.fillSlots("connected_alt", self._connectedalts[connected])
         ctx.fillSlots("connected-bool", bool(rhost))
-        ctx.fillSlots("since", time.strftime(TIME_FORMAT,
-                                             time.localtime(since)))
-        ctx.fillSlots("announced", time.strftime(TIME_FORMAT,
-                                                 time.localtime(announced)))
+        ctx.fillSlots("since", format_time(time.localtime(since)))
+        ctx.fillSlots("announced", format_time(time.localtime(announced)))
         ctx.fillSlots("version", version)
         ctx.fillSlots("service_name", service_name)
         ctx.fillSlots("available_space", available_space)
index b363f857c50e04327b1345d24406bd7af685d8ca..0da799116b79e4952baf36e188685ff6caa2a067 100644 (file)
@@ -4,6 +4,7 @@ import simplejson
 from twisted.internet import defer
 from nevow import rend, inevow, tags as T
 from allmydata.util import base32, idlib
+from allmydata.util.time_format import format_time
 from allmydata.web.common import getxmlfile, get_arg, \
      abbreviate_time, abbreviate_rate, abbreviate_size, plural, compute_rate
 from allmydata.interfaces import IUploadStatus, IDownloadStatus, \
@@ -162,9 +163,7 @@ class UploadStatusPage(UploadResultsRendererMixin, rend.Page):
         return d
 
     def render_started(self, ctx, data):
-        TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
-        started_s = time.strftime(TIME_FORMAT,
-                                  time.localtime(data.get_started()))
+        started_s = format_time(time.localtime(data.get_started()))
         return started_s
 
     def render_si(self, ctx, data):
@@ -614,9 +613,7 @@ class DownloadStatusPage(DownloadResultsRendererMixin, rend.Page):
         return d
 
     def render_started(self, ctx, data):
-        TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
-        started_s = time.strftime(TIME_FORMAT,
-                                  time.localtime(data.get_started()))
+        started_s = format_time(time.localtime(data.get_started()))
         return started_s + " (%s)" % data.get_started()
 
     def render_si(self, ctx, data):
@@ -647,9 +644,7 @@ class DownloadStatusTimelinePage(rend.Page):
     docFactory = getxmlfile("download-status-timeline.xhtml")
 
     def render_started(self, ctx, data):
-        TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
-        started_s = time.strftime(TIME_FORMAT,
-                                  time.localtime(data.get_started()))
+        started_s = format_time(time.localtime(data.get_started()))
         return started_s + " (%s)" % data.get_started()
 
     def render_si(self, ctx, data):
@@ -684,9 +679,7 @@ class RetrieveStatusPage(rend.Page, RateAndTimeMixin):
         self.retrieve_status = data
 
     def render_started(self, ctx, data):
-        TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
-        started_s = time.strftime(TIME_FORMAT,
-                                  time.localtime(data.get_started()))
+        started_s = format_time(time.localtime(data.get_started()))
         return started_s
 
     def render_si(self, ctx, data):
@@ -772,9 +765,7 @@ class PublishStatusPage(rend.Page, RateAndTimeMixin):
         self.publish_status = data
 
     def render_started(self, ctx, data):
-        TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
-        started_s = time.strftime(TIME_FORMAT,
-                                  time.localtime(data.get_started()))
+        started_s = format_time(time.localtime(data.get_started()))
         return started_s
 
     def render_si(self, ctx, data):
@@ -883,18 +874,14 @@ class MapupdateStatusPage(rend.Page, RateAndTimeMixin):
         self.update_status = data
 
     def render_started(self, ctx, data):
-        TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
-        started_s = time.strftime(TIME_FORMAT,
-                                  time.localtime(data.get_started()))
+        started_s = format_time(time.localtime(data.get_started()))
         return started_s
 
     def render_finished(self, ctx, data):
         when = data.get_finished()
         if not when:
             return "not yet"
-        TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
-        started_s = time.strftime(TIME_FORMAT,
-                                  time.localtime(data.get_finished()))
+        started_s = format_time(time.localtime(data.get_finished()))
         return started_s
 
     def render_si(self, ctx, data):
@@ -1110,9 +1097,7 @@ class Status(rend.Page):
     def render_row(self, ctx, data):
         s = data
 
-        TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
-        started_s = time.strftime(TIME_FORMAT,
-                                  time.localtime(s.get_started()))
+        started_s = format_time(time.localtime(s.get_started()))
         ctx.fillSlots("started", started_s)
 
         si_s = base32.b2a_or_none(s.get_storage_index())