Пример #1
0
 def main(self, argv):
     if not argv:
         self.parser.error("too few arguments.")
     args = self._parse_args(argv)
     proj = Project.selected()
     targ, app, meas, expr = self._parse_implicit(args)
     expr = self._parse_explicit_experiment(args, expr)
     if expr:
         targ, app, meas = None, None, None
         name = expr['name']
     else:
         targ = self._parse_explicit(args, Target, targ, proj, 'targets')
         app = self._parse_explicit(args, Application, app, proj,
                                    'applications')
         meas = self._parse_explicit(args, Measurement, meas, proj,
                                     'measurements')
         name = getattr(
             args, 'name',
             "%s-%s-%s" % (targ['name'], app['name'], meas['name']))
     try:
         Experiment.select(name)
     except ExperimentSelectionError:
         args = [
             name, '--target', targ['name'], '--application', app['name'],
             '--measurement', meas['name']
         ]
         retval = experiment_create_cmd.main(args)
         if retval != EXIT_SUCCESS:
             return retval
         Experiment.select(name)
     self.logger.info("Selected experiment '%s'.", name)
     rebuild_required = Experiment.rebuild_required()
     if rebuild_required:
         self.logger.info(rebuild_required)
     return EXIT_SUCCESS
Пример #2
0
 def main(self, argv):
     if not argv:
         self.parser.error("too few arguments.")
     args = self._parse_args(argv)
     proj = Project.selected()
     targ, app, meas, expr = self._parse_implicit(args)
     expr = self._parse_explicit_experiment(args, expr)
     if expr:
         targ, app, meas = None, None, None
         name = expr['name']
     else:
         targ = self._parse_explicit(args, Target, targ, proj, 'targets')
         app = self._parse_explicit(args, Application, app, proj, 'applications')
         meas = self._parse_explicit(args, Measurement, meas, proj, 'measurements')
         name = getattr(args, 'name', "%s-%s-%s" % (targ['name'], app['name'], meas['name']))
     try:
         Experiment.select(name)
     except ExperimentSelectionError:
         args = [name,
                 '--target', targ['name'],
                 '--application', app['name'],
                 '--measurement', meas['name']]
         retval = experiment_create_cmd.main(args)
         if retval != EXIT_SUCCESS:
             return retval
         Experiment.select(name)
     self.logger.info("Selected experiment '%s'.", name)
     rebuild_required = Experiment.rebuild_required()
     if rebuild_required: 
         self.logger.info(rebuild_required)
     return EXIT_SUCCESS
Пример #3
0
 def main(self, argv):
     args = self._parse_args(argv)
     name = args.name
     Experiment.select(name)
     self.logger.info("Selected experiment '%s'.", name)
     rebuild_required = Experiment.rebuild_required()
     if rebuild_required:
         self.logger.info(rebuild_required)
     return EXIT_SUCCESS
Пример #4
0
 def on_update(self, changes):
     from taucmdr.model.experiment import Experiment
     from taucmdr.model.compiler import Compiler
     try:
         old_value, new_value = changes['experiment']
     except KeyError:
         # We only care about changes to experiment
         return
     if old_value and new_value:
         new_expr = Experiment.controller().one(new_value)
         old_expr = Experiment.controller().one(old_value)
         for model_attr in 'target', 'application', 'measurement':
             if old_expr[model_attr] != new_expr[model_attr]:
                 new_model = new_expr.populate(model_attr)
                 old_model = old_expr.populate(model_attr)
                 for attr, props in new_model.attributes.iteritems():
                     if props.get('rebuild_required'):
                         new_value = new_model.get(attr, None)
                         old_value = old_model.get(attr, None)
                         if old_value != new_value:
                             if props.get('model') == Compiler:
                                 new_comp = Compiler.controller(
                                     self.storage).one(new_value)
                                 old_comp = Compiler.controller(
                                     self.storage).one(old_value)
                                 new_path = new_comp[
                                     'path'] if new_comp else None
                                 old_path = old_comp[
                                     'path'] if old_comp else None
                                 message = {attr: (old_path, new_path)}
                                 self.controller(
                                     self.storage).push_to_topic(
                                         'rebuild_required', message)
                             elif props.get('argparse').get(
                                     'metavar') == '<metric>':
                                 old_papi = [
                                     metric for metric in old_value
                                     if 'PAPI' in metric
                                 ]
                                 new_papi = [
                                     metric for metric in new_value
                                     if 'PAPI' in metric
                                 ]
                                 if bool(old_papi) != bool(new_papi):
                                     message = {
                                         attr: (old_value, new_value)
                                     }
                                     self.controller(
                                         self.storage).push_to_topic(
                                             'rebuild_required', message)
                             else:
                                 message = {attr: (old_value, new_value)}
                                 self.controller(
                                     self.storage).push_to_topic(
                                         'rebuild_required', message)
