Beispiel #1
0
def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]
    
    # Load initial parameters from the command-line
    master_path = argv[0]
    prototype_name = argv[1]
    data = {
        'name': argv[2],
        'full_name': argv[3],
    }
    
    # Load master env and the prototype
    env = open_environment(master_path)
    prototype = Prototype(env, prototype_name)
    
    # Run the prototype and add the project to the master table
    prototype.execute(data)
    db = env.get_db_cnx()
    cursor = db.cursor()
    cursor.execute('INSERT INTO tracforge_projects (name, env_path) VALUES (%s, %s)',
                   (data['name'], data['env'].path))
    db.commit()
Beispiel #2
0
    def render_admin_panel(self, req, cat, page, path_info):
        data = {}

        # General stuff
        add_stylesheet(req, "tracforge/css/admin.css")

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

        data["prototypes"] = Prototype.select(self.env)
        return "admin_tracforge_prototypes.html", data
    def render_admin_panel(self, req, cat, page, path_info):
        data = {}
        
        # General stuff
        add_stylesheet(req, 'tracforge/css/admin.css')

        # Subpage dispatchers
        if path_info:
            if path_info == 'new':
                return self._show_prototype(req, path_info, action='new')
            else:
                return self._show_prototype(req, path_info, action='edit')
        
        data['prototypes'] = Prototype.select(self.env)
        return 'admin_tracforge_prototypes.html', data
Beispiel #4
0
def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]

    # Load initial parameters from the command-line
    master_path = argv[0]
    prototype_name = argv[1]
    data = {
        'name': argv[2],
        'full_name': argv[3],
    }

    # Load master env and the prototype
    env = open_environment(master_path)
    prototype = Prototype(env, prototype_name)

    # Run the prototype and add the project to the master table
    prototype.execute(data)
    db = env.get_db_cnx()
    cursor = db.cursor()
    cursor.execute(
        'INSERT INTO tracforge_projects (name, env_path) VALUES (%s, %s)',
        (data['name'], data['env'].path))
    db.commit()
Beispiel #5
0
 def render_admin_panel(self, req, cat, page, path_info):
     if path_info:
         return self._render_project_view(req, cat, page, path_info)
     
     data = {}
     
     if req.method == 'POST':
         if 'create' in req.args.keys(): # Project creation
             name = req.args.get('shortname', '').strip()
             full_name = req.args.get('fullname', '').strip()
             proto_name = req.args.get('prototype', '').strip()
             if not (name and full_name and proto_name):
                 raise TracError('All arguments are required')
             
             # Make the models
             proto = Prototype(self.env, proto_name)
             if not proto.exists:
                 raise TracError('Penguins on fire')
             
             # Use $PATH on non-Win32
             if os.name == 'nt':
                 spawn = os.spawnv
             else:
                 spawn = os.spawnvp
             
             # Spawn the helper script
             helper = self.helper_script.split()
             helper += [self.env.path, proto_name, name, full_name]
             helper.insert(1, os.path.basename(helper[0]))
             spawn(os.P_NOWAIT, helper.pop(0), helper)
             
             # Redirect to the watcher page
             req.redirect(req.href.admin(cat, page, name))
         elif 'delete' in req.args.keys(): # Project deleteion
             raise TracError, 'Not implemented yet. Sorry.'
     
     data['projects'] = sorted([Project(self.env, n) for n in Project.select(self.env)], key=lambda p: p.name)
     data['prototypes'] = Prototype.select(self.env)
     data['env_base_path'] = os.path.join(os.path.dirname(self.env.path), '')
     
     add_script(req, 'tracforge/js/typewatch1.1.js')
     return 'admin_tracforge_projects.html', data
