acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

com.py (2943B)

      1 #!/usr/bin/env python3
      2 
      3 import sys
      4 import os.path
      5 from os import path
      6 import os, fnmatch
      7 import re
      8 import subprocess
      9 import com
     10 
     11 def cmd(c, ask_on_err = True):
     12   print("\n" + c)
     13   r = os.system(c)
     14   if r:
     15     print("### Error: " + str(r))
     16     if ask_on_err:
     17         input("Press Enter to continue execution...")
     18 
     19 def define_set(fn, name, value):
     20     print("In " + fn + " set " + name + " to " + value)
     21 
     22     new_content = ""
     23     s = r'^ *# *define +' + str(name).rstrip() + ' +'
     24 
     25     f = open(fn, "r")
     26     for i in f.read().splitlines():
     27         r = re.search(s, i)
     28         if r:
     29             d = i.split("define")
     30             i = d[0] + "define " + name + " " + value
     31         new_content += i + '\n'
     32 
     33     f.close()
     34 
     35     f = open(fn, "w")
     36     f.write(new_content)
     37     f.close()
     38 
     39 def ver_format(ver):
     40     s = "v" + str(ver[0]) + "."  + str(ver[1]) + "."  + str(ver[2])
     41     if(ver[3] != ""): s = s + "-" + ver[3]
     42     return s
     43 
     44 def get_lvgl_version():
     45     print("Get lvgl's version ")
     46 
     47     ver = [0, 0, 0, ""]
     48 
     49     f = open("./lvgl.h", "r")
     50 
     51     lastNum = re.compile(r'(?:[^\d]*(\d+)[^\d]*)+')
     52     for i in f.read().splitlines():
     53         r = re.search(r'^#define LVGL_VERSION_MAJOR ', i)
     54         if r:
     55             m = lastNum.search(i)
     56             if m: ver[0] = m.group(1)
     57 
     58         r = re.search(r'^#define LVGL_VERSION_MINOR ', i)
     59         if r:
     60             m = lastNum.search(i)
     61             if m: ver[1] = m.group(1)
     62 
     63         r = re.search(r'^#define LVGL_VERSION_PATCH ', i)
     64         if r:
     65             m = lastNum.search(i)
     66             if m: ver[2] = m.group(1)
     67 
     68     f.close()
     69 
     70     print("Version found: " + ver_format(ver))
     71 
     72     return ver
     73 
     74 def push(c):
     75     cmd("git push " + c)
     76 
     77 def update_version(ver):
     78   ver_str = ver_format(ver)
     79   ver_num = ver[0] + "." + ver[1] + "." + ver[2]
     80 
     81   templ = fnmatch.filter(os.listdir('.'), '*_templ*.h')
     82 
     83   if len(templ) > 0 and templ[0]:
     84       print("Updating version in " + templ[0])
     85       cmd("sed -i -r 's/v[0-9]+\.[0-9]+\.[0-9]+.*/"+ "v" + ver_num + "/' " + templ[0])
     86 
     87   if os.path.exists("library.json"):
     88       print("Updating version in library.json")
     89       cmd("sed -i -r 's/[0-9]+\.[0-9]+\.[0-9]+/"+ ver_num +"/' library.json")
     90 
     91   if path.exists("library.properties"):
     92       print("Updating version in library.properties")
     93       cmd("sed -i -r 's/version=[0-9]+\.[0-9]+\.[0-9]+/"+ "version=" + ver_num + "/' library.properties")
     94 
     95   if path.exists("conf.py"):
     96       cmd("sed -i -r 's/v[0-9]+\.[0-9]+\.[0-9]+.*/" + ver_str + "/' conf.py")
     97 
     98   if path.exists("Kconfig"):
     99       cmd("sed -i -r 's/v[0-9]+\.[0-9]+\.[0-9]+.*/" + ver_str + "/' Kconfig")
    100 
    101   if path.exists("lvgl.h"):
    102       define_set("./lvgl.h", "LVGL_VERSION_MAJOR", str(ver[0]))
    103       define_set("./lvgl.h", "LVGL_VERSION_MINOR", str(ver[1]))
    104       define_set("./lvgl.h", "LVGL_VERSION_PATCH", str(ver[2]))
    105       define_set("./lvgl.h", "LVGL_VERSION_INFO", "\"" + ver[3] + "\"")
    106 
    107   cmd("git commit -am 'Update versions to " + ver_str + "'")
    108