sitefuel 0.0.0b → 0.1.0a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/README.rdoc +81 -0
  2. data/{RELEASE_NOTES → RELEASE_NOTES.rdoc} +0 -0
  3. data/bin/sitefuel +64 -111
  4. data/lib/sitefuel/CommandLine.rb +142 -0
  5. data/lib/sitefuel/Configuration.rb +49 -13
  6. data/lib/sitefuel/License.rb +292 -0
  7. data/lib/sitefuel/SiteFuelLogger.rb +34 -5
  8. data/lib/sitefuel/SiteFuelRuntime.rb +217 -44
  9. data/lib/sitefuel/extensions/ArrayComparisons.rb +2 -2
  10. data/lib/sitefuel/extensions/ColumnPrinter.rb +276 -0
  11. data/lib/sitefuel/extensions/DynamicClassMethods.rb +2 -2
  12. data/lib/sitefuel/extensions/FileComparison.rb +2 -2
  13. data/lib/sitefuel/extensions/FileTree.rb +94 -0
  14. data/lib/sitefuel/extensions/Silently.rb +2 -2
  15. data/lib/sitefuel/extensions/StringFormatting.rb +52 -8
  16. data/lib/sitefuel/extensions/SymbolComparison.rb +4 -2
  17. data/lib/sitefuel/extensions/TerminalInfo.rb +53 -0
  18. data/lib/sitefuel/external/AbstractExternalProgram.rb +65 -11
  19. data/lib/sitefuel/external/ExternalProgramTestCase.rb +2 -2
  20. data/lib/sitefuel/external/GIT.rb +50 -3
  21. data/lib/sitefuel/external/JPEGTran.rb +2 -2
  22. data/lib/sitefuel/external/PNGCrush.rb +2 -2
  23. data/lib/sitefuel/external/SVN.rb +57 -0
  24. data/lib/sitefuel/processors/AbstractExternalProgramProcessor.rb +17 -4
  25. data/lib/sitefuel/processors/AbstractProcessor.rb +64 -47
  26. data/lib/sitefuel/processors/AbstractStringBasedProcessor.rb +20 -3
  27. data/lib/sitefuel/processors/CSSProcessor.rb +2 -2
  28. data/lib/sitefuel/processors/Configurable.rb +94 -0
  29. data/lib/sitefuel/processors/HAMLProcessor.rb +4 -4
  30. data/lib/sitefuel/processors/HTMLProcessor.rb +2 -2
  31. data/lib/sitefuel/processors/JavaScriptProcessor.rb +2 -2
  32. data/lib/sitefuel/processors/PHPProcessor.rb +2 -2
  33. data/lib/sitefuel/processors/PNGProcessor.rb +2 -2
  34. data/lib/sitefuel/processors/RHTMLProcessor.rb +2 -2
  35. data/lib/sitefuel/processors/SASSProcessor.rb +4 -4
  36. data/test/{test_images → images}/sample_jpg01.jpg +0 -0
  37. data/test/{test_images → images}/sample_png01.png +0 -0
  38. data/test/processor_listing.rb +2 -2
  39. data/test/{test_programs → programs}/versioning.rb +2 -2
  40. data/test/repositories/git/few_files/deployment.yml +0 -0
  41. data/test/repositories/git/few_files/index.html +10 -0
  42. data/test/repositories/git/few_files/style.css +2 -0
  43. data/test/repositories/svn/testrepo1/README.txt +5 -0
  44. data/test/repositories/svn/testrepo1/conf/authz +32 -0
  45. data/test/repositories/svn/testrepo1/conf/passwd +8 -0
  46. data/test/repositories/svn/testrepo1/conf/svnserve.conf +47 -0
  47. data/test/repositories/svn/testrepo1/db/current +1 -0
  48. data/test/repositories/svn/testrepo1/db/format +2 -0
  49. data/test/repositories/svn/testrepo1/db/fs-type +1 -0
  50. data/test/repositories/svn/testrepo1/db/fsfs.conf +37 -0
  51. data/test/repositories/svn/testrepo1/db/min-unpacked-rev +1 -0
  52. data/test/repositories/svn/testrepo1/db/rep-cache.db +0 -0
  53. data/test/repositories/svn/testrepo1/db/revprops/0/0 +5 -0
  54. data/test/repositories/svn/testrepo1/db/revprops/0/1 +13 -0
  55. data/test/repositories/svn/testrepo1/db/revs/0/0 +11 -0
  56. data/test/repositories/svn/testrepo1/db/revs/0/1 +0 -0
  57. data/test/repositories/svn/testrepo1/db/txn-current +1 -0
  58. data/test/repositories/svn/testrepo1/db/txn-current-lock +0 -0
  59. data/test/repositories/svn/testrepo1/db/uuid +1 -0
  60. data/test/repositories/svn/testrepo1/db/write-lock +0 -0
  61. data/test/repositories/svn/testrepo1/format +1 -0
  62. data/test/repositories/svn/testrepo1/hooks/post-commit.tmpl +50 -0
  63. data/test/repositories/svn/testrepo1/hooks/post-lock.tmpl +45 -0
  64. data/test/repositories/svn/testrepo1/hooks/post-revprop-change.tmpl +57 -0
  65. data/test/repositories/svn/testrepo1/hooks/post-unlock.tmpl +43 -0
  66. data/test/repositories/svn/testrepo1/hooks/pre-commit.tmpl +85 -0
  67. data/test/repositories/svn/testrepo1/hooks/pre-lock.tmpl +71 -0
  68. data/test/repositories/svn/testrepo1/hooks/pre-revprop-change.tmpl +66 -0
  69. data/test/repositories/svn/testrepo1/hooks/pre-unlock.tmpl +63 -0
  70. data/test/repositories/svn/testrepo1/hooks/start-commit.tmpl +68 -0
  71. data/test/repositories/svn/testrepo1/locks/db-logs.lock +3 -0
  72. data/test/repositories/svn/testrepo1/locks/db.lock +3 -0
  73. data/test/sites/simplehtml/deployment.yml +19 -0
  74. data/test/{test_sites → sites}/simplehtml/index.html +0 -0
  75. data/test/{test_sites → sites}/simplehtml/style.css +0 -0
  76. data/test/sites/sitefuelteaser/deployment.yml +13 -0
  77. data/test/sites/sitefuelteaser/img/hd.png +0 -0
  78. data/test/sites/sitefuelteaser/img/logo.png +0 -0
  79. data/test/sites/sitefuelteaser/img/uses-sitefuel.png +0 -0
  80. data/test/sites/sitefuelteaser/index.html +1 -1
  81. data/test/sites/sitefuelteaser/master.css +18 -0
  82. data/test/test_AbstractExternalProgram.rb +5 -5
  83. data/test/test_AbstractProcessor.rb +4 -4
  84. data/test/test_AbstractStringBasedProcessor.rb +2 -2
  85. data/test/test_AllProcessors.rb +4 -4
  86. data/test/test_ArrayComparisons.rb +4 -4
  87. data/test/test_CSSProcessor.rb +4 -4
  88. data/test/test_ColumnPrinter.rb +40 -0
  89. data/test/test_Configurable.rb +106 -0
  90. data/test/test_FileComparisons.rb +4 -4
  91. data/test/test_GIT.rb +41 -0
  92. data/test/{test_HAMLProcessor.rb.rb → test_HAMLProcessor.rb} +4 -4
  93. data/test/test_HTMLProcessor.rb +4 -4
  94. data/test/test_JPEGTran.rb +4 -4
  95. data/test/test_JavaScriptProcessor.rb +3 -2
  96. data/test/test_PHPProcessor.rb +4 -4
  97. data/test/test_PNGCrush.rb +8 -8
  98. data/test/test_PNGProcessor.rb +5 -5
  99. data/test/test_RHTMLProcessor.rb +4 -4
  100. data/test/test_SASSProcessor.rb +4 -4
  101. data/test/test_SVN.rb +44 -0
  102. data/test/test_SiteFuelLogging.rb +4 -4
  103. data/test/test_SiteFuelRuntime.rb +42 -4
  104. data/test/test_StringFormatting.rb +27 -4
  105. data/test/test_SymbolComparison.rb +4 -4
  106. data/test/ts_all.rb +2 -2
  107. metadata +94 -20
  108. data/README +0 -86
  109. data/test/test_sites/simplehtml/deployment.yml +0 -22
