/ install.py
install.py
 1  #!/usr/bin/python
 2  import os
 3  import shutil
 4  import subprocess
 5  
 6  def match(dest, content):
 7      if not os.path.exists(dest): return False
 8      with open(dest, "rb") as f: destcontent = f.read()
 9      return content == destcontent
10  
11  def copy(destdir, srcdir, name, *, destname=None):
12      if destname is None: destname = name
13      src = os.path.join(srcdir, name)
14      dest = os.path.join(destdir, destname)
15      with open(src, "rb") as f: content = f.read()
16      put(dest, content)
17  
18  def put(dest, content):
19      if not match(dest, content):
20          with open(dest, "wb") as f: f.write(content)
21  
22  SRCPATH = 'src'
23  DSTPATH = 'CIRCUITPY'
24  
25  for dirpath, dirnames, filenames in os.walk('src', followlinks=True):
26      outpath = os.path.join(DSTPATH, os.path.relpath(dirpath, SRCPATH))
27      os.makedirs(outpath, exist_ok=True)
28  
29      for f in filenames:
30          if f.startswith('.'): continue
31          copy(outpath, dirpath, f)