annotate bin/chronicle-spooler @ 300:b593b701d057

Added tag release-3.4 for changeset eba6872a5309
author Steve Kemp <steve@steve.org.uk>
date Wed, 10 Dec 2008 20:35:34 +0000
parents 389f234d4111
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
194
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
1 #!/usr/bin/perl -w
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
2
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
3 =head1 NAME
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
4
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
5 chronicle-spooler - Automatically post pre-written entries.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
6
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
7 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
8
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
9 =head1 SYNOPSIS
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
10
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
11
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
12 Path Options:
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
13
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
14 --config Specify a configuration file to read.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
15 --spool-dir Specify where pending entries are located.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
16 --live-dir Specify where the entries should be moved to.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
17
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
18
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
19 Post-Spool Commands:
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
20
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
21 --post-move Specify a command to execute once entries have been moved.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
22
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
23 Optional Features:
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
24
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
25 --test Only report on what would be executed.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
26
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
27 Help Options:
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
28
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
29 --help Show the help information for this script.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
30 --manual Read the manual for this script.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
31
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
32 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
33
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
34
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
35 =head1 ABOUT
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
36
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
37 chronicle-spooler is a companion scrip to the chronicle blog compiler.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
38
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
39 It is designed to facilitate posting new entries automatically upon
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
40 particular dates. (ie. If you have ten written blog entries in a spool
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
41 directory it will move them into place upon the date you've specified.)
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
42
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
43 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
44
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
45
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
46 =head1 DATE SPECIFICATION
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
47
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
48 To specify the date a particular entry should be made live you
217
6dadbc23cd74 Ran through ispell
Steve Kemp <steve@steve.org.uk>
parents: 215
diff changeset
49 must add another pseudo-header to your blog entry files, as follows:
194
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
50
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
51 =for example begin
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
52
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
53 Title: This is the title of the blog post
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
54 Date: 2nd March 2007
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
55 Publish: 15th April 2008
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
56 Tags: one, two, three, long tag
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
57
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
58 The text of your entry goes here.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
59
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
60 =for example end
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
61
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
62 In this example we know that this entry will be made live upon the
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
63 15th April 2008, and not before.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
64
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
65 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
66
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
67 =head1 AUTHOR
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
68
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
69 Steve
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
70 --
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
71 http://www.steve.org.uk/
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
72
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
73 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
74
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
75 =head1 LICENSE
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
76
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
77 Copyright (c) 2008 by Steve Kemp. All rights reserved.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
78
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
79 This module is free software;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
80 you can redistribute it and/or modify it under
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
81 the same terms as Perl itself.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
82 The LICENSE file contains the full text of the license.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
83
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
84 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
85
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
86
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
87 use strict;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
88 use warnings;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
89
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
90
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
91 use Date::Parse;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
92 use File::Copy;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
93 use Getopt::Long;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
94 use Pod::Usage;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
95
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
96
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
97 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
98 # Release number
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
99 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
100 # NOTE: Set by 'make release'.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
101 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
102 my $RELEASE = 'UNRELEASED';
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
103
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
104
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
105 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
106 # Our configuration options.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
107 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
108 my %CONFIG;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
109
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
110
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
111 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
112 # Read the global and per-user configuration files, if they exist.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
113 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
114 readConfigurationFile("/etc/chroniclerc");
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
115 readConfigurationFile( $ENV{ 'HOME' } . "/.chroniclerc" );
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
116
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
117
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
118 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
119 # Parse the command line arguments.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
120 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
121 parseCommandLineArguments();
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
122
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
123
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
124 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
125 # Another configuration file?
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
126 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
127 readConfigurationFile( $CONFIG{ 'config' } ) if ( defined $CONFIG{ 'config' } );
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
128
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
129
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
130 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
131 # Make sure we have arguments which are sane.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
132 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
133 # Specifically we need an input directory and an output directory.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
134 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
135 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
136 sanityCheckArguments();
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
137
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
138
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
139 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
140 # Find the potentially pending entries.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
141 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
142 my @files = findPendingPosts( $CONFIG{ 'spool-dir' } );
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
143
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
144
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
145 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
146 # Process each entry
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
147 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
148 my $live = 0;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
149 foreach my $entry ( sort(@files) )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
150 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
151 if ( shouldBeLive($entry) )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
152 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
153 if ( $CONFIG{ 'test' } )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
154 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
155 print "test: make entry live: $entry\n";
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
156 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
157 else
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
158 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
159 makeEntryLive($entry);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
160 $live += 1;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
161 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
162 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
163 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
164
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
165
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
166 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
167 # If we should run our command do so.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
168 #
215
967ecb541df9 Updated to improve the date + time handling of files.
Steve Kemp <steve@steve.org.uk>
parents: 198
diff changeset
169 if ( ( $CONFIG{ 'post-move' } ) && $live )
194
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
170 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
171 if ( $CONFIG{ 'test' } )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
172 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
173 print "test: should run: $CONFIG{'post-move'}\n";
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
174 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
175 else
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
176 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
177 system( $CONFIG{ 'post-move' } );
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
178 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
179 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
180
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
181
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
182
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
183 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
184 # All done.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
185 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
186 exit;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
187
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
188
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
189
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
190 =begin doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
191
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
192 Parse the command line arguments this script was given.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
193
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
194 =end doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
195
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
196 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
197
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
198 sub parseCommandLineArguments
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
199 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
200 my $HELP = 0;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
201 my $MANUAL = 0;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
202 my $VERSION = 0;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
203
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
204 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
205 # Parse options.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
206 #
257
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
207 if (
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
208 !GetOptions(
194
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
209
257
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
210 # input / output
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
211 "spool-dir=s", \$CONFIG{ 'spool-dir' },
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
212 "live-dir=s", \$CONFIG{ 'live-dir' },
194
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
213
257
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
214 # testing?
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
215 "test", \$CONFIG{ 'test' },
194
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
216
257
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
217 # command?
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
218 "post-move=s", \$CONFIG{ 'post-move' },
194
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
219
257
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
220 # Help options
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
221 "help", \$HELP,
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
222 "manual", \$MANUAL,
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
223 "verbose", \$CONFIG{ 'verbose' },
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
224 "version", \$VERSION,
194
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
225
257
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
226 )
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
227 )
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
228 {
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
229 exit;
389f234d4111 Failure to parse options should make the script exit
Steve Kemp <steve@steve.org.uk>
parents: 217
diff changeset
230 }
194
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
231
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
232 pod2usage(1) if $HELP;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
233 pod2usage( -verbose => 2 ) if $MANUAL;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
234
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
235 if ($VERSION)
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
236 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
237 print("chronicle release $RELEASE\n");
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
238 exit;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
239 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
240 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
241
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
242
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
243
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
244 =begin doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
245
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
246 Read the specified configuration file if it exists.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
247
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
248 =end doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
249
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
250 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
251
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
252 sub readConfigurationFile
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
253 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
254 my ($file) = (@_);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
255
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
256 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
257 # If it doesn't exist ignore it.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
258 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
259 return if ( !-e $file );
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
260
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
261
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
262 my $line = "";
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
263
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
264 open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
265 while ( defined( $line = <FILE> ) )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
266 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
267 chomp $line;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
268 if ( $line =~ s/\\$// )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
269 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
270 $line .= <FILE>;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
271 redo unless eof(FILE);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
272 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
273
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
274 # Skip lines beginning with comments
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
275 next if ( $line =~ /^([ \t]*)\#/ );
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
276
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
277 # Skip blank lines
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
278 next if ( length($line) < 1 );
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
279
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
280 # Strip trailing comments.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
281 if ( $line =~ /(.*)\#(.*)/ )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
282 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
283 $line = $1;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
284 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
285
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
286 # Find variable settings
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
287 if ( $line =~ /([^=]+)=([^\n]+)/ )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
288 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
289 my $key = $1;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
290 my $val = $2;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
291
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
292 # Strip leading and trailing whitespace.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
293 $key =~ s/^\s+//;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
294 $key =~ s/\s+$//;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
295 $val =~ s/^\s+//;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
296 $val =~ s/\s+$//;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
297
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
298 # command expansion?
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
299 if ( $val =~ /(.*)`([^`]+)`(.*)/ )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
300 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
301
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
302 # store
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
303 my $pre = $1;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
304 my $cmd = $2;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
305 my $post = $3;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
306
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
307 # get output
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
308 my $output = `$cmd`;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
309 chomp($output);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
310
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
311 # build up replacement.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
312 $val = $pre . $output . $post;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
313 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
314
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
315 # Store value.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
316 $CONFIG{ $key } = $val;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
317 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
318 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
319
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
320 close(FILE);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
321 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
322
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
323
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
324
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
325 =begin doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
326
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
327 Sanity check our arguments, and setup to make sure there is nothing
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
328 obviously broken.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
329
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
330 =end doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
331
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
332 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
333
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
334 sub sanityCheckArguments
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
335 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
336 if ( ( !$CONFIG{ 'spool-dir' } )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
337 || ( !-d $CONFIG{ 'spool-dir' } ) )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
338 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
339 print <<EOF;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
340
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
341 Please specify the spool directory, which contains the entries which
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
342 are to be moved into the live directory in the future.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
343
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
344 EOF
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
345 exit;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
346 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
347
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
348 if ( ( !$CONFIG{ 'live-dir' } )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
349 || ( !-d $CONFIG{ 'live-dir' } ) )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
350 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
351 print <<EOF;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
352
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
353 Please specify the output directory into which entries should be
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
354 moved to make them live.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
355
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
356 EOF
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
357 exit;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
358 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
359 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
360
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
361
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
362
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
363 =begin doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
364
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
365 Find any files that might be in the pending directory.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
366
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
367 =end doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
368
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
369 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
370
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
371 sub findPendingPosts
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
372 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
373 my ($dir) = (@_);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
374
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
375 my $pattern = "*";
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
376 my @files;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
377
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
378 foreach my $file ( sort( glob("$dir/$pattern") ) )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
379 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
380 push( @files, $file ) unless ( -d $file );
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
381 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
382
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
383 return (@files);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
384 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
385
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
386
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
387 =begin doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
388
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
389 Read the given file and see if it should be published now.
217
6dadbc23cd74 Ran through ispell
Steve Kemp <steve@steve.org.uk>
parents: 215
diff changeset
390 That means that the file contained a "Publish:" pseudo-header
194
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
391 which is either in the past, or equal to todays date.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
392
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
393 =end doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
394
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
395 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
396
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
397 sub shouldBeLive
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
398 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
399 my ($file) = (@_);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
400
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
401 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
402 # If the file doesn't exist we don't publish it. Huh?
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
403 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
404 return 0 if ( !-e $file );
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
405
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
406 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
407 # Look for a header
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
408 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
409 my $header = "";
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
410
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
411 open( FILE, "<", $file )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
412 or die "Failed to read file $file - $!";
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
413
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
414 foreach my $line (<FILE>)
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
415 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
416 if ( ( $line =~ /^Publish:(.*)/i )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
417 && ( !length($header) ) )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
418 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
419 $header = $1;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
420
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
421 # Strip leading and trailing whitespace.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
422 $header =~ s/^\s+//;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
423 $header =~ s/\s+$//;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
424 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
425 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
426 close(FILE);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
427
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
428 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
429 # No header? Not to be published
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
430 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
431 return 0 if ( length($header) < 1 );
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
432
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
433 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
434 # OK we got a header - is it current / past?
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
435 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
436 my $today = time;
198
889827a88e34 perltidy
Steve Kemp <steve@steve.org.uk>
parents: 194
diff changeset
437 if ( !defined($today) )
194
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
438 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
439 print "FAILED TO FIND TODAY\n";
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
440 return 0;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
441 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
442
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
443 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
444 # Date of entry
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
445 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
446 my $ent = str2time($header);
198
889827a88e34 perltidy
Steve Kemp <steve@steve.org.uk>
parents: 194
diff changeset
447 if ( !defined($ent) )
194
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
448 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
449 print "FAILED TO PARSE: '$header'\n";
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
450 return 0;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
451 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
452
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
453
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
454 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
455 # Do the date test.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
456 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
457 if ( $ent < $today )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
458 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
459 return 1;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
460 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
461 else
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
462 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
463 return 0;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
464 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
465 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
466
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
467
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
468
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
469 =begin doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
470
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
471 Move the specified file into our "live" directory.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
472
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
473 =end doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
474
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
475 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
476
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
477 sub makeEntryLive
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
478 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
479 my ($file) = (@_);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
480
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
481
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
482 if ( -d $CONFIG{ 'live-dir' } )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
483 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
484
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
485 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
486 # Is there already a file there with that name?
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
487 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
488 # If so don't truncate it.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
489 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
490 my $dir = $file;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
491 my $base = $file;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
492 if ( $base =~ /^(.*)[\\\/](.*)$/ )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
493 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
494 $dir = $1;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
495 $base = $2;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
496 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
497
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
498 while ( -e "$CONFIG{'live-dir'}/$base" )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
499 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
500 $base = "x$base";
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
501 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
502
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
503 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
504 # Moving
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
505 #
198
889827a88e34 perltidy
Steve Kemp <steve@steve.org.uk>
parents: 194
diff changeset
506 File::Copy::move( $file, $CONFIG{ 'live-dir' } . "/" . $base );
194
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
507 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
508 else
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
509 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
510 print "Weirdness $CONFIG{'live-dir'} is not a directory!\n";
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
511 exit;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
512 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
513 }