@@ -0,0 +1,292 @@
1
+ #
2
+ # File:: License.rb
3
+ # Author:: wkm
4
+ # Copyright:: 2009, Zanoccio LLC.
5
+ # License:: GPL version 2.0 (see LICENSE.rb)
6
+ #
7
+ # Contains the GPL version 2 so we can print it when someone types
8
+ # `sitefuel --license`
9
+ #
10
+
11
+ module SiteFuel
12
+ LICENSE = <<END
13
+ GNU GENERAL PUBLIC LICENSE
14
+ Version 2, June 1991
15
+
16
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
17
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ Everyone is permitted to copy and distribute verbatim copies
19
+ of this license document, but changing it is not allowed.
20
+
21
+ Preamble
22
+
23
+ The licenses for most software are designed to take away your
24
+ freedom to share and change it. By contrast, the GNU General Public
25
+ License is intended to guarantee your freedom to share and change free
26
+ software--to make sure the software is free for all its users. This
27
+ General Public License applies to most of the Free Software
28
+ Foundation's software and to any other program whose authors commit to
29
+ using it. (Some other Free Software Foundation software is covered by
30
+ the GNU Lesser General Public License instead.) You can apply it to
31
+ your programs, too.
32
+
33
+ When we speak of free software, we are referring to freedom, not
34
+ price. Our General Public Licenses are designed to make sure that you
35
+ have the freedom to distribute copies of free software (and charge for
36
+ this service if you wish), that you receive source code or can get it
37
+ if you want it, that you can change the software or use pieces of it
38
+ in new free programs; and that you know you can do these things.
39
+
40
+ To protect your rights, we need to make restrictions that forbid
41
+ anyone to deny you these rights or to ask you to surrender the rights.
42
+ These restrictions translate to certain responsibilities for you if you
43
+ distribute copies of the software, or if you modify it.
44
+
45
+ For example, if you distribute copies of such a program, whether
46
+ gratis or for a fee, you must give the recipients all the rights that
47
+ you have. You must make sure that they, too, receive or can get the
48
+ source code. And you must show them these terms so they know their
49
+ rights.
50
+
51
+ We protect your rights with two steps: (1) copyright the software, and
52
+ (2) offer you this license which gives you legal permission to copy,
53
+ distribute and/or modify the software.
54
+
55
+ Also, for each author's protection and ours, we want to make certain
56
+ that everyone understands that there is no warranty for this free
57
+ software. If the software is modified by someone else and passed on, we
58
+ want its recipients to know that what they have is not the original, so
59
+ that any problems introduced by others will not reflect on the original
60
+ authors' reputations.
61
+
62
+ Finally, any free program is threatened constantly by software
63
+ patents. We wish to avoid the danger that redistributors of a free
64
+ program will individually obtain patent licenses, in effect making the
65
+ program proprietary. To prevent this, we have made it clear that any
66
+ patent must be licensed for everyone's free use or not licensed at all.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ GNU GENERAL PUBLIC LICENSE
72
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
73
+
74
+ 0. This License applies to any program or other work which contains
75
+ a notice placed by the copyright holder saying it may be distributed
76
+ under the terms of this General Public License. The "Program", below,
77
+ refers to any such program or work, and a "work based on the Program"
78
+ means either the Program or any derivative work under copyright law:
79
+ that is to say, a work containing the Program or a portion of it,
80
+ either verbatim or with modifications and/or translated into another
81
+ language. (Hereinafter, translation is included without limitation in
82
+ the term "modification".) Each licensee is addressed as "you".
83
+
84
+ Activities other than copying, distribution and modification are not
85
+ covered by this License; they are outside its scope. The act of
86
+ running the Program is not restricted, and the output from the Program
87
+ is covered only if its contents constitute a work based on the
88
+ Program (independent of having been made by running the Program).
89
+ Whether that is true depends on what the Program does.
90
+
91
+ 1. You may copy and distribute verbatim copies of the Program's
92
+ source code as you receive it, in any medium, provided that you
93
+ conspicuously and appropriately publish on each copy an appropriate
94
+ copyright notice and disclaimer of warranty; keep intact all the
95
+ notices that refer to this License and to the absence of any warranty;
96
+ and give any other recipients of the Program a copy of this License
97
+ along with the Program.
98
+
99
+ You may charge a fee for the physical act of transferring a copy, and
100
+ you may at your option offer warranty protection in exchange for a fee.
101
+
102
+ 2. You may modify your copy or copies of the Program or any portion
103
+ of it, thus forming a work based on the Program, and copy and
104
+ distribute such modifications or work under the terms of Section 1
105
+ above, provided that you also meet all of these conditions:
106
+
107
+ a) You must cause the modified files to carry prominent notices
108
+ stating that you changed the files and the date of any change.
109
+
110
+ b) You must cause any work that you distribute or publish, that in
111
+ whole or in part contains or is derived from the Program or any
112
+ part thereof, to be licensed as a whole at no charge to all third
113
+ parties under the terms of this License.
114
+
115
+ c) If the modified program normally reads commands interactively
116
+ when run, you must cause it, when started running for such
117
+ interactive use in the most ordinary way, to print or display an
118
+ announcement including an appropriate copyright notice and a
119
+ notice that there is no warranty (or else, saying that you provide
120
+ a warranty) and that users may redistribute the program under
121
+ these conditions, and telling the user how to view a copy of this
122
+ License. (Exception: if the Program itself is interactive but
123
+ does not normally print such an announcement, your work based on
124
+ the Program is not required to print an announcement.)
125
+
126
+ These requirements apply to the modified work as a whole. If
127
+ identifiable sections of that work are not derived from the Program,
128
+ and can be reasonably considered independent and separate works in
129
+ themselves, then this License, and its terms, do not apply to those
130
+ sections when you distribute them as separate works. But when you
131
+ distribute the same sections as part of a whole which is a work based
132
+ on the Program, the distribution of the whole must be on the terms of
133
+ this License, whose permissions for other licensees extend to the
134
+ entire whole, and thus to each and every part regardless of who wrote it.
135
+
136
+ Thus, it is not the intent of this section to claim rights or contest
137
+ your rights to work written entirely by you; rather, the intent is to
138
+ exercise the right to control the distribution of derivative or
139
+ collective works based on the Program.
140
+
141
+ In addition, mere aggregation of another work not based on the Program
142
+ with the Program (or with a work based on the Program) on a volume of
143
+ a storage or distribution medium does not bring the other work under
144
+ the scope of this License.
145
+
146
+ 3. You may copy and distribute the Program (or a work based on it,
147
+ under Section 2) in object code or executable form under the terms of
148
+ Sections 1 and 2 above provided that you also do one of the following:
149
+
150
+ a) Accompany it with the complete corresponding machine-readable
151
+ source code, which must be distributed under the terms of Sections
152
+ 1 and 2 above on a medium customarily used for software interchange; or,
153
+
154
+ b) Accompany it with a written offer, valid for at least three
155
+ years, to give any third party, for a charge no more than your
156
+ cost of physically performing source distribution, a complete
157
+ machine-readable copy of the corresponding source code, to be
158
+ distributed under the terms of Sections 1 and 2 above on a medium
159
+ customarily used for software interchange; or,
160
+
161
+ c) Accompany it with the information you received as to the offer
162
+ to distribute corresponding source code. (This alternative is
163
+ allowed only for noncommercial distribution and only if you
164
+ received the program in object code or executable form with such
165
+ an offer, in accord with Subsection b above.)
166
+
167
+ The source code for a work means the preferred form of the work for
168
+ making modifications to it. For an executable work, complete source
169
+ code means all the source code for all modules it contains, plus any
170
+ associated interface definition files, plus the scripts used to
171
+ control compilation and installation of the executable. However, as a
172
+ special exception, the source code distributed need not include
173
+ anything that is normally distributed (in either source or binary
174
+ form) with the major components (compiler, kernel, and so on) of the
175
+ operating system on which the executable runs, unless that component
176
+ itself accompanies the executable.
177
+
178
+ If distribution of executable or object code is made by offering
179
+ access to copy from a designated place, then offering equivalent
180
+ access to copy the source code from the same place counts as
181
+ distribution of the source code, even though third parties are not
182
+ compelled to copy the source along with the object code.
183
+
184
+ 4. You may not copy, modify, sublicense, or distribute the Program
185
+ except as expressly provided under this License. Any attempt
186
+ otherwise to copy, modify, sublicense or distribute the Program is
187
+ void, and will automatically terminate your rights under this License.
188
+ However, parties who have received copies, or rights, from you under
189
+ this License will not have their licenses terminated so long as such
190
+ parties remain in full compliance.
191
+
192
+ 5. You are not required to accept this License, since you have not
193
+ signed it. However, nothing else grants you permission to modify or
194
+ distribute the Program or its derivative works. These actions are
195
+ prohibited by law if you do not accept this License. Therefore, by
196
+ modifying or distributing the Program (or any work based on the
197
+ Program), you indicate your acceptance of this License to do so, and
198
+ all its terms and conditions for copying, distributing or modifying
199
+ the Program or works based on it.
200
+
201
+ 6. Each time you redistribute the Program (or any work based on the
202
+ Program), the recipient automatically receives a license from the
203
+ original licensor to copy, distribute or modify the Program subject to
204
+ these terms and conditions. You may not impose any further
205
+ restrictions on the recipients' exercise of the rights granted herein.
206
+ You are not responsible for enforcing compliance by third parties to
207
+ this License.
208
+
209
+ 7. If, as a consequence of a court judgment or allegation of patent
210
+ infringement or for any other reason (not limited to patent issues),
211
+ conditions are imposed on you (whether by court order, agreement or
212
+ otherwise) that contradict the conditions of this License, they do not
213
+ excuse you from the conditions of this License. If you cannot
214
+ distribute so as to satisfy simultaneously your obligations under this
215
+ License and any other pertinent obligations, then as a consequence you
216
+ may not distribute the Program at all. For example, if a patent
217
+ license would not permit royalty-free redistribution of the Program by
218
+ all those who receive copies directly or indirectly through you, then
219
+ the only way you could satisfy both it and this License would be to
220
+ refrain entirely from distribution of the Program.
221
+
222
+ If any portion of this section is held invalid or unenforceable under
223
+ any particular circumstance, the balance of the section is intended to
224
+ apply and the section as a whole is intended to apply in other
225
+ circumstances.
226
+
227
+ It is not the purpose of this section to induce you to infringe any
228
+ patents or other property right claims or to contest validity of any
229
+ such claims; this section has the sole purpose of protecting the
230
+ integrity of the free software distribution system, which is
231
+ implemented by public license practices. Many people have made
232
+ generous contributions to the wide range of software distributed
233
+ through that system in reliance on consistent application of that
234
+ system; it is up to the author/donor to decide if he or she is willing
235
+ to distribute software through any other system and a licensee cannot
236
+ impose that choice.
237
+
238
+ This section is intended to make thoroughly clear what is believed to
239
+ be a consequence of the rest of this License.
240
+
241
+ 8. If the distribution and/or use of the Program is restricted in
242
+ certain countries either by patents or by copyrighted interfaces, the
243
+ original copyright holder who places the Program under this License
244
+ may add an explicit geographical distribution limitation excluding
245
+ those countries, so that distribution is permitted only in or among
246
+ countries not thus excluded. In such case, this License incorporates
247
+ the limitation as if written in the body of this License.
248
+
249
+ 9. The Free Software Foundation may publish revised and/or new versions
250
+ of the General Public License from time to time. Such new versions will
251
+ be similar in spirit to the present version, but may differ in detail to
252
+ address new problems or concerns.
253
+
254
+ Each version is given a distinguishing version number. If the Program
255
+ specifies a version number of this License which applies to it and "any
256
+ later version", you have the option of following the terms and conditions
257
+ either of that version or of any later version published by the Free
258
+ Software Foundation. If the Program does not specify a version number of
259
+ this License, you may choose any version ever published by the Free Software
260
+ Foundation.
261
+
262
+ 10. If you wish to incorporate parts of the Program into other free
263
+ programs whose distribution conditions are different, write to the author
264
+ to ask for permission. For software which is copyrighted by the Free
265
+ Software Foundation, write to the Free Software Foundation; we sometimes
266
+ make exceptions for this. Our decision will be guided by the two goals
267
+ of preserving the free status of all derivatives of our free software and
268
+ of promoting the sharing and reuse of software generally.
269
+
270
+ NO WARRANTY
271
+
272
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
273
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
274
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
275
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
276
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
277
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
278
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
279
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
280
+ REPAIR OR CORRECTION.
281
+
282
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
283
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
284
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
285
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
286
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
287
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
288
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
289
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
290
+ POSSIBILITY OF SUCH DAMAGES.
291
+ END
292
+ end
@@ -1,8 +1,8 @@
1
1
  #
