diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2024-01-18 19:09:58 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2024-01-18 19:09:58 +0100 |
commit | cc7362d28bd9c43cb6839809f86e59874f2fe458 (patch) | |
tree | 1053748f5890c769d1e99806bc0c8bcffca6f0fe /libbe/storage/vcs | |
parent | 003bd13629d9db2f14156f97b74a4672e9ecdf77 (diff) | |
download | bugseverywhere-cc7362d28bd9c43cb6839809f86e59874f2fe458.tar.gz |
2to3 conversion of the repo.
Diffstat (limited to 'libbe/storage/vcs')
-rw-r--r-- | libbe/storage/vcs/__init__.py | 2 | ||||
-rw-r--r-- | libbe/storage/vcs/base.py | 38 | ||||
-rw-r--r-- | libbe/storage/vcs/bzr.py | 30 | ||||
-rw-r--r-- | libbe/storage/vcs/darcs.py | 6 | ||||
-rw-r--r-- | libbe/storage/vcs/git.py | 6 | ||||
-rw-r--r-- | libbe/storage/vcs/hg.py | 6 |
6 files changed, 44 insertions, 44 deletions
diff --git a/libbe/storage/vcs/__init__.py b/libbe/storage/vcs/__init__.py index 2fd8dc4..56c66b3 100644 --- a/libbe/storage/vcs/__init__.py +++ b/libbe/storage/vcs/__init__.py @@ -32,7 +32,7 @@ The base `VCS` class also serves as a filesystem Storage backend (not versioning) in the event that a user has no VCS installed. """ -import base +from . import base set_preferred_vcs = base.set_preferred_vcs vcs_by_name = base.vcs_by_name diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index 687575f..dfd007f 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -255,7 +255,7 @@ class CachedPathID (object): def disconnect(self): if self._changed == True: f = codecs.open(self._cache_path, 'w', self.encoding) - for uuid,path in self._cache.items(): + for uuid,path in list(self._cache.items()): f.write('%s\t%s\n' % (uuid, path)) f.close() self._cache = {} @@ -558,12 +558,12 @@ class VCS (libbe.storage.base.VersionedStorage): for num in num_part.split('.'): try: self._parsed_version.append(int(num)) - except ValueError, e: + except ValueError as e: # bzr version number might contain non-numerical tags splitter = re.compile(r'[\D]') # Match non-digits splits = splitter.split(num) # if len(tag) > 1 some splits will be empty; remove - splits = filter(lambda s: s != '', splits) + splits = [s for s in splits if s != ''] tag_starti = len(splits[0]) num_starti = num.find(splits[1], tag_starti) tag = num[tag_starti:num_starti] @@ -573,7 +573,7 @@ class VCS (libbe.storage.base.VersionedStorage): for current,other in zip(self._parsed_version, args): if type(current) != type (other): # one of them is a pre-release string - if type(current) != types.IntType: + if type(current) != int: return -1 else: return 1 @@ -586,12 +586,12 @@ class VCS (libbe.storage.base.VersionedStorage): if verlen == arglen: return 0 elif verlen > arglen: - if type(self._parsed_version[arglen]) != types.IntType: + if type(self._parsed_version[arglen]) != int: return -1 # self is a prerelease else: return 1 else: - if type(args[verlen]) != types.IntType: + if type(args[verlen]) != int: return 1 # args is a prerelease else: return -1 @@ -732,7 +732,7 @@ class VCS (libbe.storage.base.VersionedStorage): if revision == None: try: path = self.path(id, revision, relpath=False) - except InvalidID, e: + except InvalidID as e: return False return os.path.exists(path) path = self.path(id, revision, relpath=True) @@ -763,7 +763,7 @@ class VCS (libbe.storage.base.VersionedStorage): if os.path.exists(path): shutil.rmtree(path) path = self._cached_path_id.path(id, relpath=True) - for id,p in self._cached_path_id._cache.items(): + for id,p in list(self._cached_path_id._cache.items()): if p.startswith(path): self._cached_path_id.remove_id(id) @@ -818,7 +818,7 @@ class VCS (libbe.storage.base.VersionedStorage): try: relpath = self.path(id, revision, relpath=True) contents = self._vcs_get_file_contents(relpath, revision) - except InvalidID, e: + except InvalidID as e: if default == libbe.util.InvalidObject: raise e return default @@ -833,7 +833,7 @@ class VCS (libbe.storage.base.VersionedStorage): def _set(self, id, value): try: path = self._cached_path_id.path(id) - except InvalidID, e: + except InvalidID as e: raise if not os.path.exists(path): raise InvalidID(id) @@ -923,7 +923,7 @@ class VCS (libbe.storage.base.VersionedStorage): """ try: ret = search_parent_directories(path, filename) - except AssertionError, e: + except AssertionError as e: return None return ret @@ -1054,8 +1054,8 @@ class VCS (libbe.storage.base.VersionedStorage): path, decode=True).rstrip() relpath = self._u_rel_path(path) contents = self._vcs_get_file_contents(relpath, revision=revision) - if type(contents) != types.UnicodeType: - contents = unicode(contents, self.encoding) + if type(contents) != str: + contents = str(contents, self.encoding) return contents.strip() def _setup_storage_version(self): @@ -1104,7 +1104,7 @@ if libbe.TESTING == True: def test_installed(self): """See if the VCS is installed. """ - self.failUnless(self.s.installed() == True, + self.assertTrue(self.s.installed() == True, '%(name)s VCS not found' % vars(self.Class)) @@ -1114,7 +1114,7 @@ if libbe.TESTING == True: """ if self.s.installed(): self.s.disconnect() - self.failUnless(self.s._detect(self.dirname) == True, + self.assertTrue(self.s._detect(self.dirname) == True, 'Did not detected %(name)s VCS after initialising' % vars(self.Class)) self.s.connect() @@ -1125,7 +1125,7 @@ if libbe.TESTING == True: if self.s.installed() and self.Class.name != 'None': self.s.disconnect() self.s.destroy() - self.failUnless(self.s._detect(self.dirname) == False, + self.assertTrue(self.s._detect(self.dirname) == False, 'Detected %(name)s VCS before initialising' % vars(self.Class)) self.s.init() @@ -1136,7 +1136,7 @@ if libbe.TESTING == True: rp = os.path.realpath(self.s.repo) dp = os.path.realpath(self.dirname) vcs_name = self.Class.name - self.failUnless( + self.assertTrue( dp == rp or rp == None, "%(vcs_name)s VCS root in wrong dir (%(dp)s %(rp)s)" % vars()) @@ -1151,7 +1151,7 @@ if libbe.TESTING == True: return name,email = libbe.ui.util.user.parse_user_id(user_id) if email != None: - self.failUnless('@' in email, email) + self.assertTrue('@' in email, email) def make_vcs_testcase_subclasses(vcs_class, namespace): c = vcs_class() @@ -1167,7 +1167,7 @@ if libbe.TESTING == True: # Make VCSTestCase subclasses for vcs_class in the namespace. vcs_testcase_classes = [ c for c in ( - ob for ob in globals().values() if isinstance(ob, type)) + ob for ob in list(globals().values()) if isinstance(ob, type)) if issubclass(c, VCSTestCase) \ and c.Class == VCS] diff --git a/libbe/storage/vcs/bzr.py b/libbe/storage/vcs/bzr.py index 0c92058..6da299a 100644 --- a/libbe/storage/vcs/bzr.py +++ b/libbe/storage/vcs/bzr.py @@ -39,11 +39,11 @@ import os import os.path import re import shutil -import StringIO +import io import sys import libbe -import base +from . import base if libbe.TESTING == True: import doctest @@ -84,7 +84,7 @@ class Bzr(base.VCS): def _vcs_root(self, path): """Find the root of the deepest repository containing path.""" cmd = bzrlib.builtins.cmd_root() - cmd.outf = StringIO.StringIO() + cmd.outf = io.StringIO() cmd.run(filename=path) if self.version_cmp(2,2,0) < 0: cmd.cleanup_now() @@ -92,7 +92,7 @@ class Bzr(base.VCS): def _vcs_init(self, path): cmd = bzrlib.builtins.cmd_init() - cmd.outf = StringIO.StringIO() + cmd.outf = io.StringIO() cmd.run(location=path) if self.version_cmp(2,2,0) < 0: cmd.cleanup_now() @@ -105,7 +105,7 @@ class Bzr(base.VCS): def _vcs_add(self, path): path = os.path.join(self.repo, path) cmd = bzrlib.builtins.cmd_add() - cmd.outf = StringIO.StringIO() + cmd.outf = io.StringIO() kwargs = {'file_ids_from': self.repo} if self.repo == os.path.realpath(os.getcwd()): # Work around bzr file locking on Windows. @@ -126,7 +126,7 @@ class Bzr(base.VCS): # --force to also remove unversioned files. path = os.path.join(self.repo, path) cmd = bzrlib.builtins.cmd_remove() - cmd.outf = StringIO.StringIO() + cmd.outf = io.StringIO() cmd.run(file_list=[path], file_deletion_strategy='force') if self.version_cmp(2,2,0) < 0: cmd.cleanup_now() @@ -150,14 +150,14 @@ class Bzr(base.VCS): path = os.path.join(self.repo, path) revision = self._parse_revision_string(revision) cmd = bzrlib.builtins.cmd_cat() - cmd.outf = StringIO.StringIO() + cmd.outf = io.StringIO() if self.version_cmp(1,6,0) < 0: # old bzrlib cmd_cat uses sys.stdout not self.outf for output. stdout = sys.stdout sys.stdout = cmd.outf try: cmd.run(filename=path, revision=revision) - except bzrlib.errors.BzrCommandError, e: + except bzrlib.errors.BzrCommandError as e: if 'not present in revision' in str(e): raise base.InvalidPath(path, root=self.repo, revision=revision) raise @@ -177,7 +177,7 @@ class Bzr(base.VCS): def _vcs_isdir(self, path, revision): try: self._vcs_listdir(path, revision) - except AttributeError, e: + except AttributeError as e: if 'children' in str(e): return False raise @@ -187,7 +187,7 @@ class Bzr(base.VCS): path = os.path.join(self.repo, path) revision = self._parse_revision_string(revision) cmd = bzrlib.builtins.cmd_ls() - cmd.outf = StringIO.StringIO() + cmd.outf = io.StringIO() try: if self.version_cmp(2,0,0) >= 0: cmd.run(revision=revision, path=path, recursive=recursive) @@ -197,7 +197,7 @@ class Bzr(base.VCS): # (https://bugs.launchpad.net/bzr/+bug/158690) cmd.run(revision=revision, path=path, non_recursive=False) - except bzrlib.errors.BzrCommandError, e: + except bzrlib.errors.BzrCommandError as e: if 'not present in revision' in str(e): raise base.InvalidPath(path, root=self.repo, revision=revision) raise @@ -212,12 +212,12 @@ class Bzr(base.VCS): def _vcs_commit(self, commitfile, allow_empty=False): cmd = bzrlib.builtins.cmd_commit() - cmd.outf = StringIO.StringIO() + cmd.outf = io.StringIO() cwd = os.getcwd() os.chdir(self.repo) try: cmd.run(file=commitfile, unchanged=allow_empty) - except bzrlib.errors.BzrCommandError, e: + except bzrlib.errors.BzrCommandError as e: strings = ['no changes to commit.', # bzr 1.3.1 'No changes to commit.'] # bzr 1.15.1 if self._u_any_in_string(strings, str(e)) == True: @@ -231,7 +231,7 @@ class Bzr(base.VCS): def _vcs_revision_id(self, index): cmd = bzrlib.builtins.cmd_revno() - cmd.outf = StringIO.StringIO() + cmd.outf = io.StringIO() cmd.run(location=self.repo) if self.version_cmp(2,2,0) < 0: cmd.cleanup_now() @@ -245,7 +245,7 @@ class Bzr(base.VCS): def _diff(self, revision): revision = self._parse_revision_string(revision) cmd = bzrlib.builtins.cmd_diff() - cmd.outf = StringIO.StringIO() + cmd.outf = io.StringIO() # for some reason, cmd_diff uses sys.stdout not self.outf for output. stdout = sys.stdout sys.stdout = cmd.outf diff --git a/libbe/storage/vcs/darcs.py b/libbe/storage/vcs/darcs.py index ec100b4..41262f5 100644 --- a/libbe/storage/vcs/darcs.py +++ b/libbe/storage/vcs/darcs.py @@ -104,10 +104,10 @@ class Darcs(base.VCS): for num in num_part.split('.'): try: self._parsed_version.append(int(num)) - except ValueError, e: + except ValueError as e: self._parsed_version.append(num) for current,other in zip(self._parsed_version, args): - if type(current) != types.IntType: + if type(current) != int: raise NotImplementedError( 'Cannot parse non-integer portion "%s" of Darcs version "%s"' % (current, self.version())) @@ -284,7 +284,7 @@ class Darcs(base.VCS): assert patch.tag == 'patch', patch.tag for child in patch.getchildren(): if child.tag == 'name': - text = unescape(unicode(child.text).decode('unicode_escape').strip()) + text = unescape(str(child.text).decode('unicode_escape').strip()) revisions.append(text) revisions.reverse() return revisions diff --git a/libbe/storage/vcs/git.py b/libbe/storage/vcs/git.py index 851af19..9a15c92 100644 --- a/libbe/storage/vcs/git.py +++ b/libbe/storage/vcs/git.py @@ -32,7 +32,7 @@ import unittest try: import pygit2 as _pygit2 -except ImportError, error: +except ImportError as error: _pygit2 = None _pygit2_import_error = error else: @@ -65,7 +65,7 @@ class PygitGit(base.VCS): Using :py:mod:`pygit2` for the Git activity. """ name='pygit2' - _null_hex = u'0' * 40 + _null_hex = '0' * 40 def __init__(self, *args, **kwargs): base.VCS.__init__(self, *args, **kwargs) @@ -162,7 +162,7 @@ class PygitGit(base.VCS): def _git_get_commit(self, revision): if isinstance(revision, str): - revision = unicode(revision, 'ascii') + revision = str(revision, 'ascii') commit = self._pygit_repository.revparse_single(revision) assert commit.type == _pygit2.GIT_OBJ_COMMIT, commit return commit diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index f2976ff..0ebdfb0 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -47,12 +47,12 @@ import os import os.path import re import shutil -import StringIO +import io import sys import time # work around http://mercurial.selenic.com/bts/issue618 import libbe -import base +from . import base if libbe.TESTING == True: import doctest @@ -85,7 +85,7 @@ class Hg(base.VCS): fullargs = ['--cwd', kwargs['cwd']] fullargs.extend(args) cwd = os.getcwd() - output = StringIO.StringIO() + output = io.StringIO() if self.version_cmp(1,9) >= 0: req = mercurial.dispatch.request(fullargs, fout=output) mercurial.dispatch.dispatch(req) |