hgext/zeroconf/__init__.py
author Renato Cunha <renatoc@gmail.com>
Mon, 14 Jun 2010 16:56:20 -0300
changeset 11340 938fefb57db5
parent 11005 c9b4e9431af7
child 11504 6bfb76cb8873
permissions -rw-r--r--
hgext/zeroconf/__init__.py: Separate relative and absolute imports. 2to3 complains when relative and absolute imports are mixed, this fix just separates them on the zeroconf extension. According to 2to3, the other modules are fine.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     1
# zeroconf.py - zeroconf support for Mercurial
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     2
#
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     3
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8191
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9489
diff changeset
     6
# GNU General Public License version 2 or any later version.
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     7
8894
868670dbc237 extensions: improve the consistency of synopses
Cédric Duval <cedricduval@free.fr>
parents: 8866
diff changeset
     8
'''discover and advertise repositories on the local network
7606
e86ca711544d zeroconf: add extension documentation
David Soria Parra <dsp@php.net>
parents: 7295
diff changeset
     9
8003
14f27921932a zeroconf: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7874
diff changeset
    10
Zeroconf enabled repositories will be announced in a network without
14f27921932a zeroconf: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7874
diff changeset
    11
the need to configure a server or a service. They can be discovered
14f27921932a zeroconf: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7874
diff changeset
    12
without knowing their actual IP address.
7606
e86ca711544d zeroconf: add extension documentation
David Soria Parra <dsp@php.net>
parents: 7295
diff changeset
    13
8003
14f27921932a zeroconf: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7874
diff changeset
    14
To allow other people to discover your repository using run "hg serve"
9276
51e85071caf0 zeroconf: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9218
diff changeset
    15
in your repository::
7606
e86ca711544d zeroconf: add extension documentation
David Soria Parra <dsp@php.net>
parents: 7295
diff changeset
    16
9218
d3db87d68337 zeroconf: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 9078
diff changeset
    17
  $ cd test
d3db87d68337 zeroconf: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 9078
diff changeset
    18
  $ hg serve
7606
e86ca711544d zeroconf: add extension documentation
David Soria Parra <dsp@php.net>
parents: 7295
diff changeset
    19
9218
d3db87d68337 zeroconf: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 9078
diff changeset
    20
You can discover zeroconf enabled repositories by running "hg paths"::
7606
e86ca711544d zeroconf: add extension documentation
David Soria Parra <dsp@php.net>
parents: 7295
diff changeset
    21
9218
d3db87d68337 zeroconf: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 9078
diff changeset
    22
  $ hg paths
d3db87d68337 zeroconf: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 9078
diff changeset
    23
  zc-test = http://example.com:8000/test
7606
e86ca711544d zeroconf: add extension documentation
David Soria Parra <dsp@php.net>
parents: 7295
diff changeset
    24
'''
e86ca711544d zeroconf: add extension documentation
David Soria Parra <dsp@php.net>
parents: 7295
diff changeset
    25
11340
938fefb57db5 hgext/zeroconf/__init__.py: Separate relative and absolute imports.
Renato Cunha <renatoc@gmail.com>
parents: 11005
diff changeset
    26
import socket, time, os
938fefb57db5 hgext/zeroconf/__init__.py: Separate relative and absolute imports.
Renato Cunha <renatoc@gmail.com>
parents: 11005
diff changeset
    27
938fefb57db5 hgext/zeroconf/__init__.py: Separate relative and absolute imports.
Renato Cunha <renatoc@gmail.com>
parents: 11005
diff changeset
    28
import Zeroconf
10342
579aae5aa549 zeroconf: override default destination folder on clone
Henrik Stuart <hg@hstuart.dk>
parents: 10317
diff changeset
    29
from mercurial import ui, hg, encoding
7216
292fb2ad2846 extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents: 7088
diff changeset
    30