2
2
  # File:: SiteFuelLogger.rb
3
3
  # Author:: wkm
4
- # Copyright:: 2009
5
- # License:: GPL
4
+ # Copyright:: 2009, Zanoccio LLC.
5
+ # License:: GPL version 2.0 (see LICENSE.rb)
6
6
  #
7
7
 
8
8
  module SiteFuel
@@ -40,6 +40,7 @@ module SiteFuel
40
40
  # clean:: gives a clean logging output intended for human use
41
41
  attr_accessor :log_style
42
42
 
43
+
43
44
  def initialize(filename = STDOUT)
44
45
  super(filename)
45
46
 
@@ -54,31 +55,37 @@ module SiteFuel
54
55
  @progname = 'SiteFuel'
55
56
  end
56
57
 
58
+
57
59
  def fatal(*args)
58
60
  @fatal_count += 1
59
61
  super(*args)
60
62
  end
61
63
 
64
+
62
65
  def error(*args)
63
66
  @error_count += 1
64
67
  super(*args)
65
68
  end
66
69
 
70
+
67
71
  def warn(*args)
68
72
  @warn_count += 1
69
73
  super(*args)
70
74
  end
71
75
 
76
+
72
77
  def info(*args)
73
78
  @info_count += 1
74
79
  super(*args)
