From: Leif Ryge Date: Mon, 4 Jan 2016 16:00:59 +0000 (+0000) Subject: replace TIME_FORMAT constant with format_time func X-Git-Url: https://git.rkrishnan.org/vdrive/README.win32?a=commitdiff_plain;h=refs%2Fpull%2F222%2Fhead;p=tahoe-lafs%2Ftahoe-lafs.git replace TIME_FORMAT constant with format_time func This is for #1077 but does not resolve it as this does (should) not actually change any HTML output. It is just a cleanup. --- diff --git a/src/allmydata/util/time_format.py b/src/allmydata/util/time_format.py index 0f8f2f38..f159ebec 100644 --- a/src/allmydata/util/time_format.py +++ b/src/allmydata/util/time_format.py @@ -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() diff --git a/src/allmydata/web/common.py b/src/allmydata/web/common.py index 52fed6a0..f4229bb2 100644 --- a/src/allmydata/web/common.py +++ b/src/allmydata/web/common.py @@ -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']: diff --git a/src/allmydata/web/introweb.py b/src/allmydata/web/introweb.py index 6287af63..d8e420d0 100644 --- a/src/allmydata/web/introweb.py +++ b/src/allmydata/web/introweb.py @@ -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): diff --git a/src/allmydata/web/root.py b/src/allmydata/web/root.py index 8a9969c6..06c6d5b4 100644 --- a/src/allmydata/web/root.py +++ b/src/allmydata/web/root.py @@ -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) diff --git a/src/allmydata/web/status.py b/src/allmydata/web/status.py index b363f857..0da79911 100644 --- a/src/allmydata/web/status.py +++ b/src/allmydata/web/status.py @@ -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())