Ejemplo n.º 1
0
 def _parse_implicit(self, args):
     projects = set()
     targets = set()
     applications = set()
     measurements = set()
     proj_ctrl = Project.controller()
     targ_ctrl = Target.controller(PROJECT_STORAGE)
     app_ctrl = Application.controller(PROJECT_STORAGE)
     meas_ctrl = Measurement.controller(PROJECT_STORAGE)
     for flag in 'impl_project', 'impl_target', 'impl_application', 'impl_measurement':
         for name in getattr(args, flag, []):
             prj = proj_ctrl.one({"name": name})
             tar = targ_ctrl.one({"name": name})
             app = app_ctrl.one({"name": name})
             mes = meas_ctrl.one({"name": name})
             ptam = set([prj, tar, app, mes]) - set([None])
             if len(ptam) > 1:
                 self.parser.error("'%s' is ambiguous.  Please use --project, --target, --application,"
                                   " or --measurement to specify configuration type." % name)
             elif len(ptam) == 0:
                 self.parser.error("'%s' is not a project, target, application, or measurement." % name)
             elif prj:
                 projects.add(prj)
             elif tar:
                 targets.add(tar)
             elif app:
                 applications.add(app)
             elif mes:
                 measurements.add(mes)
     return projects, targets, applications, measurements
Ejemplo n.º 2
0
 def _parse_implicit(self, args, targets, applications, measurements):
     targ_ctrl = Target.controller(PROJECT_STORAGE)
     app_ctrl = Application.controller(PROJECT_STORAGE)
     meas_ctrl = Measurement.controller(PROJECT_STORAGE)
     for flag in 'impl_targets', 'impl_applications', 'impl_measurements':
         for name in getattr(args, flag, []):
             tar = targ_ctrl.one({"name": name})
             app = app_ctrl.one({"name": name})
             mes = meas_ctrl.one({"name": name})
             tam = set([tar, app, mes]) - set([None])
             if len(tam) > 1:
                 self.parser.error("'%s' is ambiguous.  Please use --target, --application,"
                                   " or --measurement to specify configuration type" % name)
             elif len(tam) == 0:
                 self.parser.error("'%s' is not a target, application, or measurement" % name)
             elif tar:
                 targets.add(tar)
             elif app:
                 applications.add(app)
             elif mes:
                 measurements.add(mes)
Ejemplo n.º 3
0
    def main(self, argv):
        from tau.cli.commands.project.list import COMMAND as project_list

        args = self.parser.parse_args(args=argv)
        self.logger.debug('Arguments: %s', args)
    
        tar_ctrl = Target.controller(PROJECT_STORAGE)
        app_ctrl = Application.controller(PROJECT_STORAGE)
        meas_ctrl = Measurement.controller(PROJECT_STORAGE)
        proj_ctrl = Project.controller()
    
        project_name = args.name
        project = proj_ctrl.one({'name': project_name})
        if not project:
            self.parser.error("'%s' is not a project name. Type `%s` to see valid names." % 
                              (project_name, project_list.command))
    
        updates = dict(project.element)
        updates['name'] = getattr(args, 'new_name', project_name)
        targets = set(project['targets'])
        applications = set(project['applications'])
        measurements = set(project['measurements'])
        added = set()
        removed = set()
        
        for attr, ctrl, dest in [('add_targets', tar_ctrl, targets),
                                 ('add_applications', app_ctrl, applications),
                                 ('add_measurements', meas_ctrl, measurements)]:
            names = getattr(args, attr, [])
            for name in names:
                found = ctrl.one({'name': name})
                if not found:
                    self.parser.error("There is no %s named '%s'" % (ctrl.model.name, name))
                dest.add(found.eid)
                added.add(found)
    
        for name in set(getattr(args, "add", [])):
            tar = tar_ctrl.one({'name': name})
            app = app_ctrl.one({'name': name})
            mes = meas_ctrl.one({'name': name})
            tam = set([tar, app, mes]) - set([None])
            if len(tam) > 1:
                self.parser.error("'%s' is ambiguous. Use --add-targets, --add-applications,"
                                  " or --add-measurements to specify configuration type" % name)
            elif len(tam) == 0:
                self.parser.error("'%s' is not a target, application, or measurement" % name)
            else:
                added.update(tam)
            if tar:
                targets.add(tar.eid)
            elif app:
                applications.add(app.eid)
            elif mes:
                measurements.add(mes.eid)
    
        for attr, ctrl, dest in [('remove_targets', tar_ctrl, targets),
                                 ('remove_applications', app_ctrl, applications),
                                 ('remove_measurements', meas_ctrl, measurements)]:
            names = getattr(args, attr, [])
            for name in names:
                found = ctrl.one({'name': name})
                if not found:
                    self.parser.error('There is no %s named %r' % (ctrl.model.name, name))
                dest.remove(found.eid)
                removed.add(found)
    
        for name in set(getattr(args, "remove", [])):
            tar = tar_ctrl.one({'name': name})
            app = app_ctrl.one({'name': name})
            mes = meas_ctrl.one({'name': name})
            tam = set([tar, app, mes]) - set([None])
            if len(tam) > 1:
                self.parser.error("'%s' is ambiguous. Use --remove-targets, --remove-applications,"
                                  " or --remove-measurements to specify configuration type" % name)
            elif len(tam) == 0:
                self.parser.error("'%s' is not a target, application, or measurement" % name)
            else:
                removed.update(tam)
            if tar:
                targets.remove(tar.eid)
            elif app:
                applications.remove(app.eid)
            elif mes:
                measurements.remove(mes.eid)
    
        updates['targets'] = list(targets)
        updates['applications'] = list(applications)
        updates['measurements'] = list(measurements)
    
        proj_ctrl.update(updates, {'name': project_name})
        for model in added:
            self.logger.info("Added %s '%s' to project configuration '%s'.", 
                             model.name.lower(), model[model.key_attribute], project_name)
        for model in removed:
            self.logger.info("Removed %s '%s' from project configuration '%s'.", 
                             model.name.lower(), model[model.key_attribute], project_name)
        return EXIT_SUCCESS