Merge pull request #119 from PiBrewing/bookworm-test

Merge Bookworm test into developmnent
This commit is contained in:
Alexander Vollkopf 2023-11-01 14:03:42 +01:00 committed by GitHub
commit 268077720a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 64 additions and 29 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.2.0.a1" __version__ = "4.2.0.a6"
__codename__ = "Indian Summer" __codename__ = "Indian Summer"

View file

@ -38,14 +38,28 @@ class CraftBeerPiCli():
def setup_one_wire(self): def setup_one_wire(self):
print("Setting up 1Wire") print("Setting up 1Wire")
with open('/boot/config.txt', 'w') as f: with open('/boot/config.txt', 'r') as f:
f.write("dtoverlay=w1-gpio,gpiopin=4,pullup=on") lines=f.readlines()
#f.write("dtoverlay=w1-gpio,gpiopin=4,pullup=on")
lines.append("dtoverlay=w1-gpio,gpiopin=4,pullup=on")
configtempfile=os.path.join(self.config.get_file_path(""),"config.txt")
with open(configtempfile, 'w') as f:
for line in lines:
f.write(line)
destfile="/boot/config.txt"
#copy and remove afterwards as mv will work, but raise an error message due to different file owners
shutil.os.system('sudo cp "{}" "{}"'.format(configtempfile,destfile))
shutil.os.system('rm -rf "{}"'.format(configtempfile))
print("/boot/config.txt created") print("/boot/config.txt created")
def list_one_wire(self): def list_one_wire(self):
print("List 1Wire") print("List 1Wire")
call(["modprobe", "w1-gpio"]) call(["sudo","modprobe", "w1-gpio"])
call(["modprobe", "w1-therm"]) call(["sudo","modprobe", "w1-therm"])
try: try:
for dirname in os.listdir('/sys/bus/w1/devices'): for dirname in os.listdir('/sys/bus/w1/devices'):
if (dirname.startswith("28") or dirname.startswith("10")): if (dirname.startswith("28") or dirname.startswith("10")):
@ -150,16 +164,34 @@ class CraftBeerPiCli():
else: else:
print("CraftBeerPi Autostart is {}OFF{}".format(Fore.RED,Style.RESET_ALL)) print("CraftBeerPi Autostart is {}OFF{}".format(Fore.RED,Style.RESET_ALL))
elif(name == "on"): elif(name == "on"):
user=os.getlogin()
path="/usr/local/bin/cbpi"
if os.path.exists("/home/"+user+"/.local/bin/cbpi") is True:
path="/home/"+user+"/.local/bin/cbpi"
print("Add craftbeerpi.service to systemd") print("Add craftbeerpi.service to systemd")
try: try:
if os.path.exists(os.path.join("/etc/systemd/system","craftbeerpi.service")) is False: if os.path.exists(os.path.join("/etc/systemd/system","craftbeerpi.service")) is False:
templatefile=self.config.get_file_path("craftbeerpi.template")
shutil.os.system('cp "{}" "{}"'.format(templatefile,self.config.get_file_path("craftbeerpi.service")))
srcfile = self.config.get_file_path("craftbeerpi.service") srcfile = self.config.get_file_path("craftbeerpi.service")
import jinja2
templateLoader = jinja2.FileSystemLoader(searchpath=os.path.join(self.config.get_file_path("")))
templateEnv = jinja2.Environment(loader=templateLoader)
operatingsystem = str(platform.system()).lower()
if operatingsystem.startswith("win"):
srcfile=str(srcfile).replace('\\','/')
template = templateEnv.get_template("craftbeerpi.service")
outputText = template.render(user=user, path=path)
with open(srcfile, "w") as fh:
fh.write(outputText)
destfile = os.path.join("/etc/systemd/system") destfile = os.path.join("/etc/systemd/system")
shutil.copy(srcfile, destfile) shutil.os.system('sudo mv "{}" "{}"'.format(srcfile,destfile))
print("Copied craftbeerpi.service to /etc/systemd/system") print("Copied craftbeerpi.service to /etc/systemd/system")
os.system('systemctl enable craftbeerpi.service') shutil.os.system('sudo systemctl enable craftbeerpi.service')
print('Enabled craftbeerpi service') print('Enabled craftbeerpi service')
os.system('systemctl start craftbeerpi.service') shutil.os.system('sudo systemctl start craftbeerpi.service')
print('Started craftbeerpi.service') print('Started craftbeerpi.service')
else: else:
print("craftbeerpi.service is already located in /etc/systemd/system") print("craftbeerpi.service is already located in /etc/systemd/system")
@ -167,20 +199,20 @@ class CraftBeerPiCli():
print(e) print(e)
return return
return return
elif(name == "off"): elif(name == "off"):
print("Remove craftbeerpi.service from systemd") print("Remove craftbeerpi.service from systemd")
try: try:
status = os.popen('systemctl list-units --type=service --state=running | grep craftbeerpi.service').read() status = os.popen('systemctl list-units --type=service --state=running | grep craftbeerpi.service').read()
if status.find("craftbeerpi.service") != -1: if status.find("craftbeerpi.service") != -1:
os.system('systemctl stop craftbeerpi.service') shutil.os.system('sudo systemctl stop craftbeerpi.service')
print('Stopped craftbeerpi service') print('Stopped craftbeerpi service')
os.system('systemctl disable craftbeerpi.service') shutil.os.system('sudo systemctl disable craftbeerpi.service')
print('Removed craftbeerpi.service as service') print('Removed craftbeerpi.service as service')
else: else:
print('craftbeerpi.service service is not running') print('craftbeerpi.service service is not running')
if os.path.exists(os.path.join("/etc/systemd/system","craftbeerpi.service")) is True: if os.path.exists(os.path.join("/etc/systemd/system","craftbeerpi.service")) is True:
os.remove(os.path.join("/etc/systemd/system","craftbeerpi.service")) shutil.os.system('sudo rm -rf "{}"'.format(os.path.join("/etc/systemd/system","craftbeerpi.service")))
print("Deleted craftbeerpi.service from /etc/systemd/system") print("Deleted craftbeerpi.service from /etc/systemd/system")
else: else:
print("craftbeerpi.service is not located in /etc/systemd/system") print("craftbeerpi.service is not located in /etc/systemd/system")
@ -188,8 +220,6 @@ class CraftBeerPiCli():
print(e) print(e)
return return
return return
def chromium(self, name): def chromium(self, name):
'''Enable or disable autostart''' '''Enable or disable autostart'''
if(name == "status"): if(name == "status"):
@ -203,7 +233,7 @@ class CraftBeerPiCli():
if os.path.exists(os.path.join("/etc/xdg/autostart/","chromium.desktop")) is False: if os.path.exists(os.path.join("/etc/xdg/autostart/","chromium.desktop")) is False:
srcfile = self.config.get_file_path("chromium.desktop") srcfile = self.config.get_file_path("chromium.desktop")
destfile = os.path.join("/etc/xdg/autostart/") destfile = os.path.join("/etc/xdg/autostart/")
shutil.copy(srcfile, destfile) shutil.os.system('sudo cp "{}" "{}"'.format(srcfile,destfile))
print("Copied chromium.desktop to /etc/xdg/autostart/") print("Copied chromium.desktop to /etc/xdg/autostart/")
else: else:
print("chromium.desktop is already located in /etc/xdg/autostart/") print("chromium.desktop is already located in /etc/xdg/autostart/")
@ -215,7 +245,7 @@ class CraftBeerPiCli():
print("Remove chromium.desktop from /etc/xdg/autostart/") print("Remove chromium.desktop from /etc/xdg/autostart/")
try: try:
if os.path.exists(os.path.join("/etc/xdg/autostart/","chromium.desktop")) is True: if os.path.exists(os.path.join("/etc/xdg/autostart/","chromium.desktop")) is True:
os.remove(os.path.join("/etc/xdg/autostart/","chromium.desktop")) shutil.os.system('sudo rm -rf "{}"'.format(os.path.join("/etc/xdg/autostart/","chromium.desktop")))
print("Deleted chromium.desktop from /etc/xdg/autostart/") print("Deleted chromium.desktop from /etc/xdg/autostart/")
else: else:
print("chromium.desktop is not located in /etc/xdg/autostart/") print("chromium.desktop is not located in /etc/xdg/autostart/")

