Revision 8
uporaba.html | ||
---|---|---|
46 | 46 |
|
47 | 47 |
<div class="section" id="uporaba"> |
48 | 48 |
<h1>Uporaba<a class="headerlink" href="#uporaba" title="Povezava na naslov">¶</a></h1> |
49 |
<p>Primeri uporabe web servisa za Python in SOAP knjižico <a class="reference external" href="https://fedorahosted.org/suds/">SUDS</a>, ki jo namestimo z:</p> |
|
49 |
<p>Primeri uporabe web servisa na Ubuntu 10.04 za Python in SOAP knjižico <a class="reference external" href="https://fedorahosted.org/suds/">SUDS</a>, ki jo namestimo z:</p>
|
|
50 | 50 |
<div class="highlight-python"><pre>sudo easy_install suds</pre> |
51 | 51 |
</div> |
52 | 52 |
<div class="section" id="nadzorni-modul"> |
53 | 53 |
<h2>Nadzorni modul<a class="headerlink" href="#nadzorni-modul" title="Povezava na naslov">¶</a></h2> |
54 | 54 |
<p>Nadozrni modul skrbi za dostop do naprave.</p> |
55 | 55 |
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">suds.client</span> <span class="kn">import</span> <span class="n">Client</span> |
56 |
<span class="n">client</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
|
|
56 |
<span class="n">management</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
|
|
57 | 57 |
|
58 |
<span class="n">url</span> <span class="o">=</span> <span class="s">'http://<webservice_host>/lidar/LIDAR?wsdl'</span>
|
|
58 |
<span class="n">url</span> <span class="o">=</span> <span class="s">'http://<webservice_host>/lidar/Management?wsdl'</span>
|
|
59 | 59 |
<span class="n">api_key</span> <span class="o">=</span> <span class="s">'api_key'</span> |
60 | 60 |
<span class="n">username</span> <span class="o">=</span> <span class="s">'username'</span> |
61 | 61 |
<span class="n">password</span> <span class="o">=</span> <span class="s">'password'</span> |
... | ... | |
63 | 63 |
</div> |
64 | 64 |
<div class="section" id="avtentikacija"> |
65 | 65 |
<h3>Avtentikacija<a class="headerlink" href="#avtentikacija" title="Povezava na naslov">¶</a></h3> |
66 |
<div class="highlight-python"><div class="highlight"><pre><span class="n">auth_token</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">service</span><span class="o">.</span><span class="n">getAuthenticationToken</span><span class="p">(</span><span class="n">api_key</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="p">)</span>
|
|
66 |
<div class="highlight-python"><div class="highlight"><pre><span class="n">auth_token</span> <span class="o">=</span> <span class="n">management</span><span class="o">.</span><span class="n">service</span><span class="o">.</span><span class="n">getAuthenticationToken</span><span class="p">(</span><span class="n">api_key</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="p">)</span>
|
|
67 | 67 |
<span class="k">if</span> <span class="n">auth_token</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span> |
68 |
<span class="k">print</span> <span class="s">'Authenticated! Auth token: </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">auth_token</span>
|
|
68 |
<span class="k">print</span> <span class="s">'Prijavljen! Auth token: </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">auth_token</span>
|
|
69 | 69 |
</pre></div> |
70 | 70 |
</div> |
71 | 71 |
</div> |
72 | 72 |
<div class="section" id="zaklep"> |
73 | 73 |
<h3>Zaklep<a class="headerlink" href="#zaklep" title="Povezava na naslov">¶</a></h3> |
74 |
<div class="highlight-python"><div class="highlight"><pre><span class="n">lock_token</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">service</span><span class="o">.</span><span class="n">getLockToken</span><span class="p">(</span><span class="n">auth_token</span><span class="p">)</span> |
|
75 |
<span class="k">if</span> <span class="n">lock_token</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span> |
|
76 |
<span class="k">print</span> <span class="s">'Locked! Lock token: </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">lock_token</span> |
|
74 |
<div class="highlight-python"><div class="highlight"><pre><span class="n">status</span> <span class="o">=</span> <span class="n">management</span><span class="o">.</span><span class="n">service</span><span class="o">.</span><span class="n">getStatus</span><span class="p">(</span><span class="n">auth_token</span><span class="p">)</span> |
|
75 |
<span class="k">if</span> <span class="n">status</span> <span class="o">==</span> <span class="s">'unlocked'</span><span class="p">:</span> |
|
76 |
<span class="n">lock_token</span> <span class="o">=</span> <span class="n">management</span><span class="o">.</span><span class="n">service</span><span class="o">.</span><span class="n">getLockToken</span><span class="p">(</span><span class="n">auth_token</span><span class="p">)</span> |
|
77 |
<span class="k">if</span> <span class="n">lock_token</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span> |
|
78 |
<span class="k">print</span> <span class="s">'Naprava zaklenjena! Lock token: </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">lock_token</span> |
|
79 |
|
|
80 |
<span class="c"># TODO: Uporaba zaklenjene naprave z uporabo lock_token</span> |
|
77 | 81 |
</pre></div> |
78 | 82 |
</div> |
79 | 83 |
</div> |
80 | 84 |
<div class="section" id="odklep"> |
81 | 85 |
<h3>Odklep<a class="headerlink" href="#odklep" title="Povezava na naslov">¶</a></h3> |
82 |
<div class="highlight-python"><div class="highlight"><pre><span class="n">unlock</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">service</span><span class="o">.</span><span class="n">unlock</span><span class="p">(</span><span class="n">lock_token</span><span class="p">)</span>
|
|
86 |
<div class="highlight-python"><div class="highlight"><pre><span class="n">unlock</span> <span class="o">=</span> <span class="n">management</span><span class="o">.</span><span class="n">service</span><span class="o">.</span><span class="n">unlock</span><span class="p">(</span><span class="n">lock_token</span><span class="p">)</span>
|
|
83 | 87 |
<span class="k">if</span> <span class="n">unlock</span><span class="p">:</span> |
84 |
<span class="k">print</span> <span class="s">'Unlocked!'</span>
|
|
88 |
<span class="k">print</span> <span class="s">'Naprava odklenjena!'</span>
|
|
85 | 89 |
</pre></div> |
86 | 90 |
</div> |
87 | 91 |
</div> |
Also available in: Unified diff