75
80
  end
76
81
 
82
+
77
83
  def debug(*args)
78
84
  @debug_count += 1
79
85
  super(*args)
80
86
  end
81
87
 
88
+
82
89
  # implement our own #add so we can have cleaner logs
83
90
  def format_message(severity, date_time, program_name, msg)
84
91
  case @log_style
@@ -94,14 +101,16 @@ module SiteFuel
94
101
  when 'WARN'
95
102
  string = yellow(string)
96
103
 
97
- when 'DEBUG'
98
- string = string
104
+ when 'INFO', 'DEBUG'
105
+ string = dark(string)
99
106
  end
100
107
  string
101
108
  end
102
109
  end
103
110
  end
104
111
 
112
+
113
+
105
114
  # mixin for adding logging functionality to any class, typically included
106
115
  # by every SiteFuel class
107
116
  module Logging
@@ -110,19 +119,39 @@ module SiteFuel
110
119
  @logger = logger
111
120
  end
112
121
 
122
+
113
123
  # adds a fatal error to the log
114
124
  def fatal(*args) @logger.fatal(*args); end
115
-
125
+
126
+
116
127
  # adds an error to the log
117
128
  def error(*args) @logger.error(*args); end
118
129
 
130
+
119
131
  # adds a warning to the log
120
132
  def warn(*args) @logger.warn(*args); end
