1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
<html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
4
<title>lib/datastore_repo.rb</title>
5
<link href="screen.css" media="all" rel="stylesheet" type="text/css" />
6
<link href="print.css" media="print" rel="stylesheet" type="text/css" />
8
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
9
<script type="text/javascript" src="rcov.js"></script>
12
<h1>Appcontroller C0 Coverage Information - RCov</h1>
13
<h2>lib/datastore_repo.rb</h2>
17
<div class="report_table_wrapper">
18
<table class='report' id='report_table'>
21
<th class="left_align">Name</th>
22
<th class="right_align">Total Lines</th>
23
<th class="right_align">Lines of Code</th>
24
<th class="left_align">Total Coverage</th>
25
<th class="left_align">Code Coverage</th>
30
<td class="left_align"><a href="lib-datastore_repo_rb.html">lib/datastore_repo.rb</a></td>
31
<td class='right_align'><tt>137</tt></td>
32
<td class='right_align'><tt>82</tt></td>
33
<td class="left_align"><div class="percent_graph_legend"><tt class=''>100.00%</tt></div>
34
<div class="percent_graph">
35
<div class="covered" style="width:100px"></div>
36
<div class="uncovered" style="width:0px"></div>
38
<td class="left_align"><div class="percent_graph_legend"><tt class=''>100.00%</tt></div>
39
<div class="percent_graph">
40
<div class="covered" style="width:100px"></div>
41
<div class="uncovered" style="width:0px"></div>
50
<div class="key"><pre><span class='marked'>Code reported as executed by Ruby looks like this...</span><span class='marked1'>and this: this line is also marked as covered.</span><span class='inferred'>Lines considered as run by rcov, but not reported by Ruby, look like this,</span><span class='inferred1'>and this: these lines were inferred by rcov (using simple heuristics).</span><span class='uncovered'>Finally, here's a line marked as not executed.</span></pre></div>
52
<h3>Coverage Details</h3>
54
<table class="details">
60
<td><pre><a name="line1">1</a> # Programmer: Chris Bunch</pre></td>
66
<td><pre><a name="line2">2</a> </pre></td>
72
<td><pre><a name="line3">3</a> </pre></td>
78
<td><pre><a name="line4">4</a> require 'datastore'</pre></td>
84
<td><pre><a name="line5">5</a> require 'repo'</pre></td>
90
<td><pre><a name="line6">6</a> </pre></td>
96
<td><pre><a name="line7">7</a> </pre></td>
101
<tr class="inferred">
102
<td><pre><a name="line8">8</a> # A class that abstracts away access to our Repository application (also known</pre></td>
107
<tr class="inferred">
108
<td><pre><a name="line9">9</a> # as the Repo). Since it's a web application, it can be hosted anywhere, and thus</pre></td>
113
<tr class="inferred">
114
<td><pre><a name="line10">10</a> # this class dictates what we expect the application to return. Implementers of</pre></td>
119
<tr class="inferred">
120
<td><pre><a name="line11">11</a> # this class need only tell us where we can expect to find the Repo application</pre></td>
125
<tr class="inferred">
126
<td><pre><a name="line12">12</a> # and how to make sure it's running there.</pre></td>
132
<td><pre><a name="line13">13</a> class DatastoreRepo</pre></td>
137
<tr class="inferred">
138
<td><pre><a name="line14">14</a> </pre></td>
143
<tr class="inferred">
144
<td><pre><a name="line15">15</a> </pre></td>
149
<tr class="inferred">
150
<td><pre><a name="line16">16</a> # The host (IP:port) that the Repo app is hosted at.</pre></td>
156
<td><pre><a name="line17">17</a> attr_accessor :host</pre></td>
161
<tr class="inferred">
162
<td><pre><a name="line18">18</a> </pre></td>
167
<tr class="inferred">
168
<td><pre><a name="line19">19</a> </pre></td>
173
<tr class="inferred">
174
<td><pre><a name="line20">20</a> # The name of this datastore, which DatastoreFactory will use to find this</pre></td>
179
<tr class="inferred">
180
<td><pre><a name="line21">21</a> # Datastore. Implementers should use a unique name amongst Datastore</pre></td>
185
<tr class="inferred">
186
<td><pre><a name="line22">22</a> # implementers.</pre></td>
192
<td><pre><a name="line23">23</a> NAME = ""</pre></td>
197
<tr class="inferred">
198
<td><pre><a name="line24">24</a> </pre></td>
203
<tr class="inferred">
204
<td><pre><a name="line25">25</a> </pre></td>
209
<tr class="inferred">
210
<td><pre><a name="line26">26</a> # Creates a new connection to the Repo running on AppScale. Since AppScale</pre></td>
215
<tr class="inferred">
216
<td><pre><a name="line27">27</a> # starts the Repo automatically, this initialization does not start it</pre></td>
221
<tr class="inferred">
222
<td><pre><a name="line28">28</a> # or verify that it is running (although it perhaps should do the latter).</pre></td>
228
<td><pre><a name="line29">29</a> def initialize(credentials)</pre></td>
234
<td><pre><a name="line30">30</a> raise NotImplementedError.new("Can't init an abstract Repo")</pre></td>
239
<tr class="inferred">
240
<td><pre><a name="line31">31</a> end</pre></td>
245
<tr class="inferred">
246
<td><pre><a name="line32">32</a> </pre></td>
251
<tr class="inferred">
252
<td><pre><a name="line33">33</a> </pre></td>
257
<tr class="inferred">
258
<td><pre><a name="line34">34</a> # Writes the contents of the remotely specified file to the local filesystem.</pre></td>
264
<td><pre><a name="line35">35</a> def get_output_and_save_to_fs(repo_path, local_path)</pre></td>
270
<td><pre><a name="line36">36</a> data = get_output_and_return_contents(repo_path)</pre></td>
276
<td><pre><a name="line37">37</a> HelperFunctions.write_file(local_path, data)</pre></td>
281
<tr class="inferred">
282
<td><pre><a name="line38">38</a> end</pre></td>
287
<tr class="inferred">
288
<td><pre><a name="line39">39</a> </pre></td>
293
<tr class="inferred">
294
<td><pre><a name="line40">40</a> </pre></td>
299
<tr class="inferred">
300
<td><pre><a name="line41">41</a> # Returns the output of the given file as a string.</pre></td>
306
<td><pre><a name="line42">42</a> def get_output_and_return_contents(repo_path)</pre></td>
312
<td><pre><a name="line43">43</a> Djinn.log_debug("Attempting to get output for file [#{repo_path}]")</pre></td>
318
<td><pre><a name="line44">44</a> return do_http_get_for_get(repo_path, :output)</pre></td>
323
<tr class="inferred">
324
<td><pre><a name="line45">45</a> end</pre></td>
329
<tr class="inferred">
330
<td><pre><a name="line46">46</a> </pre></td>
335
<tr class="inferred">
336
<td><pre><a name="line47">47</a> </pre></td>
341
<tr class="inferred">
342
<td><pre><a name="line48">48</a> # Writes the contents of the given file to a file hosted in the Repo.</pre></td>
347
<tr class="inferred">
348
<td><pre><a name="line49">49</a> # If the given file is a directory, we also write all files / directories</pre></td>
353
<tr class="inferred">
354
<td><pre><a name="line50">50</a> # found in that directory.</pre></td>
360
<td><pre><a name="line51">51</a> def write_remote_file_from_local_file(repo_path, local_path)</pre></td>
366
<td><pre><a name="line52">52</a> if File.directory?(local_path)</pre></td>
372
<td><pre><a name="line53">53</a> files_to_upload = HelperFunctions.shell("ls #{local_path}")</pre></td>
378
<td><pre><a name="line54">54</a> files_to_upload.split.each { |file|</pre></td>
384
<td><pre><a name="line55">55</a> full_repo_path = repo_path + "/" + file</pre></td>
390
<td><pre><a name="line56">56</a> full_local_path = local_path + "/" + file</pre></td>
396
<td><pre><a name="line57">57</a> Djinn.log_debug("Recursive dive - now saving remote " +</pre></td>
401
<tr class="inferred">
402
<td><pre><a name="line58">58</a> "[#{full_repo_path}], local [#{full_local_path}]")</pre></td>
408
<td><pre><a name="line59">59</a> temp = write_remote_file_from_local_file(full_repo_path, full_local_path)</pre></td>
414
<td><pre><a name="line60">60</a> if !temp</pre></td>
420
<td><pre><a name="line61">61</a> Djinn.log_debug("Setting remote [#{full_repo_path}] failed - reported [#{temp}]")</pre></td>
426
<td><pre><a name="line62">62</a> return false</pre></td>
431
<tr class="inferred">
432
<td><pre><a name="line63">63</a> end</pre></td>
437
<tr class="inferred">
438
<td><pre><a name="line64">64</a> }</pre></td>
443
<tr class="inferred">
444
<td><pre><a name="line65">65</a> </pre></td>
450
<td><pre><a name="line66">66</a> return true</pre></td>
455
<tr class="inferred">
456
<td><pre><a name="line67">67</a> else</pre></td>
462
<td><pre><a name="line68">68</a> Djinn.log_debug("Attempting to put local file #{local_path} into file #{repo_path}")</pre></td>
468
<td><pre><a name="line69">69</a> val = HelperFunctions.read_file(local_path, chomp=false)</pre></td>
474
<td><pre><a name="line70">70</a> return do_http_post_for_set(repo_path, :output, val)</pre></td>
479
<tr class="inferred">
480
<td><pre><a name="line71">71</a> end</pre></td>
485
<tr class="inferred">
486
<td><pre><a name="line72">72</a> end</pre></td>
491
<tr class="inferred">
492
<td><pre><a name="line73">73</a> </pre></td>
497
<tr class="inferred">
498
<td><pre><a name="line74">74</a> </pre></td>
503
<tr class="inferred">
504
<td><pre><a name="line75">75</a> # Writes the contents of the given string to a file hosted in the Repo.</pre></td>
510
<td><pre><a name="line76">76</a> def write_remote_file_from_string(repo_path, string)</pre></td>
516
<td><pre><a name="line77">77</a> Djinn.log_debug("Attempting to put local file into location #{repo_path}")</pre></td>
522
<td><pre><a name="line78">78</a> return do_http_post_for_set(repo_path, :output, string)</pre></td>
527
<tr class="inferred">
528
<td><pre><a name="line79">79</a> end</pre></td>
533
<tr class="inferred">
534
<td><pre><a name="line80">80</a> </pre></td>
539
<tr class="inferred">
540
<td><pre><a name="line81">81</a> </pre></td>
545
<tr class="inferred">
546
<td><pre><a name="line82">82</a> # Retrieves the access policy for the given file.</pre></td>
552
<td><pre><a name="line83">83</a> def get_acl(repo_path)</pre></td>
558
<td><pre><a name="line84">84</a> Djinn.log_debug("Attempting to get acl for file [#{repo_path}]")</pre></td>
564
<td><pre><a name="line85">85</a> return do_http_get_for_get(repo_path, :acl)</pre></td>
569
<tr class="inferred">
570
<td><pre><a name="line86">86</a> end</pre></td>
575
<tr class="inferred">
576
<td><pre><a name="line87">87</a> </pre></td>
581
<tr class="inferred">
582
<td><pre><a name="line88">88</a> </pre></td>
587
<tr class="inferred">
588
<td><pre><a name="line89">89</a> # Sets the access policy for the given file hosted in the Repo.</pre></td>
594
<td><pre><a name="line90">90</a> def set_acl(repo_path, acl)</pre></td>
600
<td><pre><a name="line91">91</a> Djinn.log_debug("Attempting to set acl to [#{acl}] for file #{repo_path}")</pre></td>
606
<td><pre><a name="line92">92</a> return do_http_post_for_set(repo_path, :acl, acl)</pre></td>
611
<tr class="inferred">
612
<td><pre><a name="line93">93</a> end</pre></td>
617
<tr class="inferred">
618
<td><pre><a name="line94">94</a> </pre></td>
623
<tr class="inferred">
624
<td><pre><a name="line95">95</a> </pre></td>
629
<tr class="inferred">
630
<td><pre><a name="line96">96</a> # Queries the Repo app to see if the given file exists.</pre></td>
636
<td><pre><a name="line97">97</a> def does_file_exist?(repo_path)</pre></td>
642
<td><pre><a name="line98">98</a> Djinn.log_debug("Performing a does_file_exist? on file [#{repo_path}]")</pre></td>
648
<td><pre><a name="line99">99</a> exists_url = "http://#{@host}/doesexist"</pre></td>
654
<td><pre><a name="line100">100</a> params = {'SECRET' => HelperFunctions.get_secret(), 'KEY' => repo_path}</pre></td>
660
<td><pre><a name="line101">101</a> result = Net::HTTP.post_form(URI.parse(exists_url), params).body</pre></td>
666
<td><pre><a name="line102">102</a> if result == "true"</pre></td>
672
<td><pre><a name="line103">103</a> return true</pre></td>
677
<tr class="inferred">
678
<td><pre><a name="line104">104</a> else</pre></td>
684
<td><pre><a name="line105">105</a> return false</pre></td>
689
<tr class="inferred">
690
<td><pre><a name="line106">106</a> end</pre></td>
695
<tr class="inferred">
696
<td><pre><a name="line107">107</a> end</pre></td>
701
<tr class="inferred">
702
<td><pre><a name="line108">108</a> </pre></td>
707
<tr class="inferred">
708
<td><pre><a name="line109">109</a> </pre></td>
713
<tr class="inferred">
714
<td><pre><a name="line110">110</a> # A convenience method that can be used to perform GET requests on the</pre></td>
719
<tr class="inferred">
720
<td><pre><a name="line111">111</a> # Repo app, returning whatever it returns.</pre></td>
726
<td><pre><a name="line112">112</a> def do_http_get_for_get(repo_path, type)</pre></td>
732
<td><pre><a name="line113">113</a> Djinn.log_debug("Performing a get on key [#{repo_path}], type [#{type}]")</pre></td>
738
<td><pre><a name="line114">114</a> get_url = "http://#{@host}/get"</pre></td>
744
<td><pre><a name="line115">115</a> params = {'SECRET' => HelperFunctions.get_secret(), 'KEY' => repo_path, </pre></td>
749
<tr class="inferred">
750
<td><pre><a name="line116">116</a> 'TYPE' => type}</pre></td>
756
<td><pre><a name="line117">117</a> data = Net::HTTP.post_form(URI.parse(get_url), params).body</pre></td>
762
<td><pre><a name="line118">118</a> return Base64.decode64(data)</pre></td>
767
<tr class="inferred">
768
<td><pre><a name="line119">119</a> end</pre></td>
773
<tr class="inferred">
774
<td><pre><a name="line120">120</a> </pre></td>
779
<tr class="inferred">
780
<td><pre><a name="line121">121</a> </pre></td>
785
<tr class="inferred">
786
<td><pre><a name="line122">122</a> # A convenience method that can be used to perform POST requests on the</pre></td>
791
<tr class="inferred">
792
<td><pre><a name="line123">123</a> # Repo app, returning a boolean corresponding to if the operation succeeded.</pre></td>
798
<td><pre><a name="line124">124</a> def do_http_post_for_set(repo_path, type, val)</pre></td>
804
<td><pre><a name="line125">125</a> encoded_val = Base64.encode64(val)</pre></td>
810
<td><pre><a name="line126">126</a> set_url = "http://#{@host}/set"</pre></td>
816
<td><pre><a name="line127">127</a> params = {'SECRET' => HelperFunctions.get_secret(), 'KEY' => repo_path,</pre></td>
821
<tr class="inferred">
822
<td><pre><a name="line128">128</a> 'VALUE' => encoded_val, 'TYPE' => type}</pre></td>
828
<td><pre><a name="line129">129</a> result = Net::HTTP.post_form(URI.parse(set_url), params).body</pre></td>
834
<td><pre><a name="line130">130</a> Djinn.log_debug("set key=#{repo_path} type=#{type} returned #{result}")</pre></td>
840
<td><pre><a name="line131">131</a> if result == "success"</pre></td>
846
<td><pre><a name="line132">132</a> return true</pre></td>
851
<tr class="inferred">
852
<td><pre><a name="line133">133</a> else</pre></td>
858
<td><pre><a name="line134">134</a> return false</pre></td>
863
<tr class="inferred">
864
<td><pre><a name="line135">135</a> end</pre></td>
869
<tr class="inferred">
870
<td><pre><a name="line136">136</a> end</pre></td>
875
<tr class="inferred">
876
<td><pre><a name="line137">137</a> end</pre></td>
882
<p>Generated on Sat Feb 25 19:19:09 -0800 2012 with <a href="http://github.com/relevance/rcov">rcov 0.9.8</a></p>