File: wasm-run.py

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (54 lines) | stat: -rwxr-xr-x 1,538 bytes parent folder | download
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
52
53
54
#!/usr/bin/env python3

import argparse
import os
import subprocess
import sys


def collect_wasm_env(local_env=os.environ, prefix='WASM_RUN_CHILD_'):
    return dict((key[len(prefix):], value)
                for key, value in local_env.items() if key.startswith(prefix))


class WasmtimeRunner(object):
    def __init__(self):
        pass

    def run(self, args):
        command = self.invocation(args)
        if args.verbose:
            print(' '.join(command), file=sys.stderr)

        if not args.dry_run:
            subprocess.check_call(command)

    def invocation(self, args):
        command = ["wasmkit-cli", "run"]
        envs = collect_wasm_env()
        for key in envs:
            command.append("--env")
            command.append(f"{key}={envs[key]}")
        command.append("--")
        command.extend(args.command)
        return command


def main():
    parser = argparse.ArgumentParser()

    parser.add_argument('-v', '--verbose', action='store_true', dest='verbose',
                        help='print commands as they are run')
    parser.add_argument('-n', '--dry-run', action='store_true', dest='dry_run',
                        help="print the commands that would have been run, but"
                             " don't actually run them")
    parser.add_argument('command', nargs=argparse.REMAINDER,
                        help='the command to run', metavar='command...')

    args = parser.parse_args()
    runner = WasmtimeRunner()
    runner.run(args)


if __name__ == "__main__":
    main()