121
133
 
134
+
122
135
  # adds an info message to the log
123
136
  def info(*args) @logger.info(*args); end
124
137
 
138
+
125
139
  # adds a debugging message to the log
126
140
  def debug(*args) @logger.debug(*args); end
127
141
  end
142
+
143
+
144
+
145
+ # module for extending classes and thus giving class methods logging
146
+ # capability
147
+ module ClassLogging
148
+ @@logger = SiteFuelLogger.instance
149
+
150
+ def fatal(*args) @@logger.fatal(*args); end
151
+ def error(*args) @@logger.error(*args); end
152
+ def warn(*args) @@logger.warn(*args); end
153
+ def info(*args) @@logger.info(*args); end
154
+ def debug(*args) @@logger.debug(*args); end
155
+
156
+ end
128
157
  end
@@ -1,8 +1,8 @@
1
1
  #
2
2
  # File:: SiteFuelRuntime.rb
3
3
  # Author:: wkm
4
- # Copyright:: 2009
5
- # License:: GPL
4
+ # Copyright:: 2009, Zanoccio LLC.
5
+ # License:: GPL version 2.0 (see LICENSE.rb)
6
6
  #
7
7
  # Defines the primary interface class used by sitefuel to do actual work.
8
8
  # Keeping this as a class let's us abstract away the command line interface
