aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
diff options
context:
space:
mode:
authorChris Ball <cjb@laptop.org>2009-06-26 16:16:10 -0400
committerChris Ball <cjb@laptop.org>2009-06-26 16:16:10 -0400
commitacf7b0cc492142ef0bbf1c04aed652a53caf7fe1 (patch)
tree83caecf530df36cc9f88bd94373b0fea0129b979 /libbe
parent34b2884112e3c3ca0cc0ac83df68c66f6b2729c4 (diff)
parent97aeb18b20f901950da0355471fdc17055f3f4a8 (diff)
downloadbugseverywhere-acf7b0cc492142ef0bbf1c04aed652a53caf7fe1.tar.gz
Merge with W. Trevor King's tree, which allows attaching binary files to bugs.
Diffstat (limited to 'libbe')
-rw-r--r--libbe/arch.py4
-rw-r--r--libbe/bug.py2
-rw-r--r--libbe/bzr.py4
-rw-r--r--libbe/cmdutil.py8
-rw-r--r--libbe/comment.py22
-rw-r--r--libbe/git.py4
-rw-r--r--libbe/hg.py4
-rw-r--r--libbe/rcs.py24
8 files changed, 49 insertions, 23 deletions
diff --git a/libbe/arch.py b/libbe/arch.py
index cd0f3b2..441c5a9 100644
--- a/libbe/arch.py
+++ b/libbe/arch.py
@@ -240,9 +240,9 @@ class Arch(RCS):
self._u_invoke_client("delete-id", path)
def _rcs_update(self, path):
pass
- def _rcs_get_file_contents(self, path, revision=None):
+ def _rcs_get_file_contents(self, path, revision=None, binary=False):
if revision == None:
- return RCS._rcs_get_file_contents(self, path, revision)
+ return RCS._rcs_get_file_contents(self, path, revision, binary=binary)
else:
status,output,error = \
self._invoke_client("file-find", path, revision)
diff --git a/libbe/bug.py b/libbe/bug.py
index 28f5253..4f297f9 100644
--- a/libbe/bug.py
+++ b/libbe/bug.py
@@ -288,7 +288,7 @@ class Bug(settings_object.SavedSettingsObject):
if show_comments == True:
comout = self.comment_root.xml_thread(auto_name_map=True,
bug_shortname=shortname)
- ret += comout
+ ret += comout+'\n'
ret += '</bug>'
return ret
diff --git a/libbe/bzr.py b/libbe/bzr.py
index 98ca571..21030e2 100644
--- a/libbe/bzr.py
+++ b/libbe/bzr.py
@@ -56,9 +56,9 @@ class Bzr(RCS):
self._u_invoke_client("remove", "--force", path)
def _rcs_update(self, path):
pass
- def _rcs_get_file_contents(self, path, revision=None):
+ def _rcs_get_file_contents(self, path, revision=None, binary=False):
if revision == None:
- return RCS._rcs_get_file_contents(self, path, revision)
+ return RCS._rcs_get_file_contents(self, path, revision, binary=binary)
else:
status,output,error = \
self._u_invoke_client("cat","-r",revision,path)
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py
index 6be7540..5873607 100644
--- a/libbe/cmdutil.py
+++ b/libbe/cmdutil.py
@@ -79,11 +79,17 @@ def help(cmd=None):
for name, module in iter_commands():
cmdlist.append((name, module.__desc__))
longest_cmd_len = max([len(name) for name,desc in cmdlist])
- ret = ["Bugs Everywhere - Distributed bug tracking\n",
+ ret = ["Bugs Everywhere - Distributed bug tracking",
+ "",
+ "usage: be [command] [command_options ...] [command_args ...]",
+ "or: be help",
+ "or: be help [command]",
+ "",
"Supported commands"]
for name, desc in cmdlist:
numExtraSpaces = longest_cmd_len-len(name)
ret.append("be %s%*s %s" % (name, numExtraSpaces, "", desc))
+
return "\n".join(ret)
def completions(cmd):
diff --git a/libbe/comment.py b/libbe/comment.py
index df5a63f..9fa4a30 100644
--- a/libbe/comment.py
+++ b/libbe/comment.py
@@ -16,6 +16,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA
+import email.mime.base, email.encoders
import os
import os.path
import time
@@ -150,11 +151,13 @@ class Comment(Tree, settings_object.SavedSettingsObject):
def _get_comment_body(self):
if self.rcs != None and self.sync_with_disk == True:
import rcs
- return self.rcs.get_file_contents(self.get_path("body"))
+ binary = not self.content_type.startswith("text/")
+ return self.rcs.get_file_contents(self.get_path("body"), binary=binary)
def _set_comment_body(self, old=None, new=None, force=False):
if (self.rcs != None and self.sync_with_disk == True) or force==True:
assert new != None, "Can't save empty comment"
- self.rcs.set_file_contents(self.get_path("body"), new)
+ binary = not self.content_type.startswith("text/")
+ self.rcs.set_file_contents(self.get_path("body"), new, binary=binary)
@Property
@change_hook_property(hook=_set_comment_body)
@@ -236,13 +239,21 @@ class Comment(Tree, settings_object.SavedSettingsObject):
"""
if shortname == None:
shortname = self.uuid
+ if self.content_type.startswith("text/"):
+ body = (self.body or "").rstrip('\n')
+ else:
+ maintype,subtype = self.content_type.split('/',1)
+ msg = email.mime.base.MIMEBase(maintype, subtype)
+ msg.set_payload(self.body or "")
+ email.encoders.encode_base64(msg)
+ body = msg.as_string()
info = [("uuid", self.uuid),
("short-name", shortname),
("in-reply-to", self.in_reply_to),
("from", self._setting_attr_string("From")),
("date", self.time_string),
("content-type", self.content_type),
- ("body", (self.body or "").rstrip('\n'))]
+ ("body", body)]
lines = ["<comment>"]
for (k,v) in info:
if v not in [settings_object.EMPTY, None]:
@@ -276,7 +287,10 @@ class Comment(Tree, settings_object.SavedSettingsObject):
lines.append("")
#lines.append(textwrap.fill(self.body or "",
# width=(79-indent)))
- lines.extend((self.body or "").splitlines())
+ if self.content_type.startswith("text/"):
+ lines.extend((self.body or "").splitlines())
+ else:
+ lines.append("Content type %s not printable. Try XML output instead" % self.content_type)
# some comments shouldn't be wrapped...
istring = ' '*indent
diff --git a/libbe/git.py b/libbe/git.py
index 401b5e5..5da1f86 100644
--- a/libbe/git.py
+++ b/libbe/git.py
@@ -70,9 +70,9 @@ class Git(RCS):
self._u_invoke_client("rm", "-f", path)
def _rcs_update(self, path):
self._rcs_add(path)
- def _rcs_get_file_contents(self, path, revision=None):
+ def _rcs_get_file_contents(self, path, revision=None, binary=False):
if revision == None:
- return RCS._rcs_get_file_contents(self, path, revision)
+ return RCS._rcs_get_file_contents(self, path, revision, binary=binary)
else:
arg = "%s:%s" % (revision,path)
status,output,error = self._u_invoke_client("show", arg)
diff --git a/libbe/hg.py b/libbe/hg.py
index a7413af..9b566b9 100644
--- a/libbe/hg.py
+++ b/libbe/hg.py
@@ -59,9 +59,9 @@ class Hg(RCS):
self._u_invoke_client("rm", path)
def _rcs_update(self, path):
pass
- def _rcs_get_file_contents(self, path, revision=None):
+ def _rcs_get_file_contents(self, path, revision=None, binary=False):
if revision == None:
- return RCS._rcs_get_file_contents(self, path, revision)
+ return RCS._rcs_get_file_contents(self, path, revision, binary=binary)
else:
status,output,error = \
self._u_invoke_client("cat","-r",revision,path)
diff --git a/libbe/rcs.py b/libbe/rcs.py
index c0b92e7..9c2defe 100644
--- a/libbe/rcs.py
+++ b/libbe/rcs.py
@@ -40,8 +40,7 @@ def _get_matching_rcs(matchfn):
rcs = module.new()
if matchfn(rcs) == True:
return rcs
- else:
- del(rcs)
+ del(rcs)
return RCS()
def rcs_by_name(rcs_name):
@@ -173,14 +172,17 @@ class RCS(object):
at path.
"""
pass
- def _rcs_get_file_contents(self, path, revision=None):
+ def _rcs_get_file_contents(self, path, revision=None, binary=False):
"""
Get the file contents as they were in a given revision.
Revision==None specifies the current revision.
"""
assert revision == None, \
"The %s RCS does not support revision specifiers" % self.name
- f = codecs.open(os.path.join(self.rootdir, path), "r", self.encoding)
+ if binary == False:
+ f = codecs.open(os.path.join(self.rootdir, path), "r", self.encoding)
+ else:
+ f = open(path, "rb")
contents = f.read()
f.close()
return contents
@@ -205,7 +207,8 @@ class RCS(object):
except OSError, e:
if e.errno == errno.ENOENT:
return False
- raise e
+ except CommandError:
+ return False
def detect(self, path="."):
"""
Detect whether a directory is revision controlled with this RCS.
@@ -290,7 +293,7 @@ class RCS(object):
at path.
"""
self._rcs_update(self._u_rel_path(path))
- def get_file_contents(self, path, revision=None, allow_no_rcs=False):
+ def get_file_contents(self, path, revision=None, allow_no_rcs=False, binary=False):
"""
Get the file as it was in a given revision.
Revision==None specifies the current revision.
@@ -299,18 +302,21 @@ class RCS(object):
raise NoSuchFile(path)
if self._use_rcs(path, allow_no_rcs):
relpath = self._u_rel_path(path)
- contents = self._rcs_get_file_contents(relpath,revision)
+ contents = self._rcs_get_file_contents(relpath,revision,binary=binary)
else:
f = codecs.open(path, "r", self.encoding)
contents = f.read()
f.close()
return contents
- def set_file_contents(self, path, contents, allow_no_rcs=False):
+ def set_file_contents(self, path, contents, allow_no_rcs=False, binary=False):
"""
Set the file contents under version control.
"""
add = not os.path.exists(path)
- f = codecs.open(path, "w", self.encoding)
+ if binary == False:
+ f = codecs.open(path, "w", self.encoding)
+ else:
+ f = open(path, "wb")
f.write(contents)
f.close()