Created
June 22, 2016 17:41
-
-
Save gsquire/fc021f102f8d927ccaf930b2228d9a6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
A simple tool to generate rust documentation and copy it to a location to be served from. | |
Requires Python 3.5. | |
""" | |
import os | |
import os.path | |
import shlex | |
import subprocess | |
import sys | |
from distutils.dir_util import copy_tree | |
""" | |
Run the doc generator through cargo and check that it completed | |
successfully. | |
""" | |
def generate_cargo_docs(): | |
args = shlex.split('cargo doc --no-deps') | |
output = subprocess.run(args, stdout=subprocess.PIPE) | |
if output.returncode != 0: | |
print('error running cargo doc command:\n {}'.format(output.stdout), file=sys.stderr) | |
sys.exit(1) | |
print('generated documentation...') | |
""" | |
Given a destination folder, recursively copy the docs to it. | |
The destination must be an absolute path. | |
""" | |
def copy_docs(dest): | |
if not os.path.isabs(dest): | |
print('path provided is not absolute, not copying docs...', file=sys.stderr) | |
sys.exit(1) | |
# This method is preferred over shutil.copytree because it allows for the destination | |
# to already exist. | |
copy_tree('target/doc', dest) | |
print('copied docs to {}'.format(dest)) | |
def main(): | |
if len(sys.argv) < 2: | |
print('must supply destination directory to copy docs to...', file=sys.stderr) | |
sys.exit(1) | |
destination = sys.argv[1] | |
generate_cargo_docs() | |
copy_docs(destination) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment