Add is_debian() convenience function

This commit is contained in:
Lance Edgar 2020-09-23 22:40:59 -05:00
parent e8821b3395
commit 7471dd1bf5
2 changed files with 23 additions and 1 deletions

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar
# Copyright © 2010-2020 Lance Edgar
#
# This file is part of Rattail.
#
@ -28,6 +28,7 @@ Fabric deployment and maintenance.
"""
from .core import (
is_debian,
get_debian_version,
get_ubuntu_version,
Deployer,

View file

@ -64,6 +64,27 @@ def is_link(c, path, use_sudo=False):
return False if result.failed else True
def get_os_release_id(c):
"""
Return the "ID" field from `/etc/os-release` file
"""
contents = c.run('cat /etc/os-release').stdout.strip()
data = {}
for line in contents.split('\n'):
field, value = line.split('=')
data[field] = value
return data['ID']
def is_debian(c):
"""
Return boolean indicating if this machine is Debian (proper, as opposed to
some derivative).
"""
release_id = get_os_release_id(c)
return release_id == 'debian'
def get_debian_version(c):
"""
Fetch the version of Debian running on the target system.