annotate bin/chronicle-spooler @ 254:2b67eb6c74eb

Sync with the debian sid reelasse
author Steve Kemp <steve@steve.org.uk>
date Sun, 25 May 2008 15:24:45 +0100
parents 6dadbc23cd74
children 389f234d4111
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 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
207 GetOptions(
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
208
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
209 # input / output
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
210 "spool-dir=s", \$CONFIG{ 'spool-dir' },
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
211 "live-dir=s", \$CONFIG{ 'live-dir' },
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
212
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
213 # testing?
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
214 "test", \$CONFIG{ 'test' },
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
215
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
216 # command?
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
217 "post-move=s", \$CONFIG{ 'post-move' },
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
218
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
219 # Help options
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
220 "help", \$HELP,
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
221 "manual", \$MANUAL,
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
222 "verbose", \$CONFIG{ 'verbose' },
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
223 "version", \$VERSION,
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
224
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
225 );
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
226
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
227 pod2usage(1) if $HELP;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
228 pod2usage( -verbose => 2 ) if $MANUAL;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
229
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
230 if ($VERSION)
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 print("chronicle release $RELEASE\n");
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
233 exit;
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 }
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
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
238
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
239 =begin doc
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 Read the specified configuration file if it exists.
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 =end doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
244
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
245 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
246
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
247 sub readConfigurationFile
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
248 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
249 my ($file) = (@_);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
250
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 # If it doesn't exist ignore it.
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 return if ( !-e $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 my $line = "";
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 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
260 while ( defined( $line = <FILE> ) )
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 chomp $line;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
263 if ( $line =~ s/\\$// )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
264 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
265 $line .= <FILE>;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
266 redo unless eof(FILE);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
267 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
268
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
269 # Skip lines beginning with comments
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
270 next if ( $line =~ /^([ \t]*)\#/ );
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
271
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
272 # Skip blank lines
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
273 next if ( length($line) < 1 );
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
274
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
275 # Strip trailing comments.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
276 if ( $line =~ /(.*)\#(.*)/ )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
277 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
278 $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
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
281 # Find variable settings
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
282 if ( $line =~ /([^=]+)=([^\n]+)/ )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
283 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
284 my $key = $1;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
285 my $val = $2;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
286
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
287 # Strip leading and trailing whitespace.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
288 $key =~ s/^\s+//;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
289 $key =~ s/\s+$//;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
290 $val =~ s/^\s+//;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
291 $val =~ s/\s+$//;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
292
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
293 # command expansion?
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
294 if ( $val =~ /(.*)`([^`]+)`(.*)/ )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
295 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
296
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
297 # store
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
298 my $pre = $1;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
299 my $cmd = $2;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
300 my $post = $3;
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 # get output
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
303 my $output = `$cmd`;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
304 chomp($output);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
305
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
306 # build up replacement.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
307 $val = $pre . $output . $post;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
308 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
309
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
310 # Store value.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
311 $CONFIG{ $key } = $val;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
312 }
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 close(FILE);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
316 }
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 =begin doc
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 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
323 obviously broken.
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 =end 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 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
328
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
329 sub sanityCheckArguments
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
330 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
331 if ( ( !$CONFIG{ 'spool-dir' } )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
332 || ( !-d $CONFIG{ 'spool-dir' } ) )
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 print <<EOF;
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 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
337 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
338
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
339 EOF
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
340 exit;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
341 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
342
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
343 if ( ( !$CONFIG{ 'live-dir' } )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
344 || ( !-d $CONFIG{ 'live-dir' } ) )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
345 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
346 print <<EOF;
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 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
349 moved to make them live.
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 EOF
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
352 exit;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
353 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
354 }
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
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
357
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
358 =begin doc
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 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
361
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
362 =end doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
363
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
364 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
365
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
366 sub findPendingPosts
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
367 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
368 my ($dir) = (@_);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
369
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
370 my $pattern = "*";
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
371 my @files;
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 foreach my $file ( sort( glob("$dir/$pattern") ) )
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 push( @files, $file ) unless ( -d $file );
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
376 }
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 return (@files);
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
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 =begin doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
383
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
384 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
385 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
386 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
387
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
388 =end doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
389
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
390 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
391
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
392 sub shouldBeLive
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
393 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
394 my ($file) = (@_);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
395
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 # 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
398 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
399 return 0 if ( !-e $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 # Look for a header
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 my $header = "";
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 open( FILE, "<", $file )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
407 or die "Failed to read file $file - $!";
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 foreach my $line (<FILE>)
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 if ( ( $line =~ /^Publish:(.*)/i )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
412 && ( !length($header) ) )
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 $header = $1;
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 # Strip leading and trailing whitespace.
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
417 $header =~ s/^\s+//;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
418 $header =~ s/\s+$//;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
419 }
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 close(FILE);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
422
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
423 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
424 # No header? Not to be published
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 return 0 if ( length($header) < 1 );
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 # 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
430 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
431 my $today = time;
198
889827a88e34 perltidy
Steve Kemp <steve@steve.org.uk>
parents: 194
diff changeset
432 if ( !defined($today) )
194
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 print "FAILED TO FIND TODAY\n";
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
435 return 0;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
436 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
437
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 # Date of entry
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
440 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
441 my $ent = str2time($header);
198
889827a88e34 perltidy
Steve Kemp <steve@steve.org.uk>
parents: 194
diff changeset
442 if ( !defined($ent) )
194
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 print "FAILED TO PARSE: '$header'\n";
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
445 return 0;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
446 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
447
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 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
450 # Do the date test.
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 if ( $ent < $today )
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 return 1;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
455 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
456 else
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
457 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
458 return 0;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
459 }
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
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
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
464 =begin doc
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 Move the specified file into our "live" directory.
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 =end doc
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
469
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
470 =cut
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
471
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
472 sub makeEntryLive
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
473 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
474 my ($file) = (@_);
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
475
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 if ( -d $CONFIG{ 'live-dir' } )
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
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 # 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
482 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
483 # If so don't truncate it.
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 my $dir = $file;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
486 my $base = $file;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
487 if ( $base =~ /^(.*)[\\\/](.*)$/ )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
488 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
489 $dir = $1;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
490 $base = $2;
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
491 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
492
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
493 while ( -e "$CONFIG{'live-dir'}/$base" )
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
494 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
495 $base = "x$base";
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 #
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
499 # Moving
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
500 #
198
889827a88e34 perltidy
Steve Kemp <steve@steve.org.uk>
parents: 194
diff changeset
501 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
502 }
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
503 else
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
504 {
4004fa368f64 Added as simple proof of concept
Steve Kemp <steve@steve.org.uk>
parents:
diff changeset
505 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
506 exit;
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 }