summaryrefslogtreecommitdiffstats
path: root/test/AS/fixture/myas.py
blob: a348aceeea5c26bea8f1a359f86622e712fdf083 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import sys


def my_win32_as():
    args = sys.argv[1:]
    inf = None
    while args:
        a = args[0]
        if a == '-o':
            out = args[1]
            args = args[2:]
            continue
        args = args[1:]
        if not a[0] in '/-':
            if not inf:
                inf = a
            continue
        if a[:3] == '/Fo':
            out = a[3:]

    with open(inf, 'rb') as ifp, open(out, 'wb') as ofp:
        for line in ifp:
            if not line.startswith(b'#as'):
                ofp.write(line)


def my_as():
    import getopt

    try:
        opts, args = getopt.getopt(sys.argv[1:], 'co:')
    except getopt.GetoptError:
        # we may be called with --version, just quit if so
        sys.exit(0)
    for opt, arg in opts:
        if opt == '-o':
            out = arg

    if args:
        with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp:
            for line in ifp:
                if not line.startswith(b'#as'):
                    ofp.write(line)


if __name__ == "__main__":
    if sys.platform == 'win32':
        my_win32_as()
    else:
        my_as()
    sys.exit(0)