-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhek-sync.py
40 lines (34 loc) · 1.46 KB
/
hek-sync.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/env python
import shutil
import glob
from os import path, stat
from pathlib import Path
import sys
if len(sys.argv) != 2:
print("Usage: hek-sync.py <hek-root>")
sys.exit(1)
dev_root = "."
hek_root = sys.argv[1]
def do_copy(src_file, dst_file):
Path(dst_file).parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(src_file, dst_file)
def sync(pattern):
dev_files = {path.relpath(f, dev_root): stat(f).st_mtime for f in glob.glob(path.join(dev_root, path.normpath(pattern)), recursive=True)}
hek_files = {path.relpath(f, hek_root): stat(f).st_mtime for f in glob.glob(path.join(hek_root, path.normpath(pattern)), recursive=True)}
for f in {*dev_files.keys(), *hek_files.keys()}:
if f in dev_files and (f not in hek_files or dev_files[f] > hek_files[f]):
print("Copying to HEK: " + f)
do_copy(path.join(dev_root, f), path.join(hek_root, f))
elif f in hek_files and (f not in dev_files or hek_files[f] > dev_files[f]):
print("Copying to local: " + f)
do_copy(path.join(hek_root, f), path.join(dev_root, f))
sync("data/levels/alpine/**/**.tif")
sync("data/levels/alpine/**/**.JMS")
sync("data/levels/alpine/**/**.hsc")
sync("data/scenery/wildflower/**/**.tif")
sync("data/scenery/wildflower/**/**.JMS")
sync("data/sky/sky_alpine/**/**.tif")
sync("data/sky/sky_alpine/**/**.JMS")
sync("tags/levels/alpine/**/**.*")
sync("tags/scenery/wildflower/**/**.*")
sync("tags/sky/sky_alpine/**/**.*")