Ejemplo n.º 1
0
    def process_admin_request(self, req, cat, page, path_info):
        # Page locations
        req.hdf['tracforge.href'] = {
            'prototypes': req.href.admin(cat, page),
            'configset': req.href.admin(cat, page, 'configset'),
            'new': req.href.admin(cat, page, 'new'),
            'htdocs': req.href.chrome('tracforge'),
        }
        
        # General stuff
        add_stylesheet(req, 'tracforge/css/admin.css')
        add_script(req, 'tracforge/js/jquery.js')
        req.cat = cat
        req.page = page

        # Subpage dispatchers
        if path_info:
            if path_info == 'configset':
                return self.process_configset_admin_request(req, cat, page, path_info)
            elif path_info == 'new':
                return self._show_prototype(req, path_info, action='new')
            else:
                return self._show_prototype(req, path_info, action='edit')
        
    
        req.hdf['tracforge.prototypes.tags'] = list(Prototype.select(self.env))
        
        return 'admin_tracforge_prototypes.cs', None
Ejemplo n.º 2
0
    def process_admin_request(self, req, cat, page, path_info):
        # Page locations
        req.hdf['tracforge.href'] = {
            'prototypes': req.href.admin(cat, page),
            'configset': req.href.admin(cat, page, 'configset'),
            'new': req.href.admin(cat, page, 'new'),
            'htdocs': req.href.chrome('tracforge'),
        }

        # General stuff
        add_stylesheet(req, 'tracforge/css/admin.css')
        add_script(req, 'tracforge/js/jquery.js')
        req.cat = cat
        req.page = page

        # Subpage dispatchers
        if path_info:
            if path_info == 'configset':
                return self.process_configset_admin_request(
                    req, cat, page, path_info)
            elif path_info == 'new':
                return self._show_prototype(req, path_info, action='new')
            else:
                return self._show_prototype(req, path_info, action='edit')

        req.hdf['tracforge.prototypes.tags'] = list(Prototype.select(self.env))

        return 'admin_tracforge_prototypes.cs', None
Ejemplo n.º 3
0
    def process_admin_request(self, req, cat, page, path_info):
        # Page locations
        req.hdf["tracforge.href"] = {
            "prototypes": req.href.admin(cat, page),
            "configset": req.href.admin(cat, page, "configset"),
            "new": req.href.admin(cat, page, "new"),
            "htdocs": req.href.chrome("tracforge"),
        }

        # General stuff
        add_stylesheet(req, "tracforge/css/admin.css")
        add_script(req, "tracforge/js/jquery.js")
        req.cat = cat
        req.page = page

        # Subpage dispatchers
        if path_info:
            if path_info == "configset":
                return self.process_configset_admin_request(req, cat, page, path_info)
            elif path_info == "new":
                return self._show_prototype(req, path_info, action="new")
            else:
                return self._show_prototype(req, path_info, action="edit")

        req.hdf["tracforge.prototypes.tags"] = list(Prototype.select(self.env))

        return "admin_tracforge_prototypes.cs", None
Ejemplo n.º 4
0
    def _show_prototype(self, req, path_info, action):
        """Handler for creating a new prototype."""
        add_stylesheet(req, 'tracforge/css/prototypes_new.css')
        add_script(req, 'tracforge/js/interface/iutil.js')
        add_script(req, 'tracforge/js/jquery.animatedswap.js')
        req.hdf['tracforge.prototypes.name'] = path_info.strip('/')

        if req.method == 'POST':
            if req.args.get(
                    'save'
            ):  # Save either a new prototype or a changed existing ones
                name = req.args.get('name')
                if action == 'edit':
                    name = path_info.strip('/')
                if not name:
                    raise TracError(
                        'You must specify a name for the prototype')
                if name in ('new', 'configset'):
                    raise TracError('"new" and "configset" are reserved names')

                data = req.args.get('data')
                if data is None:
                    raise TracError(
                        "Warning: Peguins on fire. You might have JavaScript off, don't do that"
                    )
                data = data[4:]  # Strip off the 'data' literal at the start
                if not data:
                    raise TracError(
                        "You must have at least one step in a prototype")

                proto = Prototype(self.env, name)
                if action == 'new' and proto.exists:
                    raise TracError("Prototype %s already exists" % name)
                del proto[:]
                for x in data.split('|'):
                    proto.append(x.split(',', 1))
                proto.save()
            elif req.args.get('cancel'):
                pass  # This should just redirect back
            elif req.args.get(
                    'delete'
            ) and action == 'edit':  # Show the confirmation screen
                return 'admin_tracforge_prototypes_delete.cs', None
            elif req.args.get(
                    'reallydelete'
            ) and action == 'edit':  # Actually delete this prototype
                name = path_info.strip('/')
                proto = Prototype(self.env, name)
                if not proto.exists:
                    raise TracError('Prototype %s does not exist' % name)
                proto.delete()
            req.redirect(req.href.admin(req.cat, req.page))

        #steps = {}
        #for p in self.setup_participants:
        #    for a in p.get_setup_actions():
        #        steps[a] = {
        #            'provider': p,
        #            'description': p.get_setup_action_description(a),
        #        }
        steps = TracForgeAdminSystem(self.env).get_project_setup_participants()

        initial_steps = []
        if action == 'new':  # For a new one, use the specified defaults
            initial_steps = Prototype.default(
                self.env)  # XXX: This should really read from trac.ini somehow
        elif action == 'edit':
            proto = Prototype(self.env, path_info.strip('/'))
            if not proto.exists:
                raise TracError('Unknown prototype %s' % proto.tag)
            initial_steps = proto
        else:
            raise TracError('Invalid action %s' % action)

        req.hdf['tracforge.prototypes.action'] = action
        req.hdf['tracforge.prototypes.steps'] = steps
        req.hdf['tracforge.prototypes.initialsteps'] = initial_steps
        req.hdf['tracforge.prototypes.liststeps'] = [
            k for k in steps.iterkeys() if k not in initial_steps
        ]

        return 'admin_tracforge_prototypes_show.cs', None
