File: sim.py

package info (click to toggle)
gnucap-python 0.0.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,672 kB
  • sloc: python: 7,873; sh: 4,384; cpp: 1,786; makefile: 252
file content (60 lines) | stat: -rw-r--r-- 1,208 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
55
56
57
58
59
60
# Copyright (C) 2018 Felix Salfelder
# Author: Felix Salfelder <felix@salfelder.org>

from __future__ import print_function

import gnucap
import sys

from gnucap import component as c
from gnucap import install_device

try:
	a = gnucap.SIM()
	assert(False)
except RuntimeError:
	print("SIM construction refused (correct)")

class MyAC(gnucap.SIM):
	def do_it(self, cmd, scope):
		print("HELLOWORLD")
	def setup(self, cmd):
		pass
	def sweep(self):
		pass

class MyAC2(gnucap.SIM):
	def do_it(self, cmd, scope):
		print("HELLOWORLD2")
	def setup(self, cmd):
		pass
	def sweep(self):
		pass

ac = MyAC()
ac2 = MyAC2()
print("install1")
d1 = gnucap.install_command("myac1", ac)
print("install2")
d2 = gnucap.install_command("myac", ac2)
d3 = gnucap.install_command("myac", ac)
d4 = gnucap.install_command("ac", ac)

gnucap.command("set trace")
gnucap.command("ac 1 2 * 2")
gnucap.command("myac1 1 2 * 2")
gnucap.command("myac:0 1 2 * 2")
gnucap.command("myac 1 2 * 2")

print("side effects?")
del(d2)
gnucap.command("myac:0 1 2 * 2") # bad command? yes. this was d2
print("....")
sys.stdout.flush()
gnucap.command("myac 1 2 * 2")
gnucap.command("myac1 1 2 * 2")


print("done")

# gnucap.parse("myac 1 2 * 2")