equal
deleted
inserted
replaced
22 |
22 |
23 import cone_common |
23 import cone_common |
24 from cone.public import api, plugin, utils, exceptions |
24 from cone.public import api, plugin, utils, exceptions |
25 from cone.confml import persistentconfml |
25 from cone.confml import persistentconfml |
26 from cone.storage.filestorage import FileStorage |
26 from cone.storage.filestorage import FileStorage |
27 import report_util |
27 from cone.report import report_util |
28 |
28 |
29 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
29 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
30 |
30 |
31 |
31 |
32 VERSION = '1.0' |
32 VERSION = '1.0' |
64 'content_report.html', |
64 'content_report.html', |
65 'Create a report of the content files in the configuration.'), |
65 'Create a report of the content files in the configuration.'), |
66 } |
66 } |
67 |
67 |
68 def main(): |
68 def main(): |
|
69 """ Get information about project / configurations. """ |
69 shortcut_container = report_util.ReportShortcutContainer(REPORT_SHORTCUTS, |
70 shortcut_container = report_util.ReportShortcutContainer(REPORT_SHORTCUTS, |
70 None) |
71 None) |
71 |
72 |
72 parser = OptionParser(version="%%prog %s" % VERSION) |
73 parser = OptionParser(version="%%prog %s" % VERSION) |
73 |
74 |
145 "the features listed in the setting value report. The first view "\ |
146 "the features listed in the setting value report. The first view "\ |
146 "defined in the file will be used.", |
147 "defined in the file will be used.", |
147 metavar="FILE", |
148 metavar="FILE", |
148 default=None) |
149 default=None) |
149 |
150 |
|
151 info_group.add_option("--print-active-root", |
|
152 action="store_true", |
|
153 help="Print active root in the current project and exit.") |
|
154 |
150 parser.add_option_group(info_group) |
155 parser.add_option_group(info_group) |
151 |
156 |
152 (options, args) = parser.parse_args() |
157 (options, args) = parser.parse_args() |
153 cone_common.handle_common_options(options) |
158 cone_common.handle_common_options(options) |
|
159 |
|
160 if options.print_active_root: |
|
161 print_active_root(options) |
|
162 sys.exit(0) |
154 |
163 |
155 if not shortcut_container.is_valid_shortcut(options.report_type): |
164 if not shortcut_container.is_valid_shortcut(options.report_type): |
156 parser.error("Invalid report type: %s" % options.report_type) |
165 parser.error("Invalid report type: %s" % options.report_type) |
157 if (options.report_type or options.template) and \ |
166 if (options.report_type or options.template) and \ |
158 (not options.configs and not options.config_wildcards and not options.config_regexes): |
167 (not options.configs and not options.config_wildcards and not options.config_regexes): |
168 print "Loaded view '%s' from '%s'" % (view.get_name(), options.view_file) |
177 print "Loaded view '%s' from '%s'" % (view.get_name(), options.view_file) |
169 except ViewLoadError, e: |
178 except ViewLoadError, e: |
170 print e |
179 print e |
171 sys.exit(1) |
180 sys.exit(1) |
172 |
181 |
173 current = api.Project(api.Storage.open(options.project,"r")) |
182 current = api.Project(api.Storage.open(options.project,"r", username=options.username, password=options.password)) |
174 print "Opened project in %s" % options.project |
183 print "Opened project in %s" % options.project |
175 |
184 |
176 # Get a list of configurations if necessary |
185 # Get a list of configurations if necessary |
177 config_list = None |
186 config_list = None |
178 if options.configs or options.config_wildcards or options.config_regexes: |
187 if options.configs or options.config_wildcards or options.config_regexes: |
214 report_name) |
223 report_name) |
215 data_providers = {'impl_data' : ImplDataProvider(configs[0], options.impl_filter), |
224 data_providers = {'impl_data' : ImplDataProvider(configs[0], options.impl_filter), |
216 'api_data' : ApiDataProvider(configs[0]), |
225 'api_data' : ApiDataProvider(configs[0]), |
217 'content_data': ContentDataProvider(configs[0]), |
226 'content_data': ContentDataProvider(configs[0]), |
218 'value_data' : ValueDataProvider(configs, view)} |
227 'value_data' : ValueDataProvider(configs, view)} |
219 report_util.generate_report(template, report, {'data': ReportDataProxy(data_providers)}) |
228 report_util.generate_report(template, report, {'data': ReportDataProxy(data_providers)}, [ROOT_PATH]) |
220 else: |
229 else: |
221 # Printing configuration info |
230 # Printing configuration info |
222 config_name = config_list[0] |
231 config_name = config_list[0] |
223 config = current.get_configuration(config_name) |
232 config = current.get_configuration(config_name) |
224 print "Opened configuration %s" % config_name |
233 print "Opened configuration %s" % config_name |
231 configlist.sort() |
240 configlist.sort() |
232 for config in configlist: |
241 for config in configlist: |
233 print config |
242 print config |
234 if current: current.close() |
243 if current: current.close() |
235 |
244 |
|
245 def print_active_root(options): |
|
246 storage = api.Storage.open(options.project,"r", username=options.username, password=options.password) |
|
247 active_root = storage.get_active_configuration() |
|
248 if active_root: |
|
249 print "Active root: %s" % active_root |
|
250 else: |
|
251 print "No active root." |
|
252 |
236 |
253 |
237 # ============================================================================ |
254 # ============================================================================ |
238 # Report data proxy and data providers |
255 # Report data proxy and data providers |
239 # ============================================================================ |
256 # ============================================================================ |
240 |
257 |
283 def generate_data(self): |
300 def generate_data(self): |
284 """ |
301 """ |
285 Generate the actual report data. Called when get_data() is called |
302 Generate the actual report data. Called when get_data() is called |
286 the first time. |
303 the first time. |
287 """ |
304 """ |
288 raise NotImplmentedError() |
305 raise NotImplementedError() |
289 |
306 |
290 # ---------------------------------------------------------------------------- |
307 # ---------------------------------------------------------------------------- |
291 |
308 |
292 class ApiDataProvider(ReportDataProviderBase): |
309 class ApiDataProvider(ReportDataProviderBase): |
293 def __init__(self, config): |
310 def __init__(self, config): |
366 self.type = kwargs['type'] |
383 self.type = kwargs['type'] |
367 self.desc = kwargs['desc'] |
384 self.desc = kwargs['desc'] |
368 self.options = kwargs['options'] |
385 self.options = kwargs['options'] |
369 |
386 |
370 class Config(object): |
387 class Config(object): |
371 def __init__(self, path, values): |
388 def __init__(self, name, path, values, refs): |
|
389 self.name = name |
372 self.path = path |
390 self.path = path |
373 self.values = values |
391 self.values = values |
|
392 self.refs = refs |
374 |
393 |
375 class SequenceColumn(object): |
394 class SequenceColumn(object): |
376 def __init__(self, ref, name, type): |
395 def __init__(self, ref, name, type): |
377 self.ref = ref |
396 self.ref = ref |
378 self.name = name |
397 self.name = name |
441 try: |
460 try: |
442 feature = dview.get_feature(entry.ref) |
461 feature = dview.get_feature(entry.ref) |
443 values[entry.ref] = self._resolve_value(feature) |
462 values[entry.ref] = self._resolve_value(feature) |
444 except exceptions.NotFound: |
463 except exceptions.NotFound: |
445 pass |
464 pass |
446 |
465 # Get the feature refs from last layer |
447 output_configs.append(self.Config(config.get_path(), values)) |
466 last_layer_refs = set(config.get_last_configuration().list_leaf_datas()) |
|
467 output_configs.append(self.Config(config.get_name(), config.get_path(), values, last_layer_refs)) |
448 |
468 |
449 # Add a 'modified' attribute to all features |
469 # Add a 'modified' attribute to all features |
450 for group in feature_groups: |
470 for group in feature_groups: |
451 for feature in group.features: |
471 for feature in group.features: |
452 modified = False |
472 modified = False |
638 """Exception raised if _load_view_from_file() fails""" |
658 """Exception raised if _load_view_from_file() fails""" |
639 pass |
659 pass |
640 |
660 |
641 def _load_view_from_file(filename): |
661 def _load_view_from_file(filename): |
642 """ |
662 """ |
643 Load the first view from the given ConfML file. |
663 Load the last view from the given ConfML file. |
644 @raise ViewLoadError: An error occurred when loading the file. |
664 @raise ViewLoadError: An error occurred when loading the file. |
645 """ |
665 """ |
646 file_abspath = os.path.abspath(filename) |
666 file_abspath = os.path.abspath(filename) |
647 file_dir = os.path.dirname(file_abspath) |
667 file_dir = os.path.dirname(file_abspath) |
648 file_name = os.path.basename(file_abspath) |
668 file_name = os.path.basename(file_abspath) |