本文整理汇总了Python中nikola.__main__.main函数的典型用法代码示例。如果您正苦于以下问题:Python main函数的具体用法?Python main怎么用?Python main使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了main函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_future_post
def test_future_post(self):
""" Ensure that the future post is not present in the index and sitemap."""
index_path = os.path.join(self.target_dir, "output", "index.html")
sitemap_path = os.path.join(self.target_dir, "output", "sitemap.xml")
foo_path = os.path.join(self.target_dir, "output", "posts", "foo", "index.html")
bar_path = os.path.join(self.target_dir, "output", "posts", "bar", "index.html")
self.assertTrue(os.path.isfile(index_path))
self.assertTrue(os.path.isfile(foo_path))
self.assertTrue(os.path.isfile(bar_path))
with io.open(index_path, "r", encoding="utf8") as inf:
index_data = inf.read()
with io.open(sitemap_path, "r", encoding="utf8") as inf:
sitemap_data = inf.read()
self.assertTrue('foo/' in index_data)
self.assertFalse('bar/' in index_data)
self.assertTrue('foo/' in sitemap_data)
self.assertFalse('bar/' in sitemap_data)
# Run deploy command to see if future post is deleted
with cd(self.target_dir):
__main__.main(["deploy"])
self.assertTrue(os.path.isfile(index_path))
self.assertTrue(os.path.isfile(foo_path))
self.assertFalse(os.path.isfile(bar_path))
示例2: test_check_links_fail
def test_check_links_fail(self):
with cd(self.target_dir):
os.unlink(os.path.join("output", "archive.html"))
try:
__main__.main(['check', '-l'])
except SystemExit as e:
self.assertNotEqual(e.code, 0)
示例3: test_check_files_fail
def test_check_files_fail(self):
with cd(self.target_dir):
with codecs.open(os.path.join("output", "foobar"), "wb+", "utf8") as outf:
outf.write("foo")
try:
__main__.main(['check', '-f'])
except SystemExit as e:
self.assertNotEqual(e.code, 0)
示例4: build
def build(self):
"""Build the site."""
try:
self.oldlocale = locale.getlocale()
locale.setlocale(locale.LC_ALL, ("en_US", "utf8"))
except:
pytest.skip('no en_US locale!')
else:
with cd(self.target_dir):
__main__.main(["build", "--invariant"])
finally:
try:
locale.setlocale(locale.LC_ALL, self.oldlocale)
except:
pass
示例5: _execute
def _execute(self, command, args):
self.logger = get_logger(
CommandGitHubDeploy.name, self.site.loghandlers
)
# Check if ghp-import is installed
check_ghp_import_installed()
# Build before deploying
build = main(['build'])
if build != 0:
self.logger.error('Build failed, not deploying to GitHub')
sys.exit(build)
# Clean non-target files
l = self._doitargs['cmds'].get_plugin('list')(config=self.config, **self._doitargs)
only_on_output, _ = real_scan_files(l, self.site)
for f in only_on_output:
os.unlink(f)
# Commit and push
self._commit_and_push()
return
示例6: _execute
def _execute(self, options, args):
"""Run the deployment."""
self.logger = get_logger(CommandGitHubDeploy.name, STDERR_HANDLER)
# Check if ghp-import is installed
check_ghp_import_installed()
# Build before deploying
build = main(['build'])
if build != 0:
self.logger.error('Build failed, not deploying to GitHub')
return build
# Clean non-target files
only_on_output, _ = real_scan_files(self.site)
for f in only_on_output:
os.unlink(f)
# Remove drafts and future posts if requested (Issue #2406)
undeployed_posts = clean_before_deployment(self.site)
if undeployed_posts:
self.logger.notice("Deleted {0} posts due to DEPLOY_* settings".format(len(undeployed_posts)))
# Commit and push
self._commit_and_push(options['commit_message'])
return
示例7: setUpClass
def setUpClass(self):
self.metadata_option = "ADDITIONAL_METADATA"
script_root = os.path.dirname(__file__)
test_dir = os.path.join(script_root, "data", "test_config")
nikola.main(["--conf=" + os.path.join(test_dir, "conf.py")])
self.simple_config = nikola.config
nikola.main(["--conf=" + os.path.join(test_dir, "prod.py")])
self.complex_config = nikola.config
nikola.main(["--conf=" + os.path.join(test_dir, "config.with+illegal(module)name.characters.py")])
self.complex_filename_config = nikola.config
self.check_base_equality(self.complex_filename_config)
示例8: _execute
def _execute(self, command, args):
self.logger = get_logger(
CommandGitHubDeploy.name, self.site.loghandlers
)
self._source_branch = self.site.config.get(
'GITHUB_SOURCE_BRANCH', 'master'
)
self._deploy_branch = self.site.config.get(
'GITHUB_DEPLOY_BRANCH', 'gh-pages'
)
self._remote_name = self.site.config.get(
'GITHUB_REMOTE_NAME', 'origin'
)
self._pull_before_commit = self.site.config.get(
'GITHUB_PULL_BEFORE_COMMIT', False
)
self._ensure_git_repo()
self._exit_if_output_committed()
if not self._prompt_continue():
return
build = main(['build'])
if build != 0:
self.logger.error('Build failed, not deploying to GitHub')
sys.exit(build)
only_on_output, _ = real_scan_files(self.site)
for f in only_on_output:
os.unlink(f)
self._checkout_deploy_branch()
self._copy_output()
self._commit_and_push()
return
示例9: _execute
def _execute(self, command, args):
"""Run the deployment."""
self.logger = get_logger(CommandGitHubDeploy.name, STDERR_HANDLER)
# Check if ghp-import is installed
check_ghp_import_installed()
# Build before deploying
build = main(['build'])
if build != 0:
self.logger.error('Build failed, not deploying to GitHub')
return build
# Clean non-target files
only_on_output, _ = real_scan_files(self.site)
for f in only_on_output:
os.unlink(f)
# Commit and push
self._commit_and_push()
return
示例10: _execute
def _execute(self, command, args):
self.logger = get_logger(CommandGitHubDeploy.name, self.site.loghandlers)
# Check if ghp-import is installed
check_ghp_import_installed()
# Build before deploying
build = main(["build"])
if build != 0:
self.logger.error("Build failed, not deploying to GitHub")
return build
# Clean non-target files
only_on_output, _ = real_scan_files(self.site)
for f in only_on_output:
os.unlink(f)
# Commit and push
self._commit_and_push()
return
示例11: test_check_files
def test_check_files(self):
with cd(self.target_dir):
try:
__main__.main(['check', '-f'])
except SystemExit as e:
self.assertEqual(e.code, 0)
示例12: _run_command
def _run_command(self, args=[]):
from nikola.__main__ import main
with self._captured_output() as out:
main(['plugin', '-u', PLUGIN_URL] + args)
out.seek(0)
return out.read()
示例13: _run_command
def _run_command(self, args=[]):
from nikola.__main__ import main
return main(args)
示例14: test_subdir_run
def test_subdir_run(self):
"""Check whether build works from posts/"""
with cd(os.path.join(self.target_dir, 'posts')):
result = __main__.main(['build'])
self.assertEquals(result, 0)
示例15: test_check_files
def test_check_files(self):
with cd(self.target_dir):
self.assertIsNone(__main__.main(['check', '-f']))