Exemple #1
0
    def main(self, argv):
        args = self.parser.parse_args(args=argv)
        self.logger.debug('Arguments: %s', args)
        store = STORAGE_LEVELS[getattr(args, arguments.STORAGE_LEVEL_FLAG)[0]]
        ctrl = self.model.controller(store)
        key_attr = self.model.key_attribute
        key = getattr(args, key_attr)

        compilers = self.parse_compiler_flags(args)
        self.logger.debug('Arguments after parsing compiler flags: %s', args)
        
        data = {attr: getattr(args, attr) for attr in self.model.attributes if hasattr(args, attr)}
        for keyword, comp in compilers.iteritems():
            self.logger.debug("%s=%s (%s)", keyword, comp.absolute_path, comp.info.short_descr)
            record = Compiler.controller(store).register(comp)
            data[comp.info.role.keyword] = record.eid

        try:
            ctrl.create(data)
        except UniqueAttributeError:
            self.parser.error("A %s with %s='%s' already exists" % (self.model_name, key_attr, key))
        if ctrl.storage is PROJECT_STORAGE:
            from tau.cli.commands.project.edit import COMMAND as project_edit_cmd
            proj_ctrl = Project.controller()
            try:
                proj = proj_ctrl.selected()
            except ProjectSelectionError:
                self.logger.info("Created a new %s '%s'. Use `%s` to add the new %s to a project.", 
                                 self.model_name, key, project_edit_cmd, self.model_name)
            else:
                project_edit_cmd.main([proj['name'], '--add', key])
        else:
            self.logger.info("Created a new %s-level %s: '%s'.", ctrl.storage.name, self.model_name, key)
        return EXIT_SUCCESS
Exemple #2
0
 def main(self, argv):
     args = self.parser.parse_args(args=argv)
     self.logger.debug('Arguments: %s', args)
     store = STORAGE_LEVELS[getattr(args, arguments.STORAGE_LEVEL_FLAG)[0]]
     ctrl = self.model.controller(store)
     key_attr = self.model.key_attribute
     key = getattr(args, key_attr)
     data = {attr: getattr(args, attr) for attr in self.model.attributes if hasattr(args, attr)}
     try:
         ctrl.create(data)
     except UniqueAttributeError:
         self.parser.error("A %s with %s='%s' already exists" % (self.model_name, key_attr, key))
     if ctrl.storage is PROJECT_STORAGE:
         from tau.cli.commands.project.edit import COMMAND as project_edit_cmd
         proj_ctrl = Project.controller()
         try:
             proj = proj_ctrl.selected()
         except ProjectSelectionError:
             self.logger.info("Created a new %s '%s'. Use `%s` to add the new %s to a project.", 
                              self.model_name, key, project_edit_cmd, self.model_name)
         else:
             project_edit_cmd.main([proj['name'], '--add', key])
     else:
         self.logger.info("Created a new %s-level %s: '%s'.", ctrl.storage.name, self.model_name, key)
     return EXIT_SUCCESS