def test_generate_settings_local_with_sqlite(self): """Testing Site.generate_settings_local with SQLite""" site = Site(install_dir=self.sitedir1, options={}) site.domain_name = 'reviews.example.com' site.db_type = 'sqlite3' site.db_name = '/path/to/reviewboard.db' site.cache_info = 'localhost:1666' site.cache_type = 'memcached' site.secret_key = \ 'acdef12345acdef123456abcdef123456abcdef12345abcdef12345' site.generate_settings_local() self._check_settings_local( self.sitedir1, 'DATABASES = {\n' ' "default": {\n' ' "ENGINE": "django.db.backends.sqlite3",\n' ' "NAME": "/path/to/reviewboard.db"\n' ' }\n' '}\n' 'CACHES = {\n' ' "default": {\n' ' "BACKEND": "django.core.cache.backends.memcached' '.MemcachedCache",\n' ' "LOCATION": "localhost:1666"\n' ' }\n' '}\n' 'SECRET_KEY = "acdef12345acdef123456abcdef123456abcdef12345' 'abcdef12345"\n' 'SITE_ROOT = ""\n' 'DEBUG = False\n' 'ALLOWED_HOSTS = [\n' ' "reviews.example.com"\n' ']\n')
def main(): if not os.path.exists(os.path.join("reviewboard", "manage.py")): sys.stderr.write("This must be run from the top-level Review Board " "directory\n") sys.exit(1) # Insert the current directory first in the module path so we find the # correct reviewboard package. sys.path.insert(0, os.getcwd()) from reviewboard.cmdline.rbsite import Site parse_options(sys.argv[1:]) # Re-use the Site class, since it has some useful functions. site = Site("reviewboard", SiteOptions) create_settings() build_egg_info() if options.install_media: install_media(site) if options.sync_db: print "Synchronizing database..." site.abs_install_dir = os.getcwd() site.sync_database(allow_input=True) print print "Your Review Board tree is ready for development." print
def main(): if not os.path.exists(os.path.join("reviewboard", "manage.py")): sys.stderr.write("This must be run from the top-level Review Board " "directory\n") sys.exit(1) # Insert the current directory first in the module path so we find the # correct reviewboard package. sys.path.insert(0, os.getcwd()) from reviewboard.cmdline.rbsite import Site # Re-use the Site class, since it has some useful functions. site = Site("reviewboard", SiteOptions) create_settings() build_egg_info() install_media(site) print "Synchronizing database..." site.sync_database(allow_input=True) print print "Your Review Board tree is ready for development." print
def _check_upgrade_wsgi(self, stored_wsgi_text, expected_wsgi_text): """Check that upgrading reviewboard.wsgi produces the expected results. Args: stored_wsgi_text (unicode): The contents of the :file:`htdocs/reviewboard.wsgi` file to write and upgrade. expected_wsgi_text (unicode): The expected content of the file. Raises: AssertionError: An expectation failed. """ sitedir = self.sitedir2 site = Site(install_dir=sitedir, options={}) filename = os.path.join(site.abs_install_dir, 'htdocs', 'reviewboard.wsgi') with open(filename, 'w') as fp: fp.write(stored_wsgi_text % { 'sitedir': sitedir, }) site.upgrade_wsgi() with open(filename, 'r') as fp: self.assertMultiLineEqual( fp.read(), expected_wsgi_text % { 'sitedir': sitedir, })
def _get_wsgi_upgrade_needed(self, stored_wsgi_text): """Return Site.get_wsgi_upgrade_needed with the provided file. Args: stored_settings (dict): A dictionary of settings that would be stored in :file:`settings_local.py`. Returns: bool: The result of :py:class:`~reviewboard.cmdline.rbsite.Site. get_settings_upgrade_needed`. """ sitedir = self.sitedir2 site = Site(install_dir=sitedir, options={}) filename = os.path.join(site.abs_install_dir, 'htdocs', 'reviewboard.wsgi') with open(filename, 'w') as fp: fp.write(stored_wsgi_text % { 'sitedir': sitedir, }) return site.get_wsgi_upgrade_needed()
def _get_settings_upgrade_needed(self, stored_settings): """Return Site.get_settings_upgrade_needed with the provided settings. Args: stored_settings (dict): A dictionary of settings that would be stored in :file:`settings_local.py`. Returns: bool: The result of :py:class:`~reviewboard.cmdline.rbsite.Site. get_settings_upgrade_needed`. """ class SettingsLocal(object): pass for key, value in six.iteritems(stored_settings): setattr(SettingsLocal, key, value) site = Site(install_dir=self.sitedir2, options={}) self.spy_on(site.get_settings_local, op=kgb.SpyOpReturn(SettingsLocal)) return site.get_settings_upgrade_needed()
def main(): """The entry point of the prepare-dev script.""" if not os.path.exists(os.path.join("reviewboard", "manage.py")): sys.stderr.write("This must be run from the top-level Review Board " "directory\n") sys.exit(1) options = parse_options(sys.argv[1:]) if options.install_deps: install_dependencies() # Insert the current directory first in the module path so we find the # correct reviewboard package. sys.path.insert(0, os.getcwd()) from reviewboard.cmdline.rbsite import Site, ConsoleUI import reviewboard.cmdline.rbsite reviewboard.cmdline.rbsite.ui = ConsoleUI() # Re-use the Site class, since it has some useful functions. site_path = os.path.abspath('reviewboard') site = Site(site_path, SiteOptions) create_settings(options) if options.install_hooks: install_git_hooks() if options.install_media: install_media(site) try: if options.sync_db: print('Synchronizing database...') site.abs_install_dir = os.getcwd() site.sync_database(allow_input=True) except KeyboardInterrupt: sys.stderr.write( 'The process was canceled in the middle of creating the database, ' 'which can result in a corrupted setup. Please remove the ' 'database file and run ./reviewboard/manage.py syncdb.') return print() print('Your Review Board tree is ready for development.') print()
def _check_upgrade_settings(self, stored_settings, stored_settings_text, expected_settings_text): """Check that upgrading settings produces the expected results. Args: stored_settings (dict): A dictionary of settings that would be stored in :file:`settings_local.py`. stored_settings_text (unicode): The content of the :file:`settings_local.py` file to write and upgrade. expected_settings_text (unicode): The content of just the settings, without any blank lines or comments. Raises: AssertionError: An expectation failed. """ class SettingsLocal(object): pass for key, value in six.iteritems(stored_settings): setattr(SettingsLocal, key, value) site = Site(install_dir=self.sitedir2, options={}) self.spy_on(site.get_settings_local, op=kgb.SpyOpReturn(SettingsLocal)) with open(os.path.join(site.abs_install_dir, 'conf', 'settings_local.py'), 'w') as fp: fp.write(stored_settings_text) site.upgrade_settings() self._check_settings_local(site.abs_install_dir, expected_settings_text)
def _create(self): with open(os.path.join(self.path, 'settings_local.py'), 'wb') as fh: fh.write(SETTINGS_LOCAL) # TODO figure out how to suppress logging when invoking via native # Python API. f = open(os.devnull, 'w') subprocess.check_call(self.manage + ['syncdb', '--noinput'], cwd=self.path, env=self.env, stdout=f, stderr=f) subprocess.check_call(self.manage + ['enable-extension', 'rbbz.extension.BugzillaExtension'], cwd=self.path, env=self.env, stdout=f, stderr=f) subprocess.check_call(self.manage + ['enable-extension', 'rbmozui.extension.RBMozUI'], cwd=self.path, env=self.env, stdout=f, stderr=f) from reviewboard.cmdline.rbsite import Site, parse_options class dummyoptions(object): no_input = True site_root = '/' db_type = 'sqlite3' copy_media = True site = Site(self.path, dummyoptions()) site.rebuild_site_directory() from djblets.siteconfig.models import SiteConfiguration sc = SiteConfiguration.objects.get_current() sc.set('site_static_root', os.path.join(self.path, 'htdocs', 'static')) sc.set('site_media_root', os.path.join(self.path, 'htdocs', 'media')) # Hook up rbbz authentication. sc.set('auth_backend', 'bugzilla') sc.set('auth_bz_xmlrpc_url', '%s/xmlrpc.cgi' % self.bugzilla_url) sc.save()
def test_generate_settings_local_with_postgres(self): """Testing Site.generate_settings_local with Postgres""" site = Site(install_dir=self.sitedir1, options={}) site.domain_name = 'reviews.example.com' site.db_type = 'postgresql' site.db_name = 'test-database' site.db_user = '******' site.db_pass = '******' site.db_host = 'db.example.com' site.db_port = 12345 site.cache_info = 'localhost:1666' site.cache_type = 'memcached' site.secret_key = \ 'acdef12345acdef123456abcdef123456abcdef12345abcdef12345' site.generate_settings_local() self._check_settings_local( self.sitedir1, 'DATABASES = {\n' ' "default": {\n' ' "ENGINE": "django.db.backends.postgresql",\n' ' "NAME": "test-database",\n' ' "USER": "******",\n' ' "PASSWORD": "******",\n' ' "HOST": "db.example.com",\n' ' "PORT": 12345\n' ' }\n' '}\n' 'CACHES = {\n' ' "default": {\n' ' "BACKEND": "django.core.cache.backends.memcached' '.MemcachedCache",\n' ' "LOCATION": "localhost:1666"\n' ' }\n' '}\n' 'SECRET_KEY = "acdef12345acdef123456abcdef123456abcdef12345' 'abcdef12345"\n' 'SITE_ROOT = ""\n' 'DEBUG = False\n' 'ALLOWED_HOSTS = [\n' ' "reviews.example.com"\n' ']\n')
def main(): """The entry point of the prepare-dev script.""" global ui if not os.path.exists(os.path.join("reviewboard", "manage.py")): sys.stderr.write("This must be run from the top-level Review Board " "directory\n") sys.exit(1) options = parse_options(sys.argv[1:]) if options.install_deps: install_dependencies() # Insert the current directory first in the module path so we find the # correct reviewboard package. sys.path.insert(0, os.getcwd()) from reviewboard.cmdline.rbsite import Site, ConsoleUI import reviewboard.cmdline.rbsite ui = ConsoleUI() reviewboard.cmdline.rbsite.ui = ui page = ui.page('Welcome to Review Board!') ui.text(page, "Let's get your development environment set up and ready to go. " "This will set up your settings_local.py file, your database, " "initial static media files, and prepare an administrator " "account.") ui.text(page, "If you have any issues, first see if it's answered in our FAQ:") ui.urllink(page, FAQ_URL) ui.text(page, "If you're a student working on Review Board, you can also " "get help from your mentors. If you're a contributor, please " "contact [email protected]") # Re-use the Site class, since it has some useful functions. site_path = os.path.abspath('reviewboard') site = Site(site_path, SiteOptions) create_settings(options) if options.install_hooks: install_git_hooks() try: if options.sync_db: site.abs_install_dir = os.getcwd() ui.page('Setting up the Review Board database') site.setup_settings() site.update_database(allow_input=True, report_progress=True) except KeyboardInterrupt: ui.error( 'The process was canceled in the middle of creating the database, ' 'which can result in a corrupted setup. Please remove the ' 'database file and run `./reviewboard/manage.py evolve --execute`') return if options.install_media: install_media(site) create_superuser(site) page = ui.page('Your Review Board tree is ready for development!') ui.text(page, 'You can now run your development server by running ' '`./contrib/internal/devserver.py`')
fh.write(line) if not log_directory_found: fh.write('LOGGING_DIRECTORY = "/var/log/reviewboard"\n') if not production_found: fh.write('PRODUCTION = False\n') if not extra_apps_found: fh.write('RB_EXTRA_APPS = ["django_extensions"]\n') class FakeOptions(object): copy_media = False print('initialising review board') from reviewboard.cmdline.rbsite import Site site = Site(ROOT, FakeOptions()) site.run_manage_command('syncdb', ['--noinput']) site.setup_settings() from reviewboard import initialize initialize() # we need to toggle disable/enable state to get first run code to run site.run_manage_command('disable-extension', ['mozreview.extension.MozReviewExtension']) site.run_manage_command('disable-extension', ['rbbz.extension.BugzillaExtension']) site.run_manage_command('disable-extension', ['rbmotd.extension.MotdExtension']) site.run_manage_command('enable-extension', ['mozreview.extension.MozReviewExtension']) site.run_manage_command('enable-extension',
extra_apps_found = True fh.write(line) if not log_directory_found: fh.write('LOGGING_DIRECTORY = "/var/log/reviewboard"\n') if not production_found: fh.write('PRODUCTION = False\n') if not extra_apps_found: fh.write('RB_EXTRA_APPS = ["django_extensions"]\n') class FakeOptions(object): copy_media = False print('initialising review board') from reviewboard.cmdline.rbsite import Site site = Site(ROOT, FakeOptions()) site.run_manage_command('syncdb', ['--noinput']) site.setup_settings() from reviewboard import initialize initialize() # we need to toggle disable/enable state to get first run code to run site.run_manage_command('disable-extension', ['mozreview.extension.MozReviewExtension']) site.run_manage_command('disable-extension', ['rbbz.extension.BugzillaExtension']) site.run_manage_command('disable-extension', ['rbmotd.extension.MotdExtension']) site.run_manage_command('enable-extension', ['mozreview.extension.MozReviewExtension']) site.run_manage_command('enable-extension',
def main(): """The entry point of the prepare-dev script.""" global console if not os.path.exists(os.path.join("reviewboard", "manage.py")): sys.stderr.write("This must be run from the top-level Review Board " "directory\n") sys.exit(1) options = parse_options(sys.argv[1:]) if options.install_deps: install_dependencies(options) # Insert the current directory first in the module path so we find the # correct reviewboard package. sys.path.insert(0, os.getcwd()) from reviewboard.cmdline import rbsite from reviewboard.cmdline.rbsite import Site, setup_rbsite from reviewboard.cmdline.utils.console import get_console setup_rbsite() console = get_console() console.allow_color = True console.header('Welcome to Review Board!', leading_newlines=False) console.print( "Let's get your development environment set up and ready to go. This " "will set up your settings_local.py file, your database, initial " "static media files, and prepare an administrator account." "\n" "If you have any issues, first see if it's answered in our FAQ:" "\n" "%(faq_url)s" "\n" "If you're a student working on Review Board, you can also get help " "from your mentors. If you're a contributor, please contact:" "\n" "*****@*****.**" % { 'faq_url': FAQ_URL, }) # Re-use the Site class, since it has some useful functions. site_path = os.path.abspath('reviewboard') site = Site(site_path, SiteOptions) create_settings(options) if options.install_hooks: install_git_hooks() try: if options.sync_db: site.abs_install_dir = os.getcwd() console.header('Setting up the Review Board database') site.setup_settings() site.update_database(allow_input=True, report_progress=True) except KeyboardInterrupt: console.error( 'The process was canceled in the middle of creating the database, ' 'which can result in a corrupted setup. Please remove the ' 'database file and run:') console.error(' ./reviewboard/manage.py createdb', wrap=False) return if options.install_media: install_media(site) create_superuser(site) console.header('Your Review Board tree is ready for development!') console.print('You can now run your development server by running:') console.print() console.print(' ./contrib/internal/devserver.py', wrap=False) console.print()