Example #1
0
def dfs_dir(root_dir,markdown_file,level,logger=mylog.default_logger()):
    # generate the filelist, ignore the hidden files.
    hiden_file=re.compile(r'^\.|main_title\.md|\.synopsis$|\.markdown')
    effective_file=re.compile(r'(^.*_+|^[0-9]*_*)(.*)\.md$')
    efflists=[ filename for filename in os.listdir(root_dir) if  effective_file.match(filename)]
    efflists_title=[ effective_file.match(filename).group(2) for filename in os.listdir(root_dir) if  effective_file.match(filename)]

    alllists=[ filename for filename in os.listdir(root_dir) if not hiden_file.match(filename)]

    #
    for filename,title in zip(efflists,efflists_title):
        path = os.path.join(root_dir, filename)
        # print logger
        logger.debug(filename+title)


        # write the file content according to level
        #TODO: 文件夹的处理,文件夹名+.md, .synopsis的处理
        if os.path.isdir(path):
            markdown_file.write('#'*level+title)
            markdown_file.write('\n')
            # if os.path.exists(str(path)+'/00.content'):
                # markdown_file.write(str(sh.cat(path+'/00.content'))+'\n')
            dfs_dir(path, markdown_file, level+1)
        else:
            if title:
                markdown_file.write('#'*level+title)
            markdown_file.write('\n')
            markdown_file.write(str(sh.sed('s/^#/'+'#'*level+'#/',path)))
Example #2
0
def main(logger=mylog.default_logger()):
    # load arguments and logger
    arguments = docopt(__doc__, version='0.0')
    # print arguments
    # script self name
    self_name=os.path.basename(sys.argv[0])
    # log
    # logfile=self_name.replace('py','log')
    # logger=set_mylogger(arguments,logfile)
    # load config
    # main_config=load_config('.ll')

    # set filename varibles
    # main_title=os.path.basename(os.getcwd())
    # markdown_file_name=os.path.join(os.getcwd(),'build',main_title+'.markdown')
    # docx_file_name=main_title+'.docx'
    # rtf_file_name=main_title+'.rtf'

    md_pattern=re.compile(r'\.md$')

    markdown_file_name=arguments.get('<filename>')
    if markdown_file_name:
        if os.path.isdir(markdown_file_name):
            walk_sed(markdown_file_name)
        else:
            sh.sed('-i','-e','s/^#//',markdown_file_name)
            # sh.sed('-i','-e','s/^#/'+'#/',markdown_file_name)
    else:
        walk_sed('.')
Example #3
0
File: mytex.py Project: lhrkkk/auto
def main(logger=mylog.default_logger()):
    # load arguments and logger
    arguments = docopt(__doc__, version='0.0')
    # script self name
    self_name=os.path.basename(sys.argv[0])
    # log
    logfile=self_name.replace('py','log')
    logger=set_mylogger(arguments,logfile)
    # load config
    # main_config=load_config('.ll')

    # set filename varibles
    # main_title=os.path.basename(os.getcwd())
    # markdown_file_name=os.path.join(os.getcwd(),'build',main_title+'.markdown')
    # docx_file_name=main_title+'.docx'
    # rtf_file_name=main_title+'.rtf'

    latexmk_arg=['-pdf','-f','-quiet','-e',r'$pdflatex=q/xelatex %O -interaction=nonstopmode %S/']
    if arguments['--quiet']:
        latexmk_arg.append('-quiet')

    if arguments['<tex_file_name>']:
        latexmk_arg.append(arguments['<tex_file_name>'])
        try:
            sh.latexmk(*latexmk_arg)

        except Exception, e:
            pass
        pdf_file_name=arguments['<tex_file_name>'].replace('tex','pdf')
        if arguments['--view'] and os.path.exists(pdf_file_name):
            sh.open(pdf_file_name)
