ich habe hier 2 Funktionen. In diesen (python 2.6) will ich eine Liste übergeben und weiter bearbeiten. Vielleicht kann mir jemand sagen was ich falsch mache.
In Funktion1 erstelle ich eine Liste mit random values. Diese nennt sich cs_id . Das befüllen funktioniert. Diese Liste gebe ich mit
Code: Alles auswählen
return cs_id
Code: Alles auswählen
cs_id = func.unzip(InputFile, Instances)
func.changecs(cs_id, LicenseKeys, ConfigFile, ConfigDir, Instances)
Dort erhalte ich den Fehler:
Code: Alles auswählen
Traceback (most recent call last):
File "warmaker.py", line 33, in <module>
func.changecs(cs_id, LicenseKeys, ConfigFile, ConfigDir, Instances)
File "/root/PycharmProjects/warmaker/functions.py", line 71, in changecs
cspath.append(cs_id + '/conf/contentserver/initial-config.txt')
TypeError: can only concatenate list (not "str") to list
Übergabe der Liste:
Code: Alles auswählen
cs_id = func.unzip(InputFile, Instances)
func.changecs(cs_id, LicenseKeys, ConfigFile, ConfigDir, Instances)
Code: Alles auswählen
def unzip(InputFile, Instances):
cs_id = []
for i in xrange(Instances):
cs_id.append('CS_' + id_generator())
i += 1
if os.path.isfile(InputFile): # check if file exists
print 'Found ' + InputFile
else:
print InputFile + ' not fonund. Try again.'
sys.exit()
print 'Building ' + str(Instances) + ' instances... '
for c in xrange(Instances):
extract = zipfile.ZipFile(InputFile)
extract.extractall(cs_id[c])
extract.close()
c += 1
return cs_id
Code: Alles auswählen
def changecs(cs_id, LicenseKeys, ConfigFile, ConfigDir, Instances):
g = 0
cspath = []
keystore = []
print "Open initial-config.txt to change values"
print "Reading keyfile"
f = open(LicenseKeys, "r")
for line in LicenseKeys:
keystore.append(f.readline())
keystore = map(str.strip, keystore) # map strip to list, delete \n, create a new list, give it back to keystore
f.close()
for g in cs_id:
cspath.append(cs_id[g] + '/conf/contentserver/initial-config.txt')
# open path
f = open(cspath[g], "r")
csproperties = f.read()
f.close()
# change parameters
result = (csproperties
.replace("License Key=", "License Key=" + keystore[g])
.replace("Config File=", "Config File=" + ConfigFile)
.replace("Config Directory =", "Config Directory=" + ConfigDir))
# write
f = open(cspath[g], 'w')
f.write(result)
f.close()
g += 1
print "Values changed"