Beispiel #6
0
    def _show_prototype(self, req, path_info, action):
        """Handler for creating a new prototype."""
        data = {"name": path_info, "action": action}

        proto = None
        if req.method == "POST":
            proto = Prototype(self.env, "")

            for i in itertools.count():
                a = req.args.get("step-%s" % i)
                if a is not None:
                    proto.append((a, req.args["args-%s" % a]))
                else:
                    break

            if "movedown" in req.args:
                i = int(req.args["movedown"])
                x = proto.pop(i)
                proto.insert(i + 1, x)
            elif "moveup" in req.args:
                i = int(req.args["moveup"])
                x = proto.pop(i)
                proto.insert(i - 1, x)
            elif "remove" in req.args:
                i = int(req.args["remove"])
                del proto[i]
            elif "add" in req.args:
                proto.append((req.args["type"], ""))
            elif "save" in req.args:
                proto.tag = (action == "new" and req.args["name"] or data["name"]).strip()
                if not proto.tag or proto.tag == "new":
                    raise TracError('Invalid prototype name "%s"', proto.tag)
                proto.save()
                req.redirect(req.href.admin("tracforge/prototypes", proto.tag))
            elif "cancel" in req.args:
                req.redirect(req.href.admin("tracforge/prototypes"))
            elif "delete" in req.args:
                proto.tag = data["name"]
                proto.delete()
                req.redirect(req.href.admin("tracforge/prototypes"))

            # Try to figure out the name
            if action == "new":
                proto.tag = req.args["name"]
            else:
                proto.tag = "(modified) %s" % data["name"]

        # 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),
        #        }
        data["steps"] = TracForgeAdminSystem(self.env).get_project_setup_participants()

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

        add_stylesheet(req, "tracforge/css/prototypes_new.css")
        # add_script(req, 'tracforge/js/interface/iutil.js')
        # add_script(req, 'tracforge/js/jquery.animatedswap.js')
        return "admin_tracforge_prototype.html", data
 def _show_prototype(self, req, path_info, action):
     """Handler for creating a new prototype."""
     data = {
         'name': path_info,
         'action': action,
     }
     
     proto = None
     if req.method == 'POST':
         proto = Prototype(self.env, '')
         
         for i in itertools.count():
             a = req.args.get('step-%s'%i)
             if a is not None:
                 proto.append((a, req.args['args-%s'%a]))
             else:
                 break
         
         if 'movedown' in req.args:
             i = int(req.args['movedown'])
             x = proto.pop(i)
             proto.insert(i+1, x)
         elif 'moveup' in req.args:
             i = int(req.args['moveup'])
             x = proto.pop(i)
             proto.insert(i-1, x)
         elif 'remove' in req.args:
             i = int(req.args['remove'])
             del proto[i]
         elif 'add' in req.args:
             proto.append((req.args['type'], ''))
         elif 'save' in req.args:
             proto.tag = (action == 'new' and req.args['name'] or data['name']).strip()
             if not proto.tag or proto.tag == 'new':
                 raise TracError('Invalid prototype name "%s"', proto.tag)
             proto.save()
             req.redirect(req.href.admin('tracforge/prototypes', proto.tag))
         elif 'cancel' in req.args:
             req.redirect(req.href.admin('tracforge/prototypes'))
         elif 'delete' in req.args:
             proto.tag =  data['name']
             proto.delete()
             req.redirect(req.href.admin('tracforge/prototypes'))
         
         # Try to figure out the name
         if action == 'new':
             proto.tag = req.args['name']
         else:
             proto.tag = '(modified) %s'%data['name']
         
         
     #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),
     #        }
     data['steps'] = TracForgeAdminSystem(self.env).get_project_setup_participants()
     
     if action == 'new': # For a new one, use the specified defaults 
         if proto is None:
             proto = Prototype.default(self.env) # XXX: This should really read from trac.ini somehow
     elif action == 'edit': 
         if proto is None:
             proto = Prototype(self.env, data['name'])
             if not proto.exists:
                 raise TracError('Unknown prototype %s'%proto.tag)
     else:
         raise TracError('Invalid action %s'%action)
     data['proto'] = proto
     
     add_stylesheet(req, 'tracforge/css/prototypes_new.css')
     #add_script(req, 'tracforge/js/interface/iutil.js')
     #add_script(req, 'tracforge/js/jquery.animatedswap.js')
     return 'admin_tracforge_prototype.html', data