Rat-OS / RatOS-configuration

The RatOS modular klipper configuration
146 stars 134 forks source link

Get ratos version directly from system #279

Closed GP3D84 closed 3 weeks ago

HelgeKeck commented 3 weeks ago

hey, thanks for the contribution. next time please add some spaces.

instead this here: RatOS '+ ratos_version() +'</p>

please do this RatOS ' + ratos_version() + '</p>

GP3D84 commented 3 weeks ago

hey, thanks for the contribution. next time please add some spaces.

Hi, Done :)

HelgeKeck commented 3 weeks ago

also, please add a fallback and a default value to the function in case the file cant be read. best is to try and catch it. and please check if the split works before sending it

def ratos_version():
    """
    Get current version of RatOS distro.
    """
    with open("/etc/ratos-release") as f:
        return f.read().split()[1]
HelgeKeck commented 3 weeks ago

and please put the function under the helper category image

GP3D84 commented 3 weeks ago

When I tried to put it into the class, version not load correctly Honestly, I haven't investigated much, I'll try again when I'm at home

HelgeKeck commented 3 weeks ago

When I tried to put it into the class, version not load correctly Honestly, I haven't investigated much, I'll try again when I'm at home

this is how it works

def get_ratos_version(self):
    """
    Get current version of RatOS distro.
    """
    try:
        with open("/etc/ratos-release") as f:
            return f.read().split()[1]
    except Exception as exc:
        self.debug_echo("get_ratos_version", "Something went wrong. " + str(exc))
    return "v2.1"
HelgeKeck commented 3 weeks ago

you call it then like this RatOS ' + self.get_ratos_version() + '</p>

HelgeKeck commented 3 weeks ago

put it here image

GP3D84 commented 3 weeks ago

@HelgeKeck done and thank you for your help

HelgeKeck commented 3 weeks ago

now please fix the double empty line and you are done image only one emtpy line

HelgeKeck commented 3 weeks ago

after that im ok with it

GP3D84 commented 3 weeks ago

Maybe it would be useful to save as register_command for use elsewhere? eg. https://github.com/GP3D84/RatOS-configuration/blob/development/macros/calibration.cfg#L65

HelgeKeck commented 3 weeks ago

Maybe it would be useful to save as register_command for use elsewhere? eg. https://github.com/GP3D84/RatOS-configuration/blob/development/macros/calibration.cfg#L65

i think i will jsut remoce the version tags from such messages, no need to worry now

miklschmidt commented 3 weeks ago

Thank you!