I am creating a script that checks if an GIS url contains http or https and if the url needs a password to access the data located on this server. depending on the combination (https + password? http + password? https without password?) a variable is assigned different environment variables.
if "https" in url and userinfo:
cmd1 = [r"C:\OSGeo4W\bin\ogrinfo.exe",conf, confoptionhttp, confirm, conf, confoptionauth, basic, conf, confoptionuserpw, userinfo , "WFS:"+url, "-so" ]
elif "https" in url:
cmd1 = [r"C:\OSGeo4W\bin\ogrinfo.exe",conf, confoptionhttp, confirm , "WFS:"+url, "-so" ]
elif userinfo:
cmd1 = [r"C:\OSGeo4W\bin\ogrinfo.exe", conf, confoptionauth, basic, conf, confoptionuserpw, userinfo , "WFS:"+url, "-so" ]
else:
cmd1 = [r"C:\OSGeo4W\bin\ogrinfo.exe", "WFS:"+url, "-so" ]
Since a third (and fourth) combination option might be included, the number of elifs could escalate quite quickly. I was therefore wondering if its possible to shorten the conditional statement.
Aucun commentaire:
Enregistrer un commentaire