def _clean_build(plugdir): print("Cleaning " + plugdir) __setup(plugdir, ['clean', '-a']) files = [ 'build', 'dist', 'ez_setup.py', plugdir + '.egg-info' ] files = [ os.path.join(plugdir, f) for f in files ] shell('rm', '-rf', *files, silent=False) shell('find', '.', '-name', '*.pyc', '-delete')
def benchmake(jobs): makefile = """ OBJECTS = \\ \t%s benchmark: $(OBJECTS) \t"%s" -o benchmark $(OBJECTS) %%.o: %%.c \t"%s" -c $< -o $@ %%.c: \\ \t%s """ % (' \\\n\t'.join('source%d.o' % i for i in range(NUM_SOURCE_FILES)), COMPILER, COMPILER, ' \\\n\t'.join('header%d.h' % i for i in range(NUM_HEADER_FILES))) filename = os.path.join(BUILD_DIR, 'Makefile') f = open(filename, 'w') f.write(makefile) f.close() time0 = get_time() filename = os.path.join(BUILD_DIR, 'build.py') job_arg = '-j%d' % jobs fabricate.shell('make', job_arg, '-s', '-C', BUILD_DIR) elapsed_time = get_time() - time0 return elapsed_time
def _clean_build(plugdir): print("Cleaning " + plugdir) __setup(plugdir, ['clean', '-a']) files = ['build', 'dist', 'ez_setup.py', plugdir + '.egg-info'] files = [os.path.join(plugdir, f) for f in files] shell('rm', '-rf', *files, silent=False) shell('find', '.', '-name', '*.pyc', '-delete')
def release(): if main.options.release is None: print("Must specify a version to release with --release <version>") sys.exit(1) rel = main.options.release if rel in check_output(['git', 'tag', '-l'], universal_newlines=True).split('\n'): print("Version %s is already git tagged." % rel) sys.exit(1) _require_y("Release version %s ?" % rel) _set_version(rel) run(main.options.python, 'setup.py', 'sdist', '--formats=zip,gztar,bztar', 'upload') run(main.options.python, 'setup.py', 'bdist_wheel', 'upload') shell('git', 'commit', 'setup.py', '-m', 'Release %s' % rel, silent=False) shell('git', 'tag', rel, silent=False) _set_version(rel + '-dev') shell('git', 'commit', 'setup.py', '-m', 'Bump to %s-dev' % rel, silent=False) shell('git', 'push', silent=False) shell('git', 'push', '--tags', silent=False) clean_build() print("Released!")
def _sub_repo(name, url): debug(lambda: "Updating themes") if not os.path.exists(name): run("git", "clone", url, name) with chdir(name): shell("git", "pull") shell("git", "submodule", "update", "--init", "--recursive")
def _test_deps(): _deps() shell('pip', 'install', '-r', 'requirements_tests.txt', ignore_status=False)
def build(): build_dir = BUILD_DIR pelican() themes() plugins() debug(lambda: "Building index and blogs") if not os.path.isdir(build_dir): os.mkdir(build_dir) indexfilename = os.path.join(build_dir, "index.html") with open(indexfilename, "w") as indexfile: for name in os.listdir(THEMES): if name in [ ".git" ]: continue path = os.path.join(THEMES, name) if not os.path.isdir(path): continue dest_theme = os.path.join(build_dir, name) if os.path.isdir(dest_theme): continue conf_file = os.path.join(THEMES, "configure-theme-" + name + ".py") shutil.copyfile("ipsumconf.py", conf_file) with open(conf_file, "a") as conf: conf.write('SITEURL="' + SITEURL + name + '"\n') if name == 'syte': conf.write('PLUGIN_PATH="plugins"\n') conf.write('PLUGINS=["assets"]\n') os.mkdir(dest_theme) print(_pelcmd('pelican'), '-t', path, '-o', dest_theme, '-s', conf_file, 'content') shell(_pelcmd('pelican'), '-t', path, '-o', dest_theme, '-s', conf_file, 'content', ignore_status=True, shell=True) indexfile.write('<h1><a href="' + name + '">' + name + '</a>') indexfile.write(' - <a href="' + THEMELINKBASE + name + '">source</a></h1>\n') theme_screenshot = os.path.join(THEMES, name, "screenshot.png") if os.path.exists(theme_screenshot): indexfile.write('<img src="' + name + '/screenshot.png">\n') run('cp', theme_screenshot, dest_theme) indexfile.write('<hr />\n')
def clean(): autoclean() shell('find', '.', '-name', '*.pyc', '-delete') clean_env() clean_smoke() clean_jenv() clean_test() clean_build()
def clean(): """clean all artifacts""" autoclean() shell('find', '.', '-name', '*.pyc', '-delete') clean_env() clean_sphinx() clean_test() clean_build()
def clean(): """clean all artifacts""" autoclean() shell('find', '.', '-name', '*.pyc', '-delete') clean_env() clean_sphinx() clean_jenv() clean_test() clean_build()
def _test(pytest_args=()): _test_deps() pytest_args = pytest_args or shlex.split(os.environ.get('PYTEST_ARGS', '')) shell('python', '-m', 'pytest', 'tests', *pytest_args, ignore_status=False, silent=False) shell('pyflakes', 'aspen', 'tests', ignore_status=False, silent=False)
def namecoindns_update(): gitdir = namecoindns_gitdir env = os.environ env['GIT_DIR'] = gitdir + '/.git' shell('rm', '-rf', gitdir) shell('git', 'clone', 'https://github.com/khalahan/NamecoinToBind.git', gitdir) shell(('git log -n 1 > %s/LOG_HEAD' % gitdir).split(), shell=True, env=env, cwd=gitdir, silent=False) archive = os.path.join(os.getcwd(), _docker_dir('namecoin-dns'), 'NamecoinToBind.tar.gz') shell('git', 'archive', '-o', archive, 'HEAD', cwd=gitdir, silent=False)
def benchmark(runner, jobs): if runner == 'always_runner': delete_deps() para = (', parallel_ok=True, jobs=%d' % jobs) if jobs > 1 else '' build_file = r""" from fabricate import * sources = [ %s ] def build(): compile() after() link() def compile(): for source in sources: run(%s, '-c', source + '.c') def link(): objects = [s + '.o' for s in sources] run(%s, '-o', 'benchmark', objects) def clean(): autoclean() main(runner='%s'%s) """ % (',\n '.join("'source%d'" % i for i in range(NUM_SOURCE_FILES)), repr(COMPILER), repr(COMPILER), runner, para) filename = os.path.join(BUILD_DIR, 'build.py') f = open(filename, 'w') f.write(build_file) f.close() time0 = get_time() filename = os.path.join(BUILD_DIR, 'build.py') fabricate.shell('python', filename, '-q') elapsed_time = get_time() - time0 return elapsed_time
def aspen(): _env() v = shell(_virt('python'), '-c', 'import aspen; print("found")', ignore_status=True) if "found" in v: return for dep in ASPEN_DEPS: run(_virt('pip'), 'install', '--no-index', '--find-links=' + INSTALL_DIR, dep) run(_virt('python'), 'setup.py', 'develop')
def build(): build_dir = BUILD_DIR pelican() themes() plugins() debug(lambda: "Building index and blogs") if not os.path.isdir(build_dir): os.mkdir(build_dir) indexfilename = os.path.join(build_dir, "index.html") with open(indexfilename, "w") as indexfile: for name in os.listdir(THEMES): if name in [".git"]: continue path = os.path.join(THEMES, name) if not os.path.isdir(path): continue dest_theme = os.path.join(build_dir, name) if os.path.isdir(dest_theme): continue conf_file = os.path.join(THEMES, "configure-theme-" + name + ".py") shutil.copyfile("ipsumconf.py", conf_file) with open(conf_file, "a") as conf: conf.write('SITEURL="' + SITEURL + name + '"\n') if name == 'syte': conf.write('PLUGIN_PATH="plugins"\n') conf.write('PLUGINS=["assets"]\n') os.mkdir(dest_theme) print(_pelcmd('pelican'), '-t', path, '-o', dest_theme, '-s', conf_file, 'content') shell(_pelcmd('pelican'), '-t', path, '-o', dest_theme, '-s', conf_file, 'content', ignore_status=True, shell=True) indexfile.write('<h1><a href="' + name + '">' + name + '</a>') indexfile.write(' - <a href="' + THEMELINKBASE + name + '">source</a></h1>\n') theme_screenshot = os.path.join(THEMES, name, "screenshot.png") if os.path.exists(theme_screenshot): indexfile.write('<img src="' + name + '/screenshot.png">\n') run('cp', theme_screenshot, dest_theme) indexfile.write('<hr />\n')
def _deps(envdir='env'): envdir = _env(envdir) v = shell(_virt('python', envdir), '-c', 'import aspen; print("found")', ignore_status=True) if b"found" in v: return envdir for dep in ASPEN_DEPS: run(_virt('pip', envdir), 'install', '--no-index', '--find-links=' + INSTALL_DIR, dep) run(_virt('python', envdir), 'setup.py', 'develop') return envdir
def release(): if main.options.release is None: print("Must specify a version to release with --release <version>") sys.exit(1) rel = main.options.release if rel in check_output(['git', 'tag', '-l'],universal_newlines=True).split('\n'): print("Version %s is already git tagged." % rel) sys.exit(1) _require_y("Release version %s ?" % rel) _set_version(rel) run(main.options.python, 'setup.py', 'sdist', '--formats=zip,gztar,bztar', 'upload') run(main.options.python, 'setup.py', 'bdist_wheel', 'upload') shell('git', 'commit', 'setup.py', '-m', 'Release %s' % rel, silent=False) shell('git', 'tag', rel, silent=False) _set_version(rel + '-dev') shell('git', 'commit', 'setup.py', '-m', 'Bump to %s-dev' % rel, silent=False) shell('git', 'push', silent=False) shell('git', 'push', '--tags', silent=False) clean_build() print("Released!")
def env(): if not shell('python', '--version').startswith('Python 2.7'): raise SystemExit('Error: Python 2.7 required') fab_run('python', './vendor/virtualenv-1.7.1.2.py', '--unzip-setuptools', '--prompt="[gittip] "', '--never-download', '--extra-search-dir=' + p('./vendor/'), '--distribute', p('./env/')) pip_install('-r', p('./requirements.txt')) pip_install(p('./vendor/nose-1.1.2.tar.gz')) pip_install('-e', p('./'))
def getVersion(): """ Returns the version number for the plugin """ now = datetime.datetime.now() year = now.year month = now.month day = now.day try: commit = shell('git', 'log', '-1', '--pretty=%h').strip() except WindowsError: commit = "" except ExecutionError: commit = "" return "{0}.{1}.{2}.{3}".format(year, month, day, commit)
def dev(envdir='./env'): if os.path.exists(envdir): return args = [ main.options.python ] + ENV_ARGS + [ envdir ] shell(*args, silent=False) for plugin in PLUGINS: print("Running %s install -e %s..." % (_virt('pip', envdir=envdir), plugin)) if not os.path.exists(os.path.join(plugin, 'ez_setup.py')): shutil.copy('ez_setup.py', plugin) # --find-links added for Cheroot which is current not hosted in PyPI shell(_virt('pip', envdir=envdir), 'install', '-e', './'+plugin, '--find-links=./vendor', silent=False) for pkg in DEV_DEPS: shell(_virt('pip', envdir=envdir), 'install', pkg, silent=False)
def dev(envdir='./env'): if os.path.exists(envdir): return args = [main.options.python] + ENV_ARGS + [envdir] shell(*args, silent=False) for plugin in PLUGINS: print("Running %s install -e %s..." % (_virt('pip', envdir=envdir), plugin)) if not os.path.exists(os.path.join(plugin, 'ez_setup.py')): shutil.copy('ez_setup.py', plugin) # --find-links added for Cheroot which is current not hosted in PyPI shell(_virt('pip', envdir=envdir), 'install', '-e', './' + plugin, '--find-links=./vendor', silent=False) for pkg in DEV_DEPS: shell(_virt('pip', envdir=envdir), 'install', pkg, silent=False)
def docs(): aspen() run(_virt('pip'), 'install', 'aspen-tornado') run(_virt('pip'), 'install', 'pygments') shell(_virt('aspen'), '-a:5370', '-wdoc', '-pdoc/.aspen', '--changes_reload=1', silent=False)
def clean_sphinx(): """clean sphinx artifacts""" shell('rm', '-rf', 'docs/_build')
def _clean_sub_repo(name): debug(lambda: "Cleaning " + name) shell("rm", "-rf", name)
def clean_jtest(): """clean jython test results""" shell('find', '.', '-name', '*.class', '-delete') shell('rm', '-rf', 'jython-testresults.xml')
def clean_test(): """clean test artifacts""" clean_env() shell('rm', '-rf', '.coverage', 'coverage.xml', 'testresults.xml', 'htmlcov', 'pylint.out')
def test(): """run all tests""" shell(_virt('py.test', _dev_deps()), 'tests/', ignore_status=True, silent=False)
def namecoindns_run(): env = os.environ env['NAMECOIN_USERNAME'] = '******' env['NAMECOIN_PASSWORD'] = '******' env['NAMECOIN_HOSTNAME'] = 'localhost.localdomain' shell('docker', 'run', '-d', '-t', '-p', '53053:53', '-p', '53053:53/udp', 'pjz/namecoin-dns', silent=False, env=env)
def namecoindns_clean(): shell('rm', '-rf', namecoindns_gitdir)
def test(envdir='./env'): dev(envdir=envdir) shell(_virt('py.test', envdir=envdir), 'tests/', ignore_status=True, silent=False)
def base_image(): shell('docker', 'build', '-t', 'pjzz/base', '.', cwd=_docker_dir('base'), silent=False)
def clean(): autoclean() shell('rm','-rf', BUILDDIR)
def publish(): build() shell('s3cmd', 'sync', BUILDDIR + '/', S3_BUCKET)
def clean_dev(envdir='./env'): shell('rm', '-rf', './env', silent=False)
def clean_sphinx(): """clean sphinx artifacts""" shell('rm', '-rf', 'docs/_build') shell('rm', '-rf', 'denv')
def clean_dev(): shell('rm', '-rf', 'env')
def testf(): """run tests, stopping at the first failure""" shell(_virt('py.test', _dev_deps()), '-x', 'tests/', ignore_status=True, silent=False)
def clean_test(): clean_dev() shell('rm', '-f', '.coverage', 'coverage.xml', 'testresults.xml', 'pylint.out')
def clean_jenv(): """clean up the jython environment""" shell('find', '.', '-name', '*.class', '-delete') shell('rm', '-rf', 'jenv', 'vendor/jython-installer.jar', 'jython_home')
def clean_build(): shell(main.options.python, 'setup.py', 'clean', '-a') shell('rm', '-rf', 'dist')
def _virt_version(envdir): v = shell(_virt('python', envdir), '-c', 'import sys; print(sys.version_info[:2])') return eval(v)
def test(): aspen() dev() shell(_virt('py.test'), 'tests/', ignore_status=True, silent=False)
def clean_jtest(): shell('find', '.', '-name', '*.class', '-delete') shell('rm', '-rf', 'jython-testresults.xml')
def clean_smoke(): shell('rm', '-rf', smoke_dir)
def clean_build(): debug(lambda: "Cleaning index and blogs") shell("rm", "-rf", BUILD_DIR)
def _tox(*args, **kw): _env() _install_tox() kw.setdefault('silent', False) shell('tox', '--skip-missing-interpreters', '--', *args, **kw)
def docserve(): """run the aspen website""" envdir = _deps() run(_virt('pip', envdir), 'install', 'aspen-tornado') run(_virt('pip', envdir), 'install', 'pygments') shell(_virt('python', envdir), '-m', 'aspen_io', silent=False)
def clean_test(): """clean test artifacts""" shell('rm', '-rf', '.tox') shell('rm', '-rf', '.coverage', 'coverage.xml', 'testresults.xml', 'htmlcov', 'pylint.out')
def clean_env(): shell('rm', '-rf', 'env')
def _install_tox(): # install tox if it isn't there try: shell('pip', 'show', 'tox') except ExecutionError: run('pip', 'install', 'tox')
def clean_env(): """clean env artifacts""" shell('rm', '-rf', 'env')
def clean_pelican(): debug(lambda: "Cleaning pelican") shell("rm", "-rf", PEL_BASE)