123456789101112131415161718192021222324252627282930313233343536373839404142 |
- def save_game(self):
- save_file = open("saves/main_save.xml", "w+")
- level = self.save_level()
- self.tree.append(level)
- team = self.save_team()
- self.tree.append(team)
- # Store XML tree in file
- save_file.write(etree.tostring(self.tree, pretty_print=True, encoding="unicode"))
- save_file.close()
- def save_upload_file(
- self,
- file: UploadFile,
- save_dir_path: pathlib.Path,
- job_id: str,
- dt_string: str,
- ) -> pathlib.Path:
- """Save `file` under `save_dir_path`.
- Args:
- file (UploadFile): A file want to save.
- save_dir_path (pathlib.Path): A path to directory where file will be saved.
- job_id (str): A job id. This will used part of filename.
- dt_string (str): A datetime info. This will used part of filename.
- Return:
- pathlib.Path: A path where file is saved.
- """
- if not save_dir_path.exists():
- save_dir_path.mkdir(parents=True, exist_ok=True)
- save_path: Final = save_dir_path / f"{dt_string}_{job_id}_{file.filename}"
- try:
- with save_path.open("wb") as f:
- shutil.copyfileobj(file.file, f)
- finally:
- file.file.close()
- return save_path
|