Source

hgd / hgd.py

Full commit
Steve Losh e34fd8b 

Steve Losh c862a21 
Steve Losh bb866e7 

Steve Losh e34fd8b 






Steve Losh 27a0efe 
Steve Losh e34fd8b 



Steve Losh bb866e7 
Steve Losh e34fd8b 

Steve Losh bb866e7 

Steve Losh e34fd8b 

Steve Losh 27a0efe 
Steve Losh e34fd8b 




Steve Losh bb866e7 

Steve Losh e34fd8b 

Steve Losh bb866e7 
Steve Losh e34fd8b 

Steve Losh bb866e7 


import sys
from diesel import Application, Service, until, send, sleep
from hacks import mercurial


class DieselBuffer(object):
    def __init__(self, flush=False):
        def _nop():
            return
        def _flush():
            sleep(0.000001)
        self.dflush = _flush if flush else _nop

    def write(self, s):
        # TODO: Figure out how to flush Diesel's buffer properly.
        send(s)
        self.dflush()

    def flush(self):
        sleep(0.000001)

def _run(cwd, cmd):
    flush = cmd[0] in ['push', 'pull']
    sys.stderr = sys.stdout = DieselBuffer(flush=flush)

    try:
        mercurial.dispatch.dispatch(['--cwd', cwd, '--color', 'always'] + cmd)
    finally:
        sys.stdout = sys.__stdout__
        sys.stderr = sys.__stderr__

def handle_command(remote_addr):
    cwd = until('\r\n').strip()
    cmd = until('HGDAEMONARGSDONE\r\n').strip().splitlines()[:-1]

    _run(cwd, cmd)


app = Application()
app.add_service(Service(handle_command, port=8029))
app.run()