initial
This commit is contained in:
commit
82c973b2e9
100
patchodon.py
Executable file
100
patchodon.py
Executable file
|
|
@ -0,0 +1,100 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sys, os
|
||||||
|
import argparse
|
||||||
|
import requests
|
||||||
|
|
||||||
|
VERSION = "0.1.0"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
ap = argparse.ArgumentParser(
|
||||||
|
prog=sys.argv[0],
|
||||||
|
epilog="patchodon.py version " + VERSION + " is a free software.",
|
||||||
|
description="Generate metadata from a single document change.",
|
||||||
|
)
|
||||||
|
|
||||||
|
cmds = ap.add_subparsers(required=True, dest="command")
|
||||||
|
|
||||||
|
if "POST command":
|
||||||
|
post = cmds.add_parser("post")
|
||||||
|
if "API token sources":
|
||||||
|
group = post.add_mutually_exclusive_group()
|
||||||
|
group.add_argument(
|
||||||
|
"--debug-api-token",
|
||||||
|
help=(
|
||||||
|
"specify the API token (not very secure, good for debugging"
|
||||||
|
" only)"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
group.add_argument(
|
||||||
|
"-e",
|
||||||
|
"--env-api-token",
|
||||||
|
action="store_true",
|
||||||
|
help="get the API token from environment PATCHODON_API_TOKEN",
|
||||||
|
)
|
||||||
|
|
||||||
|
post.add_argument(
|
||||||
|
"-i", "--instance-url", help="mastodon instance URL to post to"
|
||||||
|
)
|
||||||
|
post.add_argument(
|
||||||
|
"-r", "--recipient", help="recipient to tag in the initial post"
|
||||||
|
)
|
||||||
|
post.add_argument(
|
||||||
|
"patchfile",
|
||||||
|
nargs="*",
|
||||||
|
help=(
|
||||||
|
"filenames of the patch series; taken from stdin if none are"
|
||||||
|
" specified (useful for piping the output of git-format-patch"
|
||||||
|
" into patchodon)"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
if "GET command":
|
||||||
|
get = cmds.add_parser("get")
|
||||||
|
get.add_argument(
|
||||||
|
"patch_url",
|
||||||
|
help=(
|
||||||
|
"root URL of the status where the patch was posted (the status"
|
||||||
|
" should contain the patch hash)"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if "output possibilities":
|
||||||
|
group = get.add_mutually_exclusive_group()
|
||||||
|
group.add_argument(
|
||||||
|
"-a",
|
||||||
|
"--am",
|
||||||
|
help=(
|
||||||
|
"apply the patches immediately with git-am instead of"
|
||||||
|
" storing them in a directory"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
group.add_argument(
|
||||||
|
"-C",
|
||||||
|
"--out-dir",
|
||||||
|
help=(
|
||||||
|
"output the patches into a given directory (by default, `.'"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
get.add_argument(
|
||||||
|
"--overwrite",
|
||||||
|
action="store_true",
|
||||||
|
help="overwrite existing patch files instead of renaming",
|
||||||
|
)
|
||||||
|
|
||||||
|
ap.add_argument(
|
||||||
|
"-c",
|
||||||
|
"--config",
|
||||||
|
help=(
|
||||||
|
"specify a custom config INI file (it can specify a section"
|
||||||
|
" [patchodon] with keys instance_url and api_token), defaults to"
|
||||||
|
" `$HOME/.patchodon.ini'; specify /dev/null to avoid reading"
|
||||||
|
" configs"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
args = ap.parse_args()
|
||||||
|
print(args)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue