Skip to content

Commit

Permalink
Misc changes
Browse files Browse the repository at this point in the history
Signed-off-by: Qin Zhang (张琴) <qin.zhang@citrix.com>
  • Loading branch information
qinz0822 committed Oct 30, 2023
1 parent 9b8ba95 commit 29b1793
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion XSConsoleData.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def Match(self, inLine, inRegExp, inKey):
def MultipleMatch(self, inLine, inRegExp, inKey):
match = re.match(inRegExp, inLine)
if match:
if not self.data['dmi'].has_key(inKey):
if inKey not in self.data['dmi']:
self.data['dmi'][inKey] = []
self.data['dmi'][inKey].append(match.group(1))

Expand Down
2 changes: 1 addition & 1 deletion XSConsoleHotData.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __iter__(self):

# This method will hide fields called 'next' in the xapi database. If any appear, __iter__ will need to
# return a new object type and this method will need to be moved into that
def next(self):
def __next__(self):
if len(self.iterKeys) <= 0:
raise StopIteration
retVal = HotAccessor(self.name[:], self.refs[:]) # [:] copies the array
Expand Down
2 changes: 1 addition & 1 deletion XSConsoleMenus.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def Reset(self):
self.CurrentMenu().HandleEnter()

def AddChoice(self, inMenuName, inChoiceDef, inPriority = None):
if not self.menus.has_key(inMenuName):
if inMenuName not in self.menus:
raise Exception(Lang("Unknown menu '")+inMenuName+"'")

self.menus[inMenuName].AddChoiceDef(inChoiceDef, inPriority)
Expand Down
2 changes: 1 addition & 1 deletion XSConsoleState.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def SaveIfRequired(self):
self.MakeSane()
try:
if not os.path.isdir(self.savePath):
os.mkdir(self.savePath, 0700)
os.mkdir(self.savePath, 0o700)

saveFile = open(self.SaveFilename(), "w")
pickler = pickle.Pickler(saveFile)
Expand Down
33 changes: 17 additions & 16 deletions simpleconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,32 @@
import os
import shutil


# use our own ASCII only uppercase function to avoid locale issues
# not going to be fast but not important
def uppercase_ASCII_string(str):
newstr = ""
for i in range(0,len(str)):
if str[i] in string.lowercase:
newstr += chr(ord(str[i])-32)
else:
newstr += str[i]
for i in range(0, len(str)):
if str[i] in string.lowercase:
newstr += chr(ord(str[i]) - 32)
else:
newstr += str[i]

return newstr


class SimpleConfigFile:
def __str__ (self):
def __str__(self):
s = ""
keys = self.info.keys ()
keys.sort ()
keys = list(self.info.keys())
keys.sort()
for key in keys:
# FIXME - use proper escaping
if type (self.info[key]) == type(""):
if type(self.info[key]) == type(""):
s = s + key + "=\"" + self.info[key] + "\"\n"
return s

def __init__ (self):
def __init__(self):
self.info = {}

def write(self, file):
Expand Down Expand Up @@ -69,17 +71,17 @@ def read(self, file):
value = value.replace("'", '')
self.info[key] = value

def set (self, *args):
def set(self, *args):
for (key, data) in args:
self.info[uppercase_ASCII_string(key)] = data

def unset (self, *keys):
def unset(self, *keys):
for key in keys:
key = uppercase_ASCII_string(key)
if self.info.has_key (key):
del self.info[key]
if key in self.info:
del self.info[key]

def get (self, key):
def get(self, key):
key = uppercase_ASCII_string(key)
return self.info.get(key, "")

Expand Down Expand Up @@ -132,4 +134,3 @@ def write(self, dir=None):
path = os.path.join(dir, os.path.basename(self.path))

SimpleConfigFile.write(self, path)

0 comments on commit 29b1793

Please sign in to comment.