def trac_admin(env_path, *commands): admin = TracAdmin(env_path) logging.disable(logging.CRITICAL) save_stdout, sys.stdout = sys.stdout, StringIO() try: for command in commands: admin.onecmd(command) finally: sys.stdout = save_stdout logging.disable(logging.NOTSET)
def trac_admin(env_path, *commands): admin = TracAdmin(env_path) logging.disable(logging.CRITICAL) save_stdout, sys.stdout = sys.stdout, StringIO() try: for command in commands: admin.onecmd(command) finally: sys.stdout = save_stdout logging.disable(logging.NOTSET)
def setup(self, **kwargs): """Do the setup. A kwargs dictionary may be passed to override base options, potentially allowing for multiple environment creation.""" if has_babel: import babel try: locale = get_negotiated_locale([LANG]) locale = locale or babel.Locale.default() except babel.UnknownLocaleError: pass translation.activate(locale) options = dict(self.options) options.update(kwargs) if psycopg2 is None and options.get('dbtype') == 'postgres': print "psycopg2 needs to be installed to initialise a postgresql db" return False environments_path = options['envsdir'] if not os.path.exists(environments_path): os.makedirs(environments_path) new_env = os.path.join(environments_path, options['project']) tracini = os.path.abspath(os.path.join(new_env, 'conf', 'trac.ini')) baseini = os.path.abspath(os.path.join(new_env, 'conf', 'base.ini')) options['inherit'] = baseini options['db'] = self._generate_db_str(options) if 'repo_type' not in options or options['repo_type'] is None: options['repo_type'] = '' if 'repo_path' not in options or options['repo_path'] is None: options['repo_path'] = '' if (len(options['repo_type']) > 0) ^ (len(options['repo_path']) > 0): print "Error: Specifying a repository requires both the "\ "repository-type and the repository-path options." return False digestfile = os.path.abspath(os.path.join(new_env, options['digestfile'])) realm = options['realm'] adminuser = options['adminuser'] adminpass = options['adminpass'] # create base options: accounts_config = dict(ACCOUNTS_CONFIG) accounts_config['account-manager']['htdigest_file'] = digestfile accounts_config['account-manager']['htdigest_realm'] = realm trac = TracAdmin(os.path.abspath(new_env)) if not trac.env_check(): try: trac.do_initenv('%(project)s %(db)s ' '%(repo_type)s %(repo_path)s ' '--inherit=%(inherit)s ' '--nowiki' % options) except SystemExit: print ("Error: Unable to initialise the database" "Traceback for error is above") return False else: print ("Warning: Environment already exists at %s." % new_env) self.writeconfig(tracini, [{'inherit': {'file': baseini},},]) self.writeconfig(baseini, [BASE_CONFIG, accounts_config]) if os.path.exists(digestfile): backupfile(digestfile) htdigest_create(digestfile, adminuser, realm, adminpass) print "Adding TRAC_ADMIN permissions to the admin user %s" % adminuser trac.onecmd('permission add %s TRAC_ADMIN' % adminuser) # get fresh TracAdmin instance (original does not know about base.ini) bloodhound = TracAdmin(os.path.abspath(new_env)) # final upgrade print "Running upgrades" bloodhound.onecmd('upgrade') pages = [] pages.append(pkg_resources.resource_filename('bhdashboard', 'default-pages')) bloodhound.onecmd('wiki load %s' % " ".join(pages)) print "Running wiki upgrades" bloodhound.onecmd('wiki upgrade') print "Running wiki bh upgrades" bloodhound.onecmd('wiki bh-upgrade') print """ You can now start Bloodhound by running: tracd --port=8000 %s And point your browser at http://localhost:8000/%s """ % (os.path.abspath(new_env), options['project']) return True
from trac.admin.console import TracAdmin from trac.util.text import printout, printerr import sys if __name__ == "__main__": if len(sys.argv) != 2: printerr("Usage: %s <path>\nSupply the path where to create the test environment" % (sys.argv[0])) sys.exit(-1) admin = TracAdmin(sys.argv[1]) admin.onecmd("initenv \"trac-subcomponents test environment\" sqlite:db/trac.db") admin.onecmd("permission add anonymous TRAC_ADMIN") components = ("NoSubcomponents", "SuperComponent", "SuperComponent/SubComponent1", "SuperComponent/SubComponent2", "ForcedSubcomponent/ForcedSub1/ForcedSubSub", "LeafTest", "LeafTest/HasEmptyLeaf", "LeafTest/HasEmptyLeaf/Sub1", "LeafTest/HasEmptyLeaf/Sub2", "LeafTest/NoEmptyLeaf/Sub1", "LeafTest/NoEmptyLeaf/Sub2", "SixSubLevels/s1/s2/s3/s4/s5/s6") for component in components: admin.onecmd("component add %s nobody" % (component,)) printout(""" The test environment is set up at %s. You can run tracd to test this environment. Please make sure that the trac-subcomponents plugin is loaded, either by putting the plugin in %s/plugins, by making it available in general or by manipulation PYTHON_PATH. """ % (sys.argv[1], sys.argv[1])) sys.exit(0)
def setup(self, **kwargs): """Do the setup. A kwargs dictionary may be passed to override base options, potentially allowing for multiple environment creation.""" if has_babel: import babel try: locale = get_negotiated_locale([LANG]) locale = locale or babel.Locale.default() except babel.UnknownLocaleError: pass translation.activate(locale) options = dict(self.options) options.update(kwargs) if psycopg2 is None and options.get('dbtype') == 'postgres': print "psycopg2 needs to be installed to initialise a postgresql db" return False elif mysqldb is None and options.get('dbtype') == 'mysql': print "MySQLdb needs to be installed to initialise a mysql db" return False environments_path = options['envsdir'] if not os.path.exists(environments_path): os.makedirs(environments_path) new_env = os.path.join(environments_path, options['project']) tracini = os.path.abspath(os.path.join(new_env, 'conf', 'trac.ini')) baseini = os.path.abspath(os.path.join(new_env, 'conf', 'base.ini')) options['inherit'] = '"' + baseini + '"' options['db'] = self._generate_db_str(options) if 'repo_type' not in options or options['repo_type'] is None: options['repo_type'] = '' if 'repo_path' not in options or options['repo_path'] is None: options['repo_path'] = '' if (len(options['repo_type']) > 0) ^ (len(options['repo_path']) > 0): print "Error: Specifying a repository requires both the "\ "repository-type and the repository-path options." return False custom_prefix = 'default_product_prefix' if custom_prefix in options and options[custom_prefix]: default_product_prefix = options[custom_prefix] else: default_product_prefix = '@' digestfile = os.path.abspath(os.path.join(new_env, options['digestfile'])) realm = options['realm'] adminuser = options['adminuser'] adminpass = options['adminpass'] # create base options: accounts_config = dict(ACCOUNTS_CONFIG) accounts_config['account-manager']['htdigest_file'] = digestfile accounts_config['account-manager']['htdigest_realm'] = realm trac = TracAdmin(os.path.abspath(new_env)) if not trac.env_check(): try: rv = trac.do_initenv('%(project)s %(db)s ' '%(repo_type)s %(repo_path)s ' '--inherit=%(inherit)s ' '--nowiki' % options) if rv == 2: raise SystemExit except SystemExit: print ("Error: Unable to initialise the environment.") return False else: print ("Warning: Environment already exists at %s." % new_env) self.writeconfig(tracini, [{'inherit': {'file': baseini},},]) base_config = dict(BASE_CONFIG) base_config['trac']['environment_factory'] = \ 'multiproduct.hooks.MultiProductEnvironmentFactory' base_config['trac']['request_factory'] = \ 'multiproduct.hooks.ProductRequestFactory' if default_product_prefix != '@': base_config['multiproduct'] = dict( default_product_prefix=default_product_prefix ) self.writeconfig(baseini, [base_config, accounts_config]) if os.path.exists(digestfile): backupfile(digestfile) htdigest_create(digestfile, adminuser, realm, adminpass) print "Adding TRAC_ADMIN permissions to the admin user %s" % adminuser trac.onecmd('permission add %s TRAC_ADMIN' % adminuser) # get fresh TracAdmin instance (original does not know about base.ini) bloodhound = TracAdmin(os.path.abspath(new_env)) # final upgrade print "Running upgrades" bloodhound.onecmd('upgrade') pages = [] pages.append(pkg_resources.resource_filename('bhdashboard', 'default-pages')) pages.append(pkg_resources.resource_filename('bhsearch', 'default-pages')) bloodhound.onecmd('wiki load %s' % " ".join(pages)) print "Running wiki upgrades" bloodhound.onecmd('wiki upgrade') if self.apply_bhwiki_upgrades: print "Running wiki Bloodhound upgrades" bloodhound.onecmd('wiki bh-upgrade') else: print "Skipping Bloodhound wiki upgrades" print "Loading default product wiki" bloodhound.onecmd('product admin %s wiki load %s' % (default_product_prefix, " ".join(pages))) print "Running default product wiki upgrades" bloodhound.onecmd('product admin %s wiki upgrade' % default_product_prefix) if self.apply_bhwiki_upgrades: print "Running default product Bloodhound wiki upgrades" bloodhound.onecmd('product admin %s wiki bh-upgrade' % default_product_prefix) else: print "Skipping default product Bloodhound wiki upgrades" print """ You can now start Bloodhound by running: tracd --port=8000 %s And point your browser at http://localhost:8000/%s """ % (os.path.abspath(new_env), options['project']) return True
def setup(self, **kwargs): """Do the setup. A kwargs dictionary may be passed to override base options, potentially allowing for multiple environment creation.""" options = dict(self.options) options.update(kwargs) if psycopg2 is None and options.get('dbtype') == 'postgres': print "psycopg2 needs to be installed to initialise a postgresql db" return False environments_path = options['envsdir'] if not os.path.exists(environments_path): os.makedirs(environments_path) new_env = os.path.join(environments_path, options['project']) tracini = os.path.abspath(os.path.join(new_env, 'conf', 'trac.ini')) baseini = os.path.abspath(os.path.join(new_env, 'conf', 'base.ini')) options['inherit'] = baseini options['db'] = self._generate_db_str(options) if 'repo_type' not in options or options['repo_type'] is None: options['repo_type'] = '' if 'repo_path' not in options or options['repo_path'] is None: options['repo_path'] = '' digestfile = os.path.abspath( os.path.join(new_env, options['digestfile'])) realm = options['realm'] adminuser = options['adminuser'] adminpass = options['adminpass'] # create base options: accounts_config = dict(ACCOUNTS_CONFIG) accounts_config['account-manager']['htdigest_file'] = digestfile accounts_config['account-manager']['htdigest_realm'] = realm accounts_config['account-manager']['password_file'] = digestfile trac = TracAdmin(os.path.abspath(new_env)) if not trac.env_check(): try: trac.do_initenv('%(project)s %(db)s ' '%(repo_type)s %(repo_path)s ' '--inherit=%(inherit)s ' '--nowiki' % options) except SystemExit: print( "Error: Unable to initialise the database" "Traceback for error is above") return False else: print("Warning: Environment already exists at %s." % new_env) self.writeconfig(tracini, [ { 'inherit': { 'file': baseini }, }, ]) self.writeconfig(baseini, [BASE_CONFIG, accounts_config]) if os.path.exists(digestfile): backupfile(digestfile) htdigest_create(digestfile, adminuser, realm, adminpass) print "Adding TRAC_ADMIN permissions to the admin user %s" % adminuser trac.onecmd('permission add %s TRAC_ADMIN' % adminuser) # get fresh TracAdmin instance (original does not know about base.ini) bloodhound = TracAdmin(os.path.abspath(new_env)) # final upgrade print "Running upgrades" bloodhound.onecmd('upgrade') pages = pkg_resources.resource_filename('bhdashboard', 'default-pages') bloodhound.onecmd('wiki load %s' % pages) print "Running wiki upgrades" bloodhound.onecmd('wiki upgrade') print """ You can now start Bloodhound by running: tracd --port=8000 %s And point your browser at http://localhost:8000/%s """ % (os.path.abspath(new_env), options['project']) return True
from trac.admin.console import TracAdmin from trac.util.text import printout, printerr import sys if __name__ == "__main__": if len(sys.argv) != 2: printerr( "Usage: %s <path>\nSupply the path where to create the test environment" % (sys.argv[0])) sys.exit(-1) admin = TracAdmin(sys.argv[1]) admin.onecmd( "initenv \"trac-subcomponents test environment\" sqlite:db/trac.db") admin.onecmd("permission add anonymous TRAC_ADMIN") components = ("NoSubcomponents", "SuperComponent", "SuperComponent/SubComponent1", "SuperComponent/SubComponent2", "ForcedSubcomponent/ForcedSub1/ForcedSubSub", "LeafTest", "LeafTest/HasEmptyLeaf", "LeafTest/HasEmptyLeaf/Sub1", "LeafTest/HasEmptyLeaf/Sub2", "LeafTest/NoEmptyLeaf/Sub1", "LeafTest/NoEmptyLeaf/Sub2", "SixSubLevels/s1/s2/s3/s4/s5/s6") for component in components: admin.onecmd("component add %s nobody" % (component, )) printout(""" The test environment is set up at %s. You can run tracd to test this environment. Please make sure that the trac-subcomponents plugin is loaded, either by putting the plugin in %s/plugins, by making it available in general