Skip to content

Commit

Permalink
global: configure and run yapf
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Luebbe <[email protected]>
  • Loading branch information
jluebbe committed Dec 19, 2016
1 parent cacbce1 commit 56d5947
Show file tree
Hide file tree
Showing 37 changed files with 464 additions and 253 deletions.
12 changes: 8 additions & 4 deletions labgrid/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import yaml


def _dict_representer(dumper, data):
return dumper.represent_dict(data.items())

Expand All @@ -11,13 +12,16 @@ def _dict_constructor(loader, node):


yaml.add_representer(OrderedDict, _dict_representer)
yaml.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
_dict_constructor)
yaml.add_constructor(
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, _dict_constructor
)


def load_config(filename):
try:
with open(filename) as file:
return yaml.load(file)
except FileNotFoundError:
raise NoConfigFoundError("{} could not be found".format(self.config_file))

raise NoConfigFoundError(
"{} could not be found".format(self.config_file)
)
1 change: 0 additions & 1 deletion labgrid/driver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
from .externalconsoledriver import ExternalConsoleDriver
from .exception import NoDriverError, NoResourceError, CleanUpError
from .powerdriver import ManualPowerDriver, ExternalPowerDriver

10 changes: 7 additions & 3 deletions labgrid/driver/bareboxdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ class BareboxDriver(CommandProtocol, LinuxBootProtocol):

def __attrs_post_init__(self):
# FIXME: Hard coded for only one driver, should find the correct one in order
self.console = self.target.get_driver(ConsoleProtocol) #pylint: disable=no-member,attribute-defined-outside-init
self.console = self.target.get_driver(
ConsoleProtocol
) #pylint: disable=no-member,attribute-defined-outside-init
if not self.console:
raise NoDriverError("Target has no {} driver".format(ConsoleProtocol))
self.target.drivers.append(self) #pylint: disable=no-member
raise NoDriverError(
"Target has no {} driver".format(ConsoleProtocol)
)
self.target.drivers.append(self) #pylint: disable=no-member

def run(self, cmd):
pass
Expand Down
2 changes: 2 additions & 0 deletions labgrid/driver/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ class NoDriverError(Exception):
class NoResourceError(Exception):
msg = attr.ib(validator=attr.validators.instance_of(str))


@attr.s
class ExecutionError(Exception):
msg = attr.ib(validator=attr.validators.instance_of(str))


@attr.s
class CleanUpError(Exception):
msg = attr.ib(validator=attr.validators.instance_of(str))
13 changes: 5 additions & 8 deletions labgrid/driver/externalconsoledriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class ExternalConsoleDriver(ConsoleProtocol):
cmd = attr.ib(validator=attr.validators.instance_of(str))

def __attrs_post_init__(self):
self.target.drivers.append(self) #pylint: disable=no-member
self.status = 0 #pylint: disable=attribute-defined-outside-init
self.target.drivers.append(self) #pylint: disable=no-member
self.status = 0 #pylint: disable=attribute-defined-outside-init
self._child = None
self.open()

Expand All @@ -29,10 +29,9 @@ def open(self):
if self.status:
return
cmd = shlex.split(self.cmd)
self._child = subprocess.Popen(cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=None)
self._child = subprocess.Popen(
cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=None
)

# make stdout non-blocking
stdout_fd = self._child.stdout.fileno()
Expand Down Expand Up @@ -83,5 +82,3 @@ def write(self, data: bytes):
result = self._child.stdin.write(data)
self._child.stdin.flush()
return result


14 changes: 11 additions & 3 deletions labgrid/driver/powerdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ class ManualPowerDriver(PowerProtocol):
name = attr.ib(validator=attr.validators.instance_of(str))

def on(self):
input("Turn the target {name} ON and press enter".format(name=self.name))
input(
"Turn the target {name} ON and press enter".format(name=self.name)
)

def off(self):
input("Turn the target {name} OFF and press enter".format(name=self.name))
input(
"Turn the target {name} OFF and press enter".
format(name=self.name)
)