from mercurial import extensions
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    31
from mercurial.hgweb import hgweb_mod
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    32
from mercurial.hgweb import hgwebdir_mod
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    33
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    34
# publish
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    35
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    36
server = None
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    37
localip = None
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    38
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    39
def getip():
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    40
    # finds external-facing interface without sending any packets (Linux)
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    41
    try:
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    42
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    43
        s.connect(('1.0.0.1', 0))
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    44
        ip = s.getsockname()[0]
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    45
        return ip
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    46
    except:
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    47
        pass
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    48
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    49
    # Generic method, sometimes gives useless results
8264
63ea850b3312 zeroconf: guess ip for Zeroconf
Alexander Solovyov <piranha@piranha.org.ua>
parents: 8225
diff changeset
    50
    try:
63ea850b3312 zeroconf: guess ip for Zeroconf
Alexander Solovyov <piranha@piranha.org.ua>
parents: 8225
diff changeset
    51
        dumbip = socket.gethostbyaddr(socket.gethostname())[2][0]
63ea850b3312 zeroconf: guess ip for Zeroconf
Alexander Solovyov <piranha@piranha.org.ua>
parents: 8225
diff changeset
    52
        if not dumbip.startswith('127.') and ':' not in dumbip:
63ea850b3312 zeroconf: guess ip for Zeroconf
Alexander Solovyov <piranha@piranha.org.ua>
parents: 8225
diff changeset
    53
            return dumbip
10317
192083a3e6fe zeroconf: gethostbyaddr may also fail with socket.herror
Augie Fackler <durin42@gmail.com>
parents: 10263
diff changeset
    54
    except (socket.gaierror, socket.herror):
8264
63ea850b3312 zeroconf: guess ip for Zeroconf
Alexander Solovyov <piranha@piranha.org.ua>
parents: 8225
diff changeset
    55
        dumbip = '127.0.0.1'
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    56
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    57
    # works elsewhere, but actually sends a packet
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    58
    try:
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    59
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    60
        s.connect(('1.0.0.1', 1))
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    61
        ip = s.getsockname()[0]
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    62
        return ip
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    63
    except:
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    64
        pass
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    65
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    66
    return dumbip
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    67
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    68
def publish(name, desc, path, port):
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    69
    global server, localip
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    70
    if not server:
8264
63ea850b3312 zeroconf: guess ip for Zeroconf
Alexander Solovyov <piranha@piranha.org.ua>
parents: 8225
diff changeset
    71
        ip = getip()
63ea850b3312 zeroconf: guess ip for Zeroconf
Alexander Solovyov <piranha@piranha.org.ua>
parents: 8225
diff changeset
    72
        if ip.startswith('127.'):
7295
66d0fc108044 zeroconf: Don't break serve if no internet connection is present.
Augie Fackler <durin42@gmail.com>
parents: 7282
diff changeset
    73
            # if we have no internet connection, this can happen.
66d0fc108044 zeroconf: Don't break serve if no internet connection is present.
Augie Fackler <durin42@gmail.com>
parents: 7282
diff changeset
    74
            return
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    75
        localip = socket.inet_aton(ip)
8264
63ea850b3312 zeroconf: guess ip for Zeroconf
Alexander Solovyov <piranha@piranha.org.ua>
parents: 8225
diff changeset
    76
        server = Zeroconf.Zeroconf(ip)
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    77
7845
c2cd8d772805 zeroconf: advertise repositories with hostname
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7777
diff changeset
    78
    hostname = socket.gethostname().split('.')[0]
c2cd8d772805 zeroconf: advertise repositories with hostname
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7777
diff changeset
    79
    host = hostname + ".local"
