make tint colour timestamps stable across machines
authorAlex Chan <alex@alexwlchan.net>
Wed, 16 Dec 2020 20:38:48 +0000 (20:38 +0000)
committerAlex Chan <alex@alexwlchan.net>
Wed, 16 Dec 2020 20:38:48 +0000 (20:38 +0000)
scripts/render_html.py
src/tint_colors.json

index 92c76e2..08dffa7 100755 (executable)
@@ -26,6 +26,43 @@ def rsync(dir1, dir2):
     subprocess.check_call(["rsync", "--recursive", "--delete", dir1, dir2])
 
 
+def git(*args):
+    return subprocess.check_output(["git"] + list(args)).strip().decode("utf8")
+
+
+def set_git_timestamps():
+    """
+    For everything in the covers/ directory, set the last modified timestamp to
+    the last time it was modified in Git.  This should make tint colour computations
+    stable across machines.
+    """
+    root = git("rev-parse", "--show-toplevel")
+
+    now = datetime.datetime.now().timestamp()
+
+    for f in os.listdir("src/covers"):
+        path = os.path.join("src/covers", f)
+
+        if not os.path.isfile(path):
+            continue
+
+        stat = os.stat(path)
+
+        # If the modified time is >7 days ago, skip setting the modified time.  This means
+        # the script stays pretty fast when doing a regular sync.
+        if now - stat.st_mtime > 7 * 24 * 60 * 60 and "--reset" not in sys.argv:
+            continue
+
+        revision = git("rev-list", "--max-count=1", "HEAD", path)
+
+        timestamp, *_ = git("show", "--pretty=format:%ai", "--abbrev-commit", revision).splitlines()
+        modified_time = datetime.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S %z").timestamp()
+
+        access_time = stat.st_atime
+
+        os.utime(path, times=(access_time, modified_time))
+
+
 @attr.s
 class Book:
     title = attr.ib()
@@ -237,6 +274,8 @@ def css_hash(_):
 
 
 def main():
+    set_git_timestamps()
+
     env = Environment(
         loader=FileSystemLoader("templates"),
         autoescape=select_autoescape(["html", "xml"]),
index c715aef..f2fae96 100644 (file)
   },
   "ancillary-sword.jpg": {
     "color": [
-      0.8031659175298027,
-      0.18190345905804178,
-      0.1584522180965409
+      0.8075879666935267,
+      0.1813859790491536,
+      0.1585414987912967
     ],
-    "size": 193746
+    "size": 193762
   },
   "and-another-thing.jpg": {
     "color": [
   },
   "as-you-wish-inconceivable-tales-from-the-making-of-the-princess-bride.jpg": {
     "color": [
-      0.4885340802987862,
-      0.4375536881419234,
-      0.3940989729225023
+      0.49072815055670505,
+      0.4389595033993496,
+      0.3951128189969454
     ],
-    "size": 48789
+    "size": 48805
   },
   "atomic-accidents.jpg": {
     "color": [
       0.0,
       0.0
     ],
-    "size": 145193
+    "size": 145209
   },
   "becoming-sex-second-chances-and-figuring-out-who-the-hell-i-am.jpg": {
     "color": [
   },
   "carmilla.jpg": {
     "color": [
-      0.36604859335038364,
-      0.42139812446717817,
-      0.47374254049445863
+      0.38050615595075243,
+      0.43780209758321936,
+      0.49236206110351116
     ],
-    "size": 102643
+    "size": 102659
   },
   "carrying-the-fire.jpg": {
     "color": [
   },
   "forgotten-sacrifice-the-arctic-convoys-of-world-war-ii.jpg": {
     "color": [
-      0.3387502861066608,
-      0.4116655222400246,
-      0.484290836957351
+      0.33728578045391366,
+      0.4113478462251042,
+      0.48483094025011586
     ],
-    "size": 29537
+    "size": 29553
   },
   "from-ace-to-ze.jpg": {
     "color": [
       0.0,
       0.0
     ],
-    "size": 66167
+    "size": 66183
   },
   "laymans-guide-to-the-greek-gods.jpg": {
     "color": [
   },
   "love-of-country-a-hebridean-journey.jpg": {
     "color": [
-      0.3675931911226029,
-      0.4485383897148603,
-      0.27787114845938377
+      0.36661711616054365,
+      0.44771005875274295,
+      0.2782048559496001
     ],
-    "size": 231698
+    "size": 231714
   },
   "make-games-with-python.jpg": {
     "color": [
   },
   "programmed-inequality.jpg": {
     "color": [
-      0.3175222816399287,
-      0.37591800356506244,
-      0.5814795008912658
+      0.31630453983395157,
+      0.37468645115703947,
+      0.5798445504327859
     ],
-    "size": 199078
+    "size": 199094
   },
   "protecting-information-from-classical-error-correction-to-quantum-cryptography.jpg": {
     "color": [
   },
   "the-artist-and-the-mathematician.jpg": {
     "color": [
-      0.42560080442433346,
-      0.4369297804591922,
-      0.47253226076755483
+      0.42537042740307285,
+      0.4369435034048521,
+      0.4724703144783223
     ],
-    "size": 15394
+    "size": 15410
   },
   "the-box-how-the-shipping-container-made-the-world-smaller-and-the-world-economy-bigger.jpg": {
     "color": [
   },
   "the-chinese-typewriter-a-history.jpg": {
     "color": [
-      0.7416765363863665,
-      0.16170548756415376,
-      0.18352414791419924
+      0.7389318885448916,
+      0.16504127966976256,
+      0.18477812177502545
     ],
-    "size": 175873
+    "size": 175889
   },
   "the-chronicles-of-narnia-audio-collection.jpg": {
     "color": [
   },
   "the-design-of-everyday-things.jpg": {
     "color": [
-      0.27065837717200725,
-      0.41753546947234205,
-      0.3573919974493862
+      0.11247771836007076,
+      0.5028520499108734,
+      0.5286177280829687
     ],
-    "size": 631406
+    "size": 631422
   },
   "the-elements-of-style.jpg": {
     "color": [
       0.0,
       0.01568627450980392
     ],
-    "size": 36488
+    "size": 36504
   },
   "the-ones-who-walk-away-from-omelas.jpg": {
     "color": [
   },
   "the-origins-of-unfairness.jpg": {
     "color": [
-      0.21697835203445537,
-      0.3352374475801882,
-      0.2242094525671544
+      0.16862745098039217,
+      0.40784313725490196,
+      0.3803921568627451
     ],
-    "size": 49668
+    "size": 49684
   },
   "the-other-greek.jpg": {
     "color": [
-      0.36401384083044974,
+      0.3640138408304499,
       0.36960784313725487,
       0.31707035755478663
     ],
-    "size": 69618
+    "size": 69634
   },
   "the-paper-menagerie-and-other-stories.jpg": {
     "color": [
   },
   "the-wrong-kind-of-snow-how-the-weather-made-britain.jpg": {
     "color": [
-      0.37249544626593817,
-      0.44019072109718205,
-      0.4740490731811851
+      0.3724954462659384,
+      0.440190721097182,
+      0.47404907318118517
     ],
-    "size": 19779
+    "size": 19814
   },
   "think-black.jpg": {
     "color": [
       0.00392156862745098,
       0.00392156862745098
     ],
-    "size": 31223
+    "size": 31244
   },
   "unicorn.png": {
     "color": [