Bin nicht so der Python Hero aber könnt Ihr mal nach Syntax fehler mit druf gucken?
z.B.
config_file_contents = config_file.readall()
scheint ja falsch zu sein! Danke im Vorraus.
Code: Alles auswählen
import shutil
from tempfile import mktemp
import re
line = re.sub(r"</?\[\d+>", "", line)
def main()
#Source in Temp_Datei umwandeln
source_path = input('Path to source files: ')
temp_dir_path = mktemp(prefix='tmp_iso_', dir='/media')
shutil.copytree(source_path, temp_dir_path)
config_file_path = findConfigFile(temp_dir_path)
config_file = open(config_file)
config_file_contents = config_file.readall() #hier muss der gesammte Text der datei ausgelesen werden.
config_file_contents = replace(config_file_contents, "kennwort", "...")
config_file_contents = replace(config_file_contents, "ip", "192.168.0.1.")
config_file.writeAllText(fileContents)
def replace(text, name, value)
#text= "jdskfjdasklf %kennwort% fkdjasfkdas"
#name="kennwort"
#value="23"
#
#==> "jdskfjdasklf 23 fkdjasfkdas"
return re.sub("\%"+name+"\%", value, text)
def findConfigFile(basePath)
#Datei editieren
try:
if os.path.exists(basePath+"/datei.xml"):
return basePath+"/datei.xml"
else if os.path.exists(basePath+"/preseedautodeploy.cfg"):
return basePath+"/preseedautodeploy.cfg"
main()