2019-09-07 05:08:48 +08:00
|
|
|
#!/usr/bin/env python3
|
2015-06-06 17:05:21 +08:00
|
|
|
"""
|
|
|
|
Make single page versions of the documentation for release and
|
|
|
|
conversion into man pages etc.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
2020-07-13 21:07:00 +08:00
|
|
|
import time
|
2015-06-06 17:05:21 +08:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
docpath = "docs/content"
|
|
|
|
outfile = "MANUAL.md"
|
|
|
|
|
|
|
|
# Order to add docs segments to make outfile
|
|
|
|
docs = [
|
2020-05-16 01:17:46 +08:00
|
|
|
"_index.md",
|
2015-06-06 17:05:21 +08:00
|
|
|
"install.md",
|
|
|
|
"docs.md",
|
2016-01-07 23:20:32 +08:00
|
|
|
"remote_setup.md",
|
2015-09-27 23:13:20 +08:00
|
|
|
"filtering.md",
|
2019-08-26 03:32:41 +08:00
|
|
|
"gui.md",
|
2018-03-05 19:44:16 +08:00
|
|
|
"rc.md",
|
2015-09-03 06:37:42 +08:00
|
|
|
"overview.md",
|
2019-06-20 23:18:02 +08:00
|
|
|
"flags.md",
|
2021-07-21 02:45:41 +08:00
|
|
|
"docker.md",
|
2022-03-18 19:22:23 +08:00
|
|
|
"bisync.md",
|
2017-07-09 06:31:58 +08:00
|
|
|
|
|
|
|
# Keep these alphabetical by full name
|
2019-06-27 02:39:01 +08:00
|
|
|
"fichier.md",
|
2018-02-07 02:23:47 +08:00
|
|
|
"alias.md",
|
2017-07-09 06:31:58 +08:00
|
|
|
"amazonclouddrive.md",
|
2015-06-06 17:05:21 +08:00
|
|
|
"s3.md",
|
2017-07-09 06:31:58 +08:00
|
|
|
"b2.md",
|
|
|
|
"box.md",
|
2017-11-13 01:54:25 +08:00
|
|
|
"cache.md",
|
2019-08-30 22:18:40 +08:00
|
|
|
"chunker.md",
|
2019-08-28 05:50:07 +08:00
|
|
|
"sharefile.md",
|
2017-07-09 06:31:58 +08:00
|
|
|
"crypt.md",
|
2020-12-02 08:47:07 +08:00
|
|
|
"compress.md",
|
2022-04-21 00:57:43 +08:00
|
|
|
"combine.md",
|
2015-06-06 17:05:21 +08:00
|
|
|
"dropbox.md",
|
2020-08-11 22:09:00 +08:00
|
|
|
"filefabric.md",
|
2017-07-09 06:31:58 +08:00
|
|
|
"ftp.md",
|
2015-06-06 17:05:21 +08:00
|
|
|
"googlecloudstorage.md",
|
2017-07-09 06:31:58 +08:00
|
|
|
"drive.md",
|
2019-06-18 00:50:58 +08:00
|
|
|
"googlephotos.md",
|
2021-11-01 23:42:05 +08:00
|
|
|
"hasher.md",
|
2020-09-29 01:29:44 +08:00
|
|
|
"hdfs.md",
|
2022-07-08 01:58:22 +08:00
|
|
|
"hidrive.md",
|
2017-07-09 06:31:58 +08:00
|
|
|
"http.md",
|
2022-04-12 17:38:44 +08:00
|
|
|
"internetarchive.md",
|
2018-08-08 02:51:12 +08:00
|
|
|
"jottacloud.md",
|
2019-02-22 23:50:04 +08:00
|
|
|
"koofr.md",
|
2019-09-10 04:56:16 +08:00
|
|
|
"mailru.md",
|
2017-10-15 18:45:39 +08:00
|
|
|
"mega.md",
|
2018-05-03 23:31:06 +08:00
|
|
|
"memory.md",
|
2021-10-15 06:01:46 +08:00
|
|
|
"netstorage.md",
|
2017-07-25 22:18:13 +08:00
|
|
|
"azureblob.md",
|
2017-07-09 06:31:58 +08:00
|
|
|
"onedrive.md",
|
2017-07-17 13:36:45 +08:00
|
|
|
"opendrive.md",
|
2022-10-17 14:19:23 +08:00
|
|
|
"oracleobjectstorage.md",
|
2017-06-26 07:47:54 +08:00
|
|
|
"qingstor.md",
|
2021-11-01 23:42:05 +08:00
|
|
|
"sia.md",
|
2017-07-09 06:31:58 +08:00
|
|
|
"swift.md",
|
2017-09-19 23:09:43 +08:00
|
|
|
"pcloud.md",
|
2023-04-04 23:33:48 +08:00
|
|
|
"pikpak.md",
|
2019-08-26 22:25:20 +08:00
|
|
|
"premiumizeme.md",
|
2019-08-06 20:47:52 +08:00
|
|
|
"putio.md",
|
2020-04-26 01:55:18 +08:00
|
|
|
"seafile.md",
|
2017-02-01 04:34:11 +08:00
|
|
|
"sftp.md",
|
2022-09-30 23:10:57 +08:00
|
|
|
"smb.md",
|
2022-02-05 01:58:04 +08:00
|
|
|
"storj.md",
|
2019-10-24 19:35:50 +08:00
|
|
|
"sugarsync.md",
|
2022-03-18 19:22:23 +08:00
|
|
|
"tardigrade.md", # stub only to redirect to storj.md
|
2021-04-19 23:18:18 +08:00
|
|
|
"uptobox.md",
|
2018-09-07 22:08:29 +08:00
|
|
|
"union.md",
|
2017-10-03 03:29:23 +08:00
|
|
|
"webdav.md",
|
2017-07-09 06:31:58 +08:00
|
|
|
"yandex.md",
|
2020-10-08 06:17:50 +08:00
|
|
|
"zoho.md",
|
2017-07-09 06:31:58 +08:00
|
|
|
|
2015-06-06 17:05:21 +08:00
|
|
|
"local.md",
|
|
|
|
"changelog.md",
|
|
|
|
"bugs.md",
|
2015-07-31 03:26:29 +08:00
|
|
|
"faq.md",
|
2015-06-06 17:05:21 +08:00
|
|
|
"licence.md",
|
|
|
|
"authors.md",
|
|
|
|
"contact.md",
|
|
|
|
]
|
|
|
|
|
2016-08-04 04:36:28 +08: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 17:05:21 +08:00
|
|
|
# Docs which aren't made into outfile
|
|
|
|
ignore_docs = [
|
|
|
|
"downloads.md",
|
2015-08-20 05:10:04 +08:00
|
|
|
"privacy.md",
|
2015-09-08 00:48:01 +08:00
|
|
|
"donate.md",
|
2015-06-06 17:05:21 +08: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)
|
2020-05-22 19:22:52 +08:00
|
|
|
# Interpret img shortcodes
|
|
|
|
# {{< img ... >}}
|
|
|
|
contents = re.sub(r'\{\{<\s*img\s+(.*?)>\}\}', r"<img \1>", contents)
|
2020-05-22 00:28:03 +08:00
|
|
|
# Make any img tags absolute
|
|
|
|
contents = re.sub(r'(<img.*?src=")/', r"\1https://rclone.org/", contents)
|
2015-06-06 17:05:21 +08:00
|
|
|
# Make [...](/links/) absolute
|
2020-02-28 21:45:04 +08:00
|
|
|
contents = re.sub(r'\]\((\/.*?\/(#.*)?)\)', r"](https://rclone.org\1)", contents)
|
2020-05-22 00:28:03 +08:00
|
|
|
# Add additional links on the front page
|
2020-05-22 19:22:52 +08:00
|
|
|
contents = re.sub(r'\{\{< rem MAINPAGELINK >\}\}', "- [Donate.](https://rclone.org/donate/)", contents)
|
2017-09-26 00:55:19 +08:00
|
|
|
# Interpret provider shortcode
|
|
|
|
# {{< provider name="Amazon S3" home="https://aws.amazon.com/s3/" config="/s3/" >}}
|
2020-05-22 19:22:52 +08:00
|
|
|
contents = re.sub(r'\{\{<\s*provider.*?name="(.*?)".*?>\}\}', r"- \1", contents)
|
|
|
|
# Remove remaining shortcodes
|
|
|
|
contents = re.sub(r'\{\{<.*?>\}\}', r"", contents)
|
|
|
|
contents = re.sub(r'\{\{%.*?%\}\}', r"", contents)
|
2015-06-06 17:05:21 +08: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
|
2019-09-07 05:08:48 +08:00
|
|
|
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))
|
2015-06-06 17:05:21 +08:00
|
|
|
raise ValueError("Missing files")
|
|
|
|
|
2016-08-04 04:36:28 +08: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)
|
2020-07-13 21:07:00 +08:00
|
|
|
|
2015-06-06 17:05:21 +08:00
|
|
|
def main():
|
|
|
|
check_docs(docpath)
|
2019-09-07 05:08:48 +08:00
|
|
|
command_docs = read_commands(docpath).replace("\\", "\\\\") # escape \ so we can use command_docs in re.sub
|
2020-07-13 21:07:00 +08:00
|
|
|
build_date = datetime.utcfromtimestamp(
|
|
|
|
int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
|
2015-06-06 17:05:21 +08:00
|
|
|
with open(outfile, "w") as out:
|
|
|
|
out.write("""\
|
|
|
|
%% rclone(1) User Manual
|
|
|
|
%% Nick Craig-Wood
|
|
|
|
%% %s
|
|
|
|
|
2020-07-13 21:07:00 +08:00
|
|
|
""" % build_date.strftime("%b %d, %Y"))
|
2015-06-06 17:05:21 +08:00
|
|
|
for doc in docs:
|
2016-08-04 04:36:28 +08: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)
|
2019-09-07 05:08:48 +08:00
|
|
|
print("Written '%s'" % outfile)
|
2015-06-06 17:05:21 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|