X-Git-Url: https://mudpy.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=mudpy%2Fdata.py;h=eeea8fb9530e1b07f41678f2177e03038c7e4f13;hb=refs%2Fheads%2Fmaster;hp=25b423b66e2cc3fd113d146779528d2f91c02c42;hpb=cd63085011ec98a8949fca48217e4efad5558908;p=mudpy.git diff --git a/mudpy/data.py b/mudpy/data.py index 25b423b..b45cd67 100644 --- a/mudpy/data.py +++ b/mudpy/data.py @@ -1,6 +1,6 @@ """Data interface functions for the mudpy engine.""" -# Copyright (c) 2004-2018 mudpy authors. Permission to use, copy, +# Copyright (c) 2004-2022 mudpy authors. Permission to use, copy, # modify, and distribute this software is granted under terms # provided in the LICENSE file distributed with this software. @@ -57,12 +57,14 @@ class Data: self.source = find_file( self.source, relative=self.relative, universe=self.universe) try: - self.data = yaml.safe_load(open(self.source)) + with open(self.source) as datafd: + self.data = yaml.safe_load(datafd) log_entry = ("Loaded file %s into memory." % self.source, 5) except FileNotFoundError: # it's normal if the file is one which doesn't exist yet self.data = {} - log_entry = ("File %s is unavailable." % self.source, 6) + log_entry = ( + "File %s was not found and will be created." % self.source, 6) try: mudpy.misc.log(*log_entry) except NameError: @@ -111,10 +113,9 @@ class Data: ): # make parent directories if necessary - if not os.path.exists(os.path.dirname(self.source)): - old_umask = os.umask(normal_umask) - os.makedirs(os.path.dirname(self.source)) - os.umask(old_umask) + old_umask = os.umask(normal_umask) + os.makedirs(os.path.dirname(self.source), exist_ok=True) + os.umask(old_umask) # backup the file if "mudpy.limit" in self.universe.contents: