aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Bentley <abentley@panoramicfeedback.com>2005-03-23 15:28:29 +0000
committerAaron Bentley <abentley@panoramicfeedback.com>2005-03-23 15:28:29 +0000
commit03b878916280732d45c474c106eb3d70b4be5e9e (patch)
tree496b27b5f6ab3dc8fc8ba5b9ef6e0bea62af6ff8
parent43d8c19ae299bab2cba0f29b560396ba6d8bd1a5 (diff)
downloadbugseverywhere-03b878916280732d45c474c106eb3d70b4be5e9e.tar.gz
Added datestamps to bugs
-rw-r--r--becommands/new.py7
-rw-r--r--becommands/show.py12
-rw-r--r--libbe/bugdir.py16
-rw-r--r--libbe/utility.py28
4 files changed, 55 insertions, 8 deletions
diff --git a/becommands/new.py b/becommands/new.py
index 7c3a952..afa6494 100644
--- a/becommands/new.py
+++ b/becommands/new.py
@@ -1,13 +1,10 @@
"""Create a new bug"""
-from libbe import bugdir, cmdutil, names
+from libbe import bugdir, cmdutil, names, utility
def execute(args):
if len(args) != 1:
raise cmdutil.UserError("Please supply a summary message")
dir = cmdutil.bug_tree()
- bug = dir.new_bug()
- bug.creator = names.creator()
- bug.severity = "minor"
- bug.status = "open"
+ bug = bugdir.new_bug(dir)
bug.summary = args[0]
bug.save()
bugs = (dir.list())
diff --git a/becommands/show.py b/becommands/show.py
index 3d1c9ed..3ec5ec4 100644
--- a/becommands/show.py
+++ b/becommands/show.py
@@ -1,10 +1,16 @@
"""Show a particular bug"""
-from libbe import bugdir, cmdutil
+from libbe import bugdir, cmdutil, utility
import os
def execute(args):
bug_dir = cmdutil.bug_tree()
if len(args) !=1:
raise cmdutil.UserError("Please specify a bug id.")
- print cmdutil.bug_summary(cmdutil.get_bug(args[0], bug_dir),
- list(bug_dir.list()))
+ bug = cmdutil.get_bug(args[0], bug_dir)
+ print cmdutil.bug_summary(bug, list(bug_dir.list())).rstrip("\n")
+ if bug.time is None:
+ time_str = "(Unknown time)"
+ else:
+ time_str = "%s (%s)" % (utility.handy_time(bug.time),
+ utility.time_to_str(bug.time))
+ print "Created: %s\n" % time_str
diff --git a/libbe/bugdir.py b/libbe/bugdir.py
index e2f40d6..d318690 100644
--- a/libbe/bugdir.py
+++ b/libbe/bugdir.py
@@ -4,6 +4,8 @@ import cmdutil
import errno
import names
import mapfile
+import time
+import utility
from rcs import rcs_by_name
class NoBugDir(Exception):
@@ -162,6 +164,9 @@ class Bug(object):
self.status = dict.get("status")
self.severity = dict.get("severity")
self.assigned = dict.get("assigned")
+ self.time = dict.get("time")
+ if self.time is not None:
+ self.time = utility.str_to_time(self.time)
def get_path(self, file):
return os.path.join(self.path, self.uuid, file)
@@ -184,10 +189,21 @@ class Bug(object):
self.add_attr(map, "target")
self.add_attr(map, "status")
self.add_attr(map, "severity")
+ if self.time is not None:
+ map["time"] = utility.time_to_str(self.time)
path = self.get_path("values")
map_save(rcs_by_name(self.rcs_name), path, map)
+def new_bug(dir):
+ bug = dir.new_bug()
+ bug.creator = names.creator()
+ bug.severity = "minor"
+ bug.status = "open"
+ bug.time = time.time()
+ return bug
+
+
def map_save(rcs, path, map):
"""Save the map as a mapfile to the specified path"""
if not os.path.exists(path):
diff --git a/libbe/utility.py b/libbe/utility.py
index a67037d..a2774d3 100644
--- a/libbe/utility.py
+++ b/libbe/utility.py
@@ -1,3 +1,6 @@
+import calendar
+import time
+
class FileString(object):
"""Bare-bones pseudo-file class
@@ -49,3 +52,28 @@ def get_file(f):
return f
+RFC_2822_TIME_FMT = "%a, %d %b %Y %H:%M:%S +0000"
+
+
+def time_to_str(time_val):
+ """Convert a time value into an RFC 2822-formatted string. This format
+ lacks sub-second data.
+ >>> time_to_str(0)
+ 'Thu, 01 Jan 1970 00:00:00 +0000'
+ """
+ return time.strftime(RFC_2822_TIME_FMT, time.gmtime(time_val))
+
+def str_to_time(str_time):
+ """Convert an RFC 2822-fomatted string into a time falue.
+ >>> str_to_time("Thu, 01 Jan 1970 00:00:00 +0000")
+ 0
+ >>> q = time.time()
+ # int(q) because the round-trip loses sub-second data
+ >>> str_to_time(time_to_str(q)) == int(q)
+ True
+ """
+ return calendar.timegm(time.strptime(str_time, RFC_2822_TIME_FMT))
+
+def handy_time(time_val):
+ return time.strftime("%a, %d %b %Y %H:%M", time.localtime(time_val))
+