summaryrefslogtreecommitdiff
path: root/cloudinit/cs_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/cs_utils.py')
-rw-r--r--cloudinit/cs_utils.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/cloudinit/cs_utils.py b/cloudinit/cs_utils.py
index 8bac9c44..6db7e117 100644
--- a/cloudinit/cs_utils.py
+++ b/cloudinit/cs_utils.py
@@ -24,14 +24,13 @@ import platform
from cloudinit import serial
-
# these high timeouts are necessary as read may read a lot of data.
READ_TIMEOUT = 60
WRITE_TIMEOUT = 10
-SERIAL_PORT = '/dev/ttyS1'
-if platform.system() == 'Windows':
- SERIAL_PORT = 'COM2'
+SERIAL_PORT = "/dev/ttyS1"
+if platform.system() == "Windows":
+ SERIAL_PORT = "COM2"
class Cepko(object):
@@ -39,6 +38,7 @@ class Cepko(object):
One instance of that object could be use for one or more
queries to the serial port.
"""
+
request_pattern = "<\n{}\n>"
def get(self, key="", request_pattern=None):
@@ -64,17 +64,18 @@ class CepkoResult(object):
as the instance is initialized and stores the result in both raw and
marshalled format.
"""
+
def __init__(self, request):
self.request = request
self.raw_result = self._execute()
self.result = self._marshal(self.raw_result)
def _execute(self):
- connection = serial.Serial(port=SERIAL_PORT,
- timeout=READ_TIMEOUT,
- writeTimeout=WRITE_TIMEOUT)
- connection.write(self.request.encode('ascii'))
- return connection.readline().strip(b'\x04\n').decode('ascii')
+ connection = serial.Serial(
+ port=SERIAL_PORT, timeout=READ_TIMEOUT, writeTimeout=WRITE_TIMEOUT
+ )
+ connection.write(self.request.encode("ascii"))
+ return connection.readline().strip(b"\x04\n").decode("ascii")
def _marshal(self, raw_result):
try:
@@ -94,4 +95,5 @@ class CepkoResult(object):
def __iter__(self):
return self.result.__iter__()
+
# vi: ts=4 expandtab