Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
reMarkAble/remarkable/scripts/runDMC.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
102 lines (77 sloc)
3.33 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
reMarkable: Convert markdown to docs using Templates | |
Copyright (C) 2020 Dan Goldsmith (djgoldsmith@googlemail.com) | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program. If not, see <https://www.gnu.org/licenses/>. | |
""" | |
import logging | |
import argparse | |
import remarkable.controller as controller | |
class CustomFormatter(logging.Formatter): | |
"""Logging Formatter to add colors and count warning / errors | |
Inspired by https://stackoverflow.com/questions/384076/how-can-i-color-python-logging-output | |
""" | |
grey = "\u001b[30;1m" | |
yellow = "\u001b[33;21m" | |
red = "\u001b[31m" | |
bold_red = "\u001b[31;1m" | |
reset = "\u001b[0m" | |
format = "[%(name)s] - %(levelname)s - %(message)s" | |
FORMATS = { | |
logging.DEBUG: grey + format + reset, | |
logging.INFO: format, | |
logging.WARNING: yellow + format + reset, | |
logging.ERROR: red + format + reset, | |
logging.CRITICAL: bold_red + format + reset | |
} | |
def format(self, record): | |
log_fmt = self.FORMATS.get(record.levelno) | |
formatter = logging.Formatter(log_fmt) | |
return formatter.format(record) | |
def main(): | |
description = "Tool to convert markdown documents into report and make parts of marking less painful" | |
parser = argparse.ArgumentParser(description=description) | |
parser.add_argument("filename", | |
help="File to Convert") | |
parser.add_argument("-t", "--template", | |
help="Template file to use for rendering") | |
parser.add_argument("-d", "--templatedir", | |
help="Local template directory") | |
parser.add_argument("-o", "--output", | |
help="Name of output file") | |
parser.add_argument("-v", "--verbose", | |
action="count", | |
default=0, | |
help="Log level verbosity. (-vv = Pink Lady Mode)") | |
arguments = parser.parse_args() | |
#Handler for Log Formatting | |
ch = logging.StreamHandler() | |
ch.setLevel(logging.DEBUG) | |
ch.setFormatter(CustomFormatter()) | |
logging.basicConfig(level=logging.WARNING, handlers=[ch]) | |
log = logging.getLogger("MAIN") | |
log.setLevel(logging.INFO) | |
if arguments.verbose == 1: | |
logging.getLogger().setLevel(logging.INFO) | |
log.info("Logging Activated") | |
elif arguments.verbose > 1: | |
logging.getLogger().setLevel(logging.DEBUG) | |
log.info("Debug Logging Activated") | |
log.debug("Tell Me More, Tell Me More, Is My syntax alright?") | |
log.info("Converting File") | |
#Otherwise | |
controller.convertFile(arguments.filename, | |
templateFile=arguments.template, | |
templateDir=arguments.templatedir, | |
outputFile=arguments.output) | |
log.info("Done") | |
if __name__ == "__main__": | |
main() |