def create_file_in_config_folder(self, filename: str, mode: int=None) -> TextIO:
"""
:param filename: the name of the file in the generated config folder
:param mode: pass an ``int`` here if you want to modify the files mode (will be umasked)
:return: an open file descriptor (``TextIO``) object that the *caller must call `.close()` on*
"""
if os.path.isfile(filename):
raise InvalidArgumentException("Call create_file_in_config_folder with a filename, not a path")
self.ensure_config_folder()
f = cast(TextIO, io.open(os.path.join(self.configfolder, filename), mode="wt", encoding="utf-8"))
if mode:
os.chmod(os.path.join(self.configfolder, filename), get_umasked_mode(mode))
return f
评论列表
文章目录