Show More
@@ -1,109 +1,117 b'' | |||
|
1 | 1 | # A minimal client for Mercurial's command server |
|
2 | 2 | |
|
3 | import os, sys, signal, struct, socket, subprocess, time, cStringIO | |
|
3 | from __future__ import absolute_import, print_function | |
|
4 | import cStringIO | |
|
5 | import os | |
|
6 | import signal | |
|
7 | import socket | |
|
8 | import struct | |
|
9 | import subprocess | |
|
10 | import sys | |
|
11 | import time | |
|
4 | 12 | |
|
5 | 13 | def connectpipe(path=None): |
|
6 | 14 | cmdline = ['hg', 'serve', '--cmdserver', 'pipe'] |
|
7 | 15 | if path: |
|
8 | 16 | cmdline += ['-R', path] |
|
9 | 17 | |
|
10 | 18 | server = subprocess.Popen(cmdline, stdin=subprocess.PIPE, |
|
11 | 19 | stdout=subprocess.PIPE) |
|
12 | 20 | |
|
13 | 21 | return server |
|
14 | 22 | |
|
15 | 23 | class unixconnection(object): |
|
16 | 24 | def __init__(self, sockpath): |
|
17 | 25 | self.sock = sock = socket.socket(socket.AF_UNIX) |
|
18 | 26 | sock.connect(sockpath) |
|
19 | 27 | self.stdin = sock.makefile('wb') |
|
20 | 28 | self.stdout = sock.makefile('rb') |
|
21 | 29 | |
|
22 | 30 | def wait(self): |
|
23 | 31 | self.stdin.close() |
|
24 | 32 | self.stdout.close() |
|
25 | 33 | self.sock.close() |
|
26 | 34 | |
|
27 | 35 | class unixserver(object): |
|
28 | 36 | def __init__(self, sockpath, logpath=None, repopath=None): |
|
29 | 37 | self.sockpath = sockpath |
|
30 | 38 | cmdline = ['hg', 'serve', '--cmdserver', 'unix', '-a', sockpath] |
|
31 | 39 | if repopath: |
|
32 | 40 | cmdline += ['-R', repopath] |
|
33 | 41 | if logpath: |
|
34 | 42 | stdout = open(logpath, 'a') |
|
35 | 43 | stderr = subprocess.STDOUT |
|
36 | 44 | else: |
|
37 | 45 | stdout = stderr = None |
|
38 | 46 | self.server = subprocess.Popen(cmdline, stdout=stdout, stderr=stderr) |
|
39 | 47 | # wait for listen() |
|
40 | 48 | while self.server.poll() is None: |
|
41 | 49 | if os.path.exists(sockpath): |
|
42 | 50 | break |
|
43 | 51 | time.sleep(0.1) |
|
44 | 52 | |
|
45 | 53 | def connect(self): |
|
46 | 54 | return unixconnection(self.sockpath) |
|
47 | 55 | |
|
48 | 56 | def shutdown(self): |
|
49 | 57 | os.kill(self.server.pid, signal.SIGTERM) |
|
50 | 58 | self.server.wait() |
|
51 | 59 | |
|
52 | 60 | def writeblock(server, data): |
|
53 | 61 | server.stdin.write(struct.pack('>I', len(data))) |
|
54 | 62 | server.stdin.write(data) |
|
55 | 63 | server.stdin.flush() |
|
56 | 64 | |
|
57 | 65 | def readchannel(server): |
|
58 | 66 | data = server.stdout.read(5) |
|
59 | 67 | if not data: |
|
60 | 68 | raise EOFError |
|
61 | 69 | channel, length = struct.unpack('>cI', data) |
|
62 | 70 | if channel in 'IL': |
|
63 | 71 | return channel, length |
|
64 | 72 | else: |
|
65 | 73 | return channel, server.stdout.read(length) |
|
66 | 74 | |
|
67 | 75 | def sep(text): |
|
68 | 76 | return text.replace('\\', '/') |
|
69 | 77 | |
|
70 | 78 | def runcommand(server, args, output=sys.stdout, error=sys.stderr, input=None, |
|
71 | 79 | outfilter=lambda x: x): |
|
72 |
print |
|
|
80 | print('*** runcommand', ' '.join(args)) | |
|
73 | 81 | sys.stdout.flush() |
|
74 | 82 | server.stdin.write('runcommand\n') |
|
75 | 83 | writeblock(server, '\0'.join(args)) |
|
76 | 84 | |
|
77 | 85 | if not input: |
|
78 | 86 | input = cStringIO.StringIO() |
|
79 | 87 | |
|
80 | 88 | while True: |
|
81 | 89 | ch, data = readchannel(server) |
|
82 | 90 | if ch == 'o': |
|
83 | 91 | output.write(outfilter(data)) |
|
84 | 92 | output.flush() |
|
85 | 93 | elif ch == 'e': |
|
86 | 94 | error.write(data) |
|
87 | 95 | error.flush() |
|
88 | 96 | elif ch == 'I': |
|
89 | 97 | writeblock(server, input.read(data)) |
|
90 | 98 | elif ch == 'L': |
|
91 | 99 | writeblock(server, input.readline(data)) |
|
92 | 100 | elif ch == 'r': |
|
93 | 101 | ret, = struct.unpack('>i', data) |
|
94 | 102 | if ret != 0: |
|
95 |
print |
|
|
103 | print(' [%d]' % ret) | |
|
96 | 104 | return ret |
|
97 | 105 | else: |
|
98 |
print |
|
|
106 | print("unexpected channel %c: %r" % (ch, data)) | |
|
99 | 107 | if ch.isupper(): |
|
100 | 108 | return |
|
101 | 109 | |
|
102 | 110 | def check(func, connect=connectpipe): |
|
103 | 111 | sys.stdout.flush() |
|
104 | 112 | server = connect() |
|
105 | 113 | try: |
|
106 | 114 | return func(server) |
|
107 | 115 | finally: |
|
108 | 116 | server.stdin.close() |
|
109 | 117 | server.wait() |
@@ -1,160 +1,158 b'' | |||
|
1 | 1 | #require test-repo |
|
2 | 2 | |
|
3 | 3 | $ cd "$TESTDIR"/.. |
|
4 | 4 | |
|
5 | 5 | $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py |
|
6 | 6 | contrib/check-code.py not using absolute_import |
|
7 | 7 | contrib/check-code.py requires print_function |
|
8 | 8 | contrib/debugshell.py not using absolute_import |
|
9 | contrib/hgclient.py not using absolute_import | |
|
10 | contrib/hgclient.py requires print_function | |
|
11 | 9 | contrib/hgfixes/fix_bytes.py not using absolute_import |
|
12 | 10 | contrib/hgfixes/fix_bytesmod.py not using absolute_import |
|
13 | 11 | contrib/hgfixes/fix_leftover_imports.py not using absolute_import |
|
14 | 12 | contrib/import-checker.py not using absolute_import |
|
15 | 13 | contrib/import-checker.py requires print_function |
|
16 | 14 | contrib/memory.py not using absolute_import |
|
17 | 15 | contrib/perf.py not using absolute_import |
|
18 | 16 | contrib/python-hook-examples.py not using absolute_import |
|
19 | 17 | contrib/revsetbenchmarks.py not using absolute_import |
|
20 | 18 | contrib/revsetbenchmarks.py requires print_function |
|
21 | 19 | contrib/showstack.py not using absolute_import |
|
22 | 20 | contrib/synthrepo.py not using absolute_import |
|
23 | 21 | contrib/win32/hgwebdir_wsgi.py not using absolute_import |
|
24 | 22 | doc/check-seclevel.py not using absolute_import |
|
25 | 23 | doc/gendoc.py not using absolute_import |
|
26 | 24 | doc/hgmanpage.py not using absolute_import |
|
27 | 25 | hgext/__init__.py not using absolute_import |
|
28 | 26 | hgext/color.py not using absolute_import |
|
29 | 27 | hgext/convert/__init__.py not using absolute_import |
|
30 | 28 | hgext/convert/bzr.py not using absolute_import |
|
31 | 29 | hgext/convert/common.py not using absolute_import |
|
32 | 30 | hgext/convert/convcmd.py not using absolute_import |
|
33 | 31 | hgext/convert/cvs.py not using absolute_import |
|
34 | 32 | hgext/convert/cvsps.py not using absolute_import |
|
35 | 33 | hgext/convert/darcs.py not using absolute_import |
|
36 | 34 | hgext/convert/filemap.py not using absolute_import |
|
37 | 35 | hgext/convert/git.py not using absolute_import |
|
38 | 36 | hgext/convert/gnuarch.py not using absolute_import |
|
39 | 37 | hgext/convert/hg.py not using absolute_import |
|
40 | 38 | hgext/convert/monotone.py not using absolute_import |
|
41 | 39 | hgext/convert/p4.py not using absolute_import |
|
42 | 40 | hgext/convert/subversion.py not using absolute_import |
|
43 | 41 | hgext/convert/transport.py not using absolute_import |
|
44 | 42 | hgext/eol.py not using absolute_import |
|
45 | 43 | hgext/extdiff.py not using absolute_import |
|
46 | 44 | hgext/factotum.py not using absolute_import |
|
47 | 45 | hgext/fetch.py not using absolute_import |
|
48 | 46 | hgext/gpg.py not using absolute_import |
|
49 | 47 | hgext/graphlog.py not using absolute_import |
|
50 | 48 | hgext/hgcia.py not using absolute_import |
|
51 | 49 | hgext/hgk.py not using absolute_import |
|
52 | 50 | hgext/highlight/__init__.py not using absolute_import |
|
53 | 51 | hgext/highlight/highlight.py not using absolute_import |
|
54 | 52 | hgext/histedit.py not using absolute_import |
|
55 | 53 | hgext/largefiles/__init__.py not using absolute_import |
|
56 | 54 | hgext/largefiles/basestore.py not using absolute_import |
|
57 | 55 | hgext/largefiles/lfcommands.py not using absolute_import |
|
58 | 56 | hgext/largefiles/lfutil.py not using absolute_import |
|
59 | 57 | hgext/largefiles/localstore.py not using absolute_import |
|
60 | 58 | hgext/largefiles/overrides.py not using absolute_import |
|
61 | 59 | hgext/largefiles/proto.py not using absolute_import |
|
62 | 60 | hgext/largefiles/remotestore.py not using absolute_import |
|
63 | 61 | hgext/largefiles/reposetup.py not using absolute_import |
|
64 | 62 | hgext/largefiles/uisetup.py not using absolute_import |
|
65 | 63 | hgext/largefiles/wirestore.py not using absolute_import |
|
66 | 64 | hgext/mq.py not using absolute_import |
|
67 | 65 | hgext/notify.py not using absolute_import |
|
68 | 66 | hgext/patchbomb.py not using absolute_import |
|
69 | 67 | hgext/purge.py not using absolute_import |
|
70 | 68 | hgext/rebase.py not using absolute_import |
|
71 | 69 | hgext/record.py not using absolute_import |
|
72 | 70 | hgext/relink.py not using absolute_import |
|
73 | 71 | hgext/schemes.py not using absolute_import |
|
74 | 72 | hgext/share.py not using absolute_import |
|
75 | 73 | hgext/shelve.py not using absolute_import |
|
76 | 74 | hgext/strip.py not using absolute_import |
|
77 | 75 | hgext/transplant.py not using absolute_import |
|
78 | 76 | hgext/win32mbcs.py not using absolute_import |
|
79 | 77 | hgext/win32text.py not using absolute_import |
|
80 | 78 | i18n/check-translation.py not using absolute_import |
|
81 | 79 | i18n/polib.py not using absolute_import |
|
82 | 80 | setup.py not using absolute_import |
|
83 | 81 | tests/filterpyflakes.py requires print_function |
|
84 | 82 | tests/generate-working-copy-states.py requires print_function |
|
85 | 83 | tests/get-with-headers.py requires print_function |
|
86 | 84 | tests/heredoctest.py requires print_function |
|
87 | 85 | tests/hypothesishelpers.py not using absolute_import |
|
88 | 86 | tests/hypothesishelpers.py requires print_function |
|
89 | 87 | tests/killdaemons.py not using absolute_import |
|
90 | 88 | tests/md5sum.py not using absolute_import |
|
91 | 89 | tests/mockblackbox.py not using absolute_import |
|
92 | 90 | tests/printenv.py not using absolute_import |
|
93 | 91 | tests/readlink.py not using absolute_import |
|
94 | 92 | tests/readlink.py requires print_function |
|
95 | 93 | tests/revlog-formatv0.py not using absolute_import |
|
96 | 94 | tests/run-tests.py not using absolute_import |
|
97 | 95 | tests/seq.py not using absolute_import |
|
98 | 96 | tests/seq.py requires print_function |
|
99 | 97 | tests/silenttestrunner.py not using absolute_import |
|
100 | 98 | tests/silenttestrunner.py requires print_function |
|
101 | 99 | tests/sitecustomize.py not using absolute_import |
|
102 | 100 | tests/svn-safe-append.py not using absolute_import |
|
103 | 101 | tests/svnxml.py not using absolute_import |
|
104 | 102 | tests/test-ancestor.py requires print_function |
|
105 | 103 | tests/test-atomictempfile.py not using absolute_import |
|
106 | 104 | tests/test-batching.py not using absolute_import |
|
107 | 105 | tests/test-batching.py requires print_function |
|
108 | 106 | tests/test-bdiff.py not using absolute_import |
|
109 | 107 | tests/test-bdiff.py requires print_function |
|
110 | 108 | tests/test-context.py not using absolute_import |
|
111 | 109 | tests/test-context.py requires print_function |
|
112 | 110 | tests/test-demandimport.py not using absolute_import |
|
113 | 111 | tests/test-demandimport.py requires print_function |
|
114 | 112 | tests/test-dispatch.py not using absolute_import |
|
115 | 113 | tests/test-dispatch.py requires print_function |
|
116 | 114 | tests/test-doctest.py not using absolute_import |
|
117 | 115 | tests/test-duplicateoptions.py not using absolute_import |
|
118 | 116 | tests/test-duplicateoptions.py requires print_function |
|
119 | 117 | tests/test-filecache.py not using absolute_import |
|
120 | 118 | tests/test-filecache.py requires print_function |
|
121 | 119 | tests/test-filelog.py not using absolute_import |
|
122 | 120 | tests/test-filelog.py requires print_function |
|
123 | 121 | tests/test-hg-parseurl.py not using absolute_import |
|
124 | 122 | tests/test-hg-parseurl.py requires print_function |
|
125 | 123 | tests/test-hgweb-auth.py not using absolute_import |
|
126 | 124 | tests/test-hgweb-auth.py requires print_function |
|
127 | 125 | tests/test-hgwebdir-paths.py not using absolute_import |
|
128 | 126 | tests/test-hybridencode.py not using absolute_import |
|
129 | 127 | tests/test-hybridencode.py requires print_function |
|
130 | 128 | tests/test-lrucachedict.py not using absolute_import |
|
131 | 129 | tests/test-lrucachedict.py requires print_function |
|
132 | 130 | tests/test-manifest.py not using absolute_import |
|
133 | 131 | tests/test-minirst.py not using absolute_import |
|
134 | 132 | tests/test-minirst.py requires print_function |
|
135 | 133 | tests/test-parseindex2.py not using absolute_import |
|
136 | 134 | tests/test-parseindex2.py requires print_function |
|
137 | 135 | tests/test-pathencode.py not using absolute_import |
|
138 | 136 | tests/test-pathencode.py requires print_function |
|
139 | 137 | tests/test-propertycache.py not using absolute_import |
|
140 | 138 | tests/test-propertycache.py requires print_function |
|
141 | 139 | tests/test-revlog-ancestry.py not using absolute_import |
|
142 | 140 | tests/test-revlog-ancestry.py requires print_function |
|
143 | 141 | tests/test-run-tests.py not using absolute_import |
|
144 | 142 | tests/test-simplemerge.py not using absolute_import |
|
145 | 143 | tests/test-status-inprocess.py not using absolute_import |
|
146 | 144 | tests/test-status-inprocess.py requires print_function |
|
147 | 145 | tests/test-symlink-os-yes-fs-no.py not using absolute_import |
|
148 | 146 | tests/test-trusted.py not using absolute_import |
|
149 | 147 | tests/test-trusted.py requires print_function |
|
150 | 148 | tests/test-ui-color.py not using absolute_import |
|
151 | 149 | tests/test-ui-color.py requires print_function |
|
152 | 150 | tests/test-ui-config.py not using absolute_import |
|
153 | 151 | tests/test-ui-config.py requires print_function |
|
154 | 152 | tests/test-ui-verbosity.py not using absolute_import |
|
155 | 153 | tests/test-ui-verbosity.py requires print_function |
|
156 | 154 | tests/test-url.py not using absolute_import |
|
157 | 155 | tests/test-url.py requires print_function |
|
158 | 156 | tests/test-walkrepo.py requires print_function |
|
159 | 157 | tests/test-wireproto.py requires print_function |
|
160 | 158 | tests/tinyproxy.py requires print_function |
General Comments 0
You need to be logged in to leave comments.
Login now