Skip to content
Snippets Groups Projects
Commit 869849ed authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

converted most calls of Detector2D from old to new API

# Automatic editing of collection of source files.
# Does not provide backup files:
# to be safe, work on fresh git commit, and use 'git stash' to revert.

import edtools as et
import re, sys

def f(t):
    t = re.sub(r'--(\d)', r'+\1', t)
    t = re.sub(r'\+-(\d)', r'-\1', t)
    t = re.sub(r'\s*\*\s*deg', r'', t)

    t = f'{eval(t)}'

    t = re.sub('\.0$', '', t)

    if t != '0':
        t += '*deg'

    return t

def user_edit(fn, ti):

    t = re.sub(r'OldDetec2D(\s+\w+)?\((n\w*|\d+),\s*([-.0-9]+\s*\*\s*deg|0),\s*([-.0-9]+\s*\*\s*deg|0),\s*(n\w*|\d+),\s*([-.0-9]+\s*\*\s*deg|0),\s*([-.0-9]+\s*\*\s*deg|0)\)',
               r'NewDetec2D\1(@(\4-\3)@, @(\7-\6)@, \2, \5, @(\4+\3)/2@, @(\7+\6)/2@)', ti)
    if t == ti:
        return ti

#    t = re.sub(r'@(\(.*?\)(/2)?)@', f(r'\1'), t)

    for m in re.finditer(r'@(\(.*?\)(/2)?)@', t):
        s = f(m.group(1))
        t = re.sub(r'@(\(.*?\)(/2)?)@', s, t, 1)

    return t

et.ed_argfiles(user_edit)
parent 748dc60e
No related branches found
No related tags found
Loading
Showing
with 33 additions and 33 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment