本文整理汇总了Python中readthedocs.projects.utils.run函数的典型用法代码示例。如果您正苦于以下问题:Python run函数的具体用法?Python run怎么用?Python run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: symlink_cnames
def symlink_cnames(self, domain=None):
"""Symlink project CNAME domains
Link from HOME/$CNAME_ROOT/<cname> ->
HOME/$WEB_ROOT/<project>
Also give cname -> project link
Link from HOME/public_cname_project/<cname> ->
HOME/<project>/
"""
if domain:
domains = [domain]
else:
domains = Domain.objects.filter(project=self.project)
for domain in domains:
self._log(u"Symlinking CNAME: {0} -> {1}".format(domain.domain, self.project.slug))
# CNAME to doc root
symlink = os.path.join(self.CNAME_ROOT, domain.domain)
run('ln -nsf {0} {1}'.format(self.project_root, symlink))
# Project symlink
project_cname_symlink = os.path.join(self.PROJECT_CNAME_ROOT, domain.domain)
run('ln -nsf %s %s' % (self.project.doc_path, project_cname_symlink))
示例2: build
def build(self, **kwargs):
project = self.version.project
os.chdir(project.conf_dir(self.version.slug))
#Default to this so we can return it always.
pdf_results = (1, '', '')
if project.use_virtualenv:
latex_results = run('%s -b latex -d _build/doctrees . _build/latex' %
project.venv_bin(version=self.version.slug, bin='sphinx-build'))
else:
latex_results = run('sphinx-build -b latex '
'-d _build/doctrees . _build/latex')
if latex_results[0] == 0:
os.chdir('_build/latex')
tex_files = glob('*.tex')
if tex_files:
# Run LaTeX -> PDF conversions
pdflatex_cmds = ['pdflatex -interaction=nonstopmode %s' % tex_file
for tex_file in tex_files]
pdf_results = run(*pdflatex_cmds)
else:
pdf_results = (0, "No tex files found", "No tex files found")
if latex_results[0] != 0 or pdf_results[0] != 0:
log.warning("PDF Building failed. Moving on.")
return (latex_results, pdf_results)
示例3: symlink_translations
def symlink_translations(self):
"""Symlink project translations
Link from $WEB_ROOT/<project>/<language>/ ->
$WEB_ROOT/<translation>/<language>/
"""
translations = {}
for trans in self.get_translations():
translations[trans.language] = trans.slug
# Make sure the language directory is a directory
language_dir = os.path.join(self.project_root, self.project.language)
if os.path.islink(language_dir):
os.unlink(language_dir)
if not os.path.lexists(language_dir):
os.makedirs(language_dir)
for (language, slug) in translations.items():
self._log(u"Symlinking translation: {0}->{1}".format(language, slug))
symlink = os.path.join(self.project_root, language)
docs_dir = os.path.join(self.WEB_ROOT, slug, language)
run('ln -nsf {0} {1}'.format(docs_dir, symlink))
# Remove old symlinks
for lang in os.listdir(self.project_root):
if (lang not in translations and
lang not in ['projects', self.project.language]):
to_delete = os.path.join(self.project_root, lang)
if os.path.islink(to_delete):
os.unlink(to_delete)
else:
shutil.rmtree(to_delete)
示例4: symlink_subprojects
def symlink_subprojects(self):
"""Symlink project subprojects
Link from $WEB_ROOT/projects/<project> ->
$WEB_ROOT/<project>
"""
subprojects = set()
rels = self.get_subprojects()
if rels.count():
# Don't creat the `projects/` directory unless subprojects exist.
if not os.path.exists(self.subproject_root):
os.makedirs(self.subproject_root)
for rel in rels:
# A mapping of slugs for the subproject URL to the actual built
# documentation
from_to = OrderedDict({rel.child.slug: rel.child.slug})
subprojects.add(rel.child.slug)
if rel.alias:
from_to[rel.alias] = rel.child.slug
subprojects.add(rel.alias)
for from_slug, to_slug in from_to.items():
self._log(u"Symlinking subproject: {0} -> {1}".format(from_slug, to_slug))
symlink = os.path.join(self.subproject_root, from_slug)
docs_dir = os.path.join(self.WEB_ROOT, to_slug)
symlink_dir = os.sep.join(symlink.split(os.path.sep)[:-1])
if not os.path.lexists(symlink_dir):
os.makedirs(symlink_dir)
run("ln -nsf %s %s" % (docs_dir, symlink))
# Remove old symlinks
if os.path.exists(self.subproject_root):
for subproj in os.listdir(self.subproject_root):
if subproj not in subprojects:
os.unlink(os.path.join(self.subproject_root, subproj))
示例5: symlink_versions
def symlink_versions(self):
"""Symlink project's versions
Link from $WEB_ROOT/<project>/<language>/<version>/ ->
HOME/user_builds/<project>/rtd-builds/<version>
"""
versions = set()
version_dir = os.path.join(self.WEB_ROOT, self.project.slug, self.project.language)
# Include active public versions,
# as well as public versions that are built but not active, for archived versions
version_queryset = self.get_version_queryset()
if version_queryset.count():
if not os.path.exists(version_dir):
os.makedirs(version_dir)
for version in version_queryset:
self._log(u"Symlinking Version: %s" % version)
symlink = os.path.join(version_dir, version.slug)
docs_dir = os.path.join(settings.DOCROOT, self.project.slug, 'rtd-builds', version.slug)
run('ln -nsf {0} {1}'.format(docs_dir, symlink))
versions.add(version.slug)
# Remove old symlinks
if os.path.exists(version_dir):
for old_ver in os.listdir(version_dir):
if old_ver not in versions:
os.unlink(os.path.join(version_dir, old_ver))
示例6: move
def move(self, **kwargs):
from_globs = glob(os.path.join(self.old_artifact_path, "*.epub"))
if not os.path.exists(self.target):
os.makedirs(self.target)
if from_globs:
from_file = from_globs[0]
to_file = os.path.join(self.target, "%s.epub" % self.version.project.slug)
run('mv -f %s %s' % (from_file, to_file))
示例7: unzip_files
def unzip_files(dest_file, html_path):
if not os.path.exists(html_path):
os.makedirs(html_path)
else:
shutil.rmtree(html_path)
os.makedirs(html_path)
run('unzip -o %s -d %s' % (dest_file, html_path))
copy_to_app_servers(html_path, html_path)
示例8: clear_artifacts
def clear_artifacts(version_pk):
""" Remove artifacts from the build server. """
version_data = api.version(version_pk).get()
version = make_api_version(version_data)
run('rm -rf %s' % version.project.full_epub_path(version.slug))
run('rm -rf %s' % version.project.full_man_path(version.slug))
run('rm -rf %s' % version.project.full_build_path(version.slug))
run('rm -rf %s' % version.project.full_latex_path(version.slug))
示例9: symlink_single_version
def symlink_single_version(self):
"""Symlink project single version
Link from $WEB_ROOT/<project> ->
HOME/user_builds/<project>/rtd-builds/latest/
"""
default_version = self.project.get_default_version()
self._log("Symlinking single_version")
symlink = self.project_root
if os.path.islink(symlink):
os.unlink(symlink)
if os.path.exists(symlink):
shutil.rmtree(symlink)
# Where the actual docs live
docs_dir = os.path.join(settings.DOCROOT, self.project.slug, 'rtd-builds', default_version)
run('ln -nsf %s/ %s' % (docs_dir, symlink))
示例10: move
def move(self, **kwargs):
project = self.version.project
outputted_path = os.path.join(project.conf_dir(self.version.slug),
'_build', 'epub')
to_path = os.path.join(settings.MEDIA_ROOT,
'epub',
project.slug,
self.version.slug)
from_globs = glob(os.path.join(outputted_path, "*.epub"))
if from_globs:
from_file = from_globs[0]
to_file = os.path.join(to_path, "%s.epub" % project.slug)
if getattr(settings, "MULTIPLE_APP_SERVERS", None):
copy_file_to_app_servers(from_file, to_file)
else:
if not os.path.exists(to_path):
os.makedirs(to_path)
run('mv -f %s %s' % (from_file, to_file))
示例11: symlink_single_version
def symlink_single_version(self):
"""Symlink project single version
Link from $WEB_ROOT/<project> ->
HOME/user_builds/<project>/rtd-builds/latest/
"""
version = self.get_default_version()
# Clean up symlinks
symlink = self.project_root
if os.path.islink(symlink):
os.unlink(symlink)
if os.path.exists(symlink):
shutil.rmtree(symlink)
# Create symlink
if version is not None:
docs_dir = os.path.join(settings.DOCROOT, self.project.slug, "rtd-builds", version.slug)
run("ln -nsf %s/ %s" % (docs_dir, symlink))
示例12: build
def build(self, **kwargs):
project = self.version.project
os.chdir(project.conf_dir(self.version.slug))
if project.use_virtualenv:
build_command = '%s -b epub . _build/epub' % project.venv_bin(
version=self.version.slug, bin='sphinx-build')
else:
build_command = "sphinx-build -b epub . _build/epub"
build_results = run(build_command)
return build_results
示例13: move
def move(self, **kwargs):
#This needs to be thought about more because of all the state above.
#We could just shove the filename on the instance or something.
project = self.version.project
os.chdir(os.path.join(project.conf_dir(self.version.slug), '_build', 'latex'))
tex_files = glob('*.tex')
for tex_file in tex_files:
to_path = os.path.join(settings.MEDIA_ROOT,
'pdf',
project.slug,
self.version.slug)
to_file = os.path.join(to_path, '%s.pdf' % project.slug)
# pdflatex names its output predictably: foo.tex -> foo.pdf
pdf_filename = os.path.splitext(tex_file)[0] + '.pdf'
from_file = os.path.join(os.getcwd(), pdf_filename)
if getattr(settings, "MULTIPLE_APP_SERVERS", None):
copy_file_to_app_servers(from_file, to_file)
else:
if not os.path.exists(to_path):
os.makedirs(to_path)
run('mv -f %s %s' % (from_file, to_file))
示例14: move
def move(self, **kwargs):
project = self.version.project
if project.full_build_path(self.version.slug):
#Copy the html files.
target = project.rtd_build_path(self.version.slug)
if "_" in project.slug:
new_slug = project.slug.replace('_','-')
new_target = target.replace(project.slug, new_slug)
#Only replace 1, so user_builds doesn't get replaced >:x
targets = [target, new_target]
else:
targets = [target]
for target in targets:
if getattr(settings, "MULTIPLE_APP_SERVERS", None):
log.info("Copying docs to remote server.")
copy_to_app_servers(project.full_build_path(self.version.slug), target)
else:
if os.path.exists(target):
shutil.rmtree(target)
log.info("Copying docs on the local filesystem")
shutil.copytree(project.full_build_path(self.version.slug), target)
#Copy the zip file.
to_path = os.path.join(settings.MEDIA_ROOT,
'htmlzip',
project.slug,
self.version.slug)
to_file = os.path.join(to_path, '%s.zip' % project.slug)
from_path = project.checkout_path(self.version.slug)
from_file = os.path.join(from_path, '%s.zip' % project.slug)
if getattr(settings, "MULTIPLE_APP_SERVERS", None):
copy_file_to_app_servers(from_file, to_file)
else:
if not os.path.exists(to_path):
os.makedirs(to_path)
run('mv -f %s %s' % (from_file, to_file))
else:
log.warning("Not moving docs, because the build dir is unknown.")
示例15: build
def build(self, **kwargs):
self.clean()
project = self.version.project
os.chdir(project.conf_dir(self.version.slug))
# Default to this so we can return it always.
results = {}
latex_results = run('%s -b latex -D language=%s -d _build/doctrees . _build/latex'
% (project.venv_bin(version=self.version.slug,
bin='sphinx-build'), project.language))
if latex_results[0] == 0:
os.chdir('_build/latex')
tex_files = glob('*.tex')
if tex_files:
# Run LaTeX -> PDF conversions
pdflatex_cmds = [('pdflatex -interaction=nonstopmode %s'
% tex_file) for tex_file in tex_files]
makeindex_cmds = [('makeindex -s python.ist %s.idx'
% os.path.splitext(tex_file)[0]) for tex_file in tex_files]
pdf_results = run(*pdflatex_cmds)
ind_results = run(*makeindex_cmds)
pdf_results = run(*pdflatex_cmds)
else:
pdf_results = (0, "No tex files found", "No tex files found")
ind_results = (0, "No tex files found", "No tex files found")
results = [
latex_results[0] + ind_results[0] + pdf_results[0],
latex_results[1] + ind_results[1] + pdf_results[1],
latex_results[2] + ind_results[2] + pdf_results[2],
]
pdf_match = PDF_RE.search(results[1])
if pdf_match:
self.pdf_file_name = pdf_match.group(1).strip()
else:
results = latex_results
return results