def _post_process_request(self, req, *args): nbargs = len(args) resp = args for f in reversed(self.filters): # As the arity of `post_process_request` has changed since # Trac 0.10, only filters with same arity gets passed real values. # Errors will call all filters with None arguments, # and results will not be not saved. extra_arg_count = arity(f.post_process_request) - 2 if extra_arg_count == nbargs: resp = f.post_process_request(req, *resp) elif nbargs == 0: f.post_process_request(req, *(None,)*extra_arg_count) return resp
def __repr__(self): if self.realm is None: return '<Resource>' path = [] r = self while r: name = r.realm if r.id: name += ':' + unicode(r.id) # id can be numerical if r.version is not None: name += '@' + unicode(r.version) path.append(name or '') r = r.parent return '<Resource %r>' % (', '.join(reversed(path)))
def _post_process_request(self, req, *args): nbargs = len(args) resp = args for f in reversed(self.filters): # As the arity of `post_process_request` has changed since # Trac 0.10, only filters with same arity gets passed real values. # Errors will call all filters with None arguments, # and results will not be not saved. extra_arg_count = arity(f.post_process_request) - 2 if extra_arg_count == nbargs: resp = f.post_process_request(req, *resp) elif nbargs == 0: f.post_process_request(req, *(None, ) * extra_arg_count) return resp
def execute(self, data, direction='execute', project=None): """Run this prototype on a new project. NOTE: If you pass in a project that isn't new, this could explode. Don't do that. """ from api import TracForgeAdminSystem steps = TracForgeAdminSystem(self.env).get_project_setup_participants() # Store this for later orig_direction = direction # Clear out the last attempt at making this project, if any db = self.env.get_db_cnx() cursor = db.cursor() cursor.execute('DELETE FROM tracforge_project_log WHERE project=%s AND direction=%s', (data['name'], direction)) cursor.execute('DELETE FROM tracforge_project_output WHERE project=%s AND direction=%s', (data['name'], direction)) db.commit() # Grab the current stdout/err old_stdout = sys.stdout old_stderr = sys.stderr if direction == 'execute': run_buffer = [(action, args, 'execute') for action, args in self] else: cursor.execute('SELECT action, args WHERE project=%s AND direction=%s AND undone=%s ORDER BY step DESC', (project, direction, 0)) run_buffer = [(action, args, 'undo') for action, args in cursor] for i, (action, args, step_direction) in enumerate(run_buffer): #print data['name'], orig_direction, action, step_direction cursor.execute('INSERT INTO tracforge_project_log (project, step, direction, action, step_direction, args, undone) VALUES (%s, %s, %s, %s, %s, %s, %s)', (data['name'], i, orig_direction, action, step_direction, args, 0)) db.commit() def log_cb(stdout, stderr): now = time.time() #print '!'1, stdout, '!', stderr values = [] if stdout: values.append((now, data['name'], orig_direction, action, 'stdout', step_direction, stdout)) if stderr: values.append((now, data['name'], orig_direction, action, 'stderr', step_direction, stderr)) if values: cursor.executemany('INSERT INTO tracforge_project_output ' \ '(ts, project, direction, action, stream, step_direction, data) VALUES ' \ '(%s, %s, %s, %s, %s, %s, %s)', values) db.commit() if getattr(steps[action]['provider'], 'capture_output', True): sys.stdout = _CaptureOutput(cursor, data['name'], orig_direction, action, 'stdout', step_direction) sys.stderr = _CaptureOutput(cursor, data['name'], orig_direction, action, 'stderr', step_direction) try: rv = getattr(steps[action]['provider'], step_direction+'_setup_action')(action, args, data, log_cb) except Exception, e: log_cb('', traceback.format_exc()) rv = False cursor.execute('UPDATE tracforge_project_log SET return=%s WHERE project=%s AND direction=%s AND action=%s AND step_direction=%s', (int(rv), data['name'], orig_direction, action, step_direction)) db.commit() if not rv and direction == 'execute': # Failure, initiate rollback direction = 'undo' del run_buffer[i+1:] run_buffer.extend([(action, args, 'undo') for action, args, _ in reversed(run_buffer)])