@@ -14,6 +14,7 @@
14
14
  module SiteFuel
15
15
 
16
16
  require 'optparse'
17
+
17
18
  require 'term/ansicolor'
18
19
 
19
20
  include Term::ANSIColor
@@ -22,15 +23,34 @@ module SiteFuel
22
23
 
23
24
  require 'sitefuel/extensions/StringFormatting'
24
25
  require 'sitefuel/extensions/FileComparison'
26
+ require 'sitefuel/extensions/TerminalInfo'
27
+ require 'sitefuel/extensions/ColumnPrinter'
28
+ require 'sitefuel/extensions/FileTree'
25
29
 
26
30
  # we need the AbstractProcessor symbol when we go child-class hunting
27
31
  require 'sitefuel/processors/AbstractProcessor'
28
32
 
33
+ require 'sitefuel/external/SVN'
34
+ require 'sitefuel/external/GIT'
35
+
29
36
  # version of SiteFuel
30
- VERSION = [0, 0, 1].freeze
37
+ VERSION = [0, 1, '0a'].freeze
31
38
 
32
39
  # a human readable version
33
40
  VERSION_TEXT = VERSION.join('.').freeze
41
+
42
+
43
+ class UnknownVersioningSystem < StandardError
44
+ attr_reader :source
45
+ def initialize(source)
46
+ @source = source
47
+ end
48
+
49
+ def to_s
50
+ "Couldn't derive versioning system from #{source}\n"+
51
+ "Use --scm=(git|svn) option to force."
52
+ end
53
+ end
34
54
 
35
55
 
36
56
  class SiteFuelRuntime
@@ -43,6 +63,12 @@ module SiteFuel
43
63
  # what is the source *from* which we are deploying
44
64
  attr_accessor :deploy_from
45
65
 
66
+ # what is the staging directory
67
+ attr_reader :staging_directory
68
+
69
+ # what is the scm system
70
+ attr_accessor :scm_system
71
+
46
72
  # what is the source *to* which we are deploying
47
73
  attr_accessor :deploy_to
48
74
 
@@ -52,14 +78,27 @@ module SiteFuel
52
78
  # only lists file which have a known processor
53
79
  attr_accessor :only_list_recognized_files
54
80
 
81
+ # whether a deployment should be aborted due to errors
82
+ attr_accessor :abort_on_errors
83
+
84
+ # whether a deployment should be aborted due to warnings
85
+ attr_accessor :abort_on_warnings
86
+
87
+
55
88
  def initialize
56
89
  @processors = SiteFuelRuntime.find_processors
57
90
  self.logger = SiteFuelLogger.instance
58
91
  SiteFuelLogger.instance.log_style = :clean
59
92
 
60
93
  @only_list_recognized_files = false
94
+
95
+ @abort_on_errors = true
96
+ @abort_on_warnings = false
97
+
98
+ @scm_system = nil
61
99
  end
62
100
 
101
+
63
102
  # gives true if the given file (typically a processor) has already been
64
103
  # loaded (by looking into $"). Unfortunately #require is easily tricked,
65
104
  # so this function uses some heuristics to prevent processors from being
@@ -74,6 +113,7 @@ module SiteFuel
74
113
  return false
75
114
  end
76
115
 
116
+
77
117
  # finds all processors under processors/ and loads them. Any file matching
78
118
  # *Processor.rb will be loaded
79
119
  def self.load_processors
@@ -112,14 +152,17 @@ module SiteFuel
112
152
  Processor::AbstractProcessor.find_processors
113
153
  end
114
154
 
155
+
115
156
  # lists the actions which are possible with this runtime.
116
157
  def actions
117
158
  [ :deploy, :stage ]
118
159
  end
119
160
 
161
+
120
162
  # gives the array of processors available to this runtime
121
163
  attr_reader :processors
122
164
 
165
+
123
166
  # adds a processor or an array of processors to the runtime
124
167
  def add_processor(proc)
125
168
  case proc
@@ -132,21 +175,23 @@ module SiteFuel
132
175
  end
133
176
  end
134
177
 
178
+
135
179
  # gives the processor to use for a given file
136
180
  def choose_processor(filename)
137
- matchingprocs = processors.clone.delete_if {|proc| not proc.processes_file?(filename) }
181
+ matching = processors.clone.delete_if {|proc| not proc.processes_file?(filename) }
138
182
 
139
183
  case
140
- when matchingprocs.length > 1
141
- chosen = matchingprocs.first
142
- raise Processor::MultipleApplicableProcessors.new(filename, matchingprocs, chosen)
143
- when matchingprocs.length == 1
144
- return matchingprocs.first
184
+ when matching.length > 1
185
+ chosen = matching.first
186
+ raise Processor::MultipleApplicableProcessors.new(filename, matching, chosen)
187
+ when matching.length == 1
188
+ return matching.first
145
189
  else
