Show More
@@ -1,7 +1,6 | |||||
1 | # A minimal client for Mercurial's command server |
|
1 | # A minimal client for Mercurial's command server | |
2 |
|
2 | |||
3 | from __future__ import absolute_import, print_function |
|
3 | from __future__ import absolute_import, print_function | |
4 | import cStringIO |
|
|||
5 | import os |
|
4 | import os | |
6 | import signal |
|
5 | import signal | |
7 | import socket |
|
6 | import socket | |
@@ -10,6 +9,13 import subprocess | |||||
10 | import sys |
|
9 | import sys | |
11 | import time |
|
10 | import time | |
12 |
|
11 | |||
|
12 | try: | |||
|
13 | import cStringIO as io | |||
|
14 | stringio = io.StringIO | |||
|
15 | except ImportError: | |||
|
16 | import io | |||
|
17 | stringio = io.StringIO | |||
|
18 | ||||
13 | def connectpipe(path=None): |
|
19 | def connectpipe(path=None): | |
14 | cmdline = ['hg', 'serve', '--cmdserver', 'pipe'] |
|
20 | cmdline = ['hg', 'serve', '--cmdserver', 'pipe'] | |
15 | if path: |
|
21 | if path: | |
@@ -83,7 +89,7 def runcommand(server, args, output=sys. | |||||
83 | writeblock(server, '\0'.join(args)) |
|
89 | writeblock(server, '\0'.join(args)) | |
84 |
|
90 | |||
85 | if not input: |
|
91 | if not input: | |
86 |
input = |
|
92 | input = stringio() | |
87 |
|
93 | |||
88 | while True: |
|
94 | while True: | |
89 | ch, data = readchannel(server) |
|
95 | ch, data = readchannel(server) |
@@ -102,8 +102,7 typical client does not want echo-back m | |||||
102 | ... print 'server exit code =', server.wait() |
|
102 | ... print 'server exit code =', server.wait() | |
103 | server exit code = 1 |
|
103 | server exit code = 1 | |
104 |
|
104 | |||
105 | >>> import cStringIO |
|
105 | >>> from hgclient import readchannel, runcommand, check, stringio | |
106 | >>> from hgclient import readchannel, runcommand, check |
|
|||
107 | >>> @check |
|
106 | >>> @check | |
108 | ... def serverinput(server): |
|
107 | ... def serverinput(server): | |
109 | ... readchannel(server) |
|
108 | ... readchannel(server) | |
@@ -123,7 +122,7 typical client does not want echo-back m | |||||
123 | ... +1 |
|
122 | ... +1 | |
124 | ... """ |
|
123 | ... """ | |
125 | ... |
|
124 | ... | |
126 |
... runcommand(server, ['import', '-'], input= |
|
125 | ... runcommand(server, ['import', '-'], input=stringio(patch)) | |
127 | ... runcommand(server, ['log']) |
|
126 | ... runcommand(server, ['log']) | |
128 | *** runcommand import - |
|
127 | *** runcommand import - | |
129 | applying patch from stdin |
|
128 | applying patch from stdin | |
@@ -211,15 +210,14 check that local configs for the cached | |||||
211 | > print 'now try to read something: %r' % sys.stdin.read() |
|
210 | > print 'now try to read something: %r' % sys.stdin.read() | |
212 | > EOF |
|
211 | > EOF | |
213 |
|
212 | |||
214 | >>> import cStringIO |
|
213 | >>> from hgclient import readchannel, runcommand, check, stringio | |
215 | >>> from hgclient import readchannel, runcommand, check |
|
|||
216 | >>> @check |
|
214 | >>> @check | |
217 | ... def hookoutput(server): |
|
215 | ... def hookoutput(server): | |
218 | ... readchannel(server) |
|
216 | ... readchannel(server) | |
219 | ... runcommand(server, ['--config', |
|
217 | ... runcommand(server, ['--config', | |
220 | ... 'hooks.pre-identify=python:hook.hook', |
|
218 | ... 'hooks.pre-identify=python:hook.hook', | |
221 | ... 'id'], |
|
219 | ... 'id'], | |
222 |
... input= |
|
220 | ... input=stringio('some input')) | |
223 | *** runcommand --config hooks.pre-identify=python:hook.hook id |
|
221 | *** runcommand --config hooks.pre-identify=python:hook.hook id | |
224 | hook talking |
|
222 | hook talking | |
225 | now try to read something: 'some input' |
|
223 | now try to read something: 'some input' | |
@@ -587,17 +585,16 changelog and manifest would have invali | |||||
587 | > dbgui = dbgui.py |
|
585 | > dbgui = dbgui.py | |
588 | > EOF |
|
586 | > EOF | |
589 |
|
587 | |||
590 | >>> import cStringIO |
|
588 | >>> from hgclient import readchannel, runcommand, check, stringio | |
591 | >>> from hgclient import readchannel, runcommand, check |
|
|||
592 | >>> @check |
|
589 | >>> @check | |
593 | ... def getpass(server): |
|
590 | ... def getpass(server): | |
594 | ... readchannel(server) |
|
591 | ... readchannel(server) | |
595 | ... runcommand(server, ['debuggetpass', '--config', |
|
592 | ... runcommand(server, ['debuggetpass', '--config', | |
596 | ... 'ui.interactive=True'], |
|
593 | ... 'ui.interactive=True'], | |
597 |
... input= |
|
594 | ... input=stringio('1234\n')) | |
598 | ... runcommand(server, ['debugprompt', '--config', |
|
595 | ... runcommand(server, ['debugprompt', '--config', | |
599 | ... 'ui.interactive=True'], |
|
596 | ... 'ui.interactive=True'], | |
600 |
... input= |
|
597 | ... input=stringio('5678\n')) | |
601 | ... runcommand(server, ['debugreadstdin']) |
|
598 | ... runcommand(server, ['debugreadstdin']) | |
602 | ... runcommand(server, ['debugwritestdout']) |
|
599 | ... runcommand(server, ['debugwritestdout']) | |
603 | *** runcommand debuggetpass --config ui.interactive=True |
|
600 | *** runcommand debuggetpass --config ui.interactive=True | |
@@ -611,14 +608,13 changelog and manifest would have invali | |||||
611 |
|
608 | |||
612 | run commandserver in commandserver, which is silly but should work: |
|
609 | run commandserver in commandserver, which is silly but should work: | |
613 |
|
610 | |||
614 | >>> import cStringIO |
|
611 | >>> from hgclient import readchannel, runcommand, check, stringio | |
615 | >>> from hgclient import readchannel, runcommand, check |
|
|||
616 | >>> @check |
|
612 | >>> @check | |
617 | ... def nested(server): |
|
613 | ... def nested(server): | |
618 | ... print '%c, %r' % readchannel(server) |
|
614 | ... print '%c, %r' % readchannel(server) | |
619 | ... class nestedserver(object): |
|
615 | ... class nestedserver(object): | |
620 |
... stdin = |
|
616 | ... stdin = stringio('getencoding\n') | |
621 |
... stdout = |
|
617 | ... stdout = stringio() | |
622 | ... runcommand(server, ['serve', '--cmdserver', 'pipe'], |
|
618 | ... runcommand(server, ['serve', '--cmdserver', 'pipe'], | |
623 | ... output=nestedserver.stdout, input=nestedserver.stdin) |
|
619 | ... output=nestedserver.stdout, input=nestedserver.stdin) | |
624 | ... nestedserver.stdout.seek(0) |
|
620 | ... nestedserver.stdout.seek(0) | |
@@ -674,8 +670,7 unix domain socket: | |||||
674 |
|
670 | |||
675 | #if unix-socket unix-permissions |
|
671 | #if unix-socket unix-permissions | |
676 |
|
672 | |||
677 | >>> import cStringIO |
|
673 | >>> from hgclient import unixserver, readchannel, runcommand, check, stringio | |
678 | >>> from hgclient import unixserver, readchannel, runcommand, check |
|
|||
679 | >>> server = unixserver('.hg/server.sock', '.hg/server.log') |
|
674 | >>> server = unixserver('.hg/server.sock', '.hg/server.log') | |
680 | >>> def hellomessage(conn): |
|
675 | >>> def hellomessage(conn): | |
681 | ... ch, data = readchannel(conn) |
|
676 | ... ch, data = readchannel(conn) | |
@@ -704,7 +699,7 unix domain socket: | |||||
704 | ... 1 |
|
699 | ... 1 | |
705 | ... +2 |
|
700 | ... +2 | |
706 | ... """ |
|
701 | ... """ | |
707 |
... runcommand(conn, ['import', '-'], input= |
|
702 | ... runcommand(conn, ['import', '-'], input=stringio(patch)) | |
708 | ... runcommand(conn, ['log', '-rtip', '-q']) |
|
703 | ... runcommand(conn, ['log', '-rtip', '-q']) | |
709 | >>> check(serverinput, server.connect) |
|
704 | >>> check(serverinput, server.connect) | |
710 | *** runcommand import - |
|
705 | *** runcommand import - |
General Comments 0
You need to be logged in to leave comments.
Login now