c2cd8d772805 zeroconf: advertise repositories with hostname
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7777
diff changeset
    80
    name = "%s-%s" % (hostname, name)
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    81
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    82
    # advertise to browsers
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    83
    svc = Zeroconf.ServiceInfo('_http._tcp.local.',
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    84
                               name + '._http._tcp.local.',
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    85
                               server = host,
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    86
                               port = port,
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    87
                               properties = {'description': desc,
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    88
                                             'path': "/" + path},
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    89
                               address = localip, weight = 0, priority = 0)
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    90
    server.registerService(svc)
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    91
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    92
    # advertise to Mercurial clients
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    93
    svc = Zeroconf.ServiceInfo('_hg._tcp.local.',
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    94
                               name + '._hg._tcp.local.',
7088
58b7b5ef6cd0 zeroconf: advertise a proper hostname for _hg services
Matt Mackall <mpm@selenic.com>
parents: 7087
diff changeset
    95
                               server = host,
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    96
                               port = port,
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    97
                               properties = {'description': desc,
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    98
                                             'path': "/" + path},
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    99
                               address = localip, weight = 0, priority = 0)
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   100
    server.registerService(svc)
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   101
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   102
class hgwebzc(hgweb_mod.hgweb):
11005
c9b4e9431af7 zeroconf: handle string hgweb config args
Matt Mackall <mpm@selenic.com>
parents: 10993
diff changeset
   103
    def __init__(self, repo, name=None, baseui=None):
c9b4e9431af7 zeroconf: handle string hgweb config args
Matt Mackall <mpm@selenic.com>
parents: 10993
diff changeset
   104
        super(hgwebzc, self).__init__(repo, name=name, baseui=baseui)
c9b4e9431af7 zeroconf: handle string hgweb config args
Matt Mackall <mpm@selenic.com>
parents: 10993
diff changeset
   105
        name = self.reponame or os.path.basename(self.repo.root)
9442
080227f584a1 zeroconf: fix hgweb published URLs (issue1819)
Patrick Mezard <pmezard@gmail.com>
parents: 8894
diff changeset
   106
        path = self.repo.ui.config("web", "prefix", "").strip('/')
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   107
        desc = self.repo.ui.config("web", "description", name)
11005
c9b4e9431af7 zeroconf: handle string hgweb config args
Matt Mackall <mpm@selenic.com>
parents: 10993
diff changeset
   108
        publish(name, desc, path,
c9b4e9431af7 zeroconf: handle string hgweb config args
Matt Mackall <mpm@selenic.com>
parents: 10993
diff changeset
   109
                int(self.repo.ui.config("web", "port", 8000)))
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   110
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   111
class hgwebdirzc(hgwebdir_mod.hgwebdir):
9442
080227f584a1 zeroconf: fix hgweb published URLs (issue1819)
Patrick Mezard <pmezard@gmail.com>
parents: 8894
diff changeset
   112
    def __init__(self, conf, baseui=None):
10993
c1b43d786889 hgweb: make baseui parameter non-positional
Matt Mackall <mpm@selenic.com>
parents: 10342
diff changeset
   113
        super(hgwebdirzc, self).__init__(conf, baseui=baseui)
9442
080227f584a1 zeroconf: fix hgweb published URLs (issue1819)
Patrick Mezard <pmezard@gmail.com>
parents: 8894
diff changeset
   114
        prefix = self.ui.config("web", "prefix", "").strip('/') + '/'
9488
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   115
        for repo, path in self.repos:
8191
35604226d712 hgweb: kill parentui references
Matt Mackall <mpm@selenic.com>
parents: 8190
diff changeset
   116
            u = self.ui.copy()
9488
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   117
            u.readconfig(os.path.join(path, '.hg', 'hgrc'))
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   118
            name = os.path.basename(repo)
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   119
            path = (prefix + repo).strip('/')
9489
cec4b0d3fb02 zeroconf: read actual description for repos in hgwebdir
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9488
diff changeset
   120
            desc = u.config('web', 'description', name)
cec4b0d3fb02 zeroconf: read actual description for repos in hgwebdir
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9488
diff changeset
   121
            publish(name, desc, path, int(u.config("web", "port", 8000)))
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   122
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   123
# listen
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   124
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   125
class listener(object):
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   126
    def __init__(self):
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   127
        self.found = {}
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   128
    def removeService(self, server, type, name):
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   129
        if repr(name) in self.found:
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   130
            del self.found[repr(name)]
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   131
    def addService(self, server, type, name):
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   132
        self.found[repr(name)] = server.getServiceInfo(type, name)
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   133
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   134
def getzcpaths():
8264
63ea850b3312 zeroconf: guess ip for Zeroconf
Alexander Solovyov <piranha@piranha.org.ua>
parents: 8225
diff changeset
   135
    ip = getip()
