Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-release > by-pkgid > 40e2f31081093569df699eb11a858fc8 > files > 140

python-copr-doc-1.94-1.mga7.noarch.rpm



<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Resources &mdash; python-copr 1.63 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../_static/jquery.js"></script>
        <script type="text/javascript" src="../_static/underscore.js"></script>
        <script type="text/javascript" src="../_static/doctools.js"></script>
        <script type="text/javascript" src="../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Error handling" href="errors.html" />
    <link rel="prev" title="Client initialization" href="initialization.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html" class="icon icon-home"> python-copr
          

          
          </a>

          
            
            
              <div class="version">
                1.63
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li>
</ul>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../ClientV1.html">Legacy client</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../ClientV2.html">Client version 2</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="initialization.html">Client initialization</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Resources</a></li>
<li class="toctree-l2"><a class="reference internal" href="errors.html">Error handling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../ClientV2.html#resources-info">Resources info</a></li>
<li class="toctree-l2"><a class="reference internal" href="../ClientV2.html#autodoc">Autodoc</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../ClientV3.html">Client version 3</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">python-copr</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../ClientV2.html">Client version 2</a> &raquo;</li>
        
      <li>Resources</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../_sources/client_v2/resources_usage.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="resources">
<h1>Resources<a class="headerlink" href="#resources" title="Permalink to this headline">ΒΆ</a></h1>
<p>Client represents API with two kinds of resources: Individuals and Collections. For example when we request
all projects with name <code class="xref any docutils literal notranslate"><span class="pre">copr</span></code> we would receive collection <a class="reference internal" href="resources.html#copr.client_v2.resources.ProjectList" title="copr.client_v2.resources.ProjectList"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProjectList</span></code></a> resource:</p>
<blockquote>
<div><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">copr</span> <span class="kn">import</span> <span class="n">create_client2_from_params</span>
<span class="go"># using dev server for test</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cl</span> <span class="o">=</span> <span class="n">create_client2_from_params</span><span class="p">(</span><span class="n">root_url</span><span class="o">=</span><span class="s2">&quot;http://copr-fe-dev.cloud.fedoraproject.org/&quot;</span><span class="p">)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">projects</span> <span class="o">=</span> <span class="n">cl</span><span class="o">.</span><span class="n">projects</span><span class="o">.</span><span class="n">get_list</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;copr&quot;</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">projects</span><span class="p">:</span>
<span class="gp">&gt;&gt;&gt; </span>   <span class="k">print</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
<span class="go">&lt;Project #1: msuchy/copr&gt;</span>
<span class="go">&lt;Project #1503: vgologuz/copr&gt;</span>
<span class="go">&lt;Project #2796: mosquito/copr&gt;</span>
</pre></div>
</div>
</div></blockquote>
<p>Access to elements in collection is done through iterator interface. Since API limits number of elements
retrieved in the one request, collections has method <a class="reference internal" href="resources.html#copr.client_v2.resources.ProjectList.next_page" title="copr.client_v2.resources.ProjectList.next_page"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">next_page()</span></code></a> to retrieve more objects:</p>
<blockquote>
<div><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">more_projects</span> <span class="o">=</span> <span class="n">projects</span><span class="o">.</span><span class="n">next_page</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">more_projects</span><span class="p">:</span>
<span class="gp">&gt;&gt;&gt; </span>   <span class="k">print</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
<span class="go">&lt;Project #2805: esmil/copr&gt;</span>
<span class="go">&lt;Project #4266: frostyx/copr&gt;</span>
</pre></div>
</div>
</div></blockquote>
<p>If we already knew project id we could get an individual <a class="reference internal" href="resources.html#copr.client_v2.resources.Project" title="copr.client_v2.resources.Project"><code class="xref py py-class docutils literal notranslate"><span class="pre">Project</span></code></a> resource:</p>
<blockquote>
<div><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">cl</span><span class="o">.</span><span class="n">projects</span><span class="o">.</span><span class="n">get_one</span><span class="p">(</span><span class="mi">1835</span><span class="p">)</span>
</pre></div>
</div>
</div></blockquote>
<p>Individual resource allows to directly access entity properties and also provides some helper functions:</p>
<blockquote>
<div><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">owner</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">(u&#39;saltstack&#39;, u&#39;salt&#39;)</span>
<span class="go"># obtain active build chroots</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">get_project_chroot_list</span><span class="p">())))</span>
<span class="go">&lt;Project chroot: fedora-22-x86_64, additional packages: [], comps size if any: 0&gt;</span>
<span class="go">&lt;Project chroot: fedora-22-i386, additional packages: [], comps size if any: 0&gt;</span>
<span class="go"># change project description (require auth)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">description</span> <span class="o">=</span> <span class="sa">u</span><span class="s2">&quot;Hello world!&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">update</span><span class="p">()</span>
<span class="go"># instead of cl.projects.update(p._entity)</span>
</pre></div>
</div>
</div></blockquote>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="errors.html" class="btn btn-neutral float-right" title="Error handling" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="initialization.html" class="btn btn-neutral float-left" title="Client initialization" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, Red Hat, Inc.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>