Python 3 port:
/!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
This commit is contained in:
parent
d21a6a660f
commit
fbfe96c505
1 changed files with 6336 additions and 6398 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT plugin for import external blogs
|
||||
|
|
@ -35,16 +35,16 @@ PLUGIN_INFO = {
|
|||
C.PI_DEPENDENCIES: ["MERGE_REQUESTS"],
|
||||
C.PI_MAIN: "MercurialHandler",
|
||||
C.PI_HANDLER: "no",
|
||||
C.PI_DESCRIPTION: _(u"""Merge request handler for Mercurial""")
|
||||
C.PI_DESCRIPTION: _("""Merge request handler for Mercurial""")
|
||||
}
|
||||
|
||||
SHORT_DESC = D_(u"handle Mercurial repository")
|
||||
CLEAN_RE = re.compile(ur'[^\w -._]', flags=re.UNICODE)
|
||||
SHORT_DESC = D_("handle Mercurial repository")
|
||||
CLEAN_RE = re.compile(r'[^\w -._]', flags=re.UNICODE)
|
||||
|
||||
|
||||
class MercurialProtocol(async_process.CommandProtocol):
|
||||
"""handle hg commands"""
|
||||
name = u"Mercurial"
|
||||
name = "Mercurial"
|
||||
command = None
|
||||
|
||||
@classmethod
|
||||
|
|
@ -54,7 +54,7 @@ class MercurialProtocol(async_process.CommandProtocol):
|
|||
@param path(unicode): path to the repository
|
||||
@param command(unicode): hg command to run
|
||||
"""
|
||||
assert u"path" not in kwargs
|
||||
assert "path" not in kwargs
|
||||
kwargs["path"] = path
|
||||
# FIXME: we have to use this workaround because Twisted's protocol.ProcessProtocol
|
||||
# is not using new style classes. This can be removed once moved to
|
||||
|
|
@ -65,15 +65,15 @@ class MercurialProtocol(async_process.CommandProtocol):
|
|||
|
||||
|
||||
class MercurialHandler(object):
|
||||
data_types = (u'mercurial_changeset',)
|
||||
data_types = ('mercurial_changeset',)
|
||||
|
||||
def __init__(self, host):
|
||||
log.info(_(u"Mercurial merge request handler initialization"))
|
||||
log.info(_("Mercurial merge request handler initialization"))
|
||||
try:
|
||||
MercurialProtocol.command = which('hg')[0]
|
||||
except IndexError:
|
||||
raise exceptions.NotFound(_(u"Mercurial executable (hg) not found, "
|
||||
u"can't use Mercurial handler"))
|
||||
raise exceptions.NotFound(_("Mercurial executable (hg) not found, "
|
||||
"can't use Mercurial handler"))
|
||||
self.host = host
|
||||
self._m = host.plugins['MERGE_REQUESTS']
|
||||
self._m.register('mercurial', self, self.data_types, SHORT_DESC)
|
||||
|
|
@ -92,11 +92,11 @@ class MercurialHandler(object):
|
|||
def import_(self, repository, data, data_type, item_id, service, node, extra):
|
||||
parsed_data = self.parse(data)
|
||||
try:
|
||||
parsed_name = parsed_data[0][u'commit_msg'].split(u'\n')[0]
|
||||
parsed_name = CLEAN_RE.sub(u'', parsed_name)[:40]
|
||||
parsed_name = parsed_data[0]['commit_msg'].split('\n')[0]
|
||||
parsed_name = CLEAN_RE.sub('', parsed_name)[:40]
|
||||
except Exception:
|
||||
parsed_name = u''
|
||||
name = u'mr_{item_id}_{parsed_name}'.format(item_id=CLEAN_RE.sub(u'', item_id),
|
||||
parsed_name = ''
|
||||
name = 'mr_{item_id}_{parsed_name}'.format(item_id=CLEAN_RE.sub('', item_id),
|
||||
parsed_name=parsed_name)
|
||||
return MercurialProtocol.run(repository, 'qimport', '-g', '--name', name,
|
||||
'--encoding=utf-8', '-', stdin=data)
|
||||
|
|
@ -111,51 +111,51 @@ class MercurialHandler(object):
|
|||
diff = []
|
||||
state = 'init'
|
||||
if lines[0] != '# HG changeset patch':
|
||||
raise exceptions.DataError(_(u'invalid changeset signature'))
|
||||
raise exceptions.DataError(_('invalid changeset signature'))
|
||||
# line index of this patch in the whole data
|
||||
patch_idx = total_lines - len(lines)
|
||||
del lines[0]
|
||||
|
||||
for idx, line in enumerate(lines):
|
||||
if state == 'init':
|
||||
if line.startswith(u'# '):
|
||||
if line.startswith(u'# User '):
|
||||
if line.startswith('# '):
|
||||
if line.startswith('# User '):
|
||||
elems = line[7:].split()
|
||||
if not elems:
|
||||
continue
|
||||
last = elems[-1]
|
||||
if (last.startswith(u'<') and last.endswith(u'>')
|
||||
and u'@' in last):
|
||||
if (last.startswith('<') and last.endswith('>')
|
||||
and '@' in last):
|
||||
patch[self._m.META_EMAIL] = elems.pop()[1:-1]
|
||||
patch[self._m.META_AUTHOR] = u' '.join(elems)
|
||||
elif line.startswith(u'# Date '):
|
||||
patch[self._m.META_AUTHOR] = ' '.join(elems)
|
||||
elif line.startswith('# Date '):
|
||||
time_data = line[7:].split()
|
||||
if len(time_data) != 2:
|
||||
log.warning(_(u'unexpected time data: {data}')
|
||||
log.warning(_('unexpected time data: {data}')
|
||||
.format(data=line[7:]))
|
||||
continue
|
||||
patch[self._m.META_TIMESTAMP] = (int(time_data[0])
|
||||
+ int(time_data[1]))
|
||||
elif line.startswith(u'# Node ID '):
|
||||
elif line.startswith('# Node ID '):
|
||||
patch[self._m.META_HASH] = line[10:]
|
||||
elif line.startswith(u'# Parent '):
|
||||
elif line.startswith('# Parent '):
|
||||
patch[self._m.META_PARENT_HASH] = line[10:]
|
||||
else:
|
||||
state = 'commit_msg'
|
||||
if state == 'commit_msg':
|
||||
if line.startswith(u'diff --git a/'):
|
||||
if line.startswith('diff --git a/'):
|
||||
state = 'diff'
|
||||
patch[self._m.META_DIFF_IDX] = patch_idx + idx + 1
|
||||
else:
|
||||
commit_msg.append(line)
|
||||
if state == 'diff':
|
||||
if line.startswith(u'# ') or idx == len(lines)-1:
|
||||
if line.startswith('# ') or idx == len(lines)-1:
|
||||
# a new patch is starting or we have reached end of patches
|
||||
if idx == len(lines)-1:
|
||||
# end of patches, we need to keep the line
|
||||
diff.append(line)
|
||||
patch[self._m.META_COMMIT_MSG] = u'\n'.join(commit_msg)
|
||||
patch[self._m.META_DIFF] = u'\n'.join(diff)
|
||||
patch[self._m.META_COMMIT_MSG] = '\n'.join(commit_msg)
|
||||
patch[self._m.META_DIFF] = '\n'.join(diff)
|
||||
patches.append(patch)
|
||||
if idx == len(lines)-1:
|
||||
del lines[:]
|
||||
|
|
|
|||
Loading…
Reference in a new issue