PNG files have a date in them so now only update them if they have actually changed.
This commit is contained in:
parent
99f46754d9
commit
5af2302053
|
@ -7,3 +7,5 @@ tests/deps/
|
|||
*.log
|
||||
*.html
|
||||
times.txt
|
||||
*_diff.png
|
||||
*.echo
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 170 KiB |
|
@ -7,7 +7,7 @@ Arduino thermostat to control a beer fridge to use it as an environmental chambe
|
|||
|
||||
---
|
||||
## HydraBot
|
||||
Current state of HydraRaptor after being modified for laser engarving.
|
||||
Current state of HydraRaptor after being modified for laser engraving.
|
||||
|
||||
![](HydraBot.png)
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ from colorama import Fore, init
|
|||
from tests import do_cmd
|
||||
import re
|
||||
from shutil import copyfile
|
||||
from tests import update_image
|
||||
|
||||
project_dir = '../..'
|
||||
target_dir = 'gallery'
|
||||
|
@ -53,7 +54,10 @@ def gallery():
|
|||
if image.startswith('![Main Assembly](assemblies/'):
|
||||
file = image[17 : -1]
|
||||
line = line.replace(image, '![](%s.png)' % project)
|
||||
copyfile(path + '/' + file, '%s/%s.png' %(target_dir, project))
|
||||
tmp_name = 'tmp.png'
|
||||
target_name = '%s/%s.png' %(target_dir, project)
|
||||
copyfile(path + '/' + file, tmp_name)
|
||||
update_image(tmp_name, target_name)
|
||||
else:
|
||||
line = line.replace(image, '')
|
||||
else:
|
||||
|
|
|
@ -28,8 +28,10 @@ import bom
|
|||
import times
|
||||
import time
|
||||
import json
|
||||
import shutil
|
||||
from deps import *
|
||||
from blurb import *
|
||||
from colorama import Fore
|
||||
|
||||
w = 4096
|
||||
h = w
|
||||
|
@ -38,7 +40,20 @@ def do_cmd(cmd, output = sys.stdout):
|
|||
for arg in cmd:
|
||||
print(arg, end = " ")
|
||||
print()
|
||||
subprocess.call(cmd, stdout = output)
|
||||
return subprocess.call(cmd, stdout = output, stderr = output)
|
||||
|
||||
def update_image(tmp_name, png_name):
|
||||
"""Update an image only if different, otherwise just change the mod time"""
|
||||
with open(os.devnull, 'w') as null:
|
||||
diff_name = png_name.replace('.png', '_diff.png')
|
||||
if not os.path.isfile(png_name) or do_cmd(("magick compare -metric AE %s %s %s" % (png_name, tmp_name, diff_name)).split(), output = null):
|
||||
shutil.copyfile(tmp_name, png_name)
|
||||
print(Fore.GREEN + png_name + " updated" + Fore.WHITE)
|
||||
else:
|
||||
os.utime(png_name, None)
|
||||
os.remove(diff_name)
|
||||
os.remove(tmp_name)
|
||||
|
||||
|
||||
def depluralise(name):
|
||||
if name[-3:] == "ies" and name != "zipties":
|
||||
|
@ -159,9 +174,11 @@ def tests(tests):
|
|||
if changed:
|
||||
print(changed)
|
||||
t = time.time()
|
||||
openscad.run("-D", "$bom=2", "--projection=p", "--imgsize=%d,%d" % (w, h), "--camera=0,0,0,70,0,315,500", "--autocenter", "--viewall", "-d", dname, "-o", png_name, scad_name);
|
||||
tmp_name = 'tmp.png'
|
||||
openscad.run("-D", "$bom=2", "--projection=p", "--imgsize=%d,%d" % (w, h), "--camera=0,0,0,70,0,315,500", "--autocenter", "--viewall", "-d", dname, "-o", tmp_name, scad_name);
|
||||
times.add_time(scad_name, t)
|
||||
do_cmd(["magick", png_name, "-trim", "-resize", "1000x600", "-bordercolor", "#ffffe5", "-border", "10", png_name])
|
||||
do_cmd(["magick", tmp_name, "-trim", "-resize", "1000x600", "-bordercolor", "#ffffe5", "-border", "10", tmp_name])
|
||||
update_image(tmp_name, png_name)
|
||||
BOM = bom.parse_bom()
|
||||
with open(bom_name, 'wt') as outfile:
|
||||
json.dump(BOM.flat_data(), outfile, indent = 4)
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
from __future__ import print_function
|
||||
from set_config import *
|
||||
import openscad
|
||||
from tests import do_cmd
|
||||
from tests import do_cmd, update_image
|
||||
import time
|
||||
import times
|
||||
from deps import *
|
||||
|
@ -33,6 +33,7 @@ import os
|
|||
import json
|
||||
import blurb
|
||||
import bom
|
||||
import shutil
|
||||
from colorama import Fore
|
||||
|
||||
def is_assembly(s):
|
||||
|
@ -151,12 +152,15 @@ def views(target, do_assemblies = None):
|
|||
if changed:
|
||||
print(changed)
|
||||
t = time.time()
|
||||
openscad.run("-D$pose=1", "-D$explode=%d" % explode, "--projection=p", "--imgsize=4096,4096", "--autocenter", "--viewall", "-d", dname, "-o", png_name, png_maker_name);
|
||||
tmp_name = 'tmp.png'
|
||||
openscad.run("-D$pose=1", "-D$explode=%d" % explode, "--projection=p", "--imgsize=4096,4096", "--autocenter", "--viewall", "-d", dname, "-o", tmp_name, png_maker_name);
|
||||
times.add_time(png_name, t)
|
||||
do_cmd(["magick", png_name, "-trim", "-resize", "1004x1004", "-bordercolor", "#ffffe5", "-border", "10", png_name])
|
||||
do_cmd(["magick", tmp_name, "-trim", "-resize", "1004x1004", "-bordercolor", "#ffffe5", "-border", "10", tmp_name])
|
||||
update_image(tmp_name, png_name)
|
||||
tn_name = png_name.replace('.png', '_tn.png')
|
||||
if mtime(png_name) > mtime(tn_name):
|
||||
do_cmd(("magick "+ png_name + " -trim -resize 280x280 -background #ffffe5 -gravity Center -extent 280x280 -bordercolor #ffffe5 -border 10 " + tn_name).split())
|
||||
do_cmd(("magick "+ png_name + " -trim -resize 280x280 -background #ffffe5 -gravity Center -extent 280x280 -bordercolor #ffffe5 -border 10 " + tmp_name).split())
|
||||
update_image(tmp_name, tn_name)
|
||||
os.remove(png_maker_name)
|
||||
done_assemblies.append(module)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue