Skip to content

Commit

Permalink
[celestica] consutil to support customize tty device name (#1155)
Browse files Browse the repository at this point in the history
* Update lib.py
* Keep the code format align see add spaces for special symbols
* remove unused code
  • Loading branch information
sandycelestica committed Oct 13, 2020
1 parent b6af9f4 commit 3a7457c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion consutil/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import re
import subprocess
import sys
import os
from swsssdk import ConfigDBConnector
from sonic_py_common import device_info
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))

Expand All @@ -27,6 +29,8 @@
FLOW_KEY = "flow_control"
DEFAULT_BAUD = "9600"

FILENAME = "udevprefix.conf"

# QUIET == True => picocom will not output any messages, and pexpect will wait for console
# switch login or command line to let user interact with shell
# Downside: if console switch output ever does not match DEV_READY_MSG, program will think connection failed
Expand All @@ -37,6 +41,15 @@
DEV_READY_MSG = r"([Ll]ogin:|[Pp]assword:|[$>#])" # login prompt or command line prompt
TIMEOUT_SEC = 0.2

platform_path, _ = device_info.get_paths_to_platform_and_hwsku_dirs()
PLUGIN_PATH = "/".join([platform_path, "plugins", FILENAME])

if os.path.exists(PLUGIN_PATH):
fp = open(PLUGIN_PATH, 'r')
line = fp.readlines()
DEVICE_PREFIX = "/dev/" + line[0]


# runs command, exit if stderr is written to, returns stdout otherwise
# input: cmd (str), output: output of cmd (str)
def run_command(cmd):
Expand Down Expand Up @@ -119,4 +132,4 @@ def getLine(target, deviceBool=False):
lineNumber = line[LINE_KEY]
targetLine = line

return targetLine if lineNumber else None
return targetLine if lineNumber else None

0 comments on commit 3a7457c

Please sign in to comment.