Ejemplo n.º 5
0
    def process_admin_request(self, req, cat, page, path_info):
        if req.method == 'POST':
            if 'create' in req.args.keys(): # Project creation
                name = req.args.get('shortname', '').strip()
                fullname = req.args.get('fullname', '').strip()
                env_path = req.args.get('env_path', '').strip()
                proto_name = req.args.get('prototype', '').strip()
                if not (name and fullname and env_path and proto_name):
                    raise TracError('All arguments are required')
                
                # Make the models
                proj = Project(self.env, name)
                proto = Prototype(self.env, proto_name)
                if not proto.exists:
                    raise TracError('Penguins on fire')
                
                # Store the project
                proj.env_path = env_path
                proj.save()
                
                # Apply the prototype
                proto.apply(req, proj)
                
                db = self.env.get_db_cnx()
                cursor = db.cursor()
                cursor.execute('SELECT action, args, return, stdout, stderr FROM tracforge_project_log WHERE project=%s ORDER BY id',(proj.name,))
                
                output = []
                for action, args, rv, out, err in cursor:
                    output.append({
                        'action': action,
                        'args': args,
                        'rv': rv,
                        'out': out.splitlines(),
                        'err': err.splitlines(),
                    })
                        
                req.hdf['tracforge.output'] = output
                req.hdf['tracforge.href.projects'] = req.href.admin(cat, page)
                #req.args['hdfdump'] = 1
                return 'admin_tracforge_project_new.cs', None
                req.redirect(req.href.admin(cat, page))
            elif 'delete' in req.args.keys(): # Project deleteion
                raise TracError, 'Not implemented yet. Sorry.'

        #self.log.debug('TracForge: Starting data grab')
        projects = [Project(self.env, n) for n in Project.select(self.env)]
        #self.log.debug('TracForge: Done with data grab')
    
        #self.log.debug('TracForge: Starting data grab')
        project_data = {}
        for proj in projects:
            #self.log.debug('TracForge: Getting data for %s', proj.name)
            project_data[proj.name] = {
                'fullname': proj.valid and proj.env.project_name or '',
                'env_path': proj.env_path,
            }
        #self.log.debug('TracForge: Done with data grab')
            
        req.hdf['tracforge.projects'] = project_data
        req.hdf['tracforge.prototypes'] = Prototype.select(self.env)
    
        return 'admin_tracforge.cs', None
             
