Changeset 508
- Timestamp:
- 10/02/08 23:09:34 (5 years ago)
- Location:
- trunk/plugins/oforgeplugin
- Files:
-
- 4 edited
-
oforge/api.py (modified) (15 diffs)
-
oforge/console.py (modified) (2 diffs)
-
setup.py (modified) (1 diff)
-
share/cgi-bin/oforge-auth.wsgi (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/oforgeplugin/oforge/api.py
r506 r508 43 43 '''MASTER_CONFIG lets oforge find the base trac site config file''' 44 44 def __init__(self, configpath=None): 45 """ 46 The master ini is the trac.ini file that all projects 47 inherit from. If the config path is not provided, we 48 will check for an oforge ini file in etc. This can 49 provide the location of the master ini. 50 """ 45 51 if not configpath: 46 52 for oforge_config in self.MASTER_CONFIG: … … 53 59 54 60 def postgres_db_props(self): 61 """ 62 Get all project dashboard db related connection options. 63 """ 55 64 props = {} 56 65 props['database'] = \ … … 67 76 68 77 def warehouse_db_cnx(self): 78 """ 79 Context for the project dashboard postgres schema. 80 """ 69 81 p = self.postgres_db_props() 70 82 … … 86 98 87 99 def getenv(self, name): 100 """ 101 Get an environment by name. 102 """ 88 103 base = self.config.get('oforge', 'trac_base') 89 104 thepath = path.join(base, name) … … 92 107 93 108 def getconfig(self, name): 109 """ 110 Return the config object of an environment by name. 111 """ 94 112 base = self.config.get('oforge', 'trac_base') 95 113 thepath = path.join(base, name, 'conf/trac.ini') … … 99 117 def get_project(self, env): 100 118 """ 101 Return a map of all project properties.119 Return a project object from the django project dashboard api. 102 120 """ 103 121 return Project.objects.get(id=env.config.getint('oforge', 'proj_id')) … … 132 150 133 151 def converttopostgres(self, name): 152 """ 153 Convert a project from sqlite to postgresql. 154 """ 134 155 # Setup vars 135 156 config = self.getconfig(name) … … 169 190 # Commit all changes 170 191 target_db_cnx.commit() 171 self._add_dashboard.project(name)172 192 except Exception, e: 173 193 config.set('trac','database', olddburl) … … 182 202 raise e 183 203 184 def warehouseproject(self, name): 185 traclocation = path.join(self.config.get('oforge', 'trac_base'), 186 name) 187 env = Environment(traclocation) 188 db = env.config.get('trac', 'database') 189 # cp old project 190 191 def _add_dashboard_project(self, name): 204 def add_dashboard_project(self, name): 205 """ 206 Connect a project to the project dashboard. 207 """ 192 208 env = self.getenv(name) 209 if env.config.get('oforge', 'proj_id', None): 210 raise OForgeException("Project already registered") 193 211 display_name = env.config.get('project', 'name') 194 212 type = env.config.get('project', 'category') … … 199 217 env.config.save() 200 218 return p.id 219 220 def remove_dashboard_project(self, name): 221 """ 222 Disconnect a project from the project dashboard. 223 """ 224 env = self.getenv(name) 225 proj_id = env.config.getint('oforge', 'proj_id', -1) 226 if proj_id != -1: 227 Project.objects.filter(id=proj_id).delete() 228 env.config.set('oforge', 'proj_id', None) 229 env.config.save() 230 else: 231 raise OForgeProjectException("Project not registered") 201 232 202 233 def createproject(self, name, **kwargs): … … 294 325 "Using source project %s"%(defaultworkspace)) 295 326 sourceenv = self.getenv(defaultworkspace) 327 src_dbstr = sourceenv.config.get('trac', 'database') 328 src_is_postgres = \ 329 re.match('^postgres', src_dbstr) 296 330 try: 297 331 self.logger.debug('Cloning default workspace') 298 self.cloneproject(sourceenv, env )332 self.cloneproject(sourceenv, env, src_is_postgres=src_is_postgres) 299 333 finally: 300 334 sourceenv.shutdown() 301 335 env.upgrade(backup=False) 302 proj_id = self. _add_dashboard_project(name)336 proj_id = self.add_dashboard_project(name) 303 337 project_created = True 304 338 self.logger.debug('Environment creation complete') … … 383 417 return env 384 418 385 def cloneproject(self, sourceenv, targetenv ):419 def cloneproject(self, sourceenv, targetenv, src_is_postgres=False): 386 420 ''' 387 421 Extract data from one project and insert it into the other … … 397 431 try: 398 432 for table in tables: 399 self._copy_table(source_db, target_db, table) 433 self._copy_table(source_db, target_db, table, 434 src_is_postgres=src_is_postgres) 400 435 except Exception, e: 401 436 target_db.rollback() … … 406 441 407 442 408 def _copy_table(self, src_db, dest_db, table, do_close_tran=False ):443 def _copy_table(self, src_db, dest_db, table, do_close_tran=False, src_is_postgres=False): 409 444 ''' 410 445 Copy a table from one DB to another … … 412 447 src_cursor = src_db.cursor() 413 448 dest_cursor = dest_db.cursor() 414 415 if src_cursor.execute("select name from sqlite_master " + \ 416 "where name = '%s'"%(table)).fetchone(): 449 test_query = """SELECT name FROM sqlite_master 450 WHERE name = '%s'"""%(table) 451 if src_is_postgres: 452 src_cursor.execute("SHOW search_path") 453 schema = src_cursor.fetchone()[0] 454 test_query = """SELECT table_name FROM information_schema.tables 455 WHERE table_name = '%s' AND 456 table_schema = '%s'"""%(table, schema) 457 # TODO: this needs to work with postgres too 458 src_cursor.execute(test_query) 459 if src_cursor.fetchone(): 417 460 src_cursor.execute('SELECT * FROM %s'%(table)) 418 461 dest_cursor.execute('SELECT * FROM %s LIMIT 1'%(table)) -
trunk/plugins/oforgeplugin/oforge/console.py
r497 r508 24 24 from oforge.api import OForge 25 25 26 MASTER_CONFIG = ('/etc/oforge.ini', '/etc/oforge/oforge.ini') 27 26 28 def oforge_admin(): 27 29 _init_oforge_logger() 28 MASTER_CONFIG = ('/etc/oforge.ini', '/etc/oforge/oforge.ini')29 30 30 31 mconfig = None … … 189 190 190 191 def convert_to_postgres(): 191 parser = OptionParser() 192 usage = "%prog [options] workspace-shortname \n - Remove workspace from dashboard." 193 parser = OptionParser(usage) 194 195 parser.set_defaults(master_trac_ini=_get_master_trac_ini()) 196 197 parser.add_option("--master-trac-ini", dest="master_trac_ini", 198 help="Master trac ini that describes project locations.") 192 199 (opts, args) = parser.parse_args() 193 200 proj = args[0] 194 201 if proj: 195 oforge = OForge( '/var/oforge/share/conf/trac.ini')202 oforge = OForge(opts.master_trac_ini) 196 203 oforge.converttopostgres(proj) 204 205 def add_to_dashboard(): 206 usage = "%prog [options] workspace-shortname \n - Remove workspace from dashboard." 207 parser = OptionParser(usage) 208 209 parser.set_defaults(master_trac_ini=_get_master_trac_ini()) 210 211 parser.add_option("--master-trac-ini", dest="master_trac_ini", 212 help="Master trac ini that describes project locations.") 213 (opts, args) = parser.parse_args() 214 proj = args[0] 215 if proj: 216 oforge = OForge(opts.master_trac_ini) 217 oforge.add_dashboard_project(proj) 218 219 def remove_from_dashboard(): 220 usage = "%prog [options] workspace-shortname \n - Remove workspace from dashboard." 221 parser = OptionParser(usage) 222 223 parser.set_defaults(master_trac_ini=_get_master_trac_ini()) 224 225 parser.add_option("--master-trac-ini", dest="master_trac_ini", 226 help="Master trac ini that describes project locations.") 227 (opts, args) = parser.parse_args() 228 proj = args[0] 229 if proj: 230 oforge = OForge(opts.master_trac_ini) 231 oforge.remove_dashboard_project(proj) 232 233 def _get_master_trac_ini(): 234 mconfig = None 235 for config_path in MASTER_CONFIG: 236 if path.exists(config_path): 237 mconfig = Configuration(config_path) 238 return mconfig.get('oforge', 'configfile', '/var/oforge/share/conf/trac.ini') 239 if not mconfig: 240 return '/var/oforge/share/conf/trac.ini' 197 241 198 242 def _init_oforge_logger(): -
trunk/plugins/oforgeplugin/setup.py
r461 r508 39 39 'oforge-projects-upgrade = oforge.console:projects_upgrade', 40 40 'oforge-convert-to-postgres = oforge.console:convert_to_postgres', 41 'oforge-add-to-dashboard = oforge.console:add_to_dashboard', 42 'oforge-remove-from-dashboard = oforge.console:remove_from_dashboard' 41 43 ]}, 42 44 zip_safe=True, -
trunk/plugins/oforgeplugin/share/cgi-bin/oforge-auth.wsgi
r461 r508 35 35 from os import path 36 36 import re 37 trac_path_match = re.compile(r'^/ [^/]+/([^/]+)')37 trac_path_match = re.compile(r'^/trac/(master/projects/)?([^/]+)') 38 38 39 39 TRAC_ENV_PARENT_DIR = "/var/oforge/trac/" … … 43 43 m=trac_path_match.match(environ.get('REQUEST_URI')) 44 44 if m: 45 env_path=path.join(TRAC_ENV_PARENT_DIR,m.group( 1))45 env_path=path.join(TRAC_ENV_PARENT_DIR,m.group(2)) 46 46 if path.isfile(path.join(env_path,'VERSION')): 47 47 try:
Note: See TracChangeset
for help on using the changeset viewer.