Пример #5
0
 def _parse_implicit(self, args):
     targets = set()
     applications = set()
     measurements = set()
     experiments = set()
     targ_ctrl = Target.controller(PROJECT_STORAGE)
     app_ctrl = Application.controller(PROJECT_STORAGE)
     meas_ctrl = Measurement.controller(PROJECT_STORAGE)
     expr_ctrl = Experiment.controller(PROJECT_STORAGE)
     for flag in 'impl_experiment', 'impl_project', 'impl_target', 'impl_application', 'impl_measurement':
         for name in getattr(args, flag, []):
             tar = targ_ctrl.one({"name": name})
             app = app_ctrl.one({"name": name})
             mes = meas_ctrl.one({"name": name})
             expr = expr_ctrl.one({"name": name})
             found = {tar, app, mes, expr} - {None}
             if len(found) > 1:
                 self.parser.error(
                     "'%s' is ambiguous. "
                     "Please use a command line flag to specify configuration type."
                     % name)
             elif not found:
                 self.parser.error(
                     "'%s' is not an experiment, target, application, or measurement."
                     % name)
             elif tar:
                 targets.add(tar)
             elif app:
                 applications.add(app)
             elif mes:
                 measurements.add(mes)
             elif expr:
                 experiments.add(expr)
     return targets, applications, measurements, experiments
Пример #6
0
 def _parse_implicit(self, args):
     targets = set()
     applications = set()
     measurements = set()
     experiments = set()
     targ_ctrl = Target.controller(PROJECT_STORAGE)
     app_ctrl = Application.controller(PROJECT_STORAGE)
     meas_ctrl = Measurement.controller(PROJECT_STORAGE)
     expr_ctrl = Experiment.controller(PROJECT_STORAGE)
     for flag in 'impl_experiment', 'impl_project', 'impl_target', 'impl_application', 'impl_measurement':
         for name in getattr(args, flag, []):
             tar = targ_ctrl.one({"name": name})
             app = app_ctrl.one({"name": name})
             mes = meas_ctrl.one({"name": name})
             expr = expr_ctrl.one({"name": name})
             found = set([tar, app, mes, expr]) - set([None])
             if len(found) > 1:
                 self.parser.error("'%s' is ambiguous. "
                                   "Please use a command line flag to specify configuration type." % name)
             elif len(found) == 0:
                 self.parser.error("'%s' is not an experiment, target, application, or measurement." % name)
             elif tar:
                 targets.add(tar)
             elif app:
                 applications.add(app)
             elif mes:
                 measurements.add(mes)
             elif expr:
                 experiments.add(expr)
     return targets, applications, measurements, experiments
Пример #7
0
 def on_update(self, changes):
     from taucmdr.error import ImmutableRecordError
     from taucmdr.model.experiment import Experiment
     expr_ctrl = Experiment.controller()
     found = expr_ctrl.search({'target': self.eid})
     used_by = [expr['name'] for expr in found if expr.data_size() > 0]
     if used_by:
         raise ImmutableRecordError(
             "Target '%s' cannot be modified because "
             "it is used by these experiments: %s" %
             (self['name'], ', '.join(used_by)))
     for expr in found:
         try:
             expr.verify()
         except IncompatibleRecordError as err:
             raise ConfigurationError(
                 "Changing measurement '%s' in this way will create an invalid condition "
                 "in experiment '%s':\n    %s." %
                 (self['name'], expr['name'], err),
                 "Delete experiment '%s' and try again." % expr['name'])
     if self.is_selected():
         for attr, change in changes.iteritems():
             props = self.attributes[attr]
             if props.get('rebuild_required'):
                 if props.get('model', None) == Compiler:
                     old_comp = Compiler.controller(self.storage).one(
                         change[0])
                     new_comp = Compiler.controller(self.storage).one(
                         change[1])
                     message = {attr: (old_comp['path'], new_comp['path'])}
                 else:
                     message = {attr: change}
                 self.controller(self.storage).push_to_topic(
                     'rebuild_required', message)
