Skip to content

Commit

Permalink
Merge pull request #312 from wanglin86769/convert-printCurrentlyDisco…
Browse files Browse the repository at this point in the history
…nnectedPVs.py-to-python3

Convert printCurrentlyDisconnectedPVs.py to python3
  • Loading branch information
jacomago authored Jan 8, 2025
2 parents 908fb07 + 56dc58c commit 8054d98
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions docs/docs/source/samples/printCurrentlyDisconnectedPVs.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
#!/usr/bin/env python
#!/usr/bin/env python3
'''This script gets a list of PVS that are currently disconnected and then prints them out by appliance'''

import os
import sys
import argparse
import time
import urllib
import urllib2
import requests
import json
import datetime
import time

def getCurrentlyDisconnectedPVs(bplURL):
'''Get a list of PVs that are currently disconnected'''
url = bplURL + '/getCurrentlyDisconnectedPVs'
req = urllib2.Request(url)
response = urllib2.urlopen(req)
the_page = response.read()
currentlyDisconnectedPVs = json.loads(the_page)
resp = requests.get(url)
resp.raise_for_status()
currentlyDisconnectedPVs = resp.json()
return currentlyDisconnectedPVs

def printByAppliance(currentlyDisconnectedPVs):
Expand All @@ -30,11 +28,11 @@ def printByAppliance(currentlyDisconnectedPVs):
instance2pv2info[appliance] = {}
instance2pv2info[appliance][currentlyDisconnectedPV['pvName']] = currentlyDisconnectedPV

for appliance in sorted(sorted(instance2pv2info)):
print "Appliance {0}:".format(appliance);
for appliance in sorted(instance2pv2info):
print("Appliance {0}:".format(appliance))
pvsInAppliance = instance2pv2info[appliance]
for pv in sorted(pvsInAppliance):
print "{0} {1}".format(pv, pvsInAppliance[pv]['connectionLostAt'])
print("{0} {1}".format(pv, pvsInAppliance[pv]['connectionLostAt']))

if __name__ == "__main__":
parser = argparse.ArgumentParser()
Expand All @@ -43,14 +41,14 @@ def printByAppliance(currentlyDisconnectedPVs):
parser.add_argument("--noNA", action='store_true', help="Print only those PVs for whom the connection lost is not N/A.")
args = parser.parse_args()
if not args.url.endswith('bpl'):
print "The URL needs to point to the mgmt bpl; for example, http://arch.slac.stanford.edu/mgmt/bpl. ", args.url
print("The URL needs to point to the mgmt bpl; for example, http://arch.slac.stanford.edu/mgmt/bpl. ", args.url)
sys.exit(1)
currentlyDisconnectedPVs = getCurrentlyDisconnectedPVs(args.url)
if args.onlyNA:
printByAppliance(filter(lambda x : x['connectionLostAt'] == 'N/A', currentlyDisconnectedPVs))
printByAppliance([x for x in currentlyDisconnectedPVs if x['connectionLostAt'] == 'N/A'])
elif args.noNA:
printByAppliance(filter(lambda x : x['connectionLostAt'] != 'N/A', currentlyDisconnectedPVs))
printByAppliance([x for x in currentlyDisconnectedPVs if x['connectionLostAt'] != 'N/A'])
else:
printByAppliance(currentlyDisconnectedPVs)



0 comments on commit 8054d98

Please sign in to comment.