replace file with open
Under python 3 the builtin 'file' no longer exists, so replace it with 'open' which works for both python 2 and 3. Change-Id: Iaf438588e4bfab2833f92de0b31b0a9cfd14e597 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
48a402de4a
commit
b41978a287
|
@ -78,9 +78,9 @@ class Daemon(object):
|
|||
# redirect standard file descriptors
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
si = file(self.stdin, 'r')
|
||||
so = file(self.stdout, 'a+')
|
||||
se = file(self.stderr, 'a+', 0)
|
||||
si = open(self.stdin, 'r')
|
||||
so = open(self.stdout, 'a+')
|
||||
se = open(self.stderr, 'a+', 0)
|
||||
os.dup2(si.fileno(), sys.stdin.fileno())
|
||||
os.dup2(so.fileno(), sys.stdout.fileno())
|
||||
os.dup2(se.fileno(), sys.stderr.fileno())
|
||||
|
@ -89,7 +89,7 @@ class Daemon(object):
|
|||
atexit.register(self.delpid)
|
||||
|
||||
pid = str(os.getpid())
|
||||
f = file(self.pidfile, 'w+')
|
||||
f = open(self.pidfile, 'w+')
|
||||
f.write("%s\n" % pid)
|
||||
f.close()
|
||||
|
||||
|
@ -102,7 +102,7 @@ class Daemon(object):
|
|||
log.error("Test")
|
||||
# Check for a pidfile to see if the daemon already runs
|
||||
try:
|
||||
pf = file(self.pidfile, 'r')
|
||||
pf = open(self.pidfile, 'r')
|
||||
pid = int(pf.read().strip())
|
||||
pf.close()
|
||||
except IOError:
|
||||
|
@ -124,7 +124,7 @@ class Daemon(object):
|
|||
def status(self):
|
||||
"""Check daemon status."""
|
||||
try:
|
||||
pf = file(self.pidfile, 'r')
|
||||
pf = open(self.pidfile, 'r')
|
||||
pid = int(pf.read().strip())
|
||||
pf.close()
|
||||
except IOError:
|
||||
|
@ -144,7 +144,7 @@ class Daemon(object):
|
|||
"""Stop the daemon."""
|
||||
# Get the pid from the pidfile
|
||||
try:
|
||||
pf = file(self.pidfile, 'r')
|
||||
pf = open(self.pidfile, 'r')
|
||||
pid = int(pf.read().strip())
|
||||
pf.close()
|
||||
except IOError:
|
||||
|
|
|
@ -36,7 +36,7 @@ class YamlParser(object):
|
|||
if not os.path.exists(self.file) or not os.path.isfile(self.file):
|
||||
raise Exception('File desnot exists')
|
||||
|
||||
stream = file(self.file, 'r')
|
||||
stream = open(self.file, 'r')
|
||||
data = yaml.load(stream)
|
||||
return data
|
||||
|
||||
|
|
Loading…
Reference in New Issue