<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def set_hwclock(clock):
    '''
    Sets the hardware clock to be either UTC or localtime

    CLI Example:

    .. code-block:: bash

        salt '*' timezone.set_hwclock UTC
    '''
    if salt.utils.path.which('timedatectl'):
        cmd = ['timedatectl', 'set-local-rtc',
               'true' if clock == 'localtime' else 'false']
        return __salt__['cmd.retcode'](cmd, python_shell=False) == 0
    else:
        os_family = __grains__['os_family']
        if os_family in ('AIX', 'NILinuxRT'):
            if clock.lower() != 'utc':
                raise SaltInvocationError(
                    'UTC is the only permitted value'
                )
            return True

        timezone = get_zone()

        if 'Solaris' in __grains__['os_family']:
            if clock.lower() not in ('localtime', 'utc'):
                raise SaltInvocationError(
                    'localtime and UTC are the only permitted values'
                )
            if 'sparc' in __grains__['cpuarch']:
                raise SaltInvocationError(
                    'UTC is the only choice for SPARC architecture'
                )
            cmd = ['rtc', '-z', 'GMT' if clock.lower() == 'utc' else timezone]
            return __salt__['cmd.retcode'](cmd, python_shell=False) == 0

        zonepath = '/usr/share/zoneinfo/{0}'.format(timezone)

        if not os.path.exists(zonepath):
            raise CommandExecutionError(
                'Zone \'{0}\' does not exist'.format(zonepath)
            )

        os.unlink('/etc/localtime')
        os.symlink(zonepath, '/etc/localtime')

        if 'Arch' in __grains__['os_family']:
            cmd = ['timezonectl', 'set-local-rtc',
                   'true' if clock == 'localtime' else 'false']
            return __salt__['cmd.retcode'](cmd, python_shell=False) == 0
        elif 'RedHat' in __grains__['os_family']:
            __salt__['file.sed'](
                '/etc/sysconfig/clock', '^ZONE=.*', 'ZONE="{0}"'.format(timezone))
        elif 'Suse' in __grains__['os_family']:
            __salt__['file.sed'](
                '/etc/sysconfig/clock', '^TIMEZONE=.*', 'TIMEZONE="{0}"'.format(timezone))
        elif 'Debian' in __grains__['os_family']:
            if clock == 'UTC':
                __salt__['file.sed']('/etc/default/rcS', '^UTC=.*', 'UTC=yes')
            elif clock == 'localtime':
                __salt__['file.sed']('/etc/default/rcS', '^UTC=.*', 'UTC=no')
        elif 'Gentoo' in __grains__['os_family']:
            if clock not in ('UTC', 'localtime'):
                raise SaltInvocationError(
                    'Only \'UTC\' and \'localtime\' are allowed'
                )
            if clock == 'localtime':
                clock = 'local'
            __salt__['file.sed'](
                '/etc/conf.d/hwclock', '^clock=.*', 'clock="{0}"'.format(clock))

    return True