Changed fstrings to % formatting

This commit is contained in:
Logan Lipke
2020-06-04 13:58:59 -07:00
parent 29c18611da
commit 80082e85b1
5 changed files with 53 additions and 53 deletions

View File

@@ -40,13 +40,13 @@ for file in searchResults:
if ver == file[1]:
webFiles.append({'filename':file[0], 'timestamp': datetime.datetime.strptime(file[2], "%Y-%m-%d %H:%M")})
if len(webFiles) == 0:
print(f"Failed to find webfile with version number {ver}")
print("Failed to find webfile with version number %s" % (ver))
sys.exit(1)
#=========CHECK DIR FOR FILES=============
filePath = f"/home/lanforge/Downloads/"
dir = glob.glob(filePath + f"LANforgeGUI_{ver}*")
filePath = "/home/lanforge/Downloads/"
dir = glob.glob(filePath + "LANforgeGUI_%s*" % ver)
dirFiles = []
for file in dir:
@@ -55,7 +55,7 @@ for file in dir:
dirFiles.append({'filename':file[25:], 'timestamp':fileTime})
if len(dirFiles) == 0:
print(f"Unable to find file in {filePath} with version {ver}")
print("Unable to find file in {filePath} with version %s" % ver)
#sys.exit(1)
#============FIND NEWEST FILES============
@@ -79,46 +79,46 @@ else:
if newestWebFile['timestamp'] > newestDirFile['timestamp']:
try:
if newestDirFile['filename'] != 'placeholder':
subprocess.call(["rm", f"{filePath}{newestDirFile['filename']}"])
subprocess.call(["rm", "%s%s" % (filePath, newestDirFile['filename'])])
print("No file found")
print(f"Downloading newest {newestWebFile['filename']} from {url}")
print("Downloading newest %s from %s" % (newestWebFile['filename'], url))
else:
print("Found newer version of GUI")
print(f"Downloading {newestWebFile['filename']} from {url}")
print("Downloading %s from %s" % (newestWebFile['filename'], url))
#=====ATTEMPT DOWNLOAD AND INSTALL=========
subprocess.call(["curl", "-o", f"{filePath}{newestWebFile['filename']}", f"{url}{newestWebFile['filename']}"])
subprocess.call(["curl", "-o", "%s%s" % (filePath, newestWebFile['filename']), "%s%s" % (url, newestWebFile['filename'])])
time.sleep(5)
except Exception as e:
print(f"{e} Download failed. Please try again.")
print("%s Download failed. Please try again." % e)
sys.exit(1)
try:
print("Attempting to extract files")
subprocess.call(["tar", "-xf", f"{filePath}{newestWebFile['filename']}", "-C", "/home/lanforge/"])
subprocess.call(["tar", "-xf", "%s%s" % (filePath, newestWebFile['filename']), "-C", "/home/lanforge/"])
except Exception as e:
print(f"{e}\nExtraction failed. Please try again")
print("%s\nExtraction failed. Please try again" % e)
sys.exit(1)
#time.sleep(90)
try:
if "/home/lanforge/.config/autostart/LANforge-auto.desktop" not in glob.glob("/home/lanforge/.config/autostart/*"):
print("Copying LANforge-auto.desktop to /home/lanforge/.config/autostart/")
subprocess.call(["cp", f"/home/lanforge/{newestWebFile['filename'][:len(newestWebFile)-18]}/LANforge-auto.desktop", "/home/lanforge/.config/autostart/"])
subprocess.call(["cp", "/home/lanforge/%s/LANforge-auto.desktop" % (newestWebFile['filename'][:len(newestWebFile)-18]), "/home/lanforge/.config/autostart/"])
except Exception as e:
print(f"{e}\nCopy failed. Please try again")
print("%s\nCopy failed. Please try again" % e)
sys.exit(1)
try:
print(f"Attempting to install {newestWebFile['filename']} at /home/lanforge")
os.system(f"cd /home/lanforge/{newestWebFile['filename'][:len(newestWebFile)-18]}; sudo bash lfgui_install.bash")
print("Attempting to install %s at /home/lanforge" % newestWebFile['filename'])
os.system("cd /home/lanforge/%s; sudo bash lfgui_install.bash" % (newestWebFile['filename'][:len(newestWebFile)-18]))
except Exception as e:
print(f"{e}\nInstallation failed. Please Try again.")
print("%s\nInstallation failed. Please Try again." % e)
sys.exit(1)
#=========ATTEMPT TO RESTART GUI==========
# try:
# print("Killing current GUI process")
# os.system("if pgrep java; then pgrep java | xargs kill -9 ;fi")
# except Exception as e:
# print(f"{e}\nProcess kill failed. Please try again")
# print("%s\nProcess kill failed. Please try again" % e)
# sys.exit(1)
else:

View File

@@ -25,11 +25,11 @@ class ConnectTest(LFCliBase):
# compare pre-test values to post-test values
@staticmethod
def CompareVals(_name, preVal, postVal):
print(f"Comparing {_name}")
print("Comparing %s" % _name)
if postVal > preVal:
print(" Test Passed")
else:
print(f" Test Failed: {_name} did not increase after 5 seconds")
print(" Test Failed: %s did not increase after 5 seconds" % _name)
def run(self):
print("See home/lanforge/Documents/connectTestLogs/connectTestLatest for specific values on latest test")
@@ -108,10 +108,10 @@ class ConnectTest(LFCliBase):
print("Creating endpoints and cross connects")
# create cx for tcp and udp
cmd = (
f"./lf_firemod.pl --action create_cx --cx_name testTCP --use_ports {staName},eth1 --use_speeds 360000,150000 --endp_type tcp > ~/Documents/connectTestLogs/connectTestLatest.log")
"./lf_firemod.pl --action create_cx --cx_name testTCP --use_ports %s,eth1 --use_speeds 360000,150000 --endp_type tcp > ~/Documents/connectTestLogs/connectTestLatest.log" % staName)
execWrap(cmd)
cmd = (
f"./lf_firemod.pl --action create_cx --cx_name testUDP --use_ports {staName},eth1 --use_speeds 360000,150000 --endp_type udp >> ~/Documents/connectTestLogs/connectTestLatest.log")
"./lf_firemod.pl --action create_cx --cx_name testUDP --use_ports %s,eth1 --use_speeds 360000,150000 --endp_type udp >> ~/Documents/connectTestLogs/connectTestLatest.log" % staName)
execWrap(cmd)
time.sleep(.05)
@@ -172,7 +172,7 @@ class ConnectTest(LFCliBase):
genl.setFlags("genTest1", "ClearPortOnStart", 1)
genl.setFlags("genTest2", "ClearPortOnStart", 1)
genl.setFlags("genTest2", "Unmanaged", 1)
genl.setCmd("genTest1", f"lfping -i 0.1 -I {staName} 10.40.0.1")
genl.setCmd("genTest1", "lfping -i 0.1 -I %s 10.40.0.1" % staName)
time.sleep(.05)
# create generic cx
@@ -276,7 +276,7 @@ class ConnectTest(LFCliBase):
for name in get_info:
if 'endpoint' not in name:
print(get_info[name])
raise ValueError (f"{name} missing endpoint value")
raise ValueError ("%s missing endpoint value" % name)
testTCPATX = get_info['testTCPA']['endpoint']['tx bytes']
testTCPARX = get_info['testTCPA']['endpoint']['rx bytes']
@@ -315,7 +315,7 @@ class ConnectTest(LFCliBase):
print("\nStarting CX Traffic")
for name in range(len(cxNames)):
cmd = (
f"./lf_firemod.pl --mgr localhost --quiet yes --action do_cmd --cmd \"set_cx_state default_tm {cxNames[name]} RUNNING\" >> /tmp/connectTest.log")
"./lf_firemod.pl --mgr localhost --quiet yes --action do_cmd --cmd \"set_cx_state default_tm %s RUNNING\" >> /tmp/connectTest.log" % (cxNames[name]))
execWrap(cmd)
# print("Sleeping for 5 seconds")
@@ -327,9 +327,9 @@ class ConnectTest(LFCliBase):
cmd = (
"./lf_portmod.pl --quiet 1 --manager localhost --port_name eth1 --show_port \"Txb,Rxb\" >> ~/Documents/connectTestLogs/connectTestLatest.log")
execWrap(cmd)
os.system(f"echo {staName} >> ~/Documents/connectTestLogs/connectTestLatest.log")
os.system("echo %s >> ~/Documents/connectTestLogs/connectTestLatest.log" % staName)
cmd = (
f"./lf_portmod.pl --quiet 1 --manager localhost --port_name {staName} --show_port \"Txb,Rxb\" >> ~/Documents/connectTestLogs/connectTestLatest.log")
"./lf_portmod.pl --quiet 1 --manager localhost --port_name %s --show_port \"Txb,Rxb\" >> ~/Documents/connectTestLogs/connectTestLatest.log" % staName)
execWrap(cmd)
# show tx and rx for endpoints PERL
@@ -374,7 +374,7 @@ class ConnectTest(LFCliBase):
print("Stopping CX Traffic")
for name in range(len(cxNames)):
cmd = (
f"./lf_firemod.pl --mgr localhost --quiet yes --action do_cmd --cmd \"set_cx_state default_tm {cxNames[name]} STOPPED\" >> /tmp/connectTest.log")
"./lf_firemod.pl --mgr localhost --quiet yes --action do_cmd --cmd \"set_cx_state default_tm %s STOPPED\" >> /tmp/connectTest.log" % (cxNames[name]))
execWrap(cmd)
# print("Sleeping for 15 seconds")
time.sleep(15)