146
190
  return nil
147
191
  end
148
192
  end
149
193
 
194
+
150
195
  # like #choose_processor but prints a message if there are clashing
151
196
  # processors and returns the first of the clashing processors.
152
197
  # (effectively alerting the user, but continuing to work)
@@ -160,6 +205,79 @@ module SiteFuel
160
205
  end
161
206
  end
162
207
 
208
+ def section_divider(name)
209
+ puts "== #{name} ".ljust(TerminalInfo.width, '=')
210
+ end
211
+
212
+
213
+ # decides what repository system to use (SVN or Git) based on the
214
+ # pull source given (eg. ssh://... is typically git; svn+ssh://... is SVN,
215
+ # etc.)
216
+ def classify_repository_system(pull_source)
217
+
218
+ # note that http:// and https:// repositories, in general could be
219
+ # anything.
220
+ case pull_source
221
+ when /^git:\/\/.*$/i,
222
+ /^ssh:\/\/.*$/i,
223
+ /^rsync:\/\/.*$/i,
224
+ /^.*\.git$/i
225
+ :git
226
+
227
+ when /^svn:\/\/.*$/i,
228
+ /^svn\+ssh:\/\/.*$/i,
229
+ /^file:\/\/.*$/i
230
+ :svn
231
+
232
+ when /^([-.a-zA-Z0-9\/])*$/i
233
+ :filesystem
234
+
235
+ else
236
+ raise UnknownVersioningSystem.new(pull_source)
237
+ end
238
+ end
239
+
240
+ def classify_repository_system!(pull_source)
241
+ classify_repository_system(pull_source)
242
+ rescue UnknownVersioningSystem => exception
243
+ fatal(exception.to_s)
244
+ exit(-1)
245
+ end
246
+
247
+
248
+ # pulls files out of a given repository or file system
249
+ def pull
250
+ if @scm_system == nil
251
+ @scm_system = classify_repository_system!(@deploy_from)
252
+ info "Using #{@scm_system} version control to access #{@deploy_from}"
253
+ end
254
+
255
+ # TODO this should be modularized; but in general there should be a
256
+ # 'discoverable' class that automates creation of plugins
257
+
258
+ case @scm_system.to_sym
259
+ when :svn
260
+ @staging_directory = External::SVN.export(@deploy_from)
261
+
262
+ when :git
263
+ @staging_directory = External::GIT.shallow_clone(@deploy_from)
264
+
265
+ when :filesystem
266
+ # kind of dangerous because it can override the source files; it's
267
+ # assumed every processor will not override the original.
268
+ @staging_directory = @deploy_from
269
+
270
+ else
271
+ fatal "Unknown SCM system: #{@scm_system}"
272
+ exit(-1)
273
+ end
274
+
275
+ info "Pulled files for staging into #{@staging_directory}"
276
+
277
+ rescue External::ProgramExitedWithFailure => exception
278
+ fatal "Couldn't pull files from SCM:\n#{exception}"
279
+ end
280
+
163
281
 
164
282
  # implements the stage command. Staging, by itself, will give statistics on
165
283
  # the deployment; how many bytes were saved by minification; etc.
@@ -167,12 +285,15 @@ module SiteFuel
167
285
  # However, #stage when part of #deploy will go and create the requisite files
168
286
  # in a temporary directory
169
287
  def stage
170
- return nil if @deploy_from == nil
288
+ pull
289
+
290
+ return nil if @staging_directory == nil
171
291
 
172
- puts '== %s '.format('Staging').ljust(80, '=')
292
+ section_divider('Staging')
293
+ printer = ColumnPrinter.new([5, :span, 6])
173
294
 
174
295
  # find all files under deploy_from
175
- files = find_all_files @deploy_from
296
+ files = find_all_files @staging_directory
176
297
 
177
298
  total_original_size = 0
178
299
  total_processed_size = 0
@@ -189,7 +310,7 @@ module SiteFuel
189
310
  processor = @resource_processors[filename]
190
311
  if processor == nil
191
312
  if only_list_recognized_files == false
192
- puts '%s %s' %['--'.ljust(8), filename.cabbrev(65)]
313
+ printer.row('--', filename)
193
314
  end
194
315
  else
195
316
  total_original_size += processor.original_size
@@ -201,16 +322,16 @@ module SiteFuel
201
322
  stats[2] += processor.processed_size
202
323
  @processor_statistics[processor.class.processor_name] = stats
203
324
 
204
- puts '%s %s %4.3f' %
205
- [
206
- cyan(processor.class.processor_name.ljust(8)),
207
- filename.cabbrev(65).ljust(65),
208
- processor.processed_size.prec_f/processor.original_size.prec_f
209
- ]
325
+ printer.row(
326
+ cyan(processor.class.processor_name),
327
+ filename,
328
+ '%4.3f'%(processor.processed_size.prec_f/processor.original_size.prec_f)
329
+ )
210
330
  end
211
331
  end
212
332
 
