-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModem.py
89 lines (75 loc) · 2.79 KB
/
Modem.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import time
import sys,os,re
import glob
from datetime import datetime
count =0
class ModemCommand():
def __init__(self):
"""ModemVailList is support model list
ModemConfList is the conf file for support command list
ChooseModem is choosen modem to use
"""
#self.ModemVailList = []
self.ModemConfList = {}
self.ChooseModem = None
#self.GetModemList()
self.TAGList=[]
self.CommandList={}
self.CommandResultList={}
def GetModemList(self):
"""Return support modem
"""
for company in os.listdir('.//Modem'):
print company
for modem in os.listdir('.//Modem//'+company):
print modem
modemName = modem.split('.')
#self.ModemVailList.append(company+" "+modemName[0])
self.ModemConfList[company+" "+modemName[0]] = ".//Modem//"+company+"//"+modem
print self.ModemConfList.keys()
return self.ModemConfList.keys()
def GetModemName(self):
"""return choosen modem name
"""
return self.ChooseModem
def SetChooseModem(self,modem):
"""set modem to use
"""
self.ChooseModem = modem
self.TAGList[:]=[]
self.CommandList.clear()
self.GetModemCommandList(self.ModemConfList[self.ChooseModem])
return self.CommandList
# def GetModemCommandList(self):
# """Return available modem command
# """
# with open(self.ModemConfList[self.ChooseModem]) as f:
# CommandList = f.read().splitlines()
# return CommandList
def GetCommandResultList(self):
"""Get the choose modem's command result list
"""
return self.CommandResultList
def GetModemCommandList(self,FilePath):
"""Get the modem command list from the conf
"""
with open(FilePath) as file:
for line in file.readlines():
line = line.strip()
line = line.split(' ')
print line
if len(line) == 1 or line[0].startswith("#"):
#is comment
continue
command = line[0]
response = line[1]#.split(",")
response = re.split(r'[,\n]',response)
response = filter(None, response)#remove empty string
if command == "TAG":
#list = response.split(',')
for value in response:
self.TAGList.append(value)
else:
self.CommandList[command]=response
self.CommandResultList[response[0]]=response[1:]
print self.CommandList, self.CommandResultList