View file

@ -2,8 +2,8 @@
Description=Craftbeer Pi Description=Craftbeer Pi
[Service] [Service]
WorkingDirectory=/home/pi WorkingDirectory=/home/{{ user }}
ExecStart=/usr/local/bin/cbpi start ExecStart={{ path }} start
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -94,7 +94,7 @@ class ConfigFolder:
#['fermenter_data.json', 'file'], created by fermentation_controller @ start if not available #['fermenter_data.json', 'file'], created by fermentation_controller @ start if not available
#['step_data.json', 'file'], created by step_controller @ start if not available #['step_data.json', 'file'], created by step_controller @ start if not available
['config.json', 'file'], ['config.json', 'file'],
['craftbeerpi.service', 'file'], ['craftbeerpi.template', 'file'],
['chromium.desktop', 'file'], ['chromium.desktop', 'file'],
['dashboard', 'folder'], ['dashboard', 'folder'],
['dashboard/widgets', 'folder'], ['dashboard/widgets', 'folder'],
@ -106,7 +106,7 @@ class ConfigFolder:
] ]
for checking in required_config_content: for checking in required_config_content:
if self.inform_missing_content(self.check_for_file_or_folder(os.path.join(self.configFolderPath, checking[0]), checking[1])): if self.inform_missing_content(self.check_for_file_or_folder(os.path.join(self.configFolderPath, checking[0]), checking[1])):
# since there is no complete config we now check if the config folde rmay be completely empty to show hints: # since there is no complete config we now check if the config folder may be completely empty to show hints:
if len(os.listdir(os.path.join(self.configFolderPath))) == 0 : if len(os.listdir(os.path.join(self.configFolderPath))) == 0 :
print("***************************************************") print("***************************************************")
print(f"the config folder '{self.configFolderPath}' seems to be completely empty") print(f"the config folder '{self.configFolderPath}' seems to be completely empty")
@ -118,7 +118,7 @@ class ConfigFolder:
print("***************************************************") print("***************************************************")
return False return False
# if cbpi_dashboard_1.json doesnt exist at the new location (configFolderPath/dashboard) # if cbpi_dashboard_1.json does'nt exist at the new location (configFolderPath/dashboard)
# we move every cbpi_dashboard_n.json file from the old location (configFolderPath) there. # we move every cbpi_dashboard_n.json file from the old location (configFolderPath) there.
# this could be a config zip file restore from version 4.0.7.a4 or prior. # this could be a config zip file restore from version 4.0.7.a4 or prior.
dashboard_1_path = os.path.join(self.configFolderPath, 'dashboard', 'cbpi_dashboard_1.json') dashboard_1_path = os.path.join(self.configFolderPath, 'dashboard', 'cbpi_dashboard_1.json')
@ -132,7 +132,7 @@ class ConfigFolder:
try: try:
with open(dashboard_1_path, 'r') as f: with open(dashboard_1_path, 'r') as f:
data = json.load(f) data = json.load(f)
if (len(data['elements']) == 0): # there may exist some pathes but pathes without elements in dashboard is not very likely if (len(data['elements']) == 0): # there may exist some paths but paths without elements in dashboard is not very likely
return True return True
else: else:
return False return False
@ -142,6 +142,11 @@ class ConfigFolder:
def inform_missing_content(self, whatsmissing : str): def inform_missing_content(self, whatsmissing : str):
if whatsmissing == "": if whatsmissing == "":
return False return False
# Starting with cbpi 4.2.0, the craftbeerpi.service file will be created dynamically from the template file based on the user id.
# Therefore, the service file is replaced with a template file in the config folder
if whatsmissing.find("craftbeerpi.template"):
self.copyDefaultFileIfNotExists("craftbeerpi.template")
return False
print("***************************************************") print("***************************************************")
print(f"CraftBeerPi config content not found: {whatsmissing}") print(f"CraftBeerPi config content not found: {whatsmissing}")
print("Please run 'cbpi setup' before starting the server ") print("Please run 'cbpi setup' before starting the server ")
@ -181,7 +186,7 @@ class ConfigFolder:
self.copyDefaultFileIfNotExists("fermenter_data.json") self.copyDefaultFileIfNotExists("fermenter_data.json")
self.copyDefaultFileIfNotExists("step_data.json") self.copyDefaultFileIfNotExists("step_data.json")
self.copyDefaultFileIfNotExists("config.json") self.copyDefaultFileIfNotExists("config.json")
self.copyDefaultFileIfNotExists("craftbeerpi.service") self.copyDefaultFileIfNotExists("craftbeerpi.template")
self.copyDefaultFileIfNotExists("chromium.desktop") self.copyDefaultFileIfNotExists("chromium.desktop")
print("Config Folder created") print("Config Folder created")
@ -206,5 +211,5 @@ class ConfigFolder:
shutil.chown(os.path.join(dirpath, filename), owner, group) shutil.chown(os.path.join(dirpath, filename), owner, group)
except: except:
print("problems assigning file or folder permissions") print("problems assigning file or folder permissions")
print("if this happend on windows its fine") print("if this happened on windows its fine")
print("if this happend in the dev container running inside windows its also fine but you might have to rebuild the container if you run into further problems") print("if this happened in the dev container running inside windows its also fine but you might have to rebuild the container if you run into further problems")

