Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Executing the following code creates a dictionnary whose keys are server's number and values are (sslport,port,host)</p> <pre><code>import re RE = ('projectName.ClusterNameServer(\d+)\.sslport=(\d+)\s+' 'projectName.ClusterNameServer\\1\.port=(\d+)\s+' 'projectName.ClusterNameServer\\1\.host=(\S+)(?:\s+|\Z)') propertyfile_name = 'servers.txt' with open(propertyfile_name) as f: dico = dict( (server,(s,p,h)) for (server,s,p,h) in re.findall(RE,f.read()) ) print dico </code></pre> <p>result</p> <pre><code>dico== {'1': ('443', '80', 'myHostA'), '2': ('443', '80', 'myHostB')} </code></pre> <p>Then the dico data can be passed " <em>to the deployment scripts</em> "; I don't know what are your possibilities to pass this data. It may be done as a flat file, or, better, a pickle file.</p> <p>The simplest solution would be to include the lines of the above code directly into the "deployment scripts" so as they would have the data without the need to receive the data from outside.</p> <p>. EDIT</p> <p>Another solution, that I find better:</p> <pre><code>import csv from itertools import ifilter propertyfile_name = 'servers.txt' with open(propertyfile_name,'rb') as f: dico = dict( ifilter(None,csv.reader(f,delimiter='=')) ) print dico </code></pre> <p>The <code>ifilter()</code> function is necessary because of blank lines in the file.</p> <p>result</p> <blockquote> <p>{'projectName.ClusterNameServer2.host': 'myHostB', 'projectName.ClusterNameServer2.port': '80', 'projectName.ClusterNameServer1.host': 'myHostA', 'projectName.ClusterNameServer1.port': '80', 'projectName.ClusterNameServer2.sslport': '443', 'projectName.ClusterNameServer1.sslport': '443'}</p> </blockquote> <p>.</p> <p>EDIT</p> <pre><code>RE = ('(projectName.ClusterNameServer\d+\.(?:sslport|port|host))=(\S+)(?:\s+|\Z)') propertyfile_name = 'servers.txt' with open(propertyfile_name) as f: dico = dict( re.findall(RE,f.read()) ) print dico </code></pre> <p>Same result</p> <p>If you want result </p> <pre><code>dico== {'1': ('443', '80', 'myHostA'), '2': ('443', '80', 'myHostB')} </code></pre> <p>I will do tomorrow</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload