diff options
author | W. Trevor King <wking@drexel.edu> | 2008-11-25 15:47:19 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2008-11-25 15:47:19 -0500 |
commit | 5699aef2a5741c5ffc24d9cb12d6bc9b085d484a (patch) | |
tree | 84ac8783ce2d1f9a28ba0bd0c256ae7179c68507 /libbe/arch.py | |
parent | ed4d971d1375a692fbd3a394237f56e851bb5d0e (diff) | |
download | bugseverywhere-5699aef2a5741c5ffc24d9cb12d6bc9b085d484a.tar.gz |
Added libbe/encoding.py to wrap input/output/file access appropriately.
I borrowed most of the code for this.
get_encoding() is from Trac
http://trac.edgewall.org/browser/trunk/trac/util/datefmt.py
format_datetime()
Trac has a BSD license
http://trac.edgewall.org/wiki/TracLicense
I don't know if such a small snippet requires us to "reproduce the
above copyright" or where we need to reproduce it if it is needed.
The stdout/stdin replacement code follows
http://wiki.python.org/moin/ShellRedirectionFails
Because of the stdout replacement, the doctests executes now need an
optional 'test' argument to turn off replacement during the doctests,
otherwise doctest flips out (since it had set up stdout to catch
output, and then we clobbered it's setup).
References:
http://wiki.python.org/moin/Unicode
http://www.amk.ca/python/howto/unicode
http://www.python.org/dev/peps/pep-0100/
I also split libbe/editor.py off from libbe.utility.py and started
explaining the motivation for the BugDir init flags in it's docstring.
Diffstat (limited to 'libbe/arch.py')
-rw-r--r-- | libbe/arch.py | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/libbe/arch.py b/libbe/arch.py index fd953a4..1173535 100644 --- a/libbe/arch.py +++ b/libbe/arch.py @@ -14,10 +14,11 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +import codecs import os +import re import shutil import time -import re import unittest import doctest @@ -133,13 +134,16 @@ class Arch(RCS): """ tagpath = os.path.join(path, "{arch}", "=tagging-method") lines_out = [] - for line in file(tagpath, "rb"): - line.decode("utf-8") + f = codecs.open(tagpath, "r", self.encoding) + for line in f: if line.startswith("source "): lines_out.append("source ^[._=a-zA-X0-9].*$\n") else: lines_out.append(line) - file(tagpath, "wb").write("".join(lines_out).encode("utf-8")) + f.close() + f = codecs.open(tagpath, "w", self.encoding) + f.write("".join(lines_out)) + f.close() def _add_project_code(self, path): # http://mwolson.org/projects/GettingStartedWithArch.html @@ -215,7 +219,9 @@ class Arch(RCS): return [os.path.join(root, p) for p in inv_str.split('\n')] def _add_dir_rule(self, rule, dirname, root): inv_path = os.path.join(dirname, '.arch-inventory') - file(inv_path, "ab").write(rule) + f = codecs.open(inv_path, "a", self.encoding) + f.write(rule) + f.close() if os.path.realpath(inv_path) not in self._list_added(root): paranoid = self.paranoid self.paranoid = False @@ -233,12 +239,16 @@ class Arch(RCS): pass def _rcs_get_file_contents(self, path, revision=None): if revision == None: - return file(self._u_abspath(path), "rb").read() + return RCS._rcs_get_file_contents(self, path, revision) else: status,output,error = \ self._invoke_client("file-find", path, revision) - path = output.rstrip('\n') - return file(self._u_abspath(path), "rb").read() + relpath = output.rstrip('\n') + abspath = os.path.join(self.rootdir, relpath) + f = codecs.open(abspath, "r", self.encoding) + contents = f.read() + f.close() + return contents def _rcs_duplicate_repo(self, directory, revision=None): if revision == None: RCS._rcs_duplicate_repo(self, directory, revision) |