~adiroiban/bzr-custom-url-schemes/bzr-2.4

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: A. S. Budden
  • Date: 2010-03-03 13:46:56 UTC
  • Revision ID: abudden@gmail.com-20100303134656-dig2gyd1myne1z3n
Added ability to add url schemes from the bzr command line.  Added basic documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
version_info = (0,1,0)
 
1
"""Custom URL Scheme - Create custom URL schemes for shortening URLS
 
2
 
 
3
Custom URL Scheme is a simple plugin for Bazaar, providing a means of
 
4
branching from remote servers without having to type out the full address
 
5
of the server.   For example, if it is desirable to retrieve branches stored
 
6
on a server with sftp, you could shorten:
 
7
 
 
8
    bzr branch sftp://my.username@server.com/path/to/bazaar/projects/work/myproj
 
9
 
 
10
to:
 
11
 
 
12
    bzr branch serv:work/myproj
 
13
 
 
14
In normal use, there are no required commands, but some commands are available 
 
15
to simplify creation of url schemes:
 
16
 
 
17
 * custom-url-scheme-add - Add a new URL scheme
 
18
 * custom-url-scheme-list - List existing URL schemes
 
19
 * custom-url-scheme-remove - Remove an existing URL scheme
 
20
 
 
21
Very little error checking is carried out at present.
 
22
"""
 
23
    
 
24
version_info = (1,0,0)
2
25
 
3
26
from bzrlib.directory_service import directories
4
27
from bzrlib.config import GlobalConfig
8
31
            'SchemeDirectory',
9
32
            'Custom URLScheme directory service',)
10
33
 
11
 
config = GlobalConfig()
12
 
parser = config._get_parser()
13
 
custom_schemes = parser.get('Custom URL Schemes', {})
14
 
for name, command in custom_schemes.items():
15
 
    while name.endswith(':'):
16
 
        name = name[:-1]
17
 
    _register_directory(name)
18
 
 
 
34
def GetCustomSchemes():
 
35
    config = GlobalConfig()
 
36
    parser = config._get_parser()
 
37
    stored_custom_schemes = parser.get('Custom URL Schemes', {})
 
38
    custom_schemes = {}
 
39
    for name, command in stored_custom_schemes.items():
 
40
        while name.endswith(':'):
 
41
            name = name[:-1]
 
42
        custom_schemes[name] = command
 
43
    return custom_schemes
 
44
 
 
45
def register_directories():
 
46
    custom_schemes = GetCustomSchemes()
 
47
    for name in custom_schemes.keys():
 
48
        _register_directory(name)
 
49
 
 
50
register_directories()
 
51
 
 
52
from bzrlib.commands import plugin_cmds
 
53
lazy_commands = (
 
54
    # module, command, [aliases]
 
55
    ('bzrlib.plugins.custom_url_scheme.commands', 'cmd_custom_url_scheme_add', []),
 
56
    ('bzrlib.plugins.custom_url_scheme.commands', 'cmd_custom_url_scheme_list', []),
 
57
    ('bzrlib.plugins.custom_url_scheme.commands', 'cmd_custom_url_scheme_remove', []),
 
58
)
 
59
 
 
60
for module, name, aliases in lazy_commands:
 
61
    plugin_cmds.register_lazy(name, aliases, module)