def generate_setup(options): """Generates a setup.py file that uses paver behind the scenes. This setup.py file will look in the directory that the user is running it in for a paver-minilib.zip and will add that to sys.path if available. Otherwise, it will just assume that paver is available.""" if 'versioned_name' in options: minilib_name = "paver-minilib-%s.zip" % VERSION is_versioned_msg = ', referring versioned minilib: %s' % minilib_name else: is_versioned_msg = "" minilib_name = 'paver-minilib.zip' def write_setup(): setup = open("setup.py", "w") setup.write("""try: import paver.tasks except ImportError: from os.path import exists if exists("%(minilib_name)s"): import sys sys.path.insert(0, "%(minilib_name)s") import paver.tasks paver.tasks.main() """ % {'minilib_name': minilib_name}) setup.close() dry("Write setup.py%s" % is_versioned_msg, write_setup)
def _create_bootstrap(script_name, packages_to_install, paver_command_line, install_paver=True, more_text="", dest_dir='.', no_site_packages=None, system_site_packages=None, unzip_setuptools=False, distribute=None, index_url=None, find_links=None): # configure easy install template easy_install_options = [] if index_url: easy_install_options.extend(["--index-url", index_url]) if find_links: easy_install_options.extend( ["--find-links", " ".join(find_links)]) easy_install_options = ( easy_install_options and "'%s', " % "', '".join(easy_install_options) or '') confd_easy_install_tmpl = (_easy_install_tmpl % ('bin_dir', easy_install_options)) if install_paver: paver_install = (confd_easy_install_tmpl % ('paver==%s' % setup_meta['version'])) else: paver_install = "" options = "" # if deprecated 'no_site_packages' was specified and 'system_site_packages' # wasn't, set it from that value if system_site_packages is None and no_site_packages is not None: system_site_packages = not no_site_packages if system_site_packages is not None: options += (" options.system_site_packages = %s\n" % bool(system_site_packages)) if unzip_setuptools: options += " options.unzip_setuptools = True\n" if distribute is not None: options += " options.use_distribute = %s\n" % bool(distribute) options += "\n" extra_text = """def adjust_options(options, args): args[:] = ['%s'] %s def after_install(options, home_dir): if sys.platform == 'win32': bin_dir = join(home_dir, 'Scripts') else: bin_dir = join(home_dir, 'bin') %s""" % (dest_dir, options, paver_install) for package in packages_to_install: extra_text += confd_easy_install_tmpl % package if paver_command_line: command_list = list(paver_command_line.split()) extra_text += " subprocess.call([join(bin_dir, 'paver'),%s)" % repr(command_list)[1:] extra_text += more_text bootstrap_contents = venv.create_bootstrap_script(extra_text) fn = script_name debug("Bootstrap script extra text: " + extra_text) def write_script(): open(fn, "w").write(bootstrap_contents) dry("Write bootstrap script %s" % fn, write_script)
def generate_setup(): """Generates a setup.py file that uses paver behind the scenes. This setup.py file will look in the directory that the user is running it in for a paver-minilib.zip and will add that to sys.path if available. Otherwise, it will just assume that paver is available.""" from paver.easy import dry def write_setup(): setup = open("setup.py", "w") setup.write( """try: import paver.tasks except ImportError: import os if os.path.exists("paver-minilib.zip"): import sys sys.path.insert(0, "paver-minilib.zip") import paver.tasks paver.tasks.main() """ ) setup.close() dry("Write setup.py", write_setup)
def gh_pages_clean(): """Clean your documentation. Update the submodule (every changes not committed and pushed will be lost), pull any changes and remove any file in options.gh_pages.docroot. """ _adjust_options() remote_name = options.gh_pages.remote_name repo = _get_repo(os.getcwd()) module = repo.submodules.get(options.gh_pages.root, None) if module is None: info("You have not yet created the gh-pages submodule.") return module.update() try: dry('Checkout the gh-pages branch', module.git.checkout, 'gh-pages') except GitCommandError: dry('Checkout the gh-pages remote branch', module.git.checkout, '-t', '%s/gh-pages' % remote_name) else: dry('Fetch any changes on the gh-pages remote branch', module.git.pull, remote_name, 'gh-pages') for dir_entry in options.gh_pages.htmlroot.listdir(): if dir_entry.isdir(): if dir_entry.basename() != '.git': dry("Remove %s" % dir_entry, dir_entry.rmtree) else: dry('Remove %s' % dir_entry, dir_entry.unlink)
def minilib(options): """Create a Paver mini library that contains enough for a simple pavement.py to be installed using a generated setup.py. This is a good temporary measure until more people have deployed paver. The output file is 'paver-minilib.zip' in the current directory. Options: extra_files list of other paver modules to include (don't include the .py extension). By default, the following modules are included: defaults, path, release, setuputils, misctasks, options, tasks, easy """ import paver paverdir = path(paver.__file__).dirname() filelist = [ '__init__', 'defaults', 'path', 'path25', 'release', 'setuputils', "misctasks", "options", "tasks", "easy" ] filelist.extend(options.get('extra_files', [])) output_file = 'paver-minilib.zip' def generate_zip(): import zipfile destfile = zipfile.ZipFile(output_file, "w", zipfile.ZIP_DEFLATED) for filename in filelist: destfile.write(paverdir / (filename + ".py"), "paver/" + (filename + ".py")) destfile.close() dry("Generate %s" % output_file, generate_zip)
def _create_bootstrap(script_name, packages_to_install, paver_command_line, install_paver=True, more_text="", dest_dir='.', no_site_packages=None, system_site_packages=None, unzip_setuptools=False, distribute=None, index_url=None, no_index=False, find_links=None, prefer_easy_install=False): # configure package installation template install_cmd_options = [] if index_url: install_cmd_options.extend(['--index-url', index_url]) if no_index: install_cmd_options.extend(['--no-index']) if find_links: for link in find_links: install_cmd_options.extend( ['--find-links', link]) install_cmd_tmpl = (_easy_install_tmpl if prefer_easy_install else _pip_then_easy_install_tmpl) confd_install_cmd_tmpl = (install_cmd_tmpl % {'bin_dir_var': 'bin_dir', 'cmd_options': install_cmd_options}) # make copy to local scope to add paver to packages to install packages_to_install = packages_to_install[:] if install_paver: packages_to_install.insert(0, 'paver==%s' % setup_meta['version']) install_cmd = confd_install_cmd_tmpl % {'packages': packages_to_install} options = "" # if deprecated 'no_site_packages' was specified and 'system_site_packages' # wasn't, set it from that value if system_site_packages is None and no_site_packages is not None: system_site_packages = not no_site_packages if system_site_packages is not None: options += (" options.system_site_packages = %s\n" % bool(system_site_packages)) if unzip_setuptools: options += " options.unzip_setuptools = True\n" if distribute is not None: options += " options.use_distribute = %s\n" % bool(distribute) options += "\n" extra_text = """def adjust_options(options, args): args[:] = ['%s'] %s def after_install(options, home_dir): if sys.platform == 'win32': bin_dir = join(home_dir, 'Scripts') else: bin_dir = join(home_dir, 'bin') %s""" % (dest_dir, options, install_cmd) if paver_command_line: command_list = list(paver_command_line.split()) extra_text += " subprocess.call([join(bin_dir, 'paver'),%s)" % repr(command_list)[1:] extra_text += more_text bootstrap_contents = venv.create_bootstrap_script(extra_text) fn = script_name debug("Bootstrap script extra text: " + extra_text) def write_script(): open(fn, "w").write(bootstrap_contents) dry("Write bootstrap script %s" % fn, write_script)
def pdf(): """Build PDF documentation using Sphinx. This uses the following options in a "sphinx" section of the options. docroot the root under which Sphinx will be working. Default: docs builddir directory under the docroot where the resulting files are put. default: build sourcedir directory under the docroot for the source files default: (empty string) Code is based on paver.doctools.html """ if not has_sphinx: raise BuildFailure('install sphinx to build html docs') options.order('sphinx', add_rest=True) paths = paver.doctools._get_paths() pdfdir = pdfdir_path() sphinxopts = ['', '-b', 'latex', '-d', paths.doctrees, paths.srcdir, pdfdir] dry("sphinx-build %s" % (" ".join(sphinxopts),), sphinx.main, sphinxopts) sh('make', cwd=pdfdir) # copy pdf into html directory paths.htmldir.makedirs_p() find_pdf_file().copy(paths.htmldir)
def minilib(options): """Create a Paver mini library that contains enough for a simple pavement.py to be installed using a generated setup.py. This is a good temporary measure until more people have deployed paver. The output file is 'paver-minilib.zip' in the current directory. Options: extra_files list of other paver modules to include (don't include the .py extension). By default, the following modules are included: defaults, path, release, setuputils, misctasks, options, tasks, easy """ import paver paverdir = path(paver.__file__).dirname() filelist = ['__init__', 'defaults', 'path', 'path25', 'release', 'setuputils', "misctasks", "options", "tasks", "easy"] filelist.extend(options.get('extra_files', [])) output_file = 'paver-minilib.zip' def generate_zip(): import zipfile destfile = zipfile.ZipFile(output_file, "w", zipfile.ZIP_DEFLATED) for filename in filelist: destfile.write( paverdir / (filename + ".py"), "paver/" + (filename + ".py")) destfile.close() dry("Generate %s" % output_file, generate_zip)
def gh_pages_build(): """Build your documentation with sphinx.""" _adjust_options() dry('Built html doc from %s to %s' % ( options.sphinx._sourcedir, options.sphinx._htmldir), sh, 'sphinx-build -d %s -b html %s %s' % ( options.sphinx._doctrees, options.sphinx._sourcedir, options.sphinx._htmldir))
def build_symlinks(options): """Build symlinks between the app and build folders.""" # Create the symbolic links from the app folder to the build folder. for filename in options.app_files + options.app_dirs + options.zip_files: # The `symlink()` function handles discrepancies between platforms. target = path.path(options.app_folder) / filename link = path.path(options.app_build) / filename easy.dry('%-4s%-20s <- %s' % ('', target, link), lambda: symlink(target, link.abspath()))
def gh_pages_build(): """Build your documentation with sphinx.""" _adjust_options() dry( 'Built html doc from %s to %s' % (options.sphinx._sourcedir, options.sphinx._htmldir), sh, 'sphinx-build -d %s -b html %s %s' % (options.sphinx._doctrees, options.sphinx._sourcedir, options.sphinx._htmldir))
def touch(self): """ Set the access/modified times of this file to the current time. Create the file if it does not exist. """ def do_touch(): fd = os.open(self, os.O_WRONLY | os.O_CREAT, 0666) os.close(fd) os.utime(self, None) dry("touch %s" % (self), do_touch)
def pdf(): paths = _latex_paths() def build_latex(): subprocess.call(["make", "all-pdf"], cwd=paths.latexdir) dry("Build pdf doc", build_latex) PDF_DESTDIR.rmtree() PDF_DESTDIR.makedirs() pdf = paths.latexdir / "samplerate.pdf" pdf.copy(PDF_DESTDIR)
def pdf(): paths = _latex_paths() def build_latex(): subprocess.call(["make", "all-pdf"], cwd=paths.latexdir) dry("Build pdf doc", build_latex) PDF_DESTDIR.rmtree() PDF_DESTDIR.makedirs() pdf = paths.latexdir / "audiolab.pdf" pdf.copy(PDF_DESTDIR)
def minilib(options): """Create a Paver mini library that contains enough for a simple pavement.py to be installed using a generated setup.py. This is a good temporary measure until more people have deployed paver. The output file is 'paver-minilib.zip' in the current directory. Options: versioned_name if set to True, paver version will be added into minilib's filename (ie paver-minilib-1.1.0.zip) purpose is to avoid import error while using different versions of minilib with easy_install (default False) extra_files list of other paver modules to include (don't include the .py extension). By default, the following modules are included: defaults, path, release, setuputils, misctasks, options, tasks, easy """ filelist = [ "__init__", "defaults", "path", "path25", "release", "setuputils", "misctasks", "options", "tasks", "easy", ] filelist.extend(options.get("extra_files", [])) output_version = "" if "versioned_name" in options: output_version = "-%s" % VERSION output_file = "paver-minilib%s.zip" % output_version def generate_zip(): # Write the mini library to a buffer. buf = StringIO() destfile = zipfile.ZipFile(buf, "w", zipfile.ZIP_DEFLATED) for filename in filelist: destfile.writestr("paver/%s.py" % filename, pkgutil.get_data("paver", "%s.py" % filename)) destfile.close() # Write the buffer to disk. f = open(output_file, "wb") f.write(buf.getvalue()) f.close() dry("Generate %s" % output_file, generate_zip)
def build_css(options): """Compiles the css files into one.""" for css_dir in options.css_dirs: for target, components in options.css_files.iteritems(): target = options.app_folder / css_dir / target with target.open('w') as target_file: for component in components: source = options.app_folder / css_dir / component easy.dry( "cat %s >> %s" % (source, target), lambda: shutil.copyfileobj(source.open('r'), target_file))
def build_css(options): """Compiles the css files into one.""" for css_dir in options.css_dirs: for target, components in options.css_files.iteritems(): target = options.app_folder / css_dir / target with target.open('w') as target_file: for component in components: source = options.app_folder / css_dir / component easy.dry( "cat %s >> %s" % (source, target), lambda: shutil. copyfileobj(source.open('r'), target_file))
def gh_pages_create(): """Create a submodule to host your documentation.""" _adjust_options() repo = _get_repo(os.getcwd()) remote_name = options.gh_pages.remote_name gh_pages_root = str(options.gh_pages.root) dry("Create a submodule at %s and a gh-pages root branch " "to host your gh-pages..." % gh_pages_root, repo.add_gh_pages_submodule, gh_pages_path=gh_pages_root, remote_name=remote_name)
def pdf(): def build_pdf(): subprocess.check_call(["make", "all-pdf"], cwd=str(DOC_BLD_LATEX)) dry("Build pdf doc", build_pdf) PDF_DESTDIR.rmtree() PDF_DESTDIR.makedirs() user = DOC_BLD_LATEX / "scipy-user.pdf" user.copy(PDF_DESTDIR / "userguide.pdf") ref = DOC_BLD_LATEX / "scipy-ref.pdf" ref.copy(PDF_DESTDIR / "reference.pdf")
def gh_pages_create(): """Create a submodule to host your documentation.""" _adjust_options() repo = _get_repo(os.getcwd()) remote_name = options.gh_pages.remote_name gh_pages_root = str(options.gh_pages.root) dry( "Create a submodule at %s and a gh-pages root branch " "to host your gh-pages..." % gh_pages_root, repo.add_gh_pages_submodule, gh_pages_path=gh_pages_root, remote_name=remote_name)
def minilib(options): """Create a Paver mini library that contains enough for a simple pavement.py to be installed using a generated setup.py. This is a good temporary measure until more people have deployed paver. The output file is 'paver-minilib.zip' in the current directory. Options: versioned_name if set to True, paver version will be added into minilib's filename (ie paver-minilib-1.1.0.zip) purpose is to avoid import error while using different versions of minilib with easy_install (default False) extra_files list of other paver modules to include (don't include the .py extension). By default, the following modules are included: defaults, path, release, setuputils, misctasks, options, tasks, easy """ filelist = [ '__init__', '__main__', 'defaults', 'release', 'path', 'version', 'setuputils', "misctasks", "options", "tasks", "easy", 'shell', 'deps/__init__', 'deps/path2', 'deps/path3' ] filelist.extend(options.get('extra_files', [])) output_version = "" if 'versioned_name' in options: output_version = "-%s" % VERSION output_file = 'paver-minilib%s.zip' % output_version def generate_zip(): # Write the mini library to a buffer. buf = six.BytesIO() destfile = zipfile.ZipFile(buf, "w", zipfile.ZIP_DEFLATED) for filename in filelist: destfile.writestr("paver/%s.py" % filename, pkgutil.get_data('paver', "%s.py" % filename)) # allow minilib to be invoked directly by Python destfile.writestr("__main__.py", "import paver.tasks; paver.tasks.main()\n") destfile.close() # Write the buffer to disk. f = open(output_file, "wb") f.write(buf.getvalue()) f.close() dry("Generate %s" % output_file, generate_zip)
def _create_bootstrap(script_name, packages_to_install, paver_command_line, install_paver=True, more_text="", dest_dir='.', no_site_packages=False, unzip_setuptools=False): if install_paver: paver_install = (_easy_install_template % ('bin_dir', 'paver==%s' % setup_meta['version'])) else: paver_install = "" options = "" if no_site_packages: options = " options.no_site_packages = True" if unzip_setuptools: if options: options += "\n" options += " options.unzip_setuptools = True" if options: options += "\n" extra_text = """def adjust_options(options, args): args[:] = ['%s'] %s def after_install(options, home_dir): if sys.platform == 'win32': bin_dir = join(home_dir, 'Scripts') else: bin_dir = join(home_dir, 'bin') %s""" % (dest_dir, options, paver_install) for package in packages_to_install: extra_text += _easy_install_template % ('bin_dir', package) if paver_command_line: command_list = [] command_list.extend(paver_command_line.split(" ")) extra_text += " subprocess.call([join(bin_dir, 'paver'),%s)" % repr( command_list)[1:] extra_text += more_text bootstrap_contents = virtualenv.create_bootstrap_script(extra_text) fn = script_name debug("Bootstrap script extra text: " + extra_text) def write_script(): open(fn, "w").write(bootstrap_contents) dry("Write bootstrap script %s" % (fn), write_script)
def __enter__(self): super().__enter__() # Ensure that we have a directory to put logs and reports self.log_dir.makedirs_p() self.har_dir.makedirs_p() self.report_dir.makedirs_p() test_utils.clean_reports_dir() # pylint: disable=no-value-for-parameter # Set the environment so that webpack understands where to compile its resources. # This setting is expected in other environments, so we are setting it for the # bok-choy test run. os.environ['EDX_PLATFORM_SETTINGS'] = 'test_static_optimized' if not (self.fasttest or self.skip_clean or self.testsonly): test_utils.clean_test_files() msg = colorize('green', "Checking for mongo, memchache, and mysql...") print(msg) check_services() if not self.testsonly: call_task('prepare_bokchoy_run', options={ 'log_dir': self.log_dir, 'coveragerc': self.coveragerc }) else: # load data in db_fixtures load_bok_choy_data() # pylint: disable=no-value-for-parameter update_fixtures() msg = colorize('green', "Confirming servers have started...") print(msg) wait_for_test_servers() try: # Create course in order to seed forum data underneath. This is # a workaround for a race condition. The first time a course is created; # role permissions are set up for forums. dry( "Installing course fixture for forums", CourseFixture('foobar_org', '1117', 'seed_forum', 'seed_foo').install) print('Forums permissions/roles data has been seeded') except FixtureError: # this means it's already been done pass if self.serversonly: self.run_servers_continuously()
def pdf(): bdir_latex = options.doc.bdir_latex destdir_pdf = options.doc.destdir_pdf def build_pdf(): subprocess.check_call(["make", "all-pdf"], cwd=str(bdir_latex)) dry("Build pdf doc", build_pdf) if os.path.exists(destdir_pdf): shutil.rmtree(destdir_pdf) os.makedirs(destdir_pdf) ref = os.path.join(bdir_latex, "scipy-ref.pdf") shutil.copy(ref, os.path.join(destdir_pdf, "reference.pdf"))
def latex(): """Build Audiolab's documentation and install it into scikits/talkbox/docs""" paths = _latex_paths() sphinxopts = ['', '-b', 'latex', paths.srcdir, paths.latexdir] dry("sphinx-build %s" % (" ".join(sphinxopts),), sphinx.main, sphinxopts) def build_latex(): subprocess.call(["make", "all-pdf"], cwd=paths.latexdir) dry("Build pdf doc", build_latex) destdir = paver.path.path("docs") / "pdf" destdir.rmtree() destdir.makedirs() pdf = paths.latexdir / "talkbox.pdf" pdf.move(destdir)
def blog(options): """Generate the blog post version of the HTML for the current module. The default behavior generates the post for the current module using its index.html file as input. To use a different file within the module directory, use the --in-file or -b option:: paver blog -b communication.html To run against a directory other than a module, use the -s or --sourcedir option:: paver blog -s PyMOTW/articles -b text_processing.html """ options.order('blog', 'sphinx', add_rest=True) module = _get_module(options) # Create output directory out = path(options.outdir) if not out.exists(): out.mkdir() blog_file = path(options.outdir) / module + '.html' title, body = dry( 'building blog post body', gen_blog_post_from_page, input_file=path(options.builddir) / 'html' / module / options.in_file, module=module, url_base=options.url_base, ) print('title {!r}'.format(title)) post_draft(title, body) return
def gh_register(): """Create a repository at GitHub and push it your local repository.""" _adjust_options() repo = _get_repo(os.getcwd()) project_name = options.setup.name project_description = options.setup.get('description','') remote_name = options.gh_pages.remote_name master_branch = options.gh_pages.master_branch credentials = Credentials.get_credentials(repo) if not credentials: sys.exit('Your github name and token git config are not set.' 'Check http://github.com/blog/170-token-authentication' % os.getcwd()) project = dry( "Create a repository called %s at %s's GitHub account..." % ( project_name, credentials.user), repo.register, project_name, credentials, description=project_description, is_public=True, remote_name=remote_name, master_branch=master_branch) if project is not None: info('Opening your project home pages:%s', project.url.http) webbrowser.open(project.url.http)
def gh_register(): """Create a repository at GitHub and push it your local repository.""" _adjust_options() repo = _get_repo(os.getcwd()) project_name = options.setup.name project_description = options.setup.get('description', '') remote_name = options.gh_pages.remote_name master_branch = options.gh_pages.master_branch credentials = Credentials.get_credentials(repo) if not credentials: sys.exit('Your github name and token git config are not set.' 'Check http://github.com/blog/170-token-authentication' % os.getcwd()) project = dry("Create a repository called %s at %s's GitHub account..." % (project_name, credentials.user), repo.register, project_name, credentials, description=project_description, is_public=True, remote_name=remote_name, master_branch=master_branch) if project is not None: info('Opening your project home pages:%s', project.url.http) webbrowser.open(project.url.http)
def sh(command, capture=False, ignore_error=False, cwd=None): """Runs an external command. If capture is True, the output of the command will be captured and returned as a string. If the command has a non-zero return code raise a BuildFailure. You can pass ignore_error=True to allow non-zero return codes to be allowed to pass silently, silently into the night. If you pass cwd='some/path' paver will chdir to 'some/path' before exectuting the command. If the dry_run option is True, the command will not actually be run.""" if isinstance(command, (list, tuple)): command = ' '.join([_shlex_quote(c) for c in command]) def runpipe(): kwargs = {'shell': True, 'cwd': cwd} if capture: kwargs['stderr'] = subprocess.STDOUT kwargs['stdout'] = subprocess.PIPE p = subprocess.Popen(command, **kwargs) p_stdout = p.communicate()[0] if p_stdout is not None: if sys.version_info[0] == 2 and sys.version_info[1] < 7: p_stdout = p_stdout.decode(sys.getdefaultencoding()) else: p_stdout = p_stdout.decode(sys.getdefaultencoding(), 'ignore') if p.returncode and not ignore_error: if capture and p_stdout is not None: error(p_stdout) raise BuildFailure("Subprocess return code: %d" % p.returncode) if capture: return p_stdout return dry(command, runpipe)
def latex(): """Build Audiolab's documentation and install it into scikits/talkbox/docs""" paths = _latex_paths() sphinxopts = ['', '-b', 'latex', paths.srcdir, paths.latexdir] dry("sphinx-build %s" % (" ".join(sphinxopts), ), sphinx.main, sphinxopts) def build_latex(): subprocess.call(["make", "all-pdf"], cwd=paths.latexdir) dry("Build pdf doc", build_latex) destdir = paver.path.path("docs") / "pdf" destdir.rmtree() destdir.makedirs() pdf = paths.latexdir / "talkbox.pdf" pdf.move(destdir)
def __enter__(self): super(BokChoyTestSuite, self).__enter__() # Ensure that we have a directory to put logs and reports self.log_dir.makedirs_p() self.har_dir.makedirs_p() self.report_dir.makedirs_p() test_utils.clean_reports_dir() # pylint: disable=no-value-for-parameter # Set the environment so that webpack understands where to compile its resources. # This setting is expected in other environments, so we are setting it for the # bok-choy test run. os.environ['EDX_PLATFORM_SETTINGS'] = 'test_static_optimized' if not (self.fasttest or self.skip_clean or self.testsonly): test_utils.clean_test_files() msg = colorize('green', "Checking for mongo, memchache, and mysql...") print msg check_services() if not self.testsonly: call_task('prepare_bokchoy_run', options={'log_dir': self.log_dir}) else: # load data in db_fixtures load_bok_choy_data() # pylint: disable=no-value-for-parameter update_fixtures() msg = colorize('green', "Confirming servers have started...") print msg wait_for_test_servers() try: # Create course in order to seed forum data underneath. This is # a workaround for a race condition. The first time a course is created; # role permissions are set up for forums. dry( "Installing course fixture for forums", CourseFixture('foobar_org', '1117', 'seed_forum', 'seed_foo').install ) print 'Forums permissions/roles data has been seeded' except FixtureError: # this means it's already been done pass if self.serversonly: self.run_servers_continuously()
def _create_bootstrap(script_name, packages_to_install, paver_command_line, install_paver=True, more_text="", dest_dir='.', no_site_packages=False, unzip_setuptools=False): if install_paver: paver_install = (_easy_install_tmpl % ('bin_dir', 'paver==%s' % setup_meta['version'])) else: paver_install = "" options = """ options.no_site_packages = %s if hasattr(options,"system_site_packages"): options.system_site_packages = %s """%(bool(no_site_packages),not bool(no_site_packages)) if unzip_setuptools: if options: options += "\n" options += " options.unzip_setuptools = True" if options: options += "\n" extra_text = """def adjust_options(options, args): args[:] = ['%s'] %s def after_install(options, home_dir): if sys.platform == 'win32': bin_dir = join(home_dir, 'Scripts') else: bin_dir = join(home_dir, 'bin') %s""" % (dest_dir, options, paver_install) for package in packages_to_install: extra_text += _easy_install_tmpl % ('bin_dir', package) if paver_command_line: command_list = list(paver_command_line.split()) extra_text += " subprocess.call([join(bin_dir, 'paver'),%s)" % repr(command_list)[1:] extra_text += more_text bootstrap_contents = venv.create_bootstrap_script(extra_text) fn = script_name debug("Bootstrap script extra text: " + extra_text) def write_script(): open(fn, "w").write(bootstrap_contents) dry("Write bootstrap script %s" % fn, write_script)
def _runcog(options, uncog=False): """Common function for the cog and runcog tasks.""" #options.order('cog', 'sphinx', add_rest=True) c = cogapp.Cog() if uncog: c.options.bNoGenerate = True c.options.bReplace = True c.options.bDeleteCode = options["cog"].get("delete_code", False) includedir = options["cog"].get('includedir', None) if includedir: markers = options["cog"].get("include_markers") include = Includer( includedir, cog=c, include_markers=options["cog"].get("include_markers")) # load cog's namespace with our convenience functions. c.options.defines['include'] = include c.options.defines['sh'] = _cogsh(c) cli_includer = CliExample(includedir, cog=c, include_markers=markers) c.options.defines["cli_example"] = cli_includer c.options.defines.update(options["sphinx"].get("defines", {})) c.options.sBeginSpec = options["cog"].get('beginspec', r'{{{cog') c.options.sEndSpec = options["cog"].get('endspec', r'}}}') c.options.sEndOutput = options["cog"].get('endoutput', r'{{{end}}}') basedir = options["sphinx"].get('basedir', None) if basedir is None: basedir = Path(options["sphinx"].get('docroot', "docs")) / \ options["sphinx"].get('sourcedir', "") basedir = Path(basedir) pattern = options["sphinx"].get("pattern", "**/*.rst") if pattern: files = basedir.glob(pattern) else: # FIXME: This cannot happen since patter is never None files = basedir.glob("**/*") for f in files: dry("cog %s" % f, c.processOneFile, f)
def wrapper(*args, **kwds): global _silence_nested_calls msg = None if not _silence_nested_calls: msg = name + ' ' + ' '.join(args) try: _silence_nested_calls = True return dry(msg, func, *args, **kwds) finally: _silence_nested_calls = False
def minilib(options): """Create a Paver mini library that contains enough for a simple pavement.py to be installed using a generated setup.py. This is a good temporary measure until more people have deployed paver. The output file is 'paver-minilib.zip' in the current directory. Options: extra_files list of other paver modules to include (don't include the .py extension). By default, the following modules are included: defaults, path, release, setuputils, misctasks, options, tasks, easy """ filelist = [ "__init__", "defaults", "path", "path25", "release", "setuputils", "misctasks", "options", "tasks", "easy", ] filelist.extend(options.get("extra_files", [])) output_file = "paver-minilib.zip" def generate_zip(): # Write the mini library to a buffer. buf = StringIO() destfile = zipfile.ZipFile(buf, "w", zipfile.ZIP_DEFLATED) for filename in filelist: destfile.writestr("paver/" + (filename + ".py"), pkgutil.get_data("paver", filename + ".py")) destfile.close() # Write the buffer to disk. f = open(output_file, "w") f.write(buf.getvalue()) f.close() dry("Generate %s" % output_file, generate_zip)
def wrapper(*args, **kwds): global _silence_nested_calls msg = None if not _silence_nested_calls: msg = name + ' ' + ' '.join(map(repr, args)) try: _silence_nested_calls = True return dry(msg, func, *args, **kwds) finally: _silence_nested_calls = False
def generate_setup(): """Generates a setup.py file that uses paver behind the scenes. This setup.py file will look in the directory that the user is running it in for a paver-minilib.zip and will add that to sys.path if available. Otherwise, it will just assume that paver is available.""" from paver.easy import dry def write_setup(): setup = open("setup.py", "w") setup.write("""import os if os.path.exists("paver-minilib.zip"): import sys sys.path.insert(0, "paver-minilib.zip") import paver.tasks paver.tasks.main() """) setup.close() dry("Write setup.py", write_setup)
def _walkWithAction(*patterns, **kwargs): use_path = path(kwargs.get('use_path', options.paved.cwd)) action = kwargs.pop('action') assert type(action) is str assert hasattr(use_path, action) use_regex = kwargs.get('use_regex') errors = kwargs.get('errors', 'warn') walk_method = kwargs.get('walk_method', 'walkfiles') for p in patterns: info("Looking for %s" % p) if use_regex: cp = re.compile(p) p = None for f in getattr(use_path, walk_method)(pattern=p, errors=errors): if use_regex and not cp.search(str(f)): continue if f.exists(): msg = "%s %s..." % (action, f) dry(msg, getattr(f, action))
def __enter__(self): super(BokChoyTestSuite, self).__enter__() # Ensure that we have a directory to put logs and reports self.log_dir.makedirs_p() self.har_dir.makedirs_p() self.report_dir.makedirs_p() test_utils.clean_reports_dir() # pylint: disable=no-value-for-parameter if not (self.fasttest or self.skip_clean or self.testsonly): test_utils.clean_test_files() msg = colorize('green', "Checking for mongo, memchache, and mysql...") print msg check_services() if not self.testsonly: call_task('prepare_bokchoy_run', options={'log_dir': self.log_dir}) # pylint: disable=no-value-for-parameter else: # load data in db_fixtures load_bok_choy_data() # pylint: disable=no-value-for-parameter msg = colorize('green', "Confirming servers have started...") print msg wait_for_test_servers() try: # Create course in order to seed forum data underneath. This is # a workaround for a race condition. The first time a course is created; # role permissions are set up for forums. dry( "Installing course fixture for forums", CourseFixture('foobar_org', '1117', 'seed_forum', 'seed_foo').install) print 'Forums permissions/roles data has been seeded' except FixtureError: # this means it's already been done pass if self.serversonly: self.run_servers_continuously()
def gh_register(): """Create a repository at GitHub and push it your local repository.""" _adjust_options() repo = _get_repo(os.getcwd()) project_name = options.setup.name project_description = options.setup.get('description', '') remote_name = options.gh_pages.remote_name master_branch = options.gh_pages.master_branch credentials = Credentials.get_credentials(repo) project = dry("Create a repository called %s at %s's GitHub account..." % (project_name, credentials.user), repo.register, project_name, credentials, description=project_description, is_public=True, remote_name=remote_name, master_branch=master_branch) if project is not None: info('Opening your project home pages:%s', project.url.http) webbrowser.open(project.url.http)
def gh_register(): """Create a repository at GitHub and push it your local repository.""" repo = _get_repo(os.getcwd()) project_name = options.setup.name project_description = options.setup.get('description','') remote_name = options.gh_pages.remote_name master_branch = options.gh_pages.master_branch credentials = Credentials.get_credentials(repo) project = dry( "Create a repository called %s at %s's GitHub account..." % ( project_name, credentials.user), repo.register, project_name, credentials, description=project_description, is_public=True, remote_name=remote_name, master_branch=master_branch) if project is not None: info('Opening your project home pages:%s', project.url.http) webbrowser.open(project.url.http)
def gh_pages_update(): """Push your documentation it to GitHub.""" _adjust_options() remote_name = options.gh_pages.remote_name repo = _get_repo(options.gh_pages.root) dry("Add modified and untracked content to git index", repo.git.add, '.') if options.gh_pages_update.get('commit_message') is None: info("No commit message set... " "You will have to commit the last changes " "and push them to GitHub") return msg = options.gh_pages_update.commit_message dry('"Commit any changes with message "%s".' % msg, repo.git.commit, '-m', msg) dry("Push any changes on the gh-pages branch.", repo.git.push, remote_name, 'gh-pages') info('You might want to update your submodule reference:\n\t' 'git add %s\n\tgit commit -m "built html doc updated"' % options.gh_pages.root)
def rmtree(self, *args, **kw): if self.exists(): dry("rmtree %s %s %s" % (self, args, kw), shutil.rmtree, self, *args, **kw)
def _create_bootstrap(script_name, packages_to_install, paver_command_line, install_paver=True, more_text="", dest_dir='.', no_site_packages=None, system_site_packages=None, unzip_setuptools=False, distribute=None, index_url=None, trusted_host=None, no_index=False, find_links=None, prefer_easy_install=False): # configure package installation template install_cmd_options = [] if index_url: install_cmd_options.extend(['--index-url', index_url]) if trusted_host: install_cmd_options.extend(['--trusted-host', trusted_host]) if no_index: install_cmd_options.extend(['--no-index']) if find_links: for link in find_links: install_cmd_options.extend(['--find-links', link]) install_cmd_tmpl = (_easy_install_tmpl if prefer_easy_install else _pip_then_easy_install_tmpl) confd_install_cmd_tmpl = (install_cmd_tmpl % { 'bin_dir_var': 'bin_dir', 'cmd_options': install_cmd_options }) # make copy to local scope to add paver to packages to install packages_to_install = packages_to_install[:] if install_paver: packages_to_install.insert(0, 'paver==%s' % setup_meta['version']) install_cmd = confd_install_cmd_tmpl % {'packages': packages_to_install} options = "" # if deprecated 'no_site_packages' was specified and 'system_site_packages' # wasn't, set it from that value if system_site_packages is None and no_site_packages is not None: system_site_packages = not no_site_packages if system_site_packages is not None: options += (" options.system_site_packages = %s\n" % bool(system_site_packages)) if unzip_setuptools: options += " options.unzip_setuptools = True\n" if distribute is not None: options += " options.use_distribute = %s\n" % bool(distribute) options += "\n" extra_text = """def adjust_options(options, args): args[:] = ['%s'] %s def after_install(options, home_dir): if sys.platform == 'win32': bin_dir = join(home_dir, 'Scripts') else: bin_dir = join(home_dir, 'bin') %s""" % (dest_dir, options, install_cmd) if paver_command_line: command_list = list(paver_command_line.split()) extra_text += " subprocess.call([join(bin_dir, 'paver'),%s)" % repr( command_list)[1:] extra_text += more_text if has_virtualenv: bootstrap_contents = venv.create_bootstrap_script(extra_text) else: raise BuildFailure(VIRTUALENV_MISSING_ERROR) fn = script_name debug("Bootstrap script extra text: " + extra_text) def write_script(): open(fn, "w").write(bootstrap_contents) dry("Write bootstrap script %s" % fn, write_script)
def rmdir(self): if self.exists(): dry("rmdir %s" % (self), os.rmdir, self)
def removedirs(self): if self.exists(): dry("removedirs %s" % (self), os.removedirs, self)
def latex(): """Build samplerate's documentation and install it into scikits/samplerate/docs""" paths = _latex_paths() sphinxopts = ['', '-b', 'latex', paths.srcdir, paths.latexdir] dry("sphinx-build %s" % (" ".join(sphinxopts),), sphinx.main, sphinxopts)
def remove(self): if self.exists(): dry("remove %s" % (self), os.remove, self)