From: David Howells Date: Fri, 11 Apr 2014 15:35:02 +0000 (+0100) Subject: Create AFS standard date and time format library module X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f3e7b26fda57f475f7710d79ed2a72e5612e6be1;p=users%2Fdhowells%2Fkafs-utils.git Create AFS standard date and time format library module Create an python library module to format date and times in the AFS standard way. Signed-off-by: David Howells --- diff --git a/suite/commands/vos/status.py b/suite/commands/vos/status.py index c2bcc29..1680628 100644 --- a/suite/commands/vos/status.py +++ b/suite/commands/vos/status.py @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA from afs.argparse import * import afs.lib.partition as partition +from afs.lib.time import * import kafs help = "Report a volume server's status" @@ -58,8 +59,8 @@ def main(params): print("--------------------------------------------") for trans in results: - print("transaction: {:d} created: {:s}".format(trans.tid, afs_time(trans.creationTime))) - print("lastActiveTime:", afs_time(trans.time)) + print("transaction: {:d} created: {:s}".format(trans.tid, time2str(trans.creationTime))) + print("lastActiveTime:", time2str(trans.time)) if iflag & kafs.ITOffline: attach_mode = "offline" elif iflag & kafs.ITBusy: diff --git a/suite/lib/time.py b/suite/lib/time.py new file mode 100644 index 0000000..fe19366 --- /dev/null +++ b/suite/lib/time.py @@ -0,0 +1,34 @@ +# +# AFS Volume management toolkit: Standard AFS date and time display format +# -*- coding: utf-8 -*- +# + +__copyright__ = """ +Copyright (C) 2014 Red Hat, Inc. All Rights Reserved. +Written by David Howells (dhowells@redhat.com) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public Licence version 2 as +published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public Licence for more details. + +You should have received a copy of the GNU General Public Licence +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +""" + +import datetime + +def time2str(time): + t = datetime.datetime.fromtimestamp(time) + return t.strftime("%a %b %d %H:%M:%S %Y") + +def time2str_or_never(time): + if time == 0: + return "Never" + t = datetime.datetime.fromtimestamp(time) + return t.strftime("%a %b %d %H:%M:%S %Y") diff --git a/suite/lib/voldisplay.py b/suite/lib/voldisplay.py index c5cf0ba..a1560cf 100644 --- a/suite/lib/voldisplay.py +++ b/suite/lib/voldisplay.py @@ -23,8 +23,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import afs.lib.addrcache as addrcache import afs.lib.partition as partition +from afs.lib.time import * import kafs -import datetime statistics_time_ranges = [ "0-60 sec ", @@ -64,12 +64,6 @@ def vol_status(vol): return "BUSY" return "UNATTACHABLE" -def vol_date(d, never = False): - if d == 0 and never: - return "Never" - t = datetime.datetime.fromtimestamp(d) - return t.strftime("%a %b %d %H:%M:%S %Y") - def yes_or_no(n): if (n): return "Y" @@ -155,11 +149,11 @@ def display_vol_information(params, vol): vol.cloneID, vol.backupID)) print(" ", "MaxQuota {:10d} K".format(vol.maxquota)) - print(" ", "Creation ", vol_date(vol.creationDate, True)) - print(" ", "Copy ", vol_date(vol.copyDate, True)) - print(" ", "Backup ", vol_date(vol.backupDate, True)) - print(" ", "Last Access", vol_date(vol.accessDate, True)) - print(" ", "Last Update", vol_date(vol.updateDate, True)) + print(" ", "Creation ", time2str_or_never(vol.creationDate)) + print(" ", "Copy ", time2str_or_never(vol.copyDate)) + print(" ", "Backup ", time2str_or_never(vol.backupDate)) + print(" ", "Last Access", time2str_or_never(vol.accessDate)) + print(" ", "Last Update", time2str_or_never(vol.updateDate)) print(" ", vol.dayUse, "accesses in the past day (i.e., vnode references)") print() @@ -273,11 +267,11 @@ def display_vol_mp_basic_information(params, vol): except AttributeError: pass print("type\t\t{:s}".format(vol_type(vol))) - print("creationDate\t{:<10d}\t{:s}".format(vol.creationDate, vol_date(vol.creationDate))) - print("accessDate\t{:<10d}\t{:s}".format(vol.accessDate, vol_date(vol.accessDate))) - print("updateDate\t{:<10d}\t{:s}".format(vol.updateDate, vol_date(vol.updateDate))) - print("backupData\t{:<10d}\t{:s}".format(vol.backupDate, vol_date(vol.backupDate))) - print("copyDate\t{:<10d}\t{:s}".format(vol.copyDate, vol_date(vol.copyDate))) + print("creationDate\t{:<10d}\t{:s}".format(vol.creationDate, time2str(vol.creationDate))) + print("accessDate\t{:<10d}\t{:s}".format(vol.accessDate, time2str(vol.accessDate))) + print("updateDate\t{:<10d}\t{:s}".format(vol.updateDate, time2str(vol.updateDate))) + print("backupData\t{:<10d}\t{:s}".format(vol.backupDate, time2str(vol.backupDate))) + print("copyDate\t{:<10d}\t{:s}".format(vol.copyDate, time2str(vol.copyDate))) try: print("flags\t\t{:<7d}\t(Optional)".format(vol.flags)) except AttributeError: