markdown-to-confluence 0.1.11__py3-none-any.whl → 0.1.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
md2conf/__main__.py CHANGED
@@ -1,129 +1,139 @@
1
- import argparse
2
- import logging
3
- import os.path
4
- import sys
5
- import typing
6
- from typing import Optional
7
-
8
- import requests
9
-
10
- from .api import ConfluenceAPI
11
- from .application import Application
12
- from .converter import ConfluenceDocumentOptions
13
- from .processor import Processor
14
- from .properties import ConfluenceProperties
15
-
16
-
17
- class Arguments(argparse.Namespace):
18
- mdpath: str
19
- domain: str
20
- path: str
21
- username: str
22
- apikey: str
23
- space: str
24
- loglevel: str
25
- ignore_invalid_url: bool
26
- generated_by: Optional[str]
27
-
28
-
29
- parser = argparse.ArgumentParser()
30
- parser.prog = os.path.basename(os.path.dirname(__file__))
31
- parser.add_argument(
32
- "mdpath", help="Path to Markdown file or directory to convert and publish."
33
- )
34
- parser.add_argument("-d", "--domain", help="Confluence organization domain.")
35
- parser.add_argument("-p", "--path", help="Base path for Confluece wiki.")
36
- parser.add_argument("-u", "--username", help="Confluence user name.")
37
- parser.add_argument(
38
- "-a",
39
- "--apikey",
40
- help="Confluence API key. Refer to documentation how to obtain one.",
41
- )
42
- parser.add_argument(
43
- "-s",
44
- "--space",
45
- help="Confluence space key for pages to be published. If omitted, will default to user space.",
46
- )
47
- parser.add_argument(
48
- "-l",
49
- "--loglevel",
50
- choices=[
51
- typing.cast(str, logging.getLevelName(level)).lower()
52
- for level in (
53
- logging.DEBUG,
54
- logging.INFO,
55
- logging.WARN,
56
- logging.ERROR,
57
- logging.CRITICAL,
58
- )
59
- ],
60
- default=logging.getLevelName(logging.INFO),
61
- help="Use this option to set the log verbosity.",
62
- )
63
- parser.add_argument(
64
- "-r",
65
- dest="root_page",
66
- help="Root Confluence page to create new pages. If omitted, will raise exception when creating new pages.",
67
- )
68
- parser.add_argument(
69
- "--generated-by",
70
- default="This page has been generated with a tool.",
71
- help="Add prompt to pages (default: 'This page has been generated with a tool.').",
72
- )
73
- parser.add_argument(
74
- "--no-generated-by",
75
- dest="generated_by",
76
- action="store_const",
77
- const=None,
78
- help="Do not add 'generated by a tool' prompt to pages.",
79
- )
80
- parser.add_argument(
81
- "--ignore-invalid-url",
82
- action="store_true",
83
- default=False,
84
- help="Emit a warning but otherwise ignore relative URLs that point to ill-specified locations.",
85
- )
86
- parser.add_argument(
87
- "--local",
88
- action="store_true",
89
- default=False,
90
- help="Write XHTML-based Confluence Storage Format files locally without invoking Confluence API.",
91
- )
92
-
93
- args = Arguments()
94
- parser.parse_args(namespace=args)
95
-
96
- logging.basicConfig(
97
- level=getattr(logging, args.loglevel.upper(), logging.INFO),
98
- format="%(asctime)s - %(levelname)s - %(funcName)s [%(lineno)d] - %(message)s",
99
- )
100
-
101
-
102
- options = ConfluenceDocumentOptions(
103
- ignore_invalid_url=args.ignore_invalid_url,
104
- generated_by=args.generated_by,
105
- root_page_id=args.root_page,
106
- )
107
- properties = ConfluenceProperties(
108
- args.domain, args.path, args.username, args.apikey, args.space
109
- )
110
- if args.local:
111
- Processor(options, properties).process(args.mdpath)
112
- else:
113
- try:
114
- with ConfluenceAPI(properties) as api:
115
- Application(
116
- api,
117
- options,
118
- ).synchronize(args.mdpath)
119
- except requests.exceptions.HTTPError as err:
120
- logging.error(err)
121
-
122
- # print details for a response with JSON body
123
- if err.response is not None:
124
- try:
125
- logging.error(err.response.json())
126
- except requests.exceptions.JSONDecodeError:
127
- pass
128
-
129
- sys.exit(1)
1
+ import argparse
2
+ import logging
3
+ import os.path
4
+ import sys
5
+ from pathlib import Path
6
+ from typing import Optional
7
+
8
+ import requests
9
+
10
+ from .api import ConfluenceAPI
11
+ from .application import Application
12
+ from .converter import ConfluenceDocumentOptions
13
+ from .processor import Processor
14
+ from .properties import ConfluenceProperties
15
+
16
+
17
+ class Arguments(argparse.Namespace):
18
+ mdpath: Path
19
+ domain: str
20
+ path: str
21
+ username: str
22
+ apikey: str
23
+ space: str
24
+ loglevel: str
25
+ ignore_invalid_url: bool
26
+ generated_by: Optional[str]
27
+
28
+
29
+ def main() -> None:
30
+ parser = argparse.ArgumentParser()
31
+ parser.prog = os.path.basename(os.path.dirname(__file__))
32
+ parser.add_argument(
33
+ "mdpath", help="Path to Markdown file or directory to convert and publish."
34
+ )
35
+ parser.add_argument("-d", "--domain", help="Confluence organization domain.")
36
+ parser.add_argument(
37
+ "-p", "--path", help="Base path for Confluence (default: '/wiki/')."
38
+ )
39
+ parser.add_argument("-u", "--username", help="Confluence user name.")
40
+ parser.add_argument(
41
+ "-a",
42
+ "--apikey",
43
+ help="Confluence API key. Refer to documentation how to obtain one.",
44
+ )
45
+ parser.add_argument(
46
+ "-s",
47
+ "--space",
48
+ help="Confluence space key for pages to be published. If omitted, will default to user space.",
49
+ )
50
+ parser.add_argument(
51
+ "-l",
52
+ "--loglevel",
53
+ choices=[
54
+ logging.getLevelName(level).lower()
55
+ for level in (
56
+ logging.DEBUG,
57
+ logging.INFO,
58
+ logging.WARN,
59
+ logging.ERROR,
60
+ logging.CRITICAL,
61
+ )
62
+ ],
63
+ default=logging.getLevelName(logging.INFO),
64
+ help="Use this option to set the log verbosity.",
65
+ )
66
+ parser.add_argument(
67
+ "-r",
68
+ dest="root_page",
69
+ help="Root Confluence page to create new pages. If omitted, will raise exception when creating new pages.",
70
+ )
71
+ parser.add_argument(
72
+ "--generated-by",
73
+ default="This page has been generated with a tool.",
74
+ help="Add prompt to pages (default: 'This page has been generated with a tool.').",
75
+ )
76
+ parser.add_argument(
77
+ "--no-generated-by",
78
+ dest="generated_by",
79
+ action="store_const",
80
+ const=None,
81
+ help="Do not add 'generated by a tool' prompt to pages.",
82
+ )
83
+ parser.add_argument(
84
+ "--ignore-invalid-url",
85
+ action="store_true",
86
+ default=False,
87
+ help="Emit a warning but otherwise ignore relative URLs that point to ill-specified locations.",
88
+ )
89
+ parser.add_argument(
90
+ "--local",
91
+ action="store_true",
92
+ default=False,
93
+ help="Write XHTML-based Confluence Storage Format files locally without invoking Confluence API.",
94
+ )
95
+
96
+ args = Arguments()
97
+ parser.parse_args(namespace=args)
98
+
99
+ # NOTE: If we switch to modern type aware CLI tool like typer
100
+ # the following line won't be necessary
101
+ args.mdpath = Path(args.mdpath)
102
+
103
+ logging.basicConfig(
104
+ level=getattr(logging, args.loglevel.upper(), logging.INFO),
105
+ format="%(asctime)s - %(levelname)s - %(funcName)s [%(lineno)d] - %(message)s",
106
+ )
107
+
108
+ options = ConfluenceDocumentOptions(
109
+ ignore_invalid_url=args.ignore_invalid_url,
110
+ generated_by=args.generated_by,
111
+ root_page_id=args.root_page,
112
+ )
113
+ properties = ConfluenceProperties(
114
+ args.domain, args.path, args.username, args.apikey, args.space
115
+ )
116
+ if args.local:
117
+ Processor(options, properties).process(args.mdpath)
118
+ else:
119
+ try:
120
+ with ConfluenceAPI(properties) as api:
121
+ Application(
122
+ api,
123
+ options,
124
+ ).synchronize(args.mdpath)
125
+ except requests.exceptions.HTTPError as err:
126
+ logging.error(err)
127
+
128
+ # print details for a response with JSON body
129
+ if err.response is not None:
130
+ try:
131
+ logging.error(err.response.json())
132
+ except requests.exceptions.JSONDecodeError:
133
+ pass
134
+
135
+ sys.exit(1)
136
+
137
+
138
+ if __name__ == "__main__":
139
+ main()