projects
/
mudpy.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Accumulate logs if necessary while loading data
[mudpy.git]
/
lib
/
mudpy
/
data.py
diff --git
a/lib/mudpy/data.py
b/lib/mudpy/data.py
index
b7d173b
..
f254dc6
100644
(file)
--- a/
lib/mudpy/data.py
+++ b/
lib/mudpy/data.py
@@
-1,11
+1,9
@@
-# -*- coding: utf-8 -*-
"""Data interface functions for the mudpy engine."""
"""Data interface functions for the mudpy engine."""
-# Copyright (c) 2004-201
4
Jeremy Stanley <fungi@yuggoth.org>. Permission
+# Copyright (c) 2004-201
5
Jeremy Stanley <fungi@yuggoth.org>. Permission
# to use, copy, modify, and distribute this software is granted under
# terms provided in the LICENSE file distributed with this software.
# to use, copy, modify, and distribute this software is granted under
# terms provided in the LICENSE file distributed with this software.
-import codecs
import os
import re
import stat
import os
import re
import stat
@@
-31,11
+29,12
@@
class DataFile:
self.data = yaml.load(open(self.filename))
except FileNotFoundError:
# it's normal if the file is one which doesn't exist yet
self.data = yaml.load(open(self.filename))
except FileNotFoundError:
# it's normal if the file is one which doesn't exist yet
+ log_entry = ("File %s is unavailable." % self.filename, 6)
try:
try:
- mudpy.misc.log(
"Couldn't read %s file." % self.filename, 6
)
+ mudpy.misc.log(
*log_entry
)
except NameError:
# happens when we're not far enough along in the init process
except NameError:
# happens when we're not far enough along in the init process
- pass
+ self.universe.setup_loglines.append(log_entry)
if not hasattr(self.universe, "files"):
self.universe.files = {}
self.universe.files[self.filename] = self
if not hasattr(self.universe, "files"):
self.universe.files = {}
self.universe.files[self.filename] = self
@@
-133,19
+132,19
@@
class DataFile:
backups.reverse()
for old_backup in backups:
if old_backup >= max_count - 1:
backups.reverse()
for old_backup in backups:
if old_backup >= max_count - 1:
- os.remove(self.filename + "." +
old_backup
)
+ os.remove(self.filename + "." +
str(old_backup)
)
elif not os.path.exists(
elif not os.path.exists(
- self.filename + "." +
old_backup + 1
+ self.filename + "." +
str(old_backup + 1)
):
os.rename(
):
os.rename(
- self.filename + "." +
old_backup
,
- self.filename + "." +
old_backup + 1
+ self.filename + "." +
str(old_backup)
,
+ self.filename + "." +
str(old_backup + 1)
)
if not os.path.exists(self.filename + ".0"):
os.rename(self.filename, self.filename + ".0")
# our data file
)
if not os.path.exists(self.filename + ".0"):
os.rename(self.filename, self.filename + ".0")
# our data file
- file_descriptor =
codecs.open(self.filename, "w", "utf-8
")
+ file_descriptor =
open(self.filename, "w
")
# if it's marked private, chmod it appropriately
if self.filename in self.universe.private_files and oct(
# if it's marked private, chmod it appropriately
if self.filename in self.universe.private_files and oct(
@@
-153,9
+152,9
@@
class DataFile:
) != 0o0600:
os.chmod(self.filename, 0o0600)
) != 0o0600:
os.chmod(self.filename, 0o0600)
- # write
, flush
and close the file
- file_descriptor.write(yaml.dump(self.data))
-
file_descriptor.flush(
)
+ # write and close the file
+ yaml.dump(self.data, allow_unicode=True, default_flow_style=False,
+
stream=file_descriptor
)
file_descriptor.close()
# unset the modified flag
file_descriptor.close()
# unset the modified flag