Ejemplo n.º 1
0
def set_mylogger(arguments,logfile):
    if arguments.get('-l') or arguments.get('--log'):
        logger=mylog.set_logger(filename=logfile, level=mylog.logging.INFO)
    elif arguments.get('-q') or arguments.get('--quiet'):
        logger=mylog.set_logger(filename=logfile, level=mylog.logging.ERROR)
    elif arguments.get('-d') or arguments.get('--debug'):
        logger=mylog.set_logger(filename=logfile, level=mylog.logging.DEBUG)
    else:
        logger=mylog.set_logger(level=mylog.logging.INFO)

    logger.debug(arguments)
    return logger
Ejemplo n.º 2
0
def set_mylogger(arguments, logfile):
    if arguments.get("-l") or arguments.get("--log"):
        logger = mylog.set_logger(filename=logfile, level=mylog.logging.INFO)
    elif arguments.get("-q") or arguments.get("--quiet"):
        logger = mylog.set_logger(filename=logfile, level=mylog.logging.ERROR)
    elif arguments.get("-d") or arguments.get("--debug"):
        logger = mylog.set_logger(filename=logfile, level=mylog.logging.DEBUG)
    else:
        logger = mylog.set_logger(level=mylog.logging.INFO)

    logger.debug(arguments)
    return logger
Ejemplo n.º 3
0
def set_mylogger(arguments, logfile):
    if arguments.get('-l') or arguments.get('--log'):
        logger = mylog.set_logger(filename=logfile, level=mylog.logging.INFO)
    elif arguments.get('-q') or arguments.get('--quiet'):
        logger = mylog.set_logger(filename=logfile, level=mylog.logging.ERROR)
    elif arguments.get('-d') or arguments.get('--debug'):
        logger = mylog.set_logger(filename=logfile, level=mylog.logging.DEBUG)
    else:
        logger = mylog.set_logger(level=mylog.logging.INFO)

    logger.debug(arguments)
    return logger
Ejemplo n.º 4
0
def main():
    arguments = docopt(__doc__, version='makemd 1.0')
    # print arguments

    # up to root
    if not up_to_main():
        print(
            ".main file not exist, bort. Please creat a .main file in the main folder."
        )
        return

    main_config = yaml.load(open(".main", 'r'))
    if not main_config:
        main_config = {}

    if arguments.get('-l') or arguments.get('--log'):
        logger = mylog.set_logger(filename='makemd.log',
                                  level=mylog.logging.INFO)
    elif arguments.get('-q') or arguments.get('--quiet'):
        logger = mylog.set_logger(filename='makemd.log',
                                  level=mylog.logging.ERROR)
    elif arguments.get('-d') or arguments.get('--debug'):
        logger = mylog.set_logger(filename='makemd.log',
                                  level=mylog.logging.DEBUG)
    else:
        logger = mylog.set_logger(level=mylog.logging.INFO)

    logger.debug(arguments)

    # load main_config
    if main_config.has_key('output_type_list'):
        logger.info('output_type_list are %s' %
                    main_config['output_type_list'])


## A .main config file sample. using yaml.
## output_type_list:
##    - latex_article
##    #- latex_report
##    #- rtf
##    #- docx

# set filename varibles
    main_title = os.path.basename(os.getcwd())
    if not os.path.exists('.build'):
        sh.mkdir('.build')
    sh.cd('.build')
    if not os.path.exists('images') and os.path.exists('../images'):
        sh.ln('-s', '../images', './')
    markdown_file_name = os.path.join(os.getcwd(), main_title + '.markdown')
    # markdown_file_name=os.path.join(os.getcwd(),main_title+'.markdown')
    docx_file_name = main_title + '.docx'
    rtf_file_name = main_title + '.rtf'

    # generate main_title.markdown file
    markdown_file = open(markdown_file_name, 'w')
    # markdown_file.write('#'+os.path.basename(os.getcwd())+'\n')
    # sh.cd('..')
    dfs_dir_byplist(os.pardir, markdown_file, 0, logger)
    markdown_file.close()
    sh.open(markdown_file_name)

    markdown_file = open(markdown_file_name, 'r')

    if main_config.has_key('output_type_list'):

        # generate latex file
        if main_config['output_type_list'] and (
                'latex_report' in main_config['output_type_list']
                or 'latex_article' in main_config['output_type_list']):
            content = markdown_file.read()
            encoding = chardet.detect(content)['encoding']
            if encoding == 'utf-8' and 'latex_report' in main_config[
                    'output_type_list']:
                # generate latex & pdf file by article
                mmd2tex(markdown_file_name, main_title, 'report', 'cn')
            if encoding == 'utf-8' and 'latex_article' in main_config[
                    'output_type_list']:
                # generate latex & pdf file by article
                mmd2tex(markdown_file_name, main_title, 'article', 'cn')

            if encoding != 'utf-8' and 'latex_report' in main_config[
                    'output_type_list']:
                mmd2tex(markdown_file_name, main_title, 'report', 'en')
            if encoding != 'utf-8' and 'latex_article' in main_config[
                    'output_type_list']:
                # generate latex & pdf file by article
                mmd2tex(markdown_file_name, main_title, 'article', 'en')
            logger.info("tex & pdf file generated")

        # generate rtf file
        if main_config['output_type_list'] and 'rtf' in main_config[
                'output_type_list']:
            mmd2rtf(markdown_file_name, rtf_file_name)
            sh.open(rtf_file_name)
            logger.info("rtf file generated")

        # generate docx file
        if main_config['output_type_list'] and 'docx' in main_config[
                'output_type_list']:
            mmd2docx(markdown_file_name, docx_file_name)
            sh.open(docx_file_name)
            logger.info("docx file generated")