View File

@@ -241,7 +241,7 @@ def findPortEids(resource_id=1, base_url="http://localhost:8080", port_names=(),
if base_url.endswith('/'):
port_url = port_url[1:]
for port_name in port_names:
url = f"{port_url}/{resource_id}/{port_name}"
url = "%s/%s/%s" % (port_url, resource_id, port_name)
lf_r = LFRequest.LFRequest(url)
try:
response = lf_r.getAsJson(debug)
@@ -263,11 +263,11 @@ def waitUntilPortsAdminDown(resource_id=1, base_url="http://localhost:8080", por
while len(up_stations) > 0:
up_stations = []
for port_name in port_list:
url = f"{base_url}{port_url}/{resource_id}/{port_name}?fields=device,down"
url = "%s%s/%s/%s?fields=device,down" % (base_url, port_url, resource_id, port_name)
lf_r = LFRequest.LFRequest(url)
json_response = lf_r.getAsJson(show_error=False)
if json_response == None:
print(f"port {port_name} disappeared")
print("port %s disappeared" % port_name)
continue
if "interface" in json_response:
json_response = json_response['interface']
@@ -288,7 +288,7 @@ def waitUntilPortsAdminUp(resource_id=1, base_url="http://localhost:8080", port_
while len(down_stations) > 0:
down_stations = []
for port_name in port_list:
url = f"{base_url}{port_url}/{resource_id}/{port_name}?fields=device,down"
url = "%s%s/%s/%s?fields=device,down" % (base_url, port_url, resource_id, port_name)
lf_r = LFRequest.LFRequest(url)
json_response = lf_r.getAsJson(show_error=False)
if json_response == None:
@@ -314,7 +314,7 @@ def waitUntilPortsDisappear(resource_id=1, base_url="http://localhost:8080", por
found_stations = []
sleep(1)
for port_name in port_list:
check_url = f"{base_url}{url}/{resource_id}/{port_name}"
check_url = "%s%s/%s/%s" % (base_url, url, resource_id, port_name)
if debug:
print("checking:"+check_url)
lf_r = LFRequest.LFRequest(check_url)
@@ -339,13 +339,13 @@ def waitUntilPortsAppear(resource_id=1, base_url="http://localhost:8080", port_l
found_stations = []
for port_name in port_list:
sleep(1)
url = f"{base_url}{port_url}/{resource_id}/{port_name}"
url = "%s/%s/%s" % (base_url, port_url, resource_id, port_name)
lf_r = LFRequest.LFRequest(url)
json_response = lf_r.getAsJson(show_error=False)
if (json_response != None):
found_stations.append(port_name)
else:
lf_r = LFRequest.LFRequest(f"{base_url}{ncshow_url}")
lf_r = LFRequest.LFRequest("%s%s" % (base_url, ncshow_url))
lf_r.addPostData({"shelf": 1, "resource": resource_id, "port": port_name, "flags": 1})
lf_r.formPost()
sleep(2)

View File

@@ -13,7 +13,7 @@ from LANforge.lfcli_base import LFCliBase
class Realm(LFCliBase):
def __init__(self, lfclient_host="localhost", lfclient_port=8080, debug=False):
super().__init__(lfclient_host, lfclient_port, debug, _halt_on_error=True)
self.lfclient_url = f"http://{lfclient_host}:{lfclient_port}"
self.lfclient_url = "http://%s:%s" % (lfclient_host, lfclient_port)
super().check_connect()
@@ -69,14 +69,14 @@ class Realm(LFCliBase):
# removes port by eid/eidpn
def removeVlanByEid(self, eid):
if (eid is None) or ("" == eid):
raise ValueError(f"removeVlanByEid wants eid like 1.1.sta0 but given[{eid}]")
raise ValueError("removeVlanByEid wants eid like 1.1.sta0 but given[%s]" % eid)
hunks = eid.split('.')
#print("- - - - - - - - - - - - - - - - -")
#pprint(hunks)
#pprint(self.lfclient_url)
#print("- - - - - - - - - - - - - - - - -")
if (len(hunks) > 3) or (len(hunks) < 2):
raise ValueError(f"removeVlanByEid wants eid like 1.1.sta0 but given[{eid}]")
raise ValueError("removeVlanByEid wants eid like 1.1.sta0 but given[%s]" % eid)
elif len(hunks) == 3:
LFUtils.removePort(hunks[1], hunks[2], self.lfclient_url)
else:
@@ -130,7 +130,7 @@ class Realm(LFCliBase):
if port_eid.find(prefix) >= 0:
port_suf = record["device"][len(prefix):]
if (port_suf >= match.group(2)) and (port_suf <= match.group(3)):
#print(f"{port_name}: suffix[{port_name}] between {match.group(2)}:{match.group(3)}")
#print("%s: suffix[%s] between %s:%s" % (port_name, port_name, match.group(2), match.group(3))
matched_map[port_eid] = record
except ValueError as e:
super().error(e)
@@ -147,7 +147,7 @@ class Realm(LFCliBase):
class CXProfile:
def __init__(self, lfclient_host, lfclient_port, debug=False):
self.lfclient_url = f"http://{lfclient_host}:{lfclient_port}/"
self.lfclient_url = "http://%s:%s/" % (lfclient_host, lfclient_port)
self.debug = debug
self.post_data = []
@@ -281,7 +281,7 @@ class StationProfile:
if (param_name is None) or (param_name == ""):
return
if command_name not in self.COMMANDS:
super().error(f"Command name name [{command_name}] not defined in {self.COMMANDS}")
super().error("Command name name [%s] not defined in %s" % (command_name, self.COMMANDS))
return
if command_name == "add_sta":
self.add_sta_data[param_name] = param_value
@@ -295,11 +295,11 @@ class StationProfile:
if (param_name is None) or (param_name == ""):
return
if command_name not in self.COMMANDS:
print(f"Command name name [{command_name}] not defined in {self.COMMANDS}")
print("Command name name [%s] not defined in %s" % (command_name, self.COMMANDS))
return
if command_name == "add_sta":
if (param_name not in add_sta.add_sta_flags) and (param_name not in add_sta.add_sta_modes):
print(f"Parameter name [{param_name}] not defined in add_sta.py")
print("Parameter name [%s] not defined in add_sta.py" % param_name)
if self.debug:
pprint(add_sta.add_sta_flags)
return
@@ -310,7 +310,7 @@ class StationProfile:
elif command_name == "set_port":
if (param_name not in set_port.set_port_current_flags) and (param_name not in set_port.set_port_cmd_flags):
print(f"Parameter name [{param_name}] not defined in set_port.py")
print("Parameter name [%s] not defined in set_port.py" % param_name)
if self.debug:
pprint(set_port.set_port_cmd_flags)
pprint(set_port.set_port_current_flags)
@@ -353,10 +353,10 @@ class StationProfile:
v = int(self.prefix, 10)
if v > 0:
num += v
template = f"sta%0{wd}d"
template = "sta%0%sd" % wd
name = template % num
#if self.debug:
# print(f"XXXXXXXXXXX {name} XXXXXXXXXXXXXXX")
# print("XXXXXXXXXXX %s XXXXXXXXXXXXXXX" % name)
return name
# Checks for errors in initialization values and creates specified number of stations using init parameters
@@ -366,7 +366,7 @@ class StationProfile:
# name = resource_radio[resource_radio.index(".") + 1:]
# if name.index(".") >= 0:
# radio_name = name[name.index(".")+1 : ]
# print(f"Building {num_stations} on radio {resource}.{radio_name}")
# print("Building %s on radio %s.%s" % (num_stations, resource, radio_name))
# except ValueError as e:
# print(e)
@@ -387,7 +387,7 @@ class StationProfile:
self.set_port_data["port"] = sta_name
sta_names.append(sta_name)
if debug:
print(f"- 381 - {sta_name}- - - - - - - - - - - - - - - - - - ")
print("- 381 - %s- - - - - - - - - - - - - - - - - - "% sta_name)
pprint(self.add_sta_data)
pprint(self.set_port_data)
print("- ~381 - - - - - - - - - - - - - - - - - - - ")
@@ -410,6 +410,6 @@ class StationProfile:
json_response = set_port_r.jsonPost(debug)
time.sleep(0.03)
print(f"created {num} stations")
print("created %s stations" % num)
#

View File

@@ -12,11 +12,11 @@ localrealm = Realm("localhost", 8080, True)
print("** Existing Stations **")
try:
sta_list = localrealm.station_list()
print(f"\n{len(sta_list)} Station List:")
print("\n%s Station List:" % len(sta_list))
print(sta_list)
del sta_list
sta_map = localrealm.station_map()
print(f"\n{len(sta_map)} Station Map:")
print("\n Station Map:" % len(sta_map))
print(sta_map)
del sta_map
print("\n Stations like wlan+:")
@@ -60,7 +60,7 @@ profile.build(1, "wiphy0", 5)
try:
sta_list = localrealm.station_list()
print(f"{len(sta_list)} Stations:")
print("%s Stations:" % {len(sta_list)})
pprint(sta_list)
print(" Stations like sta+:")
print(localrealm.find_ports_like("wlan+"))
@@ -78,7 +78,7 @@ exit(0)
print("** Existing vAPs **")
try:
vap_list = localrealm.vap_list()
print(f"{len(vap_list)} VAPs:")
print("%s VAPs:" % len(vap_list))
pprint(vap_list)
except Exception as x:
localrealm.error(x)
@@ -87,7 +87,7 @@ except Exception as x:
print("** Existing CXs **")
try:
cx_list = localrealm.cx_list()
print(f"{len(cx_list)} CXs:")
print("%s CXs:" % len(cx_list))
pprint(cx_list)
except Exception as x:
localrealm.error(x)