Example #4
0
def main(logger=mylog.default_logger()):
    # load arguments and logger
    arguments = docopt(__doc__, version='0.0')
    # script self name
    self_name=os.path.basename(sys.argv[0])
    # log
    logfile=self_name.replace('py','log')
    logger=set_mylogger(arguments,logfile)
    # load config
    # main_config=load_config('.ll')

    # set filename varibles
    main_title=os.path.basename(os.getcwd())
    plist_file_name='.Ulysses-Group.plist'
    get_name_from_plist(plist_file_name)
Example #5
0
def main(logger=mylog.default_logger()):
    # load arguments and logger
    arguments = docopt(__doc__, version="0.0")
    # script self name
    self_name = os.path.basename(sys.argv[0])
    # log
    logfile = self_name.replace("py", "log")
    logger = set_mylogger(arguments, logfile)
    # load config
    # main_config=load_config('.ll')

    # set filename varibles
    main_title = os.path.basename(os.getcwd())
    markdown_file_name = os.path.join(os.getcwd(), "build", main_title + ".markdown")
    docx_file_name = main_title + ".docx"
    rtf_file_name = main_title + ".rtf"
Example #6
0
def dfs_dir(root_dir, re_effective_file, cmd, logger=mylog.default_logger()):
    # generate the filelist, ignore the hidden files.

    # efflists=[ filename for filename in os.listdir(root_dir) if  re_effective_file.match(filename)]

    alllist = os.listdir(root_dir)
    for filename in alllist:
        path = os.path.join(root_dir, filename)

        # write the file content according to level
        # TODO: 文件夹的处理,文件夹名+.md, .synopsis的处理
        if os.path.isdir(path):
            print path
            dfs_dir(path, re_effective_file, cmd)
        elif re_effective_file.match(filename):
            os.system(cmd + " " + '"' + path + '"')
Example #7
0
def main(logger=mylog.default_logger()):
    # load arguments and logger
    arguments = docopt(__doc__, version="0.0")
    # script self name
    self_name = os.path.basename(sys.argv[0])
    # log
    logfile = self_name.replace("py", "log")
    logger = set_mylogger(arguments, logfile)
    # load config
    # main_config=load_config('.ll')

    pattern = r".*\.txt"

    cmd = "all2utf8.py"
    re_effective_file = re.compile(pattern)
    dfs_dir(".", re_effective_file, cmd)
Example #8
0
def dfs_dir_byplist(root_dir,markdown_file,level,logger=mylog.default_logger()):
    # generate the filelist, ignore the hidden files.

    effective_file=re.compile(r'(^.*_+|^[0-9]*_*)(.*)\.md$')
    plist_file_name=os.path.join(root_dir,'.Ulysses-Group.plist')
    print plist_file_name
    print root_dir, level
    filename_list,dirname_list=get_name_from_plist(plist_file_name)
    print filename_list
    alllists=filename_list+dirname_list
    efflists=[ filename for filename in filename_list if  effective_file.match(filename)]+dirname_list
    print efflists
    # efflists_title=[ effective_file.match(filename).group(2) for filename in alllists if  effective_file.match(filename)]


    #

    for filename in efflists:
        path = os.path.join(root_dir, filename)
        # print logger
        # logger.debug(filename+title)


        # write the file content according to level
        #TODO: 文件夹的处理,文件夹名+.md, .synopsis的处理
        if os.path.isdir(path):
            # markdown_file.write('#'*level+title)
            # markdown_file.write('\n\n')
            # if os.path.exists(str(path)+'/00.content'):
                # markdown_file.write(str(sh.cat(path+'/00.content'))+'\n')
            dfs_dir_byplist(path, markdown_file, level+1)
        else:
            # if title:
                # markdown_file.write('#'*level+title)
            # markdown_file.write('\n\n')
            # markdown_file.write(str(sh.sed('s/^#/'+'#'*level+'#/',path)))
            markdown_file.write(str(sh.sed('s/^#/'+'#'+'/',path)))
            markdown_file.write('\n\n')