Ejemplo n.º 5
0
def main():
    arguments = docopt(__doc__, version='makemd 1.0')
    # print arguments

    # up to root
    if not up_to_main():
        print(".main file not exist, bort. Please creat a .main file in the main folder.")
        return

    main_config=yaml.load(open(".main",'r'))
    if not main_config:
        main_config={}

    if arguments.get('-l') or arguments.get('--log'):
        logger=mylog.set_logger(filename='makemd.log', level=mylog.logging.INFO)
    elif arguments.get('-q') or arguments.get('--quiet'):
        logger=mylog.set_logger(filename='makemd.log', level=mylog.logging.ERROR)
    elif arguments.get('-d') or arguments.get('--debug'):
        logger=mylog.set_logger(filename='makemd.log', level=mylog.logging.DEBUG)
    else:
        logger=mylog.set_logger(level=mylog.logging.INFO)

    logger.debug(arguments)

    # load main_config
    if main_config.has_key('output_type_list'):
        logger.info('output_type_list are %s' % main_config['output_type_list'])
## A .main config file sample. using yaml.
## output_type_list:
##    - latex_article
##    #- latex_report
##    #- rtf
##    #- docx

    # set filename varibles
    main_title=os.path.basename(os.getcwd())
    if not os.path.exists('.build'):
        sh.mkdir('.build')
    sh.cd('.build')
    if not os.path.exists('images') and os.path.exists('../images'):
        sh.ln('-s','../images','./')
    markdown_file_name=os.path.join(os.getcwd(),main_title+'.markdown')
    # markdown_file_name=os.path.join(os.getcwd(),main_title+'.markdown')
    docx_file_name=main_title+'.docx'
    rtf_file_name=main_title+'.rtf'


    # generate main_title.markdown file
    markdown_file=open(markdown_file_name, 'w')
    # markdown_file.write('#'+os.path.basename(os.getcwd())+'\n')
    # sh.cd('..')
    dfs_dir_byplist(os.pardir,markdown_file,0,logger)
    markdown_file.close()
    sh.open(markdown_file_name)

    markdown_file=open(markdown_file_name, 'r')

    if main_config.has_key('output_type_list'):

        # generate latex file
        if main_config['output_type_list'] and ('latex_report' in main_config['output_type_list'] or 'latex_article' in main_config['output_type_list']):
            content=markdown_file.read()
            encoding=chardet.detect(content)['encoding']
            if encoding == 'utf-8' and 'latex_report' in main_config['output_type_list']:
                # generate latex & pdf file by article
                mmd2tex(markdown_file_name,main_title,'report','cn')
            if encoding == 'utf-8' and 'latex_article' in main_config['output_type_list']:
                # generate latex & pdf file by article
                mmd2tex(markdown_file_name,main_title,'article','cn')

            if encoding != 'utf-8' and 'latex_report' in main_config['output_type_list']:
                mmd2tex(markdown_file_name,main_title,'report','en')
            if encoding != 'utf-8' and 'latex_article' in main_config['output_type_list']:
                # generate latex & pdf file by article
                mmd2tex(markdown_file_name,main_title,'article','en')
            logger.info("tex & pdf file generated")


        # generate rtf file
        if  main_config['output_type_list'] and 'rtf' in main_config['output_type_list']:
            mmd2rtf(markdown_file_name,rtf_file_name)
            sh.open(rtf_file_name)
            logger.info("rtf file generated")

        # generate docx file
        if  main_config['output_type_list'] and 'docx' in main_config['output_type_list']:
            mmd2docx(markdown_file_name,docx_file_name)
            sh.open(docx_file_name)
            logger.info("docx file generated")