Skript, Samba seadistamiseks - Python
From ICO wiki
#!/usr/bin/python
#-*- coding: utf-8 -*-
# Tühikud konfifailis tekitavad probleeme :s
import sys
import ConfigParser
from ConfigParser import RawConfigParser
import subprocess
config = ConfigParser.RawConfigParser()
config.read('smb.conf')
#1. Kuvama hetkel välja jagatud kaustad
def showSectionsWithPath():
for section in config.sections():
if config.has_option(section, 'path'):
print 'Section ', section, ' has path ', config.get(section, 'path')
#2. Lubama lisada uusi kaustu
#3. Taaskäivitama Samba teenuse peale seadistuste muutmist
def addSection():
section_name = raw_input('Section name ')
print 'This is section name: ', section_name
config.add_section(section_name)
browseable = raw_input('Is browseable? (yes/no) ')
config.set(section_name, 'browseable', browseable)
only_guest = raw_input('Is only guest? (yes/no) ')
config.set(section_name, 'only guest', only_guest)
guest_ok = raw_input('Is guest ok? (yes/no) ')
config.set(section_name, 'guest ok', guest_ok)
writeable = raw_input('Is writeable? (yes/no) ')
config.set(section_name, 'writeable', writeable)
path = raw_input('Give ma a path ')
config.set(section_name, 'path', path)
public = raw_input('Is public? (yes/no) ')
config.set(section_name, 'public', public)
with open('smb.conf', 'wb') as configfile:
config.write(configfile)
subprocess.call('/etc/init.d/samba restart', shell=True)
# Hello my friend, what you want to do today?
if len(sys.argv) != 2: #
print 'Argument is missing :('
print 'Choose from: list, add'
elif sys.argv[1] == 'list':
showSectionsWithPath()
elif 'add' == sys.argv[1]:
addSection()
else:
print 'Unknown input'