def gen_mul_lyr(png, mapserver_ip, uu, wroot): lqian, lhou = os.path.splitext(png) xxuu = lqian.split('_') if len(xxuu) > 2: lidx, lslug, lname = xxuu else: lidx, lslug = xxuu lname = xxuu[-1] mqian, mhou = os.path.split(wroot) midx, mslug, mname = mhou.split('_') the_file = os.path.join(wroot, png) lyr_list = helper.lyr_list(mslug, the_file) (lyr_name, lyr_ext) = os.path.splitext(png) lyr_name_arr = lyr_name.split('_') the_name = '_'.join(lyr_name_arr[1:]) # sig = 'maplet_' + the_name sig = 'maplet_{}_{}'.format(mslug, lslug) uu['caches'][sig] = {} uu['caches'][sig]['grids'] = ['webmercator'] uu['caches'][sig]['grids'] = ['webmercator'] uu['caches'][sig]['sources'] = lyr_list new_dic = {'name': sig, 'title': sig, 'sources': [sig]} uu['layers'].append(new_dic)
def gen_html_pages2(wroot): # 处理 HTML 文件 _, the_dir = os.path.split(wroot) list_main = fetch_structure() nav_formated = format_nav(list_main) md_files = [x for x in os.listdir(wroot) if x.endswith('.xlsx') and x.startswith('meta_')] for idx_file, md_file in enumerate(md_files): name_before, name_after = os.path.split(the_dir) midx, mname, mslug = name_after.split('_') lqian, lhou = os.path.splitext(md_file) left_nav = format_leftnav(list_main, mname) file_dirs = lqian.split('_') if len(file_dirs) > 2: lidx, lname, lslug = file_dirs else: lidx, lslug = file_dirs lname = file_dirs[-1] # 对分组(grp)的XLSX进行处理。 # dir_idx, dir_slug, dir_title = the_dir.split('_') # 使用分类 slug # file_slug = '{}_{}'.format(mslug, lslug) # 使用唯一ID file_slug = '{}'.format(lslug) out_html_file = os.path.join(dst_ws, file_slug + '.html') jinja2_file = 'templates/lyr.jinja2' jinja2_file = '/'.join(jinja2_file.split('/')[1:]) if '_grp' in md_file: # 处理。 helper.render_html( 'lyrgrp.jinja2', out_html_file, nav=nav_formated, layers=helper.lyr_list(os.path.join(wroot, md_file)), IP=TILE_SVR, left_nav=left_nav, title=lname, mname=mname ) elif '[' in md_file: dispose_serial_file(md_file, wroot, mslug, lslug, jinja2_file, left_nav, mname, nav=nav_formated) else: helper.render_html( jinja2_file, out_html_file, nav=nav_formated, lyr_name=file_slug, IP=TILE_SVR, left_nav=left_nav, title=lname, mname=mname )
def gen_mul_lyr(file_name, mapproxy_mold, wroot): ''' 处理多图层。 ''' lqian, _ = os.path.splitext(file_name) tmp_arr = lqian.split('_') if len(tmp_arr) > 2: lidx, lname, lslug = tmp_arr else: lidx, lslug = tmp_arr the_file = os.path.join(wroot, file_name) lyr_list = helper.lyr_list(the_file) sig = 'maplet_{}'.format(lslug) mapproxy_mold['caches'][sig] = {} mapproxy_mold['caches'][sig]['grids'] = ['webmercator'] mapproxy_mold['caches'][sig]['sources'] = lyr_list new_dic = {'name': sig, 'title': sig, 'sources': [sig]} mapproxy_mold['layers'].append(new_dic)
def gen_html_pages(): ''' 根据输入的 MarkDown 文件,生成 HTML 结果。 ''' list_main = fetch_structure() # print('5' * 40) # pprint(list_main) nav_formated = format_nav(list_main) the_dirs = os.listdir(src_ws) the_dirs.sort() for idx_dir, the_dir in enumerate(the_dirs): wroot = os.path.join(src_ws, the_dir) if os.path.isdir(wroot): pass else: continue ################ # 处理 HTML 文件 md_files = [ x for x in os.listdir(wroot) if x.endswith('.xlsx') and x.startswith('meta_') ] for idx_file, md_file in enumerate(md_files): mqian, mhou = os.path.split(the_dir) midx, mslug, mname = mhou.split('_') lqian, lhou = os.path.splitext(md_file) xxuu = lqian.split('_') left_nav = format_leftnav(list_main, mname) if len(xxuu) > 2: lidx, lslug, lname = xxuu else: lidx, lslug = xxuu lname = xxuu[-1] # ToDo: 对分组(grp)的XLSX进行处理。 dir_idx, dir_slug, dir_title = the_dir.split('_') file_slug = '{}_{}'.format(mslug, lslug) # file_title = md_dic['title'] file_name = file_slug + '.html' out_html_file = os.path.join(dst_ws, file_name) jinja2_file = 'templates/lyr.jinja2' jinja2_file = '/'.join(jinja2_file.split('/')[1:]) if '_grp' in md_file: # ToDo: 处理。 helper.render_html('lyrgrp.jinja2', out_html_file, nav=nav_formated, layers=helper.lyr_list( mslug, os.path.join(wroot, md_file)), IP=TILE_SVR, left_nav=left_nav, title=lname, mname=mname) elif '[' in md_file: chuli_serial_file(md_file, wroot, mslug, lslug, jinja2_file, left_nav, mname, nav=nav_formated) else: helper.render_html(jinja2_file, out_html_file, nav=nav_formated, lyr_name=file_slug, IP=TILE_SVR, left_nav=left_nav, title=lname, mname=mname)
def gen_html_pages2(wroot, idx_dir=0): ''' 处理 HTML 文件 ''' _, the_dir = os.path.split(wroot) # nav_formated = format_nav(list_main) md_files = [x for x in os.listdir(wroot) if x.endswith('.xlsx') and x.startswith('meta_')] for idx_file, md_file in enumerate(md_files): name_before, name_after = os.path.split(the_dir) midx, mname, mslug = name_after.split('_') lqian, lhou = os.path.splitext(md_file) file_dirs = lqian.split('_') if len(file_dirs) > 2: lidx, lname, lslug = file_dirs else: lidx, lslug = file_dirs lname = file_dirs[-1] # 对分组(grp)的XLSX进行处理。 # dir_idx, dir_slug, dir_title = the_dir.split('_') # 使用分类 slug # file_slug = '{}_{}'.format(mslug, lslug) # 使用唯一ID file_slug = '{}'.format(lslug) outdir = os.path.join(SPHINX_SRC, 'ch{}-'.format(str(idx_dir).zfill(2)) + mslug) if os.path.exists(outdir): pass else: os.mkdir(outdir) generate_chfile(outdir, mname) if '_grp' in md_file: layers = helper.lyr_list(os.path.join(wroot, md_file)) out_html_file = os.path.join( outdir, 'sec{}-'.format(str(idx_file + 1).zfill(2)) + file_slug + '.rst' ) with open(out_html_file, 'w') as fo: fo.write('''{lname} ========================================== {mname}——{lname} 。 .. raw:: html <div id="map_kd1" data-maplet="{file_slug}" data-title="{lname}"></div> '''.format(mname=mname, lname=lname, file_slug=','.join(layers))) elif '[' in md_file: dispose_serial_file(wroot, md_file, lname, lslug, mname, outdir) else: out_html_file = os.path.join( outdir, 'sec{}-'.format(str(idx_file + 1).zfill(2)) + file_slug + '.rst' ) with open(out_html_file, 'w') as fo: fo.write('''{lname} ========================================== {mname}——{lname} 。 .. raw:: html <div id="map_kd1" data-maplet="maplet_{file_slug}" data-title="{lname}"></div> '''.format(mname=mname, lname=lname, file_slug=file_slug))