~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-09-16 01:47:06 UTC
  • mfrom: (1910.19.16 smart-server)
  • Revision ID: pqm@pqm.ubuntu.com-20060916014706-93f2994bdb0c0850
(spiv,mpool,robertc) Create a RPC protocol as the building blocks for a smart server

Show diffs side-by-side

added added

removed removed

Lines of Context:
2781
2781
        sys.stdin.readline()
2782
2782
 
2783
2783
 
 
2784
class cmd_serve(Command):
 
2785
    """Run the bzr server.
 
2786
    """
 
2787
    takes_options = [
 
2788
        Option('inet',
 
2789
               help='serve on stdin/out for use from inetd or sshd'),
 
2790
        Option('port',
 
2791
               help='listen for connections on nominated port of the form '
 
2792
                    '[hostname:]portnumber. Passing 0 as the port number will '
 
2793
                    'result in a dynamically allocated port.',
 
2794
               type=str),
 
2795
        Option('directory',
 
2796
               help='serve contents of directory',
 
2797
               type=unicode),
 
2798
        ]
 
2799
 
 
2800
    def run(self, port=None, inet=False, directory=None):
 
2801
        from bzrlib.transport import smart
 
2802
        from bzrlib.transport import get_transport
 
2803
        if directory is None:
 
2804
            directory = os.getcwd()
 
2805
        t = get_transport(directory)
 
2806
        if inet:
 
2807
            server = smart.SmartStreamServer(sys.stdin, sys.stdout, t)
 
2808
        elif port is not None:
 
2809
            if ':' in port:
 
2810
                host, port = port.split(':')
 
2811
            else:
 
2812
                host = '127.0.0.1'
 
2813
            server = smart.SmartTCPServer(t, host=host, port=int(port))
 
2814
            print 'listening on port: ', server.port
 
2815
            sys.stdout.flush()
 
2816
        else:
 
2817
            raise BzrCommandError("bzr serve requires one of --inet or --port")
 
2818
        server.serve()
 
2819
 
 
2820
 
2784
2821
# command-line interpretation helper for merge-related commands
2785
2822
def merge(other_revision, base_revision,
2786
2823
          check_clean=True, ignore_zero=False,