213
- puts '='*80
333
+ printer.divider
334
+
214
335
  puts 'Size delta: %+5d bytes; %4.3f' %
215
336
  [
216
337
  total_processed_size - total_original_size,
@@ -220,69 +341,121 @@ module SiteFuel
220
341
  staging_statistics
221
342
  end
222
343
 
344
+
223
345
  # outputs a little grid showing the number of files of each processor
224
346
  # and the total savings
225
347
  #
226
348
  # todo: this should be computed in the staging step
227
349
  def staging_statistics
350
+
228
351
  puts ''
229
- puts ' %s | %s | %s | %s' %
230
- ['processor', '# files', 'delta', 'ratio'].map{|v| bold(v)}
231
- puts ' -----------+----------+-------------+-------'
352
+
353
+ printer = ColumnPrinter.new([12, 8, :span, 6], [TerminalInfo.width, 50].min)
354
+ printer.alignment([:left, :right, :right, :right])
355
+ printer.mode(:divided)
356
+
357
+ headers = %w{processor files delta ratio}.map{|v| bold(v)}
358
+ printer.row(*headers)
359
+ printer.divider
232
360
 
233
361
  @processor_statistics.keys.sort.each do |key|
234
- puts ' %s|%9d |%+12d | %4.3f' %
235
- [
236
- key.ljust(10),
237
- @processor_statistics[key][0],
238
- @processor_statistics[key][2] - @processor_statistics[key][1],
239
- @processor_statistics[key][2].prec_f / @processor_statistics[key][1].prec_f
240
- ]
362
+ printer.row(
363
+ key,
364
+ @processor_statistics[key][0],
365
+ '%+12d'%(@processor_statistics[key][2] - @processor_statistics[key][1]),
366
+ '%4.3f'%(@processor_statistics[key][2].prec_f / @processor_statistics[key][1].prec_f)
367
+ )
241
368
  end
242
- puts ' -----------+----------+-------------+-------'
369
+ printer.divider
243
370
  puts ''
244
371
  end
245
372
 
373
+
374
+ def check_messages
375
+ error_count = SiteFuelLogger.instance.error_count
376
+ if @abort_on_errors and error_count > 0
377
+ fatal "Aborting due to errors. Use --force to deploy anyway."
378
+ exit(-1)
379
+ end
380
+
381
+ warn_count = SiteFuelLogger.instance.error_count
382
+ if @abort_on_warnings and warn_count > 0
383
+ fatal "Aborting due to warnings. Use --ignore-warnings to deploy anyway."
384
+ exit(-1)
385
+ end
386
+ end
387
+
388
+
246
389
  # create a deployment
247
390
  def deploy
248
391
  # first we have to stage the files
249
392
  stage
250
393
 
251
- files = find_all_files @deploy_from
394
+ check_messages
252
395
 
253
396
  return if @deploy_to == nil
254
- puts
255
- puts bold('Deploying:')
256
397
 
257
- unless File.exists?(@deploy_to)
258
- Dir.mkdir(@deploy_to)
259
- end
398
+ section_divider('Deploying')
399
+
400
+ file_tree = FileTree.new(@deploy_to)
401
+
260
402
  # write out content
261
- files.each do |filename|
403
+ @resource_processors.each_key do |filename|
262
404
  results = @resource_processors[filename]
263
405
  if results == nil
264
- putc 'I'
265
- else
266
406
  putc '.'
267
- results.save(@deploy_to)
407
+ else
408
+ putc results.processor_symbol
409
+ results.save(file_tree)
268
410
  end
269
411
  STDOUT.flush
270
412
  end
271
- puts
413
+
414
+
415
+ finish
416
+ end
417
+
418
+ def finish
419
+ puts ''
420
+ puts ''
421
+ section_divider('Finishing')
272
422
  end
273
423
 
424
+
274
425
  # gives an array listing of all files on a given path
275
426
  #
276
427
  # This is a very lightweight wrapper around Dir.
277
428
  def find_all_files(path)
278
- Dir[File.join(path, "**/*")]
429
+ if File.directory?(path)
430
+ Dir[File.join(path, "**/*")]
431
+ elsif File.file?(path)
432
+ return path
433
+ else
434
+ return []
435
+ end
279
436
  end
280
437
 
438
+
281
439
  # changes the verbosity of the runtime by adjusting the log level
282
440
  def verbosity(level = 1)
283
441
  case level
284
- when 1
442
+ when 0
443
+ SiteFuelLogger.instance.level = Logger::FATAL
285
444
 
445
+ when 1
446
+ SiteFuelLogger.instance.level = Logger::ERROR
447
+
448
+ when 2
449
+ SiteFuelLogger.instance.level = Logger::WARN
450
+
451
+ when 3
452
+ SiteFuelLogger.instance.level = Logger::INFO
453
+
454
+ when 4
455
+ SiteFuelLogger.instance.level = Logger::DEBUG
456
+
457
+ else
458
+ warn "Unknown verbosity level: #{level}; ignoring."
286
459
  end
287
460
  end
288
461
  end