Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

61

62

63

64

65

66

67

68

69

70

# Copyright (C) 2015 Chintalagiri Shashank 

# 

# This file is part of Tendril. 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU Affero General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 

# GNU Affero General Public License for more details. 

# 

# You should have received a copy of the GNU Affero General Public License 

# along with this program.  If not, see <http://www.gnu.org/licenses/>. 

""" 

This file is part of tendril 

See the COPYING, README, and INSTALL files for more information 

""" 

 

 

import os 

 

from crochet import setup 

setup() 

 

from twisted.internet.protocol import connectionDone  # noqa 

 

from tendril.utils.config import INSTANCE_ROOT 

from tendril.utils.fsutils import import_ 

 

 

INSTANCE_INSTRUMENTS_ROOT = os.path.join(INSTANCE_ROOT, 'instruments') 

INSTANCE_INSTRUMENTS = import_(INSTANCE_INSTRUMENTS_ROOT) 

 

instument_pool = {} 

 

 

def destroy_instrument(instst, instobj=None): 

    if instobj is None: 

        instument_pool.pop(instst) 

 

 

def get_instrument_object(instst, dedicated=False): 

    modname = instst 

    modstr = 'tendril.testing.instruments.' + modname 

    clsname = 'Instrument' + instst 

 

    if dedicated is False: 

        if modname in instument_pool.keys(): 

            if len(instument_pool[modname]) > 0: 

                return instument_pool[modname][0] 

 

    try: 

        instance = INSTANCE_INSTRUMENTS.get_test_object(instst) 

    except ValueError: 

        try: 

            mod = __import__(modstr, fromlist=[clsname]) 

            cls = getattr(mod, clsname) 

            instance = cls() 

        except ImportError: 

            raise ValueError("Instrument Unrecognized :" + instst) 

 

    if modname in instument_pool.keys(): 

        instument_pool[modname].append(instance) 

    else: 

        instument_pool[modname] = [instance] 

 

    return instance