def main(): parser = argparse.ArgumentParser(description="Vim boostrap generator") parser.add_argument("editor", type=str, choices=editors.EDITORS.keys(), help="Editor to generate config for") parser.add_argument("--langs", "-l", type=str, required=True, help="Comma seperated list of languages") args = parser.parse_args() editor = editors.get_editor(args.editor) langs = args.langs.split(',') generate(editor, langs)
def generate(): editor_name = request.POST.get("editor", "vim") editor = editors.get_editor(editor_name) ctx = {"bundle": {}, "vim": {}, "editor": editor} select_lang = request.POST.getall('langs') for l in select_lang: data = memcache.get('vim-{}'.format(l)) if not data: cache = {} for ext in ["bundle", "vim"]: with open("./vim_template/langs/{0}/{0}.{1}".format(l, ext)) as f: cache[ext] = ctx[ext][l] = f.read() memcache.add('vim-{}'.format(l), cache, 3600) else: ctx["bundle"][l] = data['bundle'] ctx["vim"][l] = data['vim'] template = None with open("./vim_template/vimrc") as f: template = Template(f.read().decode('utf-8')) if not template: template = Template("") response.headers['Content-Type'] = 'application/text' response.headers['Content-Disposition'] = 'attachment; \ filename='.format(os.path.basename(editor.name)) ctx['select_lang'] = ",".join(select_lang) def sh_exist(lang): return os.path.isfile("./vim_template/langs/{0}/{0}.sh".format(lang)) ctx['sh_exist'] = sh_exist return template.render(**ctx)
def generate(): editor_name = request.POST.get("editor", "vim") editor = editors.get_editor(editor_name) ctx = {"bundle": {}, "vim": {}, "editor": editor} select_lang = request.POST.getall('langs') for l in select_lang: data = memcache.get('vim-{}'.format(l)) if not data: cache = {} for ext in ["bundle", "vim"]: with open("./vim_template/langs/{0}/{0}.{1}".format( l, ext)) as f: cache[ext] = ctx[ext][l] = f.read() memcache.add('vim-{}'.format(l), cache, 3600) else: ctx["bundle"][l] = data['bundle'] ctx["vim"][l] = data['vim'] template = None with open("./vim_template/vimrc") as f: template = Template(f.read().decode('utf-8')) if not template: template = Template("") response.headers['Content-Type'] = 'application/text' response.headers['Content-Disposition'] = 'attachment; \ filename='.format(os.path.basename(editor.name)) ctx['select_lang'] = ",".join(select_lang) def sh_exist(lang): return os.path.isfile("./vim_template/langs/{0}/{0}.sh".format(lang)) ctx['sh_exist'] = sh_exist return template.render(**ctx)