Skip to content
Snippets Groups Projects
  • Wuttke, Joachim's avatar
    346de532
    convert all examples with sim_n argument to new style · 346de532
    Wuttke, Joachim authored
    def user_edit(fn, t):
    
        nmini = 11
        if re.search(r'(specular|varia)', fn):
            nmini = 50
    
        m = re.search(r'bp\.parse_args\(sim_n=(\d+)', t)
        if not m:
            return t
        n = m.group(1)
        t = re.sub(r"bp\.simargs\['n'\]", f'<%= sm ? {nmini} : {n} %>', t)
    
        t = re.sub(r'(bp\.parse_args\()sim_n=(\d+),\s*', r'\1', t)
        t = re.sub(r'(bp\.parse_args\()sim_n=(\d+)\)', r'\1)', t)
    
        if not re.search(r'^#!/usr/bin/env python3\n', t):
            raise Exception("missing shebang in "+fn)
        t = re.sub(r'(^#!.*?\n("""\n(.*\n)+"""\n)?)\n*',
                   r'\1'+'<% sm = (e=ENV["SHORTMODE"] and e!="OFF") %>\n', t)
    
        return t
    346de532
    History
    convert all examples with sim_n argument to new style
    Wuttke, Joachim authored
    def user_edit(fn, t):
    
        nmini = 11
        if re.search(r'(specular|varia)', fn):
            nmini = 50
    
        m = re.search(r'bp\.parse_args\(sim_n=(\d+)', t)
        if not m:
            return t
        n = m.group(1)
        t = re.sub(r"bp\.simargs\['n'\]", f'<%= sm ? {nmini} : {n} %>', t)
    
        t = re.sub(r'(bp\.parse_args\()sim_n=(\d+),\s*', r'\1', t)
        t = re.sub(r'(bp\.parse_args\()sim_n=(\d+)\)', r'\1)', t)
    
        if not re.search(r'^#!/usr/bin/env python3\n', t):
            raise Exception("missing shebang in "+fn)
        t = re.sub(r'(^#!.*?\n("""\n(.*\n)+"""\n)?)\n*',
                   r'\1'+'<% sm = (e=ENV["SHORTMODE"] and e!="OFF") %>\n', t)
    
        return t