contrib/hgclient.py
changeset 28355 897a4bbd578b
parent 22993 24c5fd2894f8
child 28836 3f45488d70df
equal deleted inserted replaced
28354:00f317788d33 28355:897a4bbd578b
     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]
    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:
    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()