/usr/lib/python2.7/dist-packages/ltsp/ltsconf.py is in python-ltsp 0.2-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | ##
## lts.conf parser
##
## Copyright (C) 2007 Canonical Ltd.
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
"""
ltsconf reads and writes the lts.conf file for ltsp servers,
does an automatic backup and has a rollback function to the
backed up config.
Copyright 2007, Canonical Ltd.
"""
import os
import os.path
def read(path):
"""
returns an array of triplets (index, key, value) and an index list
read from lts.conf in path.
example: data_array,idx=ltsconf_read(./lts.conf)
print data_array
[('default', 'SOUND', 'True'),('default','LOCALDEV','True'), ('...]
print idx
['default','00:11:25:84:CE:BA']
path: full path to lts.conf file
"""
idx = []
data_array = []
if os.path.isfile(path):
ltsconf = open(path)
ltsp_data = ltsconf.read().split('\n')
for line in ltsp_data:
line = line.strip()
if not line.startswith('#'):
if line.startswith('['):
index = line.strip('[]')
idx.append(index)
else:
if line:
key = line.split('=')[0]
value = line.split('=')[1]
data_array.append((index,key,value))
return data_array, idx
def write(path, data_array, idx):
"""
writes an lts.conf in path, containing groups listed in idx and values in
those groups from data_array. by default path/.lts.conf.bak is created before
writing the new file.
path: full path to an lts.conf file
data_array: array of triplets [(index,key,value), (index, key2, value2), ...]
idx: list of indexes [index1, index2, ... ]
"""
if os.path.isfile(path):
os.rename(path, path.rstrip('lts.conf')+'.lts.conf.bak')
ltsconf = open(path, 'w')
ltsconf.write('###########################################\n')
ltsconf.write('# AUTOGENERATED FILE, DO NOT EDIT ! #\n')
ltsconf.write('# Use the thinclient-configurator instead #\n')
ltsconf.write('# A backup of the last configuration can #\n')
ltsconf.write('# be found hidden in the same path, named #\n')
ltsconf.write('# .lts.conf.bak #\n')
ltsconf.write('###########################################\n')
for index in idx:
ltsconf.write('\n['+index+']\n')
for line in data_array:
if line[0] == index:
ltsconf.write('\t'+line[1]+'='+line[2]+'\n')
return True
def rollback(path):
"""
rolls back the config from a backed up ltsp configuration if path/.lts.conf.bak
exists.
path: full path to an lts.conf file
"""
if os.path.isfile(path):
os.rename(path.rstrip('lts.conf')+'.lts.conf.bak', path)
return True
return False
|