100 ... |
100 ... |
101 ... # server exits with 1 if the pipe closed while reading the command |
101 ... # server exits with 1 if the pipe closed while reading the command |
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) |
110 ... |
109 ... |
111 ... patch = """ |
110 ... patch = """ |
121 ... +++ b/a Thu Jan 01 00:00:00 1970 +0000 |
120 ... +++ b/a Thu Jan 01 00:00:00 1970 +0000 |
122 ... @@ -0,0 +1,1 @@ |
121 ... @@ -0,0 +1,1 @@ |
123 ... +1 |
122 ... +1 |
124 ... """ |
123 ... """ |
125 ... |
124 ... |
126 ... runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch)) |
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 |
130 *** runcommand log |
129 *** runcommand log |
131 changeset: 0:eff892de26ec |
130 changeset: 0:eff892de26ec |
209 > def hook(**args): |
208 > def hook(**args): |
210 > print 'hook talking' |
209 > print 'hook talking' |
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=cStringIO.StringIO('some 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' |
226 eff892de26ec tip |
224 eff892de26ec tip |
227 |
225 |
585 $ cat <<EOF >> .hg/hgrc |
583 $ cat <<EOF >> .hg/hgrc |
586 > [extensions] |
584 > [extensions] |
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=cStringIO.StringIO('1234\n')) |
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=cStringIO.StringIO('5678\n')) |
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 |
604 password: 1234 |
601 password: 1234 |
605 *** runcommand debugprompt --config ui.interactive=True |
602 *** runcommand debugprompt --config ui.interactive=True |
609 *** runcommand debugwritestdout |
606 *** runcommand debugwritestdout |
610 |
607 |
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 = cStringIO.StringIO('getencoding\n') |
616 ... stdin = stringio('getencoding\n') |
621 ... stdout = cStringIO.StringIO() |
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) |
625 ... print '%c, %r' % readchannel(nestedserver) # hello |
621 ... print '%c, %r' % readchannel(nestedserver) # hello |
626 ... print '%c, %r' % readchannel(nestedserver) # getencoding |
622 ... print '%c, %r' % readchannel(nestedserver) # getencoding |
672 $ cd repo |
668 $ cd repo |
673 $ hg update -q |
669 $ hg update -q |
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) |
682 ... print '%c, %r' % (ch, data) |
677 ... print '%c, %r' % (ch, data) |
683 ... runcommand(conn, ['id']) |
678 ... runcommand(conn, ['id']) |
702 ... +++ b/a |
697 ... +++ b/a |
703 ... @@ -1,1 +1,2 @@ |
698 ... @@ -1,1 +1,2 @@ |
704 ... 1 |
699 ... 1 |
705 ... +2 |
700 ... +2 |
706 ... """ |
701 ... """ |
707 ... runcommand(conn, ['import', '-'], input=cStringIO.StringIO(patch)) |
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 - |
711 applying patch from stdin |
706 applying patch from stdin |
712 *** runcommand log -rtip -q |
707 *** runcommand log -rtip -q |