def setNTPDefault(enabled, mountPoint = None): """ Fix the configuration for the default NTP service to be activated on boot or not. """ checkRoot() if mountPoint and not os.path.isdir(mountPoint): raise IOError("'{0}' does not exist or is not a directory.".format(mountPoint)) if mountPoint == None: mountPoint = '/' if enabled: os.chmod('{0}/etc/rc.d/rc.ntpd'.format(mountPoint), 0755) else: os.chmod('{0}/etc/rc.d/rc.ntpd'.format(mountPoint), 0644)
def setDefaultKeymap(keymap, mountPoint = None): """ Fix the configuration in /etc/rc.d/rc.keymap to use the specified 'keymap'. This uses 'keyboardsetup' Salix tool. """ checkRoot() if mountPoint and not os.path.isdir(mountPoint): raise IOError("'{0}' does not exist or is not a directory.".format(mountPoint)) if mountPoint == None: mountPoint = '/' ret = execChroot(mountPoint, ['/usr/sbin/keyboardsetup', '-k', keymap, '-z']) # This has been forgotten in keyboardsetup os.chmod('{0}/etc/rc.d/rc.keymap'.format(mountPoint), 0755) return ret
def setDefaultTimeZone(timezone, mountPoint = None): """ Set the default time zone, by copying the correct time zone to /etc/localtime and by setting the /etc/localtime-copied-from symlink. """ if mountPoint and not os.path.isdir(mountPoint): raise IOError("'{0}' does not exist or is not a directory.".format(mountPoint)) if mountPoint == None: mountPoint = '' checkRoot() if '/' in timezone and len(timezone.split('/')) == 2 and os.path.isfile('{0}/usr/share/zoneinfo/{1}'.format(mountPoint, timezone)): copyfile('{0}/usr/share/zoneinfo/{1}'.format(mountPoint, timezone), '{0}/etc/localtime'.format(mountPoint)) if os.path.exists('{0}/etc/localtime-copied-from'.format(mountPoint)): os.unlink('{0}/etc/localtime-copied-from'.format(mountPoint)) os.symlink('/usr/share/zoneinfo/{0}'.format(timezone), '{0}/etc/localtime-copied-from'.format(mountPoint)) else: raise Exception('This time zone: ({0}), is incorrect.'.format(timezone))
def setIbusDefault(enabled, mountPoint = None): """ Fix the configuration for default Ibus activated on boot or not. This uses 'keyboardsetup' Salix tool. """ checkRoot() if mountPoint and not os.path.isdir(mountPoint): raise IOError("'{0}' does not exist or is not a directory.".format(mountPoint)) if mountPoint == None: mountPoint = '/' cmd = ['/usr/sbin/keyboardsetup', '-i'] if enabled: cmd.append('on') else: cmd.append('off') cmd.append('-z') # must be last option because of a bug in keyboardsetup return execChroot(mountPoint, cmd)
Fix the configuration for the default NTP service to be activated on boot or not. """ checkRoot() if mountPoint and not os.path.isdir(mountPoint): raise IOError("'{0}' does not exist or is not a directory.".format(mountPoint)) if mountPoint == None: mountPoint = '/' if enabled: os.chmod('{0}/etc/rc.d/rc.ntpd'.format(mountPoint), 0755) else: os.chmod('{0}/etc/rc.d/rc.ntpd'.format(mountPoint), 0644) # Unit test if __name__ == '__main__': from assertPlus import * checkRoot() continents = listTZContinents() assertTrue(type(continents) == list) assertTrue(len(continents) > 0) assertTrue('Europe' in continents) cities = listTZCities('Europe') assertTrue(type(cities) == list) assertTrue(len(cities) > 0) assertTrue('Paris' in cities) tz = listTimeZones() assertTrue(type(tz) == dict) assertTrue(len(tz) > 0) assertTrue('Europe' in tz) assertTrue('Paris' in tz['Europe']) deftz = getDefaultTimeZone() assertTrue('/' in deftz)