63ea850b3312 zeroconf: guess ip for Zeroconf
Alexander Solovyov <piranha@piranha.org.ua>
parents: 8225
diff changeset
   136
    if ip.startswith('127.'):
63ea850b3312 zeroconf: guess ip for Zeroconf
Alexander Solovyov <piranha@piranha.org.ua>
parents: 8225
diff changeset
   137
        return
63ea850b3312 zeroconf: guess ip for Zeroconf
Alexander Solovyov <piranha@piranha.org.ua>
parents: 8225
diff changeset
   138
    server = Zeroconf.Zeroconf(ip)
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   139
    l = listener()
7874
d812029cda85 cleanup: drop variables for unused return values
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7845
diff changeset
   140
    Zeroconf.ServiceBrowser(server, "_hg._tcp.local.", l)
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   141
    time.sleep(1)
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   142
    server.close()
9488
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   143
    for value in l.found.values():
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   144
        name = value.name[:value.name.index('.')]
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   145
        url = "http://%s:%s%s" % (socket.inet_ntoa(value.address), value.port,
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   146
                                  value.properties.get("path", "/"))
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   147
        yield "zc-" + name, url
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   148
7216
292fb2ad2846 extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents: 7088
diff changeset
   149
def config(orig, self, section, key, default=None, untrusted=False):
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   150
    if section == "paths" and key.startswith("zc-"):
9488
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   151
        for name, path in getzcpaths():
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   152
            if name == key:
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   153
                return path
7216
292fb2ad2846 extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents: 7088
diff changeset
   154
    return orig(self, section, key, default, untrusted)
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   155
7238
b1a9ad7b464e zeroconf: don't break on hg showconfig
Matt Mackall <mpm@selenic.com>
parents: 7216
diff changeset
   156
def configitems(orig, self, section, untrusted=False):
9488
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   157
    repos = orig(self, section, untrusted)
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   158
    if section == "paths":
9488
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   159
        repos += getzcpaths()
33a6213a974e zeroconf: code cleanup, fixing variable names to be meaningful
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9443
diff changeset
   160
    return repos
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   161
10342
579aae5aa549 zeroconf: override default destination folder on clone
Henrik Stuart <hg@hstuart.dk>
parents: 10317
diff changeset
   162
def defaultdest(orig, source):
579aae5aa549 zeroconf: override default destination folder on clone
Henrik Stuart <hg@hstuart.dk>
parents: 10317
diff changeset
   163
    for name, path in getzcpaths():
579aae5aa549 zeroconf: override default destination folder on clone
Henrik Stuart <hg@hstuart.dk>
parents: 10317
diff changeset
   164
        if path == source:
579aae5aa549 zeroconf: override default destination folder on clone
Henrik Stuart <hg@hstuart.dk>
parents: 10317
diff changeset
   165
            return name.encode(encoding.encoding)
579aae5aa549 zeroconf: override default destination folder on clone
Henrik Stuart <hg@hstuart.dk>
parents: 10317
diff changeset
   166
    return orig(source)
579aae5aa549 zeroconf: override default destination folder on clone
Henrik Stuart <hg@hstuart.dk>
parents: 10317
diff changeset
   167
7216
292fb2ad2846 extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents: 7088
diff changeset
   168
extensions.wrapfunction(ui.ui, 'config', config)
292fb2ad2846 extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents: 7088
diff changeset
   169
extensions.wrapfunction(ui.ui, 'configitems', configitems)
10342
579aae5aa549 zeroconf: override default destination folder on clone
Henrik Stuart <hg@hstuart.dk>
parents: 10317
diff changeset
   170
extensions.wrapfunction(hg, 'defaultdest', defaultdest)
7071
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   171
hgweb_mod.hgweb = hgwebzc
643c751e60b2 zeroconf: initial implementation
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   172
hgwebdir_mod.hgwebdir = hgwebdirzc