Mercurial > libervia-backend
comparison sat/plugins/plugin_merge_req_mercurial.py @ 2620:72f6f37ab648
core: some more line limiting
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 07:23:13 +0200 |
parents | 26edcf3a30eb |
children | 2f75830a8228 |
comparison
equal
deleted
inserted
replaced
2619:e7bd2945518f | 2620:72f6f37ab648 |
---|---|
69 data = u''.join([d.decode('utf-8') for d in self.data]) | 69 data = u''.join([d.decode('utf-8') for d in self.data]) |
70 if (reason.value.exitCode == 0): | 70 if (reason.value.exitCode == 0): |
71 log.debug(_('Mercurial command succeed')) | 71 log.debug(_('Mercurial command succeed')) |
72 self._deferred.callback(data) | 72 self._deferred.callback(data) |
73 else: | 73 else: |
74 msg = _(u"Can't complete Mercurial command (error code: {code}): {message}").format( | 74 msg = (_(u"Can't complete Mercurial command (error code: {code}): {message}") |
75 code = reason.value.exitCode, | 75 .format(code = reason.value.exitCode, message = data)) |
76 message = data) | |
77 log.warning(msg) | 76 log.warning(msg) |
78 self._deferred.errback(Failure(RuntimeError(msg))) | 77 self._deferred.errback(Failure(RuntimeError(msg))) |
79 | 78 |
80 @classmethod | 79 @classmethod |
81 def run(cls, path, command, *args, **kwargs): | 80 def run(cls, path, command, *args, **kwargs): |
82 """Create a new MercurialRegisterProtocol and execute the given mercurialctl command. | 81 """Create a new MercurialRegisterProtocol and execute the given mercurial command. |
83 | 82 |
84 @param path(unicode): path to the repository | 83 @param path(unicode): path to the repository |
85 @param command(unicode): command to run | 84 @param command(unicode): command to run |
86 @param *args(unicode): command arguments | 85 @param *args(unicode): command arguments |
87 @param **kwargs: used because Python2 doesn't handle normal kw args after *args | 86 @param **kwargs: used because Python2 doesn't handle normal kw args after *args |
111 def __init__(self, host): | 110 def __init__(self, host): |
112 log.info(_(u"Mercurial merge request handler initialization")) | 111 log.info(_(u"Mercurial merge request handler initialization")) |
113 try: | 112 try: |
114 MercurialProtocol.hg = which('hg')[0] | 113 MercurialProtocol.hg = which('hg')[0] |
115 except IndexError: | 114 except IndexError: |
116 raise exceptions.NotFound(_(u"Mercurial executable (hg) not found, can't use Mercurial handler")) | 115 raise exceptions.NotFound(_(u"Mercurial executable (hg) not found, " |
116 u"can't use Mercurial handler")) | |
117 self.host = host | 117 self.host = host |
118 self._m = host.plugins['MERGE_REQUESTS'] | 118 self._m = host.plugins['MERGE_REQUESTS'] |
119 self._m.register('mercurial', self, self.data_types, SHORT_DESC) | 119 self._m.register('mercurial', self, self.data_types, SHORT_DESC) |
120 | 120 |
121 def check(self, repository): | 121 def check(self, repository): |
123 d.addCallback(lambda dummy: True) | 123 d.addCallback(lambda dummy: True) |
124 d.addErrback(lambda dummy: False) | 124 d.addErrback(lambda dummy: False) |
125 return d | 125 return d |
126 | 126 |
127 def export(self, repository): | 127 def export(self, repository): |
128 return MercurialProtocol.run(repository, 'export', '-g', '-r', 'outgoing()', '--encoding=utf-8') | 128 return MercurialProtocol.run(repository, 'export', '-g', '-r', 'outgoing()', |
129 '--encoding=utf-8') | |
129 | 130 |
130 def import_(self, repository, data, data_type, item_id, service, node, extra): | 131 def import_(self, repository, data, data_type, item_id, service, node, extra): |
131 parsed_data = self.parse(data) | 132 parsed_data = self.parse(data) |
132 try: | 133 try: |
133 parsed_name = parsed_data[0][u'commit_msg'].split(u'\n')[0] | 134 parsed_name = parsed_data[0][u'commit_msg'].split(u'\n')[0] |
134 parsed_name = re.sub(ur'[^\w -.]', u'', parsed_name, flags=re.UNICODE)[:40] | 135 parsed_name = re.sub(ur'[^\w -.]', u'', parsed_name, flags=re.UNICODE)[:40] |
135 except Exception: | 136 except Exception: |
136 parsed_name = u'' | 137 parsed_name = u'' |
137 name = u'mr_{item_id}_{parsed_name}'.format(item_id=item_id, parsed_name=parsed_name) | 138 name = u'mr_{item_id}_{parsed_name}'.format(item_id=item_id, |
138 return MercurialProtocol.run(repository, 'qimport', '-g', '--name', name, '--encoding=utf-8', '-', stdin=data) | 139 parsed_name=parsed_name) |
140 return MercurialProtocol.run(repository, 'qimport', '-g', '--name', name, | |
141 '--encoding=utf-8', '-', stdin=data) | |
139 | 142 |
140 def parse(self, data, data_type=None): | 143 def parse(self, data, data_type=None): |
141 lines = data.splitlines() | 144 lines = data.splitlines() |
142 total_lines = len(lines) | 145 total_lines = len(lines) |
143 patches = [] | 146 patches = [] |
158 if line.startswith(u'# User '): | 161 if line.startswith(u'# User '): |
159 elems = line[7:].split() | 162 elems = line[7:].split() |
160 if not elems: | 163 if not elems: |
161 continue | 164 continue |
162 last = elems[-1] | 165 last = elems[-1] |
163 if last.startswith(u'<') and last.endswith(u'>') and u'@' in last: | 166 if (last.startswith(u'<') and last.endswith(u'>') |
167 and u'@' in last): | |
164 patch[self._m.META_EMAIL] = elems.pop()[1:-1] | 168 patch[self._m.META_EMAIL] = elems.pop()[1:-1] |
165 patch[self._m.META_AUTHOR] = u' '.join(elems) | 169 patch[self._m.META_AUTHOR] = u' '.join(elems) |
166 elif line.startswith(u'# Date '): | 170 elif line.startswith(u'# Date '): |
167 time_data = line[7:].split() | 171 time_data = line[7:].split() |
168 if len(time_data) != 2: | 172 if len(time_data) != 2: |
169 log.warning(_(u'unexpected time data: {data}').format(data=line[7:])) | 173 log.warning(_(u'unexpected time data: {data}') |
174 .format(data=line[7:])) | |
170 continue | 175 continue |
171 patch[self._m.META_TIMESTAMP] = int(time_data[0]) + int(time_data[1]) | 176 patch[self._m.META_TIMESTAMP] = (int(time_data[0]) |
177 + int(time_data[1])) | |
172 elif line.startswith(u'# Node ID '): | 178 elif line.startswith(u'# Node ID '): |
173 patch[self._m.META_HASH] = line[10:] | 179 patch[self._m.META_HASH] = line[10:] |
174 elif line.startswith(u'# Parent '): | 180 elif line.startswith(u'# Parent '): |
175 patch[self._m.META_PARENT_HASH] = line[10:] | 181 patch[self._m.META_PARENT_HASH] = line[10:] |
176 else: | 182 else: |