Пример #8
0
 def on_update(self, changes):
     from taucmdr.error import ImmutableRecordError
     from taucmdr.model.experiment import Experiment
     expr_ctrl = Experiment.controller(self.storage)
     found = expr_ctrl.search({'application': self.eid})
     using_app = [expr['name'] for expr in found if expr.data_size() > 0]
     if using_app:
         raise ImmutableRecordError(
             "Application '%s' cannot be modified because "
             "it is used by these experiments: %s" %
             (self['name'], ', '.join(using_app)))
     for expr in found:
         try:
             expr.verify()
         except IncompatibleRecordError as err:
             raise ConfigurationError(
                 "Changing application '%s' in this way will create an invalid condition "
                 "in experiment '%s':\n    %s." %
                 (self['name'], expr['name'], err),
                 "Delete experiment '%s' and try again." % expr['name'])
     if self.is_selected():
         for attr, change in changes.iteritems():
             if self.attributes[attr].get('rebuild_required'):
                 self.controller(self.storage).push_to_topic(
                     'rebuild_required', {attr: change})
Пример #9
0
 def on_update(self, changes):
     from taucmdr.error import ImmutableRecordError
     from taucmdr.model.experiment import Experiment
     expr_ctrl = Experiment.controller()
     found = expr_ctrl.search({'measurement': self.eid})
     used_by = [expr['name'] for expr in found if expr.data_size() > 0]
     if used_by:
         raise ImmutableRecordError("Measurement '%s' cannot be modified because "
                                    "it is used by these experiments: %s" % (self['name'], ', '.join(used_by)))
     for expr in found:
         try:
             expr.verify()
         except IncompatibleRecordError as err:
             raise ConfigurationError("Changing measurement '%s' in this way will create an invalid condition "
                                      "in experiment '%s':\n    %s." % (self['name'], expr['name'], err),
                                      "Delete experiment '%s' and try again." % expr['name'])
     if self.is_selected():
         for attr, change in changes.iteritems():
             if self.attributes[attr].get('rebuild_required'):
                 if attr == 'metrics':
                     old_value, new_value = change
                     old_papi = [metric for metric in old_value if 'PAPI' in metric]
                     new_papi = [metric for metric in new_value if 'PAPI' in metric]
                     if bool(old_papi) != bool(new_papi):
                         self.controller(self.storage).push_to_topic('rebuild_required', {attr: change})
                 else:
                     self.controller(self.storage).push_to_topic('rebuild_required', {attr: change})
Пример #10
0
 def on_update(self, changes):
     from taucmdr.error import ImmutableRecordError
     from taucmdr.model.experiment import Experiment
     expr_ctrl = Experiment.controller()
     found = expr_ctrl.search({'target': self.eid})
     used_by = [expr['name'] for expr in found if expr.data_size() > 0]
     if used_by:
         raise ImmutableRecordError("Target '%s' cannot be modified because "
                                    "it is used by these experiments: %s" % (self['name'], ', '.join(used_by)))
     for expr in found:
         try:
             expr.verify()
         except IncompatibleRecordError as err:
             raise ConfigurationError("Changing measurement '%s' in this way will create an invalid condition "
                                      "in experiment '%s':\n    %s." % (self['name'], expr['name'], err),
                                      "Delete experiment '%s' and try again." % expr['name'])
     if self.is_selected():
         for attr, change in changes.iteritems():
             props = self.attributes[attr] 
             if props.get('rebuild_required'):
                 if props.get('model', None) == Compiler:
                     old_comp = Compiler.controller(self.storage).one(change[0])
                     new_comp = Compiler.controller(self.storage).one(change[1])
                     message = {attr: (old_comp['path'], new_comp['path'])}
                 else:
                     message = {attr: change}
                 self.controller(self.storage).push_to_topic('rebuild_required', message)
