|
1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 |
|
17 import os |
|
18 import logging |
|
19 from optparse import OptionParser, OptionGroup |
|
20 import cone_common |
|
21 from cone.public import api, exceptions |
|
22 from cone.action import fix |
|
23 from cone.validation import confmlvalidation |
|
24 |
|
25 ROOT_PATH = os.path.abspath(os.path.dirname(__file__)) |
|
26 |
|
27 VERSION = '1.0' |
|
28 |
|
29 logger = logging.getLogger('cone') |
|
30 |
|
31 def main(): |
|
32 """ Run automatic fixes for configurations. """ |
|
33 parser = OptionParser(version="ConE validate %s" % VERSION) |
|
34 |
|
35 parser.add_options(cone_common.COMMON_OPTIONS) |
|
36 |
|
37 parser.add_option("-c", "--configuration", |
|
38 dest="configuration", |
|
39 help="Defines the name of the configuration for the action", |
|
40 metavar="CONFIG") |
|
41 |
|
42 parser.add_option("-p", "--project", |
|
43 dest="project", |
|
44 default=".", |
|
45 help="defines the location of current project. Default is the "\ |
|
46 "current working directory.", |
|
47 metavar="STORAGE") |
|
48 |
|
49 group = OptionGroup(parser, 'Fix options', |
|
50 'The fix action is intended for performing fixes on a '\ |
|
51 'configuration. ') |
|
52 |
|
53 group.add_option("--print-available-fixes", |
|
54 action="store_true", |
|
55 help="Print all configuration fixer objects available.", |
|
56 default=False) |
|
57 |
|
58 group.add_option("--exclude-filter", |
|
59 action="append", |
|
60 help="Exclude problems by given filter. "\ |
|
61 "Examples: --exclude-filter=schema, --exclude-filter=schema.implml, --exclude-filter=schema.confml, --exclude-filter=schema.implml.ruleml", |
|
62 default=None) |
|
63 |
|
64 group.add_option("--include-filter", |
|
65 action="append", |
|
66 help="Include problems by given filter."\ |
|
67 "Examples: --include-filter=schema.implml, --include-filter=schema.implml.ruleml", |
|
68 default=None) |
|
69 |
|
70 parser.add_option_group(group) |
|
71 (options, _) = parser.parse_args() |
|
72 |
|
73 cone_common.handle_common_options(options) |
|
74 |
|
75 |
|
76 if options.print_available_fixes: |
|
77 print "Available fixers:" |
|
78 for fix_class in confmlvalidation.get_fixer_classes(): |
|
79 print "%s: %s" % (fix_class, fix_class.__doc__) |
|
80 return 0 |
|
81 else: |
|
82 if not options.configuration: |
|
83 parser.error("A configuration must be given! Use -c / --configuration option.") |
|
84 action = fix.ConeFixAction(include_filter=options.include_filter or [], |
|
85 exclude_filter=options.exclude_filter or [], |
|
86 username=options.username, |
|
87 password=options.password, |
|
88 project_name=options.project, |
|
89 configuration_name=options.configuration) |
|
90 |
|
91 status = action.run() |
|
92 if status: |
|
93 action.save() |
|
94 action.close() |
|
95 |
|
96 return status |
|
97 |
|
98 |
|
99 if __name__ == "__main__": |
|
100 main() |