aboutsummaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/core/target/base.py
blob: c886491360678132969f19bb8f2b083c986fc25a (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
52
53
54
55
56
# Copyright (C) 2016 Intel Corporation
# Released under the MIT license (see COPYING.MIT)
import os
import sys
import importlib

from abc import abstractmethod

# Used to keep record of registered targets, it
# uses class' targetName as the key to the class.
targetClasses = {}

def registerTarget(obj):
    """ Use as decorator to register targets for runtime testing """

    if (obj.targetName in targetClasses and
        obj.__name__ != targetClasses[obj.targetName].__name__):

        msg = ('Tried to register %s as "%s" that is used by %s' %
               (obj, obj.targetName, targetClasses[obj.targetName]))
        raise ImportError(msg)

    if not issubclass(obj, OETarget):
        raise TypeError('%s must inherit from OETarget' % obj)

    targetClasses[obj.targetName] = obj
    return obj

class OETarget(object):

    def __init__(self, logger, *args, **kwargs):
        self.logger = logger

    @abstractmethod
    def start(self):
        pass

    @abstractmethod
    def stop(self):
        pass

    @abstractmethod
    def run(self, cmd, timeout=None):
        pass

    @abstractmethod
    def copyTo(self, localSrc, remoteDst):
        pass

    @abstractmethod
    def copyFrom(self, remoteSrc, localDst):
        pass

    @abstractmethod
    def copyDirTo(self, localSrc, remoteDst):
        pass