|
5 | 5 | if not os.path.isfile("data/update2.html"): |
6 | 6 | print("Missing file: data/update2.html") |
7 | 7 | sys.exit(1) |
| 8 | + |
8 | 9 | if os.path.isdir("pack.tmp"): |
9 | 10 | shutil.rmtree('pack.tmp') |
10 | 11 | try: |
11 | | - filelist = [] |
12 | | - os.makedirs('pack.tmp/data') |
13 | | - # now gzip the stuff except zones.csv since this file is not served by mongoose but directly accessed: |
14 | | - for file in os.listdir("data"): |
15 | | - filename = os.fsdecode(file) |
16 | | - if filename == "cert.pem" or filename == "key.pem" or filename == "CH32V203.bin" or filename == "SmartEVSE.webp": |
17 | | - shutil.copy('data/' + filename, 'pack.tmp/data/' + filename) |
18 | | - filelist.append('data/' + filename) |
19 | | - continue |
20 | | - else: |
21 | | - with open('data/' + filename, 'rb') as f_in, gzip.open('pack.tmp/data/' + filename + '.gz', 'wb') as f_out: |
22 | | - f_out.writelines(f_in) |
23 | | - filelist.append('data/' + filename + '.gz') |
24 | | - continue |
25 | | - os.chdir('pack.tmp') |
26 | | - cmdstring = 'python ../pack.py ' + ' '.join(filelist) |
27 | | - os.system(cmdstring + '>../src/packed_fs.c') |
28 | | - os.chdir('..') |
| 12 | + # Skip generation if packed_fs.c is newer than everything in data/ |
| 13 | + OUTPUT = "src/packed_fs.c" |
| 14 | + if os.path.isfile(OUTPUT): |
| 15 | + packed_mtime = os.path.getmtime(OUTPUT) |
| 16 | + latest = 0 |
| 17 | + for root, _, files in os.walk("data"): |
| 18 | + for f in files: |
| 19 | + try: |
| 20 | + mtime = os.path.getmtime(os.path.join(root, f)) |
| 21 | + if mtime > latest: latest = mtime |
| 22 | + except: pass |
| 23 | + if latest > packed_mtime: |
| 24 | + filelist = [] |
| 25 | + os.makedirs('pack.tmp/data') |
| 26 | + # now gzip the stuff except zones.csv since this file is not served by mongoose but directly accessed: |
| 27 | + for file in os.listdir("data"): |
| 28 | + filename = os.fsdecode(file) |
| 29 | + if filename == "cert.pem" or filename == "key.pem" or filename == "CH32V203.bin" or filename == "SmartEVSE.webp": |
| 30 | + shutil.copy('data/' + filename, 'pack.tmp/data/' + filename) |
| 31 | + filelist.append('data/' + filename) |
| 32 | + continue |
| 33 | + else: |
| 34 | + with open('data/' + filename, 'rb') as f_in, gzip.open('pack.tmp/data/' + filename + '.gz', 'wb') as f_out: |
| 35 | + f_out.writelines(f_in) |
| 36 | + filelist.append('data/' + filename + '.gz') |
| 37 | + continue |
| 38 | + os.chdir('pack.tmp') |
| 39 | + cmdstring = 'python ../pack.py ' + ' '.join(filelist) |
| 40 | + os.system(cmdstring + '>../src/packed_fs.c') |
| 41 | + os.chdir('..') |
29 | 42 | except Exception as e: |
30 | 43 | print(f"An error occurred: {str(e)}") |
31 | 44 | sys.exit(100) |
32 | | -if shutil.rmtree("pack.tmp"): |
33 | | - print("Failed to clean up temporary files") |
34 | | - sys.exit(9) |
| 45 | +if os.path.isdir("pack.tmp"): |
| 46 | + if shutil.rmtree("pack.tmp"): |
| 47 | + print("Failed to clean up temporary files") |
| 48 | + sys.exit(9) |
35 | 49 | # cleanup CH32 bin file if it was generated: |
36 | 50 | if os.path.isfile("data/CH32V203.bin"): |
37 | 51 | os.remove("data/CH32V203.bin") |
0 commit comments