-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
943 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
__author__ = "Shyue Ping Ong, William Davidson Richards, Stephen Dacek, " \ | ||
"Xiaohui Qu" | ||
__date__ = "Jul 14 2014" | ||
__version__ = "0.7.4" | ||
__version__ = "0.7.5" | ||
|
||
from custodian import Custodian |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: ce604e9da68f63aa2c1f3752b4718248 | ||
config: 027556057d184ab38babdd14d30b0a67 | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 217 additions & 0 deletions
217
docs/_build/html/_modules/custodian/ansible/interpreter.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
|
||
|
||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
|
||
<title>custodian.ansible.interpreter — custodian 0.7.5 documentation</title> | ||
|
||
<link rel="stylesheet" href="../../../_static/proBlue.css" type="text/css" /> | ||
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" /> | ||
|
||
<script type="text/javascript"> | ||
var DOCUMENTATION_OPTIONS = { | ||
URL_ROOT: '../../../', | ||
VERSION: '0.7.5', | ||
COLLAPSE_INDEX: false, | ||
FILE_SUFFIX: '.html', | ||
HAS_SOURCE: true | ||
}; | ||
</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> | ||
<link rel="shortcut icon" href="../../../_static/favicon.ico"/> | ||
<link rel="top" title="custodian 0.7.5 documentation" href="../../../index.html" /> | ||
<link rel="up" title="Module code" href="../../index.html" /> | ||
|
||
<script type="text/javascript"> | ||
var _gaq = _gaq || []; | ||
_gaq.push(['_setAccount', 'UA-39574369-1']); | ||
_gaq.push(['_trackPageview']); | ||
</script> | ||
|
||
</head> | ||
<body> | ||
<div class="related"> | ||
<h3>Navigation</h3> | ||
<ul> | ||
<li class="right" style="margin-right: 10px"> | ||
<a href="../../../genindex.html" title="General Index" | ||
accesskey="I">index</a></li> | ||
<li class="right" > | ||
<a href="../../../py-modindex.html" title="Python Module Index" | ||
>modules</a> |</li> | ||
<li><a href="../../../index.html">custodian 0.7.5 documentation</a> »</li> | ||
<li><a href="../../index.html" accesskey="U">Module code</a> »</li> | ||
</ul> | ||
</div> | ||
|
||
<div class="document"> | ||
<div class="documentwrapper"> | ||
<div class="bodywrapper"> | ||
<div class="body"> | ||
|
||
<h1>Source code for custodian.ansible.interpreter</h1><div class="highlight"><pre> | ||
<span class="c">#!/usr/bin/env python</span> | ||
|
||
<span class="sd">"""</span> | ||
<span class="sd">This module implements a Modder class that performs modifications on objects</span> | ||
<span class="sd">using support actions.</span> | ||
<span class="sd">"""</span> | ||
|
||
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">division</span> | ||
|
||
<span class="n">__author__</span> <span class="o">=</span> <span class="s">"Shyue Ping Ong"</span> | ||
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s">"Copyright 2012, The Materials Project"</span> | ||
<span class="n">__version__</span> <span class="o">=</span> <span class="s">"0.1"</span> | ||
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s">"Shyue Ping Ong"</span> | ||
<span class="n">__email__</span> <span class="o">=</span> <span class="s">"ongsp@ucsd.edu"</span> | ||
<span class="n">__date__</span> <span class="o">=</span> <span class="s">"Jun 1, 2012"</span> | ||
|
||
|
||
<span class="kn">import</span> <span class="nn">re</span> | ||
|
||
<span class="kn">from</span> <span class="nn">custodian.ansible.actions</span> <span class="kn">import</span> <span class="n">DictActions</span> | ||
|
||
|
||
<div class="viewcode-block" id="Modder"><a class="viewcode-back" href="../../../custodian.ansible.html#custodian.ansible.interpreter.Modder">[docs]</a><span class="k">class</span> <span class="nc">Modder</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> | ||
<span class="sd">"""</span> | ||
<span class="sd"> Class to modify a dict/file/any object using a mongo-like language.</span> | ||
<span class="sd"> Keywords are mostly adopted from mongo's syntax, but instead of $, an</span> | ||
<span class="sd"> underscore precedes action keywords. This is so that the modification can</span> | ||
<span class="sd"> be inserted into a mongo db easily.</span> | ||
|
||
<span class="sd"> Allowable actions are supplied as a list of classes as an argument. Refer</span> | ||
<span class="sd"> to the action classes on what the actions do. Action classes are in</span> | ||
<span class="sd"> pymatpro.ansible.actions.</span> | ||
|
||
<span class="sd"> Examples:</span> | ||
<span class="sd"> >>> modder = Modder()</span> | ||
<span class="sd"> >>> d = {"Hello": "World"}</span> | ||
<span class="sd"> >>> mod = {'_set': {'Hello':'Universe', 'Bye': 'World'}}</span> | ||
<span class="sd"> >>> modder.modify(mod, d)</span> | ||
<span class="sd"> >>> d['Bye']</span> | ||
<span class="sd"> 'World'</span> | ||
<span class="sd"> >>> d['Hello']</span> | ||
<span class="sd"> 'Universe'</span> | ||
<span class="sd"> """</span> | ||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">actions</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">strict</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span> | ||
<span class="sd">"""</span> | ||
<span class="sd"> Initializes a Modder from a list of supported actions.</span> | ||
|
||
<span class="sd"> Args:</span> | ||
<span class="sd"> actions ([Action]): A sequence of supported actions. See</span> | ||
<span class="sd"> :mod:`custodian.ansible.actions`. Default is None,</span> | ||
<span class="sd"> which means only DictActions are supported.</span> | ||
<span class="sd"> strict (bool): Indicating whether to use strict mode. In non-strict</span> | ||
<span class="sd"> mode, unsupported actions are simply ignored without any</span> | ||
<span class="sd"> errors raised. In strict mode, if an unsupported action is</span> | ||
<span class="sd"> supplied, a ValueError is raised. Defaults to True.</span> | ||
<span class="sd"> """</span> | ||
<span class="bp">self</span><span class="o">.</span><span class="n">supported_actions</span> <span class="o">=</span> <span class="p">{}</span> | ||
<span class="n">actions</span> <span class="o">=</span> <span class="n">actions</span> <span class="k">if</span> <span class="n">actions</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="k">else</span> <span class="p">[</span><span class="n">DictActions</span><span class="p">]</span> | ||
<span class="k">for</span> <span class="n">action</span> <span class="ow">in</span> <span class="n">actions</span><span class="p">:</span> | ||
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">dir</span><span class="p">(</span><span class="n">action</span><span class="p">):</span> | ||
<span class="k">if</span> <span class="p">(</span><span class="ow">not</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s">'__\w+__'</span><span class="p">,</span> <span class="n">i</span><span class="p">))</span> <span class="ow">and</span> \ | ||
<span class="nb">callable</span><span class="p">(</span><span class="nb">getattr</span><span class="p">(</span><span class="n">action</span><span class="p">,</span> <span class="n">i</span><span class="p">)):</span> | ||
<span class="bp">self</span><span class="o">.</span><span class="n">supported_actions</span><span class="p">[</span><span class="s">"_"</span> <span class="o">+</span> <span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">action</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> | ||
<span class="bp">self</span><span class="o">.</span><span class="n">strict</span> <span class="o">=</span> <span class="n">strict</span> | ||
|
||
<div class="viewcode-block" id="Modder.modify"><a class="viewcode-back" href="../../../custodian.ansible.html#custodian.ansible.interpreter.Modder.modify">[docs]</a> <span class="k">def</span> <span class="nf">modify</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">modification</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span> | ||
<span class="sd">"""</span> | ||
<span class="sd"> Note that modify makes actual in-place modifications. It does not</span> | ||
<span class="sd"> return a copy.</span> | ||
|
||
<span class="sd"> Args:</span> | ||
<span class="sd"> modification (dict): Modification must be {action_keyword :</span> | ||
<span class="sd"> settings}. E.g., {'_set': {'Hello':'Universe', 'Bye': 'World'}}</span> | ||
<span class="sd"> obj (dict/str/object): Object to modify depending on actions. For</span> | ||
<span class="sd"> example, for DictActions, obj will be a dict to be modified.</span> | ||
<span class="sd"> For FileActions, obj will be a string with a full pathname to a</span> | ||
<span class="sd"> file.</span> | ||
<span class="sd"> """</span> | ||
<span class="k">for</span> <span class="n">action</span><span class="p">,</span> <span class="n">settings</span> <span class="ow">in</span> <span class="n">modification</span><span class="o">.</span><span class="n">items</span><span class="p">():</span> | ||
<span class="k">if</span> <span class="n">action</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">supported_actions</span><span class="p">:</span> | ||
<span class="bp">self</span><span class="o">.</span><span class="n">supported_actions</span><span class="p">[</span><span class="n">action</span><span class="p">]</span><span class="o">.</span><span class="n">__call__</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">settings</span><span class="p">)</span> | ||
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">strict</span><span class="p">:</span> | ||
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">"{} is not a supported action!"</span> | ||
<span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">action</span><span class="p">))</span> | ||
</div> | ||
<div class="viewcode-block" id="Modder.modify_object"><a class="viewcode-back" href="../../../custodian.ansible.html#custodian.ansible.interpreter.Modder.modify_object">[docs]</a> <span class="k">def</span> <span class="nf">modify_object</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">modification</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span> | ||
<span class="sd">"""</span> | ||
<span class="sd"> Modify an object that supports pymatgen's to_dict and from_dict API.</span> | ||
|
||
<span class="sd"> Args:</span> | ||
<span class="sd"> modification (dict): Modification must be {action_keyword :</span> | ||
<span class="sd"> settings}. E.g., {'_set': {'Hello':'Universe', 'Bye': 'World'}}</span> | ||
<span class="sd"> obj (object): Object to modify</span> | ||
<span class="sd"> """</span> | ||
<span class="n">d</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">to_dict</span> | ||
<span class="bp">self</span><span class="o">.</span><span class="n">modify</span><span class="p">(</span><span class="n">modification</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span> | ||
<span class="k">return</span> <span class="n">obj</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> | ||
|
||
</div></div> | ||
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">"__main__"</span><span class="p">:</span> | ||
<span class="kn">import</span> <span class="nn">doctest</span> | ||
<span class="n">doctest</span><span class="o">.</span><span class="n">testmod</span><span class="p">()</span> | ||
</pre></div> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
<div class="sphinxsidebar"> | ||
<div class="sphinxsidebarwrapper"> | ||
<div id="searchbox" style="display: none"> | ||
<h3>Quick search</h3> | ||
<form class="search" action="../../../search.html" method="get"> | ||
<input type="text" name="q" /> | ||
<input type="submit" value="Go" /> | ||
<input type="hidden" name="check_keywords" value="yes" /> | ||
<input type="hidden" name="area" value="default" /> | ||
</form> | ||
<p class="searchtip" style="font-size: 90%"> | ||
Enter search terms or a module, class or function name. | ||
</p> | ||
</div> | ||
<script type="text/javascript">$('#searchbox').show(0);</script> | ||
</div> | ||
</div> | ||
<div class="clearer"></div> | ||
</div> | ||
<div class="related"> | ||
<h3>Navigation</h3> | ||
<ul> | ||
<li class="right" style="margin-right: 10px"> | ||
<a href="../../../genindex.html" title="General Index" | ||
>index</a></li> | ||
<li class="right" > | ||
<a href="../../../py-modindex.html" title="Python Module Index" | ||
>modules</a> |</li> | ||
<li><a href="../../../index.html">custodian 0.7.5 documentation</a> »</li> | ||
<li><a href="../../index.html" >Module code</a> »</li> | ||
</ul> | ||
</div> | ||
|
||
<div class="footer"> | ||
© Copyright 2013, Shyue Ping Ong, William Davidson Richards, Stephen Dacek, Xiaohui Qu. | ||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.2. | ||
</div> | ||
<div class="footer">This page uses <a href="http://analytics.google.com/"> | ||
Google Analytics</a> to collect statistics. You can disable it by blocking | ||
the JavaScript coming from www.google-analytics.com. | ||
<script type="text/javascript"> | ||
(function() { | ||
var ga = document.createElement('script'); | ||
ga.src = ('https:' == document.location.protocol ? | ||
'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | ||
ga.setAttribute('async', 'true'); | ||
document.documentElement.firstChild.appendChild(ga); | ||
})(); | ||
</script> | ||
</div> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.