def clean_build(options): """Clean the build folder.""" # Not checking this could cause an error when trying to remove a # non-existent file. if path(options.app_build).exists(): path(options.app_build).rmtree() path(options.app_build).makedirs()
def create_plugin(options): """create a plugin skeleton to start a new project""" # this is actually needed thanks to the skeleton using jinja2 (and six, although that's changeable) try: pkg_resources.get_distribution("sideboard") except pkg_resources.DistributionNotFound: raise BuildFailure("This command must be run from within a configured virtual environment.") plugin_name = options.create_plugin.name if getattr(options.create_plugin, 'drop', False) and (PLUGINS_DIR / path(plugin_name.replace('_', '-'))).exists(): # rmtree fails if the dir doesn't exist apparently (PLUGINS_DIR / path(plugin_name.replace('_', '-'))).rmtree() kwargs = {} for opt in ['webapp', 'sqlalchemy', 'service']: kwargs[opt] = not getattr(options.create_plugin, 'no_' + opt, False) kwargs['cli'] = getattr(options.create_plugin, 'cli', False) if kwargs['cli']: kwargs['webapp'] = False kwargs['service'] = False from data.paver import skeleton skeleton.create_plugin(PLUGINS_DIR, plugin_name, **kwargs) print('{} successfully created'.format(options.create_plugin.name))
def _runcog(options, files, uncog=False): """Common function for the cog and runcog tasks.""" from paver.cog import Cog options.order('cog', 'sphinx', add_rest=True) c = Cog() if uncog: c.options.bNoGenerate = True c.options.bReplace = True c.options.bDeleteCode = options.get("delete_code", False) includedir = options.get('includedir', None) if includedir: include = Includer(includedir, cog=c, include_markers=options.get("include_markers")) # load cog's namespace with our convenience functions. c.options.defines['include'] = include c.options.defines['sh'] = _cogsh(c) c.sBeginSpec = options.get('beginspec', '[[[cog') c.sEndSpec = options.get('endspec', ']]]') c.sEndOutput = options.get('endoutput', '[[[end]]]') basedir = options.get('basedir', None) if basedir is None: basedir = path(options.get('docroot', "docs")) / options.get('sourcedir', "") basedir = path(basedir) if not files: pattern = options.get("pattern", "*.rst") if pattern: files = basedir.walkfiles(pattern) else: files = basedir.walkfiles() for f in files: dry("cog %s" % f, c.processOneFile, f)
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 create_plugin(options): """create a plugin skeleton to start a new project""" # this is actually needed thanks to the skeleton using jinja2 (and six, although that's changeable) try: pkg_resources.get_distribution("sideboard") except pkg_resources.DistributionNotFound: raise BuildFailure( "This command must be run from within a configured virtual environment." ) plugin_name = options.create_plugin.name if getattr(options.create_plugin, 'drop', False) and ( PLUGINS_DIR / path(plugin_name.replace('_', '-'))).exists(): # rmtree fails if the dir doesn't exist apparently (PLUGINS_DIR / path(plugin_name.replace('_', '-'))).rmtree() kwargs = {} for opt in ['webapp', 'sqlalchemy', 'service']: kwargs[opt] = not getattr(options.create_plugin, 'no_' + opt, False) kwargs['cli'] = getattr(options.create_plugin, 'cli', False) if kwargs['cli']: kwargs['webapp'] = False kwargs['service'] = False from data.paver import skeleton skeleton.create_plugin(PLUGINS_DIR, plugin_name, **kwargs) print('{} successfully created'.format(options.create_plugin.name))
def migrate(options): "Copy old content into place to prepare for updating" args = getattr(options, 'args', []) options.order('update', 'sphinx', add_rest=True) module = _get_module(options) # The source module name might be different from the destination # module name, so look for an explicit argument for the source. source = module args = getattr(options, 'args', []) if args: source = args[0] dest = path('source/' + module) if dest.exists(): raise ValueError('%s already exists' % dest) for src_path in options.migrate.old_locs: the_src = path(src_path + '/' + source) if not the_src.exists(): print('did not find {}'.format(the_src)) continue the_src.copytree(dest) break (dest + '/__init__.py').remove() if source != module: # Rename any modules that have the old source module name to # use the new source module name. for srcfile in dest.glob(source + '_*.py'): newname = srcfile.name.replace(source + '_', module + '_') srcfile.rename(dest + '/' + newname) sh('git add ' + dest) sh('git commit -m "%s: initial import"' % module) common_cleanups(options) sh('git add ' + dest) sh('git commit -m "%s: common cleanups"' % module) manual_review_cleanups(options)
def remake_directories(*dirnames): """Remove the directories and recreate them. """ for d in dirnames: safe_unlink(d) path(d).mkdir() return
def django_zip(options): """Create the zip file containing Django (minus unwanted stuff).""" # Write the `django.zip` file. This requires finding all of the necessary # files and writing them to a `zipfile.ZipFile` instance. Python's # stdlib `zipfile` module is written in C, so it's fast and doesn't incur # much overhead. django_src_dir = path(options.app_folder) / "django" django_zip_filename = path(options.app_build) / "django.zip" if paver.tasks.environment.dry_run: django_zip_fp = StringIO() else: # Ensure the parent directories exist. django_zip_filename.dirname().makedirs() django_zip_fp = open(django_zip_filename, mode="w") # Write the zip file to disk; this uses the `write_zip_file()` function # defined above. The try/except/finally makes sure the `django.zip` file # handle is properly closed no matter what happens. try: write_zip_file(django_zip_fp, django_zip_files(django_src_dir)) except Exception, exc: # Close and delete the (possibly corrupted) `django.zip` file. django_zip_fp.close() django_zip_filename.remove() # Raise the error, causing Paver to exit with a non-zero exit code. raise paver.tasks.BuildFailure("Error occurred creating django.zip: %r" % (exc,))
def build_rpm(specfile, vars=None): """ Builds the RPM with given specfile basename. @param specfile: The basename of specfile (expects to be in SPECS dir). @param vars: dict of additional variables to define for the rpm build. """ cmd = "rpmbuild --define '_topdir %(topdir)s'" \ + " --define 'version %(version)s'" \ + " --define 'epoch %(epoch)d'" \ + " --define 'release %(release)s'" if vars: for (k,v) in vars.items(): cmd += " --define '%s %s'" % (k,v) cmd += " -bb %(specfile)s 2>&1" sh(cmd % {'epoch': EPOCH, 'version': VERSION, 'release': RELEASE, 'topdir': RPM_TOPDIR, 'specfile': RPM_TOPDIR / path('SPECS') / path(specfile)}, capture=False) info("***************************************************************") info("Your RPM(s) have been built.") if OUTPUT_DIR: for fn in (RPM_TOPDIR / path('RPMS')).walkfiles('*.rpm'): path(fn).copy(OUTPUT_DIR) info("Copied (binary) RPM %s to %s" % (fn, OUTPUT_DIR)) for fn in (RPM_TOPDIR / path('SRPMS')).walkfiles('*.rpm'): path(fn).copy(OUTPUT_DIR) info("Copied (source) RPM %s to %s" % (fn, OUTPUT_DIR)) else: info("Binary RPMs here: %s" % (RPM_TOPDIR / path('RPMS'))) info("Source RPMs here: %s" % (RPM_TOPDIR / path('SRPMS'))) info("***************************************************************")
def lint(): LIB_HOME = path('app/src/ui/lib') JSLINT = path('tools/jslint.js') def test(inFile): cmd = 'rhino %s %s' % (JSLINT, inFile) stdin, stdout, stderr = os.popen3(cmd) err = stderr.read() if err: sys.stderr.write(err) result = stdout.read() if "No problems found" not in result: return result files = LIB_HOME.files("gvr.*.js") errors = {}; for filepath in files: error = test(filepath) if error: sys.stdout.write('E') errors[filepath] = error else: sys.stdout.write('.') sys.stdout.flush() print print len(errors), "out of", len(files), "files have errors" if len(errors) > 0: print for fn, e in errors.items(): print "="*70 print fn print "="*70 print e sys.exit(1)
def website(): """Create local copy of website files. """ # Copy the PDF to the files to be copied to the directory to install pdf_file = path(options.pdf.builddir) / 'latex' / (PROJECT + '-' + VERSION + '.pdf') pdf_file.copy(path(options.website.builddir) / 'html') return
def django_zip(options): """Create the zip file containing Django (minus unwanted stuff).""" # Write the `django.zip` file. This requires finding all of the necessary # files and writing them to a `zipfile.ZipFile` instance. Python's # stdlib `zipfile` module is written in C, so it's fast and doesn't incur # much overhead. django_src_dir = path(options.app_folder) / 'django' django_zip_filename = path(options.app_build) / 'django.zip' if paver.tasks.environment.dry_run: django_zip_fp = StringIO() else: # Ensure the parent directories exist. django_zip_filename.dirname().makedirs() django_zip_fp = open(django_zip_filename, mode='w') # Write the zip file to disk; this uses the `write_zip_file()` function # defined above. The try/except/finally makes sure the `django.zip` file # handle is properly closed no matter what happens. try: write_zip_file(django_zip_fp, django_zip_files(django_src_dir)) except Exception, exc: # Close and delete the (possibly corrupted) `django.zip` file. django_zip_fp.close() django_zip_filename.remove() # Raise the error, causing Paver to exit with a non-zero exit code. raise paver.tasks.BuildFailure( 'Error occurred creating django.zip: %r' % (exc,))
def builddeps(): """Generate a deps.js file for use with closure.""" calcdeps = path('closure/closure/bin/calcdeps.py').abspath() cwd = path(os.curdir).abspath() os.chdir(path("app/src/ui")) cmd("python %s -p lib -o deps > deps.js" % calcdeps) os.chdir(cwd)
def clean(): '''Cleans mostly everything''' path("build").rmtree() for d in [path(".")]: for f in d.walk(pattern="*.pyc"): f.remove()
def bootstrap_venv(intended_venv, bootstrap_name=None): # bootstrap wants options available in options.virtualenv which is a Bunch if os.path.exists(intended_venv): intended_venv.rmtree() venv = getattr(options, 'virtualenv', Bunch()) with open(path(os.path.dirname(intended_venv)) / path('requirements.txt')) as reqs: # we expect this to be reversed in setup.py venv.packages_to_install = [line.strip() for line in reqs.readlines()[::-1] if line.strip()] venv.dest_dir = intended_venv if bootstrap_name: venv.script_name = '{}-bootstrap.py'.format(bootstrap_name) options.virtualenv = venv virtual.bootstrap() if sys.executable: # if we can figure out the python associated with this paver, execute the bootstrap script # and we can expect the virtual env will then exist sh('{python_path} "{script_name}"'.format(python_path=sys.executable, script_name=venv.script_name)) # we're going to assume that worked, so run setup.py develop develop_plugin(intended_venv)
def webtemplatebase(): """Import the latest version of the web page template from the source. """ dest = path(options.website.template_dest).expanduser() src = path(options.website.template_source).expanduser() if not dest.exists() or (src.mtime > dest.mtime): src.copy(dest) return
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(options.app_folder) / filename link = path(options.app_build) / filename dry("%-4s%-20s <- %s" % ("", target, link), lambda: symlink(target, link))
def build_media_files(): output_folder = path(".")/".."/"output" media_files_source = path(".")/"output" for f in media_files_source.listdir(): print f if f.isdir(): f.copytree(output_folder/f.name) else: f.copy(output_folder/f.name)
def sdist(): """Create a source distribution. """ # Copy the output file to the desktop dist_files = path('dist').glob('*.tar.gz') dest_dir = path(options.sdist.outdir).expanduser() for f in dist_files: f.move(dest_dir) return
def website(options): """Create local copy of website files. """ pdf(options) webhtml(options) # Copy the PDF to the files to be copied to the directory to install pdf_file = path(options.pdf.builddir) / 'latex' / (PROJECT + '-' + VERSION + '.pdf') pdf_file.copy(path(options.website.builddir) / 'html') return
def webtemplatebase(): """Import the latest version of the web page template from the source. """ raise RuntimeError('merge changes by hand so the nav menu links do not break!') dest = path(options.website.template_dest).expanduser() src = path(options.website.template_source).expanduser() if not dest.exists() or (src.mtime > dest.mtime): src.copy(dest) return
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(options.app_folder) / filename link = path(options.app_build) / filename dry('%-4s%-20s <- %s' % ('', target, link), lambda: symlink(target, link.abspath()))
def docs_clean(options): '''Clean docs''' for d in ["html", "doctrees"]: path("%s/%s" % (DOC_BUILD_D, d)).rmtree() try: from paver.doctools import uncog uncog() except ImportError: pass
def sdist(options): """Create a source distribution. """ # Move the output file to the desktop dist_files = path('dist').glob('*.tar.gz') dest_dir = path(options.sdistext.outdir).expanduser() for f in dist_files: dest_file = dest_dir / f.basename() dest_file.unlink() f.move(dest_dir) return
def distclean(): '''Like 'clean' but also everything else''' path("tags").remove() path("dist").rmtree() path("src/eyeD3.egg-info").rmtree() for f in path(".").walk(pattern="*.orig"): f.remove() path(".ropeproject").rmtree()
def docdist(): path("./dist").exists() or os.mkdir("./dist") cwd = os.getcwd() try: os.chdir(DOC_BUILD_D) sh("tar czvf ../../dist/%s html" % DOC_DIST) os.chdir("%s/dist" % cwd) sh("md5sum %s >> %s" % (DOC_DIST, MD5_DIST)) finally: os.chdir(cwd) pass
def compile(): """Compile the javascript using closure compiler""" calcdeps = path('closure/closure/bin/calcdeps.py').abspath() compiler = path('compiler/compiler.jar').abspath() launcher = path('app/src/ui/launcher.js').abspath() cwd = path(os.curdir).abspath() os.chdir(path("app/src/ui")) cmd("python %s -i %s -p lib -o compiled -c %s " '-f "--externs=lib/externs.js" ' # '-f "--externs=lib/externs.js --compilation_level=ADVANCED_OPTIMIZATIONS" ' "> compiled.js" % (calcdeps, launcher, compiler)) os.chdir(cwd)
def sdist(options): """Create a source distribution. """ # Move the output file to the desktop dist_files = path('dist').glob('*.tar.gz') dest_dir = path(options.sdistext.outdir).expanduser() for f in dist_files: dest_file = dest_dir / f.basename() dest_file.unlink() f.move(dest_dir) sh('growlnotify -m "package built"') return
def clean(): '''Cleans mostly everything''' path("build").rmtree() for p in path(".").glob("*.pyc"): p.remove() for d in [path("./src"), path("./examples")]: for f in d.walk(pattern="*.pyc"): f.remove() try: from paver.doctools import uncog uncog() except ImportError: pass
def getwaveapi(): """Checkout/update the waveapi.""" waveapi = path("app/src/waveapi") if os.path.exists(waveapi): cmd("svn up %s" % waveapi) else: cmd("svn co http://wave-robot-python-client.googlecode.com/svn/trunk/src/waveapi %s"%waveapi)
def rsyncwebsite(options): # Copy to the server os.environ['RSYNC_RSH'] = '/usr/bin/ssh' src_path = path(options.sphinx.builddir) / 'html' sh('(cd %s; rsync --archive --delete --verbose . %s:%s)' % (src_path, options.website.server, options.website.server_path)) return
def rsyncwebsite(options): # Copy to the server os.environ['RSYNC_RSH'] = '/usr/bin/ssh' src_path = path(options.website.builddir) / 'html' sh('(cd %s; rsync --archive --delete --verbose . %s:%s)' % (src_path, options.website.server, options.website.server_path)) return
def css(options): "Generate CSS from less" src_path = 'source/_themes/pymotw/static/' file_base = 'pymotw' outfile = path(src_path + file_base + '.css') rebuild = False if not outfile.exists() or path(src_path + file_base + '.less').mtime > outfile.mtime: rebuild = True elif path(src_path + 'vars.less').mtime > outfile.mtime: rebuild = True if rebuild: sh('lessc %(file_base)s.less > %(file_base)s.css' % { 'file_base': src_path + file_base, }) path(src_path + file_base + '.css').copy( options.sphinx.builddir + '/html/_static/pymotw.css')
def bootstrap_plugin_venv(plugin_path, plugin_name, venv_name='env'): """ make a virtualenv with the specified name at the specified location :param plugin_path: the absolute path to the plugin folder :type plugin_path: unicode :param plugin_name: the name of the plugin :type plugin_name: unicode :param plugin_name: the name of the venv folder (default: env) :type plugin_name: unicode """ assert os.path.exists(plugin_path), "{} doesn't exist".format(plugin_path) intended_venv = path(plugin_path) / path(venv_name) bootstrap_venv(intended_venv, plugin_name)
def make_sideboard_venv(): """ make a virtualenv for the sideboard project """ bootstrap_venv(__here__ / path('env'), 'sideboard') develop_sideboard()
def docs(): """Generate all the documentation""" jsdocpath = path('tools') / 'jsdoc_toolkit-2.1.0' / 'jsdoc-toolkit' jsrunpath = jsdocpath / 'jsrun.jar' runpath = jsdocpath / 'app' / 'run.js' templatepath = path("doc-template") libpath = path("app") / "src" / "ui" / "lib" docspath = path("app") / "src" / "ui" / "docs" def builddoc(path): print "building docs for:%s" % path cmd("java -jar %s %s -p -a -d=docs -t=%s %s" % ( jsrunpath, runpath, templatepath, path), silent=False) paths = ' '.join([f for f in libpath.files("gvr*.js") if "test" not in f]) cmd("java -jar %s %s -p -a -d=%s -t=%s %s" % ( jsrunpath, runpath, docspath, templatepath, paths))
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 """ # Clean and recreate output directory remake_directories(options.blog.outdir) # Generate html from sphinx if paverutils is None: raise RuntimeError( 'Could not find sphinxcontrib.paverutils, will not be able to build HTML output.' ) paverutils.run_sphinx(options, 'blog') blog_file = path(options.blog.outdir) / options.blog.out_file dry( "Write blog post body to %s" % blog_file, gen_blog_post, outdir=options.blog.outdir, input_base=options.blog.in_file, blog_base=options.blog.out_file, url_base=options.blog.sourcedir, ) title = get_post_title(path(options.blog.outdir) / options.blog.in_file) if not options.no_edit: if os.path.exists('bin/SendToMarsEdit.applescript'): sh('osascript bin/SendToMarsEdit.applescript "%s" "%s"' % (blog_file, "PyMOTW: %s" % title)) elif 'EDITOR' in os.environ: sh('$EDITOR %s' % blog_file) return
def pdf(): """Generate the PDF book. """ set_templates(options.pdf.templates) run_sphinx('pdf') latex_dir = path(options.pdf.builddir) / 'latex' sh('cd %s; make' % latex_dir) return
def test(options): format = options.test.format if 'format' in options.test else 'silent' opts = ['--with-doctest'] if format == 'verbose': opts.append('--verbose') if format == 'xunit': opts.append('--with-xunit') files = path('python/mkakeibo').walk('*.py') sh('nosetests %s %s'%(' '.join(opts), ' '.join(files)))
def test_dist(): '''Makes dist packages, unpacks, and tests them.''' pkg_d = FULL_NAME with pushd("./dist") as cwd: for ext, cmd in [(".tar.gz", "tar xzf"), (".tar.bz2", "tar xjf"), (".zip", "unzip")]: if path(pkg_d).exists(): path(pkg_d).rmtree() sh("{cmd} {pkg}{ext}".format(cmd=cmd, pkg=FULL_NAME, ext=ext)) with pushd(pkg_d): # Copy tests into src pkg sh("cp -r ../../src/test ./src") sh("python setup.py nosetests") path(pkg_d).rmtree()
def tinymce_zip(options): """Create the zip file containing TinyMCE.""" tinymce_dir = path(options.app_folder) / "tiny_mce" tinymce_zip_filename = path(options.app_folder) / "tiny_mce.zip" if paver.tasks.environment.dry_run: tinymce_zip_fp = StringIO() else: # Ensure the parent directories exist. tinymce_zip_filename.dirname().makedirs() tinymce_zip_fp = open(tinymce_zip_filename, mode="w") try: write_zip_file(tinymce_zip_fp, tinymce_zip_files(tinymce_dir)) except Exception, exc: tinymce_zip_fp.close() tinymce_zip_filename.remove() raise paver.tasks.BuildFailure("Error occurred creating tinymce.zip: %r" % (exc,))
def install_pip_requirements_in_dir(dir_of_requirements_txt): path_to_pip = __here__ / path('env/bin/pip') print("---- installing dependencies in {} ----".format( dir_of_requirements_txt)) sh('{pip} install -e {dir_of_requirements_txt}'.format( pip=path_to_pip, dir_of_requirements_txt=dir_of_requirements_txt))
def copy_rpm_sources(): """ Copy the tgz, any additional sources, and SPEC file into RPM tree. """ # Copy the tgz file that we built. We are assuming a standard name here. (path(DIST_DIR) / path('%s.tar.gz' % PKG_NAME_FULL)).copy((RPM_TOPDIR / path('SOURCES'))) # Any other files in the rpm dir we'll put in there too. for fn in RPM_RESOURCES_DIR.walkfiles('*'): if not fn.endswith('.spec'): # Don't also copy the SPEC file into sources path(fn).copy((RPM_TOPDIR / path('SOURCES'))) # Finally, copy the SPEC out into the SPECS dir (path(SPEC_FILE)).copy((RPM_TOPDIR / path('SPECS')))
def distclean(): '''Like 'clean' but also everything else''' path("tags").remove() path("dist").rmtree() path("src/eyeD3.egg-info").rmtree() for f in path(".").walk(pattern="*.orig"): f.remove()
def test_dist(): '''Makes a dist package, unpacks it, and tests it.''' cwd = os.getcwd() pkg_d = os.path.splitext(SRC_DIST_TGZ)[0] try: os.chdir("./dist") sh("tar xzf %s" % SRC_DIST_TGZ) os.chdir(pkg_d) # Copy tests into src pkg sh("cp -r ../../src/test ./src") sh("python setup.py build") sh("python setup.py test") os.chdir("..") path(pkg_d).rmtree() finally: os.chdir(cwd)
def test(options): # Copy to the local site src_path = path(options.sphinx.builddir) / 'html' os.chdir(src_path) server_address = ('', 8080) httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler) httpd.serve_forever() return
def run_script( input_file, script_name, interpreter='python', include_prefix=True, ignore_error=False, trailing_newlines=True, ): """Run a script in the context of the input_file's directory, return the text output formatted to be included as an rst literal text block. Arguments: input_file The name of the file being processed by cog. Usually passed as cog.inFile. script_name The name of the Python script living in the same directory as input_file to be run. If not using an interpreter, this can be a complete command line. If using an alternate interpreter, it can be some other type of file. include_prefix=True Boolean controlling whether the :: prefix is included. ignore_error=False Boolean controlling whether errors are ignored. If not ignored, the error is printed to stdout and then the command is run *again* with errors ignored so that the output ends up in the cogged file. trailing_newlines=True Boolean controlling whether the trailing newlines are added to the output. If False, the output is passed to rstrip() then one newline is added. If True, newlines are added to the output until it ends in 2. """ # rundir = path(input_file).dirname() # if interpreter: # cmd = '%(interpreter)s %(script_name)s' % vars() # else: # cmd = script_name # real_cmd = 'cd %(rundir)s; %(cmd)s 2>&1' % vars() rundir = path(input_file).dirname() full_script_name = rundir / script_name if interpreter: cmd = '%(interpreter)s %(full_script_name)s' % vars() else: cmd = full_script_name real_cmd = cmd try: output_text = sh(real_cmd, capture=True, ignore_error=ignore_error) except Exception, err: print '*' * 50 print 'ERROR run_script(%s) => %s' % (real_cmd, err) print '*' * 50 output_text = sh(real_cmd, capture=True, ignore_error=True) print output_text print '*' * 50
def remake_directories(*dirnames): """Remove the directories and recreate them. """ for d in dirnames: d = path(d) if d.exists(): d.rmtree() d.mkdir() return
def tinymce_zip(options): """Create the zip file containing TinyMCE.""" tinymce_dir = path(options.app_folder) / 'tiny_mce' tinymce_zip_filename = path(options.app_folder) / 'tiny_mce.zip' if paver.tasks.environment.dry_run: tinymce_zip_fp = StringIO() else: # Ensure the parent directories exist. tinymce_zip_filename.dirname().makedirs() tinymce_zip_fp = open(tinymce_zip_filename, mode='w') try: write_zip_file(tinymce_zip_fp, tinymce_zip_files(tinymce_dir)) except Exception, exc: tinymce_zip_fp.close() tinymce_zip_filename.remove() raise paver.tasks.BuildFailure( 'Error occurred creating tinymce.zip: %r' % (exc, ))
def manual_review_cleanups(options): module = _get_module(options) if not path('source/{}'.format(module)).glob('*.py'): print('*** skipping changes to *.py, no python modules found') return sh("sed -i '' -e 's|print \(.*\)|print(\\1)|g' source/%s/*.py" % module) sh("sed -i '' -e 's|print$|print()|g' source/%s/*.py" % module) sh("sed -i '' -e 's|(object):|:|g' source/%s/*.py" % module) sh("sed -i '' -e 's/^ *$//g' source/%s/*.py" % module)
def review_task(options): """Create a bitbucket issue for reviewing a module. """ module = _get_module(options) if not module: raise RuntimeError('could not determine which module to use') cfg_filename = path('~/.bitbucketrc').expanduser() cfg = configparser.ConfigParser() if not cfg.read(cfg_filename): raise RuntimeError( 'Did not find configuration file {}'.format(cfg_filename)) auth = pybb_auth.OAuth1Authenticator( client_key=cfg['bitbucket']['client_key'], client_secret=cfg['bitbucket']['client_secret'], client_email=cfg['bitbucket']['email'], ) client = pybb_bb.Client(auth) repo = pybb_repo.Repository.find_repository_by_name_and_owner( repository_name='pymotw-3', owner='dhellmann', client=client, ) # The client library doesn't have issue support yet, so we have to # do it by hand. url_template = repo.v1.get_link_template('issues') url = uritemplate.expand( url_template, { 'bitbucket_url': client.get_bitbucket_url(), 'owner': 'dhellmann', 'repository_name': 'pymotw-3', }, ) args = { 'title': 'technical review for {}'.format(module), 'content': 'Perform the technical review for {}'.format(module), 'kind': 'task', 'priority': 'minor', } encoded = urllib.parse.urlencode(args) response = repo.v1.post( url=url, client=client, data=encoded, ) pprint.pprint(response) print() task_url = 'https://bitbucket.org/dhellmann/pymotw-3/issues/{}'.format( response['local_id']) print(task_url)
def safe_unlink(pathname): "Remove a file, but only if it exists." print('safe_unlink({})'.format(pathname)) p = path(pathname) if not p.exists(): return if p.isdir(): p.rmtree() else: p.unlink()
def _elide_path_prefix(infile, line): """Replace any absolute path references to my working dir with ... """ rundir = os.path.abspath(path(infile).dirname()) line = line.replace(rundir, '...') if 'VIRTUAL_ENV' in os.environ: line = line.replace(os.environ['VIRTUAL_ENV'], '...') line = line.replace('/Library/Frameworks/Python.framework/Versions/3.5', '...') return line