本文整理汇总了Python中libgiza.app.BuildApp.new方法的典型用法代码示例。如果您正苦于以下问题:Python BuildApp.new方法的具体用法?Python BuildApp.new怎么用?Python BuildApp.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libgiza.app.BuildApp
的用法示例。
在下文中一共展示了BuildApp.new方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: api
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def api(args):
c = fetch_config(args)
with BuildApp.new(pool_type=c.runstate.runner,
pool_size=c.runstate.pool_size,
force=c.runstate.force).context() as app:
app.extend_queue(apiarg_tasks(c))
示例2: build_translation_model
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def build_translation_model(args):
conf = fetch_config(args)
if args.t_translate_config is None:
tconf = conf.system.files.data.translate
elif os.path.isfile(args.t_translate_config):
tconf = TranslateConfig(args.t_translate_config, conf)
else:
logger.error(args.t_translate_config + " doesn't exist")
return
if os.path.exists(tconf.paths.project) is False:
os.makedirs(tconf.paths.project)
elif os.path.isfile(tconf.paths.project):
logger.error(tconf.paths.project + " is a file")
sys.exit(1)
elif os.listdir(tconf.paths.project) != []:
logger.error(tconf.paths.project + " must be empty")
sys.exit(1)
with open(os.path.join(tconf.paths.project, "translate.yaml"), 'w') as f:
yaml.dump(tconf.dict(), f, default_flow_style=False)
tconf.conf.runstate.pool_size = tconf.settings.pool_size
run_args = get_run_args(tconf)
app = BuildApp.new(pool_type=conf.runstate.runner,
pool_size=conf.runstate.pool_size,
force=conf.runstate.force)
os.environ['IRSTLM'] = tconf.paths.irstlm
setup_train(tconf)
setup_tune(tconf)
setup_test(tconf)
for idx, parameter_set in enumerate(run_args):
parameter_set = list(parameter_set)
parameter_set.append(idx)
parameter_set.append(tconf)
t = app.add()
t.job = build_model
t.args = parameter_set
t.description = "model_" + str(parameter_set[9])
app.run()
aggregate_model_data(tconf.paths.project)
from_addr = "[email protected]"
to_addr = [tconf.settings.email]
with open(tconf.paths.project + "/data.csv") as data:
msg = MIMEText(data.read())
msg['Subject'] = "Model Complete"
msg['From'] = from_addr
msg['To'] = ", ".join(to_addr)
server = smtplib.SMTP("localhost")
server.sendmail(from_addr, to_addr, msg.as_string())
server.quit()
示例3: source
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def source(args):
args.builder = 'html'
conf = fetch_config(args)
with BuildApp.new(pool_type=conf.runstate.runner,
pool_size=conf.runstate.pool_size,
force=conf.runstate.force).context() as app:
sphinx_content_preperation(app, conf)
示例4: robots
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def robots(args):
c = fetch_config(args)
with BuildApp.new(pool_type=c.runstate.runner,
pool_size=c.runstate.pool_size,
force=c.runstate.force).context() as app:
app.pool = 'serial'
app.extend_queue(robots_txt_tasks(c))
示例5: main
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def main(args):
"""
Removes build artifacts from ``build/`` directory.
"""
c = fetch_config(args)
app = BuildApp.new(pool_type=c.runstate.runner,
pool_size=c.runstate.pool_size,
force=c.runstate.force)
to_remove = set()
if c.runstate.git_branch is not None:
to_remove.add(os.path.join(c.paths.projectroot, c.paths.branch_output))
if c.runstate.builder != []:
for edition, language, builder in get_builder_jobs(c):
builder_path = resolve_builder_path(builder, edition, language, c)
builder_path = os.path.join(c.paths.projectroot, c.paths.branch_output, builder_path)
to_remove.add(builder_path)
dirpath, base = os.path.split(builder_path)
to_remove.add(os.path.join(dirpath, 'doctrees-' + base))
m = 'remove artifacts associated with the {0} builder in {1} ({2}, {3})'
logger.debug(m.format(builder, c.git.branches.current, edition, language))
if c.runstate.days_to_save is not None:
published_branches = ['docs-tools', 'archive', 'public', 'primer', c.git.branches.current]
published_branches.extend(c.git.branches.published)
for build in os.listdir(os.path.join(c.paths.projectroot, c.paths.output)):
build = os.path.join(c.paths.projectroot, c.paths.output, build)
branch = os.path.split(build)[1]
if branch in published_branches:
continue
elif not os.path.isdir(build):
continue
elif os.stat(build).st_mtime > c.runstate.days_to_save:
to_remove.add(build)
to_remove.add(os.path.join(c.paths.projectroot, c.paths.output, 'public', branch))
logger.debug('removed stale artifacts: "{0}" and "build/public/{0}"'.format(branch))
for fn in to_remove:
if os.path.isdir(fn):
job = shutil.rmtree
else:
job = os.remove
t = app.add('task')
t.job = job
t.args = fn
m = 'removing artifact: {0}'.format(fn)
t.description = m
logger.critical(m)
app.run()
示例6: steps
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def steps(args):
c = fetch_config(args)
with BuildApp.new(pool_type=c.runstate.runner,
pool_size=c.runstate.pool_size,
force=c.runstate.force).context() as app:
if c.runstate.clean_generated is True:
app.extend_queue(step_clean(c))
else:
app.extend_queue(step_tasks(c))
示例7: redirects
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def redirects(args):
c = fetch_config(args)
if args.dry_run is True:
print(''.join(make_redirect(c)))
else:
with BuildApp.new(pool_type=c.runstate.runner,
pool_size=c.runstate.pool_size,
force=c.runstate.force).context() as app:
app.extend_queue(redirect_tasks(c))
示例8: extract
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def extract(args):
conf = fetch_config(args)
with BuildApp.new(pool_type=conf.runstate.runner,
pool_size=conf.runstate.pool_size,
force=conf.runstate.force).context() as app:
path = fetch_package(conf.runstate._path, conf)
extract_package_at_root(path, conf)
builders = get_existing_builders(conf)
app.extend_queue(fix_build_env_tasks(builders, conf))
示例9: images
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def images(args):
c = fetch_config(args)
with BuildApp.new(pool_type=c.runstate.runner,
pool_size=c.runstate.pool_size,
force=c.runstate.force).context() as app:
if c.runstate.clean_generated is True:
app.extend_queue(image_clean(c))
else:
for (_, (bconf, sconf)) in get_restricted_builder_jobs(c):
app.extend_queue(image_tasks(bconf, sconf))
示例10: create_branch
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def create_branch(args):
"""
Takes a single branch name and (if necessary) creates a new branch. Then,
populates the ``build/<branch>`` directory for the new branch using either
the parent branch or ``master``. Safe to run multiple times (after a rebase)
to update the build cache from master.
Also calls :method:`~giza.operations.build_env.fix_build_environment()` to
tweak the new build output to update hashes and on-disk copies of the
environment to prevent unnecessary full-rebuilds from sphinx.
"""
conf = fetch_config(args)
g = GitRepo(conf.paths.projectroot)
branch = conf.runstate.git_branch
base_branch = g.current_branch()
if base_branch == branch:
base_branch = 'master'
logger.warning('seeding build data for branch "{0}" from "master"'.format(branch))
branch_builddir = os.path.join(conf.paths.projectroot,
conf.paths.output, branch)
base_builddir = os.path.join(conf.paths.projectroot,
conf.paths.output, base_branch)
if g.branch_exists(branch):
logger.info('checking out branch "{0}"'.format(branch))
else:
logger.info('creating and checking out a branch named "{0}"'.format(branch))
g.checkout_branch(branch)
cmd = "rsync -r --times --checksum {0}/ {1}".format(base_builddir, branch_builddir)
logger.info('seeding build directory for "{0}" from "{1}"'.format(branch, base_branch))
try:
subprocess.check_call(args=cmd.split())
logger.info('branch creation complete.')
except subprocess.CalledProcessError:
logger.error(cmd)
# get a new config here for the new branch
conf = fetch_config(args)
builders = get_existing_builders(conf)
with BuildApp.new(pool_type='process',
pool_size=conf.runstate.pool_size,
force=conf.runstate.force).context() as app:
app.exted_queue(fix_build_env_tasks(builders, conf))
示例11: sphinx
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def sphinx(args):
if args.runner == 'serial':
args.serial_sphinx = True
conf = fetch_config(args)
logger.warning('not for production use: this expects that content generation is complete.')
app = BuildApp.new(pool_type=conf.runstate.runner,
pool_size=conf.runstate.pool_size,
force=conf.runstate.force)
r = sphinx_builder_tasks(app, conf)
raise SystemExit(r)
示例12: main
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def main(args):
"""
Uploads all build artifacts to the production environment. Does not build or
render artifacts.
"""
c = fetch_config(args)
app = BuildApp.new(pool_type=c.runstate.runner,
pool_size=c.runstate.pool_size,
force=c.runstate.force)
deploy_tasks(c, app)
if c.runstate.dry_run is False:
app.run()
示例13: main
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def main(args):
"""
Use Sphinx to generate build artifacts. Can generate artifacts for multiple
output types, content editions and translations.
"""
conf = fetch_config(args)
app = BuildApp.new(pool_type=conf.runstate.runner,
pool_size=conf.runstate.pool_size,
force=conf.runstate.force)
with Timer("full sphinx build process"):
# In general we try to avoid passing the "app" object between functions
# and mutating it at too many places in the stack (although in earlier
# versions this was the primary idiom). This call is a noted exception,
# and makes it possible to run portions of this process in separate
# targets.
sphinx_publication(conf, app)
示例14: publish_and_deploy
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def publish_and_deploy(args):
"""
Combines the work of ``giza sphinx`` and ``giza deploy``, to produce build
artifacts and then upload those artifacts to the servers.
"""
c = fetch_config(args)
app = BuildApp.new(pool_type=c.runstate.runner,
pool_size=c.runstate.pool_size,
force=c.runstate.force)
sphinx_ret = sphinx_publication(c, app)
if sphinx_ret == 0 or c.runstate.force is True:
deploy_tasks(c, app)
if c.runstate.dry_run is False:
app.run()
else:
logger.warning(sphinx_ret + ' sphinx build(s) failed, and build not forced. not deploying.')
示例15: test_build_site
# 需要导入模块: from libgiza.app import BuildApp [as 别名]
# 或者: from libgiza.app.BuildApp import new [as 别名]
def test_build_site(args):
args.languages_to_build = args.editions_to_build = []
args.builder = 'html'
conf = fetch_config(args)
safe_create_directory('build')
with BuildApp.new(pool_type=conf.runstate.runner,
pool_size=conf.runstate.pool_size,
force=conf.runstate.force).context() as app:
try:
sphinx_publication(conf, args, app)
except:
sphinx_publication(conf, args, app)
if os.path.exists('doc-tools'):
shutil.rmtree('docs-tools')
logger.info('bootstrapped makefile system')
logger.info('updated project skeleton in current directory.')