Ejemplo n.º 6
0
    def process_admin_request(self, req, cat, page, path_info):
        if req.method == 'POST':
            if 'create' in req.args.keys(): # Project creation
                name = req.args.get('shortname', '').strip()
                fullname = req.args.get('fullname', '').strip()
                env_path = req.args.get('env_path', '').strip()
                proto_name = req.args.get('prototype', '').strip()
                if not (name and fullname and env_path and proto_name):
                    raise TracError('All arguments are required')
                
                # Make the models
                proj = Project(self.env, name)
                proto = Prototype(self.env, proto_name)
                if not proto.exists:
                    raise TracError('Penguins on fire')
                
                # Store the project
                proj.env_path = env_path
                proj.save()
                
                # Apply the prototype
                proto.apply(req, proj)
                
                db = self.env.get_db_cnx()
                cursor = db.cursor()
                cursor.execute('SELECT action, args, return, stdout, stderr FROM tracforge_project_log WHERE project=%s ORDER BY id',(proj.name,))
                
                output = []
                for action, args, rv, out, err in cursor:
                    output.append({
                        'action': action,
                        'args': args,
                        'rv': rv,
                        'out': out.splitlines(),
                        'err': err.splitlines(),
                    })
                        
                req.hdf['tracforge.output'] = output
                req.hdf['tracforge.href.projects'] = req.href.admin(cat, page)
                #req.args['hdfdump'] = 1
                return 'admin_tracforge_project_new.cs', None
                req.redirect(req.href.admin(cat, page))
            elif 'delete' in req.args.keys(): # Project deleteion
                raise TracError, 'Not implemented yet. Sorry.'

        #self.log.debug('TracForge: Starting data grab')
        projects = [Project(self.env, n) for n in Project.select(self.env)]
        #self.log.debug('TracForge: Done with data grab')
    
        #self.log.debug('TracForge: Starting data grab')
        project_data = {}
        for proj in projects:
            #self.log.debug('TracForge: Getting data for %s', proj.name)
            project_data[proj.name] = {
                'fullname': proj.valid and proj.env.project_name or '',
                'env_path': proj.env_path,
            }
        #self.log.debug('TracForge: Done with data grab')
            
        req.hdf['tracforge.projects'] = project_data
        req.hdf['tracforge.prototypes'] = Prototype.select(self.env)
    
        return 'admin_tracforge.cs', None
Ejemplo n.º 7
0
    def _show_prototype(self, req, path_info, action):
        """Handler for creating a new prototype."""
        add_stylesheet(req, 'tracforge/css/prototypes_new.css')
        add_script(req, 'tracforge/js/interface/iutil.js')
        add_script(req, 'tracforge/js/jquery.animatedswap.js')
        req.hdf['tracforge.prototypes.name'] = path_info.strip('/')
        
        if req.method == 'POST':
            if req.args.get('save'): # Save either a new prototype or a changed existing ones
                name = req.args.get('name')
                if action == 'edit':
                    name = path_info.strip('/')
                if not name:
                    raise TracError('You must specify a name for the prototype')
                if name in ('new', 'configset'):
                    raise TracError('"new" and "configset" are reserved names')
            
                data = req.args.get('data')
                if data is None:
                    raise TracError("Warning: Peguins on fire. You might have JavaScript off, don't do that")
                data = data[4:] # Strip off the 'data' literal at the start
                if not data:
                    raise TracError("You must have at least one step in a prototype")
                
                proto = Prototype(self.env, name)
                if action == 'new' and proto.exists:
                    raise TracError("Prototype %s already exists"%name)
                del proto[:]
                for x in data.split('|'):
                    proto.append(x.split(',',1))
                proto.save()
            elif req.args.get('cancel'): 
                pass # This should just redirect back
            elif req.args.get('delete') and action == 'edit': # Show the confirmation screen
                return 'admin_tracforge_prototypes_delete.cs', None
            elif req.args.get('reallydelete') and action == 'edit': # Actually delete this prototype
                name = path_info.strip('/')
                proto = Prototype(self.env, name)
                if not proto.exists:
                    raise TracError('Prototype %s does not exist'%name)
                proto.delete()
            req.redirect(req.href.admin(req.cat, req.page))

        #steps = {}
        #for p in self.setup_participants:
        #    for a in p.get_setup_actions():
        #        steps[a] = {
        #            'provider': p,
        #            'description': p.get_setup_action_description(a),
        #        }
        steps = TracForgeAdminSystem(self.env).get_project_setup_participants()
        
        initial_steps = []        
        if action == 'new': # For a new one, use the specified defaults 
            initial_steps = Prototype.default(self.env) # XXX: This should really read from trac.ini somehow
        elif action == 'edit': 
            proto = Prototype(self.env, path_info.strip('/'))
            if not proto.exists:
                raise TracError('Unknown prototype %s'%proto.tag)
            initial_steps = proto
        else:
            raise TracError('Invalid action %s'%action)

        req.hdf['tracforge.prototypes.action'] = action
        req.hdf['tracforge.prototypes.steps'] = steps
        req.hdf['tracforge.prototypes.initialsteps'] = initial_steps
        req.hdf['tracforge.prototypes.liststeps'] = [k for k in steps.iterkeys() if k not in initial_steps]
        
        return 'admin_tracforge_prototypes_show.cs', None