Skip to content

Commit

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

Convert renamePVList.py to python3
  • Loading branch information
jacomago authored Jan 9, 2025
2 parents 5e8960c + 3a14d89 commit 5ad587c
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions docs/docs/source/samples/renamePVList.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
'''Given a list of comma separated PVs, this renames all the PVs in the first column to the second column.
We assume that the PV's have been paused etc.
For example, generate a list like so
Expand All @@ -16,19 +16,18 @@
import sys
import argparse
import time
import urllib
import urllib2
import requests
import json
import datetime
import time

def renamePV(bplURL, oldName, newName):
'''Renames the pv oldName to newName'''
url = bplURL + '/renamePV?pv=' + urllib.quote_plus(oldName) + "&newname=" + urllib.quote_plus(newName)
req = urllib2.Request(url)
response = urllib2.urlopen(req)
the_page = response.read()
renamePVResponse = json.loads(the_page)
url = bplURL + '/renamePV'
params = {"pv" : oldName, "newname" : newName}
response = requests.get(url, params=params)
response.raise_for_status()
renamePVResponse = response.json()
return renamePVResponse


Expand All @@ -45,11 +44,11 @@ def renamePV(bplURL, oldName, newName):
line = line.strip()
parts = line.split(",")
if len(parts) != 2:
print "Skipping line", line
print("Skipping line", line)
continue
oldName = parts[0]
newName = parts[1]
oldName = parts[0].strip()
newName = parts[1].strip()
renameResponse = renamePV(args.url, oldName, newName)
print "{0} has been renamed to {1} with status {2}".format(oldName, newName, renameResponse['status'] if 'status' in renameResponse else "N/A")
print("{0} has been renamed to {1} with status {2}".format(oldName, newName, renameResponse['status'] if 'status' in renameResponse else "N/A"))
time.sleep(1.0)


0 comments on commit 5ad587c

Please sign in to comment.