~vmiklos/bzr-fastimport/darcs

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Ian Clatworthy
  • Date: 2008-02-16 00:05:28 UTC
  • Revision ID: ian.clatworthy@internode.on.net-20080216000528-5cb1fx6tmhyowsv8
custom parameters for processors

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
 
20
20
from bzrlib.commands import Command, register_command
21
 
from bzrlib.option import RegistryOption
 
21
from bzrlib.option import RegistryOption, ListOption
22
22
 
23
23
 
24
24
def test_suite():
26
26
    return tests.test_suite()
27
27
 
28
28
 
 
29
def _defines_to_dict(defines):
 
30
    """Convert a list of definition strings to a dictionary."""
 
31
    if defines is None:
 
32
        return None
 
33
    result = {}
 
34
    for define in defines:
 
35
        kv = define.split('=', 1)
 
36
        if len(kv) == 1:
 
37
            result[define.strip()] = 1
 
38
        else:
 
39
            result[kv[0].strip()] = kv[1].strip()
 
40
    return result
 
41
 
 
42
 
29
43
class cmd_fast_import(Command):
30
44
    """Backend for fast Bazaar data importers.
31
45
 
62
76
    takes_options = ['verbose',
63
77
                    RegistryOption.from_kwargs('method',
64
78
                        'The way to process the data.',
65
 
                        title='Processing Method', value_switches=True, enum_switch=False,
66
 
                        generic="Import the data into any format (default)",
67
 
                        info="Display information only - don't import it",
 
79
                        title='Processing Method',
 
80
                        value_switches=True, enum_switch=False,
 
81
                        safe="Import the data into any format (default).",
 
82
                        info="Display information only - don't import it.",
 
83
                        ),
 
84
                    ListOption('params', short_name='P', type=str,
 
85
                        help="Define processing specific parameters.",
68
86
                        ),
69
87
                     ]
70
88
    aliases = ['fastimport']
71
 
    def run(self, verbose=False, method='generic'):
 
89
    def run(self, verbose=False, method='safe', params=None):
72
90
        import sys
73
91
        from bzrlib import bzrdir
74
92
        import parser
75
93
 
 
94
        params = _defines_to_dict(params)
76
95
        if method == 'info':
77
96
            from bzrlib.plugins.fastimport.processors import info_processor
78
 
            proc = info_processor.InfoProcessor()
 
97
            proc = info_processor.InfoProcessor(params=params)
79
98
        else:
80
99
            from bzrlib.plugins.fastimport.processors import generic_processor
81
100
            control, relpath = bzrdir.BzrDir.open_containing('.')
82
 
            proc = generic_processor.GenericProcessor(control)
 
101
            proc = generic_processor.GenericProcessor(control, params=params)
83
102
 
84
103
        # Note: might need to pass the parser to the processor so that the
85
104
        # processor can be it's error reporting with source context