Mercurial > libervia-backend
comparison sat/plugins/plugin_merge_req_mercurial.py @ 3040:fee60f17ebac
jp: jp asyncio port:
/!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\
This patch implements the port of jp to asyncio, so it is now correctly using the bridge
asynchronously, and it can be used with bridges like `pb`. This also simplify the code,
notably for things which were previously implemented with many callbacks (like pagination
with RSM).
During the process, some behaviours have been modified/fixed, in jp and backends, check
diff for details.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 25 Sep 2019 08:56:41 +0200 |
parents | ab2696e34d29 |
children | 9d0df638c8b4 |
comparison
equal
deleted
inserted
replaced
3039:a1bc34f90fa5 | 3040:fee60f17ebac |
---|---|
51 def run(cls, path, command, *args, **kwargs): | 51 def run(cls, path, command, *args, **kwargs): |
52 """Create a new MercurialRegisterProtocol and execute the given mercurial command. | 52 """Create a new MercurialRegisterProtocol and execute the given mercurial command. |
53 | 53 |
54 @param path(unicode): path to the repository | 54 @param path(unicode): path to the repository |
55 @param command(unicode): hg command to run | 55 @param command(unicode): hg command to run |
56 @return D(bytes): stdout of the command | |
56 """ | 57 """ |
57 assert "path" not in kwargs | 58 assert "path" not in kwargs |
58 kwargs["path"] = path | 59 kwargs["path"] = path |
59 # FIXME: we have to use this workaround because Twisted's protocol.ProcessProtocol | 60 # FIXME: we have to use this workaround because Twisted's protocol.ProcessProtocol |
60 # is not using new style classes. This can be removed once moved to | 61 # is not using new style classes. This can be removed once moved to |
84 d.addCallback(lambda __: True) | 85 d.addCallback(lambda __: True) |
85 d.addErrback(lambda __: False) | 86 d.addErrback(lambda __: False) |
86 return d | 87 return d |
87 | 88 |
88 def export(self, repository): | 89 def export(self, repository): |
89 return MercurialProtocol.run(repository, 'export', '-g', '-r', 'outgoing()', | 90 d = MercurialProtocol.run(repository, 'export', '-g', '-r', 'outgoing()', |
90 '--encoding=utf-8') | 91 '--encoding=utf-8') |
92 d.addCallback(lambda data: data.decode('utf-8')) | |
93 return d | |
91 | 94 |
92 def import_(self, repository, data, data_type, item_id, service, node, extra): | 95 def import_(self, repository, data, data_type, item_id, service, node, extra): |
93 parsed_data = self.parse(data) | 96 parsed_data = self.parse(data) |
94 try: | 97 try: |
95 parsed_name = parsed_data[0]['commit_msg'].split('\n')[0] | 98 parsed_name = parsed_data[0]['commit_msg'].split('\n')[0] |
96 parsed_name = CLEAN_RE.sub('', parsed_name)[:40] | 99 parsed_name = CLEAN_RE.sub('', parsed_name)[:40] |
97 except Exception: | 100 except Exception: |
98 parsed_name = '' | 101 parsed_name = '' |
99 name = 'mr_{item_id}_{parsed_name}'.format(item_id=CLEAN_RE.sub('', item_id), | 102 name = 'mr_{item_id}_{parsed_name}'.format(item_id=CLEAN_RE.sub('', item_id), |
100 parsed_name=parsed_name) | 103 parsed_name=parsed_name) |
101 return MercurialProtocol.run(repository, 'qimport', '-g', '--name', name, | 104 return MercurialProtocol.run(repository, 'qimport', '-g', '--name', name, |
102 '--encoding=utf-8', '-', stdin=data) | 105 '--encoding=utf-8', '-', stdin=data) |
103 | 106 |
104 def parse(self, data, data_type=None): | 107 def parse(self, data, data_type=None): |
105 lines = data.splitlines() | 108 lines = data.splitlines() |