Skip to content

md_to_conf

main()

Main program

Source code in md_to_conf/__init__.py
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
def main():
    """
    Main program

    """
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s - \
        %(levelname)s - %(funcName)s [%(lineno)d] - \
        \t%(message)s",
    )
    LOGGER = logging.getLogger(__name__)

    # ArgumentParser to parse arguments and options
    PARSER = get_parser()

    ARGS = PARSER.parse_args()

    # Assign global variables
    try:
        # Set log level
        LOGGER.setLevel(getattr(logging, ARGS.loglevel.upper(), None))

        MARKDOWN_FILE = ARGS.markdownFile
        SPACE_KEY = ARGS.spacekey
        USERNAME = os.getenv("CONFLUENCE_USERNAME", ARGS.username)
        API_KEY = os.getenv("CONFLUENCE_API_KEY", ARGS.apikey)
        ORGNAME = os.getenv("CONFLUENCE_ORGNAME", ARGS.orgname)
        ANCESTOR = ARGS.ancestor
        NOSSL = ARGS.nossl
        DELETE = ARGS.delete
        SIMULATE = ARGS.simulate
        VERSION = ARGS.version
        MARKDOWN_SOURCE = ARGS.markdownsrc
        LABELS = ARGS.labels
        PROPERTIES = dict(ARGS.properties)
        ATTACHMENTS = ARGS.attachment
        CONTENTS = ARGS.contents
        TITLE = ARGS.title
        REMOVE_EMOJIES = ARGS.remove_emojies

        validate_args(USERNAME, API_KEY, MARKDOWN_FILE, ORGNAME)

    except Exception as err:
        LOGGER.error("\n\nException caught:\n%s ", err)
        LOGGER.error("\nFailed to process command line arguments. Exiting.")
        sys.exit(1)

    LOGGER.info("\t----------------------------------")
    LOGGER.info("\tMarkdown to Confluence Upload Tool")
    LOGGER.info("\t----------------------------------")

    LOGGER.info("Markdown file:\t%s", MARKDOWN_FILE)
    LOGGER.info("Space Key:\t%s", SPACE_KEY)

    confluence_converter: ConfluenceConverter = ConfluenceConverter(
        MARKDOWN_FILE,
        MARKDOWN_SOURCE,
        TITLE,
        ORGNAME,
        not NOSSL,
        USERNAME,
        SPACE_KEY,
        API_KEY,
        ANCESTOR,
        VERSION,
    )

    confluence_converter.convert(
        SIMULATE, DELETE, REMOVE_EMOJIES, CONTENTS, LABELS, PROPERTIES, ATTACHMENTS
    )