def cycle(self):
input("CYCLE the target {name} and press enter".format(name=self.name))
Expand All @@ -30,7 +35,10 @@ class ExternalPowerDriver(PowerProtocol):
target = attr.ib()
cmd_on = attr.ib(validator=attr.validators.instance_of(str))
cmd_off = attr.ib(validator=attr.validators.instance_of(str))
cmd_cycle = attr.ib(default=None, validator=attr.validators.optional(attr.validators.instance_of(str)))
cmd_cycle = attr.ib(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(str))
)
delay = attr.ib(default=1.0, validator=attr.validators.instance_of(float))

def on(self):
Expand Down
12 changes: 7 additions & 5 deletions labgrid/driver/serialdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ class SerialDriver(ConsoleProtocol):
target = attr.ib()

def __attrs_post_init__(self):
self.port = self.target.get_resource(SerialPort) #pylint: disable=no-member,attribute-defined-outside-init
self.port = self.target.get_resource(
SerialPort
) #pylint: disable=no-member,attribute-defined-outside-init
if not self.port:
raise NoResourceError("Target has no SerialPort Resource")
self.serial = serial.Serial() #pylint: disable=attribute-defined-outside-init
self.serial = serial.Serial(
) #pylint: disable=attribute-defined-outside-init
self.serial.port = self.port.port
self.serial.baudrate = self.port.speed
self.logger = logging.getLogger("{}({})".format(self, self.target))
self.status = 0 #pylint: disable=attribute-defined-outside-init
self.status = 0 #pylint: disable=attribute-defined-outside-init
self.serial.timeout = 30
self.open()
self.target.drivers.append(self) #pylint: disable=no-member

self.target.drivers.append(self) #pylint: disable=no-member

def read(self, size: int=1, timeout: int=0):
"""
Expand Down
33 changes: 22 additions & 11 deletions labgrid/driver/shelldriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,26 @@ class ShellDriver(CommandProtocol):
"""ShellDriver - Driver to execute commands on the shell"""
target = attr.ib()
prompt = attr.ib(default="", validator=attr.validators.instance_of(str))
login_prompt = attr.ib(default="", validator=attr.validators.instance_of(str))
login_prompt = attr.ib(
default="", validator=attr.validators.instance_of(str)
)

def __attrs_post_init__(self):
self.console = self.target.get_driver(ConsoleProtocol) #pylint: disable=no-member,attribute-defined-outside-init
self.console = self.target.get_driver(
ConsoleProtocol
) #pylint: disable=no-member,attribute-defined-outside-init
if not self.console:
raise NoDriverError("Resource has no {} Driver".format(ConsoleProtocol))
self.target.drivers.append(self) #pylint: disable=no-member
self.expect = PtxExpect(self.console) #pylint: disable=attribute-defined-outside-init
self.re_vt100 = re.compile('(\x1b\[|\x9b)[^@-_a-z]*[@-_a-z]|\x1b[@-_a-z]') #pylint: disable=attribute-defined-outside-init,anomalous-backslash-in-string
self._status = 0 #pylint: disable=attribute-defined-outside-init
raise NoDriverError(
"Resource has no {} Driver".format(ConsoleProtocol)
)
self.target.drivers.append(self) #pylint: disable=no-member
self.expect = PtxExpect(
self.console
) #pylint: disable=attribute-defined-outside-init
self.re_vt100 = re.compile(
'(\x1b\[|\x9b)[^@-_a-z]*[@-_a-z]|\x1b[@-_a-z]'
) #pylint: disable=attribute-defined-outside-init,anomalous-backslash-in-string
self._status = 0 #pylint: disable=attribute-defined-outside-init
self._check_prompt()
self._inject_run()

Expand All @@ -41,13 +51,14 @@ def run(self, cmd):
self.expect.sendline(cmp_command)
self.expect.expect(self.prompt)
# Remove VT100 Codes and split by newline
data = self.re_vt100.sub('', self.expect.before.decode('utf-8'),
count=1000000).split('\r\n')
data = self.re_vt100.sub(
'', self.expect.before.decode('utf-8'), count=1000000
).split('\r\n')
# Remove first element, the invoked cmd
data.remove(cmp_command)
del(data[-1])
del (data[-1])
exitcode = int(data[-1])
del(data[-1])
del (data[-1])
return (data, [], exitcode)
else:
return None
Expand Down
Loading

0 comments on commit 56d5947

Please sign in to comment.