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