Пример #11
0
 def _update_record(self, store, data, key):
     try:
         retval = super(MeasurementEditCommand, self)._update_record(store, data, key)
     except (ImmutableRecordError, IncompatibleRecordError) as err:
         err.hints = ["Use `%s` to create a modified copy of the measurement" % measurement_copy_cmd,
                      "Use `%s` to delete the experiments." % experiment_delete_cmd]
         raise err
     if not retval:
         rebuild_required = Experiment.rebuild_required()
         if rebuild_required: 
             self.logger.info(rebuild_required)
     return retval       
Пример #12
0
 def _update_record(self, store, data, key):
     try:
         retval = super(ApplicationEditCommand, self)._update_record(store, data, key)
     except (ImmutableRecordError, IncompatibleRecordError) as err:
         err.hints = ["Use `%s` to create a modified copy of the application" % application_copy_cmd,
                      "Use `%s` to delete the experiments." % experiment_delete_cmd]
         raise err
     if not retval:
         rebuild_required = Experiment.rebuild_required()
         if rebuild_required: 
             self.logger.info(rebuild_required)
     return retval       
Пример #13
0
 def _parse_explicit_experiment(self, args, acc):
     model_name = 'experiment'
     if hasattr(args, model_name):
         name = getattr(args, model_name)
         ctrl = Experiment.controller(PROJECT_STORAGE)
         found = ctrl.one({"name": name})
         if not found:
             self.parser.error('There is no %s named %s.' % (model_name, name))
         else:
             acc.add(found)
     if len(acc) == 1:
         return acc.pop()
     return None
Пример #14
0
 def _update_record(self, store, data, key):
     from taucmdr.cli.commands.target.copy import COMMAND as target_copy_cmd
     from taucmdr.cli.commands.experiment.delete import COMMAND as experiment_delete_cmd
     try:
         retval = super(TargetEditCommand, self)._update_record(store, data, key)
     except (ImmutableRecordError, IncompatibleRecordError) as err:
         err.hints = ["Use `%s` to create a modified copy of the target" % target_copy_cmd,
                      "Use `%s` to delete the experiments." % experiment_delete_cmd]
         raise err
     if not retval:
         rebuild_required = Experiment.rebuild_required()
         if rebuild_required: 
             self.logger.info(rebuild_required)
     return retval
Пример #15
0
 def _parse_explicit_experiment(self, args, acc):
     model_name = 'experiment'
     if hasattr(args, model_name):
         name = getattr(args, model_name)
         ctrl = Experiment.controller(PROJECT_STORAGE)
         found = ctrl.one({"name": name})
         if not found:
             self.parser.error('There is no %s named %s.' %
                               (model_name, name))
         else:
             acc.add(found)
     if len(acc) == 1:
         return acc.pop()
     return None
Пример #16
0
 def on_update(self, changes):
     from taucmdr.model.experiment import Experiment
     from taucmdr.model.compiler import Compiler
     try:
         old_value, new_value = changes['experiment']
     except KeyError:
         # We only care about changes to experiment
         return
     if old_value and new_value:
         new_expr = Experiment.controller().one(new_value)
         old_expr = Experiment.controller().one(old_value)
         for model_attr in 'target', 'application', 'measurement':
             if old_expr[model_attr] != new_expr[model_attr]:
                 new_model = new_expr.populate(model_attr)
                 old_model = old_expr.populate(model_attr)
                 for attr, props in new_model.attributes.iteritems():
                     if props.get('rebuild_required'):
                         new_value = new_model.get(attr, None)
                         old_value = old_model.get(attr, None)
                         if old_value != new_value:
                             if props.get('model') == Compiler:
                                 new_comp = Compiler.controller(self.storage).one(new_value)
                                 old_comp = Compiler.controller(self.storage).one(old_value)
                                 new_path = new_comp['path'] if new_comp else None
                                 old_path = old_comp['path'] if old_comp else None
                                 message = {attr: (old_path, new_path)}
                                 self.controller(self.storage).push_to_topic('rebuild_required', message)
                             elif props.get('argparse').get('metavar') == '<metric>':
                                 old_papi = [metric for metric in old_value if 'PAPI' in metric]
                                 new_papi = [metric for metric in new_value if 'PAPI' in metric]
                                 if bool(old_papi) != bool(new_papi):
                                     message = {attr: (old_value, new_value)}
                                     self.controller(self.storage).push_to_topic('rebuild_required', message)
                             else:
                                 message = {attr: (old_value, new_value)}
                                 self.controller(self.storage).push_to_topic('rebuild_required', message)
