2018-10-21 11:52:51 +02:00
|
|
|
#!/usr/bin/env python2
|
2015-06-06 11:05:21 +02:00
|
|
|
"""
|
|
|
|
Make single page versions of the documentation for release and
|
|
|
|
conversion into man pages etc.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
docpath = "docs/content"
|
|
|
|
outfile = "MANUAL.md"
|
|
|
|
|
|
|
|
# Order to add docs segments to make outfile
|
|
|
|
docs = [
|
|
|
|
"about.md",
|
|
|
|
"install.md",
|
|
|
|
"docs.md",
|
2016-01-07 16:20:32 +01:00
|
|
|
"remote_setup.md",
|
2015-09-27 17:13:20 +02:00
|
|
|
"filtering.md",
|
2018-03-05 12:44:16 +01:00
|
|
|
"rc.md",
|
2015-09-03 00:37:42 +02:00
|
|
|
"overview.md",
|
2017-07-09 00:31:58 +02:00
|
|
|
|
|
|
|
# Keep these alphabetical by full name
|
2018-02-06 19:23:47 +01:00
|
|
|
"alias.md",
|
2017-07-09 00:31:58 +02:00
|
|
|
"amazonclouddrive.md",
|
2015-06-06 11:05:21 +02:00
|
|
|
"s3.md",
|
2017-07-09 00:31:58 +02:00
|
|
|
"b2.md",
|
|
|
|
"box.md",
|
2017-11-12 18:54:25 +01:00
|
|
|
"cache.md",
|
2017-07-09 00:31:58 +02:00
|
|
|
"crypt.md",
|
2015-06-06 11:05:21 +02:00
|
|
|
"dropbox.md",
|
2017-07-09 00:31:58 +02:00
|
|
|
"ftp.md",
|
2015-06-06 11:05:21 +02:00
|
|
|
"googlecloudstorage.md",
|
2017-07-09 00:31:58 +02:00
|
|
|
"drive.md",
|
|
|
|
"http.md",
|
2015-11-08 16:29:58 +01:00
|
|
|
"hubic.md",
|
2018-08-07 20:51:12 +02:00
|
|
|
"jottacloud.md",
|
2017-10-15 12:45:39 +02:00
|
|
|
"mega.md",
|
2017-07-25 16:18:13 +02:00
|
|
|
"azureblob.md",
|
2017-07-09 00:31:58 +02:00
|
|
|
"onedrive.md",
|
2017-07-17 07:36:45 +02:00
|
|
|
"opendrive.md",
|
2017-06-26 01:47:54 +02:00
|
|
|
"qingstor.md",
|
2017-07-09 00:31:58 +02:00
|
|
|
"swift.md",
|
2017-09-19 17:09:43 +02:00
|
|
|
"pcloud.md",
|
2017-01-31 21:34:11 +01:00
|
|
|
"sftp.md",
|
2018-09-07 16:08:29 +02:00
|
|
|
"union.md",
|
2017-10-02 21:29:23 +02:00
|
|
|
"webdav.md",
|
2017-07-09 00:31:58 +02:00
|
|
|
"yandex.md",
|
|
|
|
|
2015-06-06 11:05:21 +02:00
|
|
|
"local.md",
|
|
|
|
"changelog.md",
|
|
|
|
"bugs.md",
|
2015-07-30 21:26:29 +02:00
|
|
|
"faq.md",
|
2015-06-06 11:05:21 +02:00
|
|
|
"licence.md",
|
|
|
|
"authors.md",
|
|
|
|
"contact.md",
|
|
|
|
]
|
|
|
|
|
2016-08-03 22:36:28 +02:00
|
|
|
# Order to put the commands in - any not on here will be in sorted order
|
|
|
|
commands_order = [
|
|
|
|
"rclone_config.md",
|
|
|
|
"rclone_copy.md",
|
|
|
|
"rclone_sync.md",
|
|
|
|
"rclone_move.md",
|
|
|
|
"rclone_delete.md",
|
|
|
|
"rclone_purge.md",
|
|
|
|
"rclone_mkdir.md",
|
|
|
|
"rclone_rmdir.md",
|
|
|
|
"rclone_check.md",
|
|
|
|
"rclone_ls.md",
|
|
|
|
"rclone_lsd.md",
|
|
|
|
"rclone_lsl.md",
|
|
|
|
"rclone_md5sum.md",
|
|
|
|
"rclone_sha1sum.md",
|
|
|
|
"rclone_size.md",
|
|
|
|
"rclone_version.md",
|
|
|
|
"rclone_cleanup.md",
|
|
|
|
"rclone_dedupe.md",
|
|
|
|
]
|
|
|
|
|
2015-06-06 11:05:21 +02:00
|
|
|
# Docs which aren't made into outfile
|
|
|
|
ignore_docs = [
|
|
|
|
"downloads.md",
|
2015-08-19 23:10:04 +02:00
|
|
|
"privacy.md",
|
2015-09-07 18:48:01 +02:00
|
|
|
"donate.md",
|
2015-06-06 11:05:21 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
def read_doc(doc):
|
|
|
|
"""Read file as a string"""
|
|
|
|
path = os.path.join(docpath, doc)
|
|
|
|
with open(path) as fd:
|
|
|
|
contents = fd.read()
|
|
|
|
parts = contents.split("---\n", 2)
|
|
|
|
if len(parts) != 3:
|
|
|
|
raise ValueError("Couldn't find --- markers: found %d parts" % len(parts))
|
|
|
|
contents = parts[2].strip()+"\n\n"
|
|
|
|
# Remove icons
|
|
|
|
contents = re.sub(r'<i class="fa.*?</i>\s*', "", contents)
|
|
|
|
# Make [...](/links/) absolute
|
2017-03-29 14:38:34 +02:00
|
|
|
contents = re.sub(r'\((\/.*?\/)\)', r"(https://rclone.org\1)", contents)
|
2017-09-25 18:55:19 +02:00
|
|
|
# Interpret provider shortcode
|
|
|
|
# {{< provider name="Amazon S3" home="https://aws.amazon.com/s3/" config="/s3/" >}}
|
|
|
|
contents = re.sub(r'\{\{<\s+provider.*?name="(.*?)".*?>\}\}', r"\1", contents)
|
2015-06-06 11:05:21 +02:00
|
|
|
return contents
|
|
|
|
|
|
|
|
def check_docs(docpath):
|
|
|
|
"""Check all the docs are in docpath"""
|
|
|
|
files = set(f for f in os.listdir(docpath) if f.endswith(".md"))
|
|
|
|
files -= set(ignore_docs)
|
|
|
|
docs_set = set(docs)
|
|
|
|
if files == docs_set:
|
|
|
|
return
|
|
|
|
print "Files on disk but not in docs variable: %s" % ", ".join(files - docs_set)
|
|
|
|
print "Files in docs variable but not on disk: %s" % ", ".join(docs_set - files)
|
|
|
|
raise ValueError("Missing files")
|
|
|
|
|
2016-08-03 22:36:28 +02:00
|
|
|
def read_command(command):
|
|
|
|
doc = read_doc("commands/"+command)
|
|
|
|
doc = re.sub(r"### Options inherited from parent commands.*$", "", doc, 0, re.S)
|
|
|
|
doc = doc.strip()+"\n"
|
|
|
|
return doc
|
|
|
|
|
|
|
|
def read_commands(docpath):
|
|
|
|
"""Reads the commands an makes them into a single page"""
|
|
|
|
files = set(f for f in os.listdir(docpath + "/commands") if f.endswith(".md"))
|
|
|
|
docs = []
|
|
|
|
for command in commands_order:
|
|
|
|
docs.append(read_command(command))
|
|
|
|
files.remove(command)
|
|
|
|
for command in sorted(files):
|
|
|
|
if command != "rclone.md":
|
|
|
|
docs.append(read_command(command))
|
|
|
|
return "\n".join(docs)
|
|
|
|
|
2015-06-06 11:05:21 +02:00
|
|
|
def main():
|
|
|
|
check_docs(docpath)
|
2016-08-03 22:36:28 +02:00
|
|
|
command_docs = read_commands(docpath)
|
2015-06-06 11:05:21 +02:00
|
|
|
with open(outfile, "w") as out:
|
|
|
|
out.write("""\
|
|
|
|
%% rclone(1) User Manual
|
|
|
|
%% Nick Craig-Wood
|
|
|
|
%% %s
|
|
|
|
|
|
|
|
""" % datetime.now().strftime("%b %d, %Y"))
|
|
|
|
for doc in docs:
|
2016-08-03 22:36:28 +02:00
|
|
|
contents = read_doc(doc)
|
|
|
|
# Substitute the commands into doc.md
|
|
|
|
if doc == "docs.md":
|
|
|
|
contents = re.sub(r"The main rclone commands.*?for the full list.", command_docs, contents, 0, re.S)
|
|
|
|
out.write(contents)
|
2015-06-06 11:05:21 +02:00
|
|
|
print "Written '%s'" % outfile
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|