Ticket #3030: no_space_names.patch
| File no_space_names.patch, 11.5 kB (added by s0undt3ch, 4 months ago) |
|---|
-
tracforge/linker/auth.py
old new 13 13 14 14 class TracForgeLoginModule(LoginModule): 15 15 """Replacement for LoginModule to slave to another environment.""" 16 16 17 17 master_path = Option('tracforge', 'master_path', 18 18 doc='Path to master Trac') 19 19 20 20 master_env = property(lambda self: open_environment(self.master_path, use_cache=True)) 21 21 master_href = property(lambda self: Href(self.master_env.base_url)) 22 22 23 23 # INavigationContributor methods 24 24 def get_active_navigation_item(self, req): 25 25 return 'login' … … 32 32 else: 33 33 yield ('metanav', 'login', 34 34 html.A('Login', href=self.master_href.login())) 35 35 36 36 # IRequestHandler methods 37 37 def process_request(self, req): 38 38 if req.path_info.startswith('/login'): … … 49 49 return LoginModule(self.master_env)._get_name_for_cookie(req, cookie) 50 50 51 51 class TracForgeCookieMunger(Component): 52 52 53 53 uri_root = Option('tracforge', 'uri_root', default='/', 54 54 doc='The smallest common URI for the whole TracForge setup') 55 55 56 56 implements(IRequestFilter) 57 57 58 58 def pre_process_request(self, req, handler): … … 73 73 if parts[2].startswith(self.uri_root) and (not parts[1] or parts[1] == req.server_name): 74 74 Request.redirect(req, referer) 75 75 76 old_redirect( req,*args, **kwords)77 76 old_redirect(*args, **kwords) 77 78 78 req.redirect = my_redirect 79 79 80 80 return handler 81 81 82 82 def post_process_request(self, req, template, content_type): 83 83 return (template, content_type) 84 84 -
tracforge/admin/admin.py
old new 1 1 # Created by Noah Kantrowitz on 2008-02-19. 2 2 # Copyright (c) 2008 Noah Kantrowitz. All rights reserved. 3 import re 3 4 import os 4 5 import os.path 5 6 … … 19 20 doc='Path to the tracforge-helper script, possibly' 20 21 'utilizing sudo or similar wrappers.') 21 22 22 implements(IAdminPanelProvider) 23 23 implements(IAdminPanelProvider) 24 24 25 # IAdminPageProvider methods 25 26 def get_admin_panels(self, req): 26 27 if req.perm.has_permission('TRACFORGE_ADMIN'): 27 28 yield ('tracforge', 'TracForge', 'admin', 'Project Admin') 28 29 29 30 def render_admin_panel(self, req, cat, page, path_info): 30 31 if path_info: 31 32 return self._render_project_view(req, cat, page, path_info) 32 33 33 34 data = {} 34 35 35 36 if req.method == 'POST': 36 37 if 'create' in req.args.keys(): # Project creation 37 38 name = req.args.get('shortname', '').strip() 39 if re.search(r'[^\w]', name): 40 raise TracError('Invalid project short name "%s". Should ' 41 ' only contain chars in [a-zA-Z0-9_]' % \ 42 name) 38 43 full_name = req.args.get('fullname', '').strip() 39 44 proto_name = req.args.get('prototype', '').strip() 40 45 if not (name and full_name and proto_name): 41 46 raise TracError('All arguments are required') 42 47 43 48 # Make the models 44 49 proto = Prototype(self.env, proto_name) 45 50 if not proto.exists: 46 51 raise TracError('Penguins on fire') 47 52 48 53 # Use $PATH on non-Win32 49 54 if os.name == 'nt': 50 55 spawn = os.spawnv 51 56 else: 52 57 spawn = os.spawnvp 53 58 54 59 # Spawn the helper script 55 60 helper = self.helper_script.split() 56 61 helper += [self.env.path, proto_name, name, full_name] 57 62 helper.insert(1, os.path.basename(helper[0])) 58 63 spawn(os.P_NOWAIT, helper.pop(0), helper) 59 64 60 65 # Redirect to the watcher page 61 66 req.redirect(req.href.admin(cat, page, name)) 62 67 elif 'delete' in req.args.keys(): # Project deleteion 63 68 raise TracError, 'Not implemented yet. Sorry.' 64 69 65 70 data['projects'] = sorted([Project(self.env, n) for n in Project.select(self.env)], key=lambda p: p.name) 66 71 data['prototypes'] = Prototype.select(self.env) 67 72 data['env_base_path'] = os.path.join(os.path.dirname(self.env.path), '') 68 73 69 74 add_script(req, 'tracforge/js/typewatch1.1.js') 70 75 return 'admin_tracforge_projects.html', data 71 76 … … 75 80 'actions': [], 76 81 } 77 82 action_map = {} 78 83 79 84 db = self.env.get_db_cnx() 80 85 cursor = db.cursor() 81 86 82 87 cursor.execute('SELECT action, step_direction, args, return FROM tracforge_project_log WHERE project=%s ORDER BY step', (data['project'],)) 83 88 for action, step_direction, args, rv in cursor: 84 89 d = { … … 90 95 } 91 96 data['actions'].append(d) 92 97 action_map[action,step_direction] = d 93 98 94 99 cursor.execute('SELECT ts, action, step_direction, stream, data FROM tracforge_project_output WHERE project=%s ORDER BY ts, stream DESC', (data['project'],)) 95 100 for ts, action, step_direction, stream, msg in cursor: 96 101 ts = float(ts) 97 102 output = action_map[action, step_direction]['output'] 98 103 if output and abs(output[-1][0] - ts) <= 1e-2 and output[-1][1] == stream: 99 104 output[-1] = (output[-1][0], output[-1][1], output[-1][2]+msg) 100 else: 105 else: 101 106 output.append((float(ts), stream, msg)) 102 107 103 108 return 'admin_tracforge_project.html', data -
tracforge/admin/prototypes_admin.py
old new 1 1 # TracForge prototype admin panel 2 import re 2 3 import itertools 3 4 4 5 from trac.core import * … … 14 15 #setup_participants = ExtensionPoint(IProjectSetupParticipant) 15 16 16 17 implements(IAdminPanelProvider) 17 18 18 19 def get_admin_panels(self, req): 19 20 if 'TRACFORGE_ADMIN' in req.perm: 20 21 yield 'tracforge', 'TracForge', 'prototypes', 'Project Prototypes' 21 22 #yield 'tracforge', 'TracForge', 'configset', 'Configset Management' 22 23 23 24 def render_admin_panel(self, req, cat, page, path_info): 24 25 data = {} 25 26 26 27 # General stuff 27 28 add_stylesheet(req, 'tracforge/css/admin.css') 28 29 … … 32 33 return self._show_prototype(req, path_info, action='new') 33 34 else: 34 35 return self._show_prototype(req, path_info, action='edit') 35 36 36 37 data['prototypes'] = Prototype.select(self.env) 37 38 return 'admin_tracforge_prototypes.html', data 38 39 39 40 def process_configset_admin_request(self, req, cat, page, path_info): 40 41 tags = ['*'] + list(ConfigSet.select(self.env)) 41 42 configs = {} … … 51 52 key = req.args.get('key') 52 53 value = req.args.get('value') 53 54 action = req.args.get('action') 54 55 55 56 # Input validation 56 57 if not (tag and section and key and action): 57 58 raise TracError('Not all values given') … … 59 60 raise TracError('Invalid action %s'%action) 60 61 if '/' in tag or '/' in section or '/' in key: 61 62 raise TracError("You cannot use '/' in a tag, section, or key") 62 63 63 64 config = ConfigSet(self.env, tag=tag, with_star=False) 64 65 config.set(section, key, value, action) 65 66 config.save() … … 73 74 for s,k in x: 74 75 config.remove(s,k) 75 76 config.save() 76 77 77 78 req.redirect(req.href.admin(cat, page, path_info)) 78 79 79 req.hdf['tracforge.tags'] = tags 80 req.hdf['tracforge.tags'] = tags 80 81 #for t in tags: # Force ordering so * is first 81 82 # req.hdf['tracforge.tags.'+t] = configs[t] 82 83 req.hdf['tracforge.configs'] = configs 83 84 84 return 'admin_tracforge_configset.cs', None 85 return 'admin_tracforge_configset.cs', None 85 86 86 87 def _show_prototype(self, req, path_info, action): 87 88 """Handler for creating a new prototype.""" … … 89 90 'name': path_info, 90 91 'action': action, 91 92 } 92 93 93 94 proto = None 94 95 if req.method == 'POST': 95 96 proto = Prototype(self.env, '') 96 97 97 98 for i in itertools.count(): 98 99 a = req.args.get('step-%s'%i) 99 100 if a is not None: 100 101 proto.append((a, req.args['args-%s'%a])) 101 102 else: 102 103 break 103 104 104 105 if 'movedown' in req.args: 105 106 i = int(req.args['movedown']) 106 107 x = proto.pop(i) … … 118 119 proto.tag = (action == 'new' and req.args['name'] or data['name']).strip() 119 120 if not proto.tag or proto.tag == 'new': 120 121 raise TracError('Invalid prototype name "%s"', proto.tag) 122 elif re.search(r'[^\w]', proto.tag): 123 raise TracError('Invalid prototype name "%s" should ' 124 ' only contain chars in [a-zA-Z0-9_]' % \ 125 proto.tag) 121 126 proto.save() 122 127 req.redirect(req.href.admin('tracforge/prototypes', proto.tag)) 123 128 elif 'cancel' in req.args: … … 126 131 proto.tag = data['name'] 127 132 proto.delete() 128 133 req.redirect(req.href.admin('tracforge/prototypes')) 129 134 130 135 # Try to figure out the name 131 136 if action == 'new': 132 137 proto.tag = req.args['name'] 133 138 else: 134 139 proto.tag = '(modified) %s'%data['name'] 135 136 140 141 137 142 #steps = {} 138 143 #for p in self.setup_participants: 139 144 # for a in p.get_setup_actions(): … … 142 147 # 'description': p.get_setup_action_description(a), 143 148 # } 144 149 data['steps'] = TracForgeAdminSystem(self.env).get_project_setup_participants() 145 146 if action == 'new': # For a new one, use the specified defaults 150 151 if action == 'new': # For a new one, use the specified defaults 147 152 if proto is None: 148 153 proto = Prototype.default(self.env) # XXX: This should really read from trac.ini somehow 149 elif action == 'edit': 154 elif action == 'edit': 150 155 if proto is None: 151 156 proto = Prototype(self.env, data['name']) 152 157 if not proto.exists: … … 154 159 else: 155 160 raise TracError('Invalid action %s'%action) 156 161 data['proto'] = proto 157 162 158 163 add_stylesheet(req, 'tracforge/css/prototypes_new.css') 159 164 #add_script(req, 'tracforge/js/interface/iutil.js') 160 165 #add_script(req, 'tracforge/js/jquery.animatedswap.js')