Пример #17
0
 def delete(self, keys, context=True):
     # pylint: disable=unexpected-keyword-arg
     from taucmdr.error import ImmutableRecordError
     from taucmdr.model.experiment import Experiment
     changing = self.search(keys, context=context)
     for model in changing:
         expr_ctrl = Experiment.controller()
         found = expr_ctrl.search({'measurement': model.eid})
         used_by = [expr['name'] for expr in found if expr.data_size() > 0]
         if used_by:
             raise ImmutableRecordError(
                 "Measurement '%s' cannot be modified because "
                 "it is used by these experiments: %s" %
                 (model['name'], ', '.join(used_by)))
     return super(MeasurementController, self).delete(keys)
Пример #18
0
 def _update_record(self, store, data, key):
     from taucmdr.cli.commands.target.copy import COMMAND as target_copy_cmd
     from taucmdr.cli.commands.experiment.delete import COMMAND as experiment_delete_cmd
     try:
         retval = super(TargetEditCommand,
                        self)._update_record(store, data, key)
     except (ImmutableRecordError, IncompatibleRecordError) as err:
         err.hints = [
             "Use `%s` to create a modified copy of the target" %
             target_copy_cmd,
             "Use `%s` to delete the experiments." % experiment_delete_cmd
         ]
         raise err
     if not retval:
         rebuild_required = Experiment.rebuild_required()
         if rebuild_required:
             self.logger.info(rebuild_required)
     return retval
Пример #19
0
 def on_update(self, changes):
     from taucmdr.error import ImmutableRecordError
     from taucmdr.model.experiment import Experiment
     expr_ctrl = Experiment.controller(self.storage)
     found = expr_ctrl.search({'application': self.eid})
     using_app = [expr['name'] for expr in found if expr.data_size() > 0]
     if using_app:
         raise ImmutableRecordError("Application '%s' cannot be modified because "
                                    "it is used by these experiments: %s" % (self['name'], ', '.join(using_app)))
     for expr in found:
         try:
             expr.verify()
         except IncompatibleRecordError as err:
             raise ConfigurationError("Changing application '%s' in this way will create an invalid condition "
                                      "in experiment '%s':\n    %s." % (self['name'], expr['name'], err),
                                      "Delete experiment '%s' and try again." % expr['name'])
     self._check_select_file()
     if self.is_selected():
         for attr, change in changes.iteritems():
             if self.attributes[attr].get('rebuild_required'):
                 self.controller(self.storage).push_to_topic('rebuild_required', {attr: change})
Пример #20
0
 def on_update(self, changes):
     from taucmdr.error import ImmutableRecordError
     from taucmdr.model.experiment import Experiment
     expr_ctrl = Experiment.controller()
     found = expr_ctrl.search({'measurement': self.eid})
     used_by = [expr['name'] for expr in found if expr.data_size() > 0]
     if used_by:
         raise ImmutableRecordError(
             "Measurement '%s' cannot be modified because "
             "it is used by these experiments: %s" %
             (self['name'], ', '.join(used_by)))
     for expr in found:
         try:
             expr.verify()
         except IncompatibleRecordError as err:
             raise ConfigurationError(
                 "Changing measurement '%s' in this way will create an invalid condition "
                 "in experiment '%s':\n    %s." %
                 (self['name'], expr['name'], err),
                 "Delete experiment '%s' and try again." % expr['name'])
     self._check_select_file()
     self._check_metrics()
     if self.is_selected():
         for attr, change in changes.iteritems():
             if self.attributes[attr].get('rebuild_required'):
                 if attr == 'metrics':
                     old_value, new_value = change
                     old_papi = [
                         metric for metric in old_value if 'PAPI' in metric
                     ]
                     new_papi = [
                         metric for metric in new_value if 'PAPI' in metric
                     ]
                     if bool(old_papi) != bool(new_papi):
                         self.controller(self.storage).push_to_topic(
                             'rebuild_required', {attr: change})
                 else:
                     self.controller(self.storage).push_to_topic(
                         'rebuild_required', {attr: change})