1234567891011121314151617181920212223242526272829303132 |
- import shutil
- from datetime import datetime, timedelta
- from pathlib import Path
- def deploy(cube_out: str, cubes_dir: str) -> None:
- for p in Path(cube_out).glob("*.mdc"):
- mtime = datetime.fromtimestamp(p.stat().st_mtime)
- if mtime < datetime.now() - timedelta(days=1):
- continue
- cube_name = p.name.lower()[:-4]
- basename = cube_name + "__" + mtime.strftime("%Y%m%d%H%M%S")
- folder = Path(cubes_dir) / basename
- if folder.exists():
- continue
- print(basename)
- folder.mkdir()
- shutil.copy2(p, folder / p.name)
- for v in Path(cubes_dir).glob(cube_name + "__*.ver"):
- v.unlink()
- old_folders = list(sorted([f.name for f in Path(cubes_dir).glob(cube_name + "__*") if f.is_dir()]))[:-3]
- for f in old_folders:
- shutil.rmtree(cubes_dir + "\\" + f, ignore_errors=True)
- with open(cubes_dir + "\\" + basename + ".ver", "w", encoding="latin-1") as fwh:
- fwh.write("Dies ist eine PowerCube-Versionsdatei. Nicht löschen!\n")
- if __name__ == "__main__":
- cube_out = "C:\\GlobalCube\\System\\OPTIMA\\Cube_out"
- cubes_dir = "C:\\GlobalCube\\Cubes"
- deploy(cube_out, cubes_dir)
|