View file

@ -170,7 +170,7 @@ def setup(cbpi):
cbpi.plugin.register("OneWire", OneWire) cbpi.plugin.register("OneWire", OneWire)
try: try:
# Global Init # Global Init
call(["modprobe", "w1-gpio"]) call(["sudo","modprobe", "w1-gpio"])
call(["modprobe", "w1-therm"]) call(["sudo","modprobe", "w1-therm"])
except Exception as e: except Exception as e:
pass pass

View file

@ -7,7 +7,7 @@ aiohttp-session==2.12.0
aiohttp-swagger==1.0.16 aiohttp-swagger==1.0.16
aiojobs==1.1.0 aiojobs==1.1.0
aiosqlite==0.17.0 aiosqlite==0.17.0
cryptography==41.0.3 cryptography==41.0.4
pyopenssl==23.2.0 pyopenssl==23.2.0
requests==2.31.0 requests==2.31.0
voluptuous==0.13.1 voluptuous==0.13.1

View file

@ -47,7 +47,7 @@ setup(name='cbpi4',
"aiohttp-swagger==1.0.16", "aiohttp-swagger==1.0.16",
"aiojobs==1.1.0 ", "aiojobs==1.1.0 ",
"aiosqlite==0.17.0", "aiosqlite==0.17.0",
"cryptography==41.0.3", "cryptography==41.0.4",
"pyopenssl==23.2.0", "pyopenssl==23.2.0",
"requests==2.31.0", "requests==2.31.0",
"voluptuous==0.13.1", "voluptuous==0.13.1",