create-ly: band: Create .ly files for all instruments
[sunny256-utils.git] / create_new
blob0fe3b7d7231b6aef7c55c9819c5867bd76a0a2cf
1 #!/usr/bin/env perl
3 #=======================================================================
4 # create_new
5 # File ID: 5dad39ac-f742-11dd-a5bf-000475e441b9
6 # Creates various pristine setups for all kind of things — documents,
7 # source code and so on.
9 # Character set: UTF-8
10 # ©opyleft 2006– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
15 use strict;
16 use warnings;
17 use Getopt::Long;
19 $| = 1;
21 our $Debug = 0;
23 our %Opt = (
25 'debug' => 0,
26 'help' => 0,
27 'no-svn' => 0,
28 'verbose' => 0,
29 'version' => 0,
33 our $progname = $0;
34 $progname =~ s/^.*\/(.*?)$/$1/;
35 our $VERSION = "0.00";
37 my $CMD_SVN = "svn";
38 my $CMD_STD = "$ENV{'HOME'}/bin/std";
39 my $CMD_KEYW = "$ENV{'HOME'}/bin/keyw";
41 Getopt::Long::Configure("bundling");
42 GetOptions(
44 "debug" => \$Opt{'debug'},
45 "help|h" => \$Opt{'help'},
46 "no-svn|n" => \$Opt{'no-svn'},
47 "verbose|v+" => \$Opt{'verbose'},
48 "version" => \$Opt{'version'},
50 ) || die("$progname: Option error. Use -h for help.\n");
52 $Opt{'debug'} && ($Debug = 1);
53 $Opt{'help'} && usage(0);
54 if ($Opt{'version'}) {
55 print_version();
56 exit(0);
59 if (!defined($ARGV[1])) {
60 die("$progname: Not enough parameters, use -h for help.\n");
63 my ($Type, $Name) = (shift, shift);
65 if ($Type =~ /^article$/) {
66 mkdir($Name) || die("$progname: mkdir $Name: $!\n");
67 system("$CMD_STD db-article >$Name/$Name.xml");
68 if (open(OutFP, ">", "$Name/Makefile")) {
69 my $svn_str_update = !$Opt{'no-svn'} && "\tsvn update \$(HTML_TARGET)\n" || "";
70 print(OutFP <<END);
71 #!/usr/bin/make
73 # \$Id\$
75 SHELL = /bin/bash
76 XSLTPROC = xsltproc
77 XSLTOPTS =
78 XHTML_XSL = \$(HOME)/xsl/xhtml/docbook.xsl
79 HTML_TARGET = $Name.html
81 all:
82 \t\$(MAKE) \$(HTML_TARGET)
84 \$(HTML_TARGET): $Name.xml
85 \t\$(XSLTPROC) -o \$(HTML_TARGET) \$(XSLTOPTS) \$(XHTML_XSL) $Name.xml
86 \txmllint --format --encode UTF-8 \$(HTML_TARGET) >$Name.tmp
87 \tmv $Name.tmp \$(HTML_TARGET)
89 check:
90 \t\@(for _f in *.xml; do \\
91 \t\techo ==== \$\$_f ====; \\
92 \t\txmllint --valid --noout \$\$_f; \\
93 \t\tdone \\
94 \t)
96 htmlclean:
97 \trm -f \$(HTML_TARGET)
98 $svn_str_update
99 clean:
100 \t\$(MAKE) htmlclean
102 valid:
103 \t\$(MAKE) check
105 close(OutFP);
106 } else {
107 warn("$progname: $Name/Makefile: Cannot create file: $!\n");
109 $Opt{'no-svn'} || my_system($CMD_SVN, "add", $Name);
110 $Opt{'no-svn'} || my_system($CMD_KEYW, "$Name/Makefile", "$Name/$Name.xml");
111 } else {
112 die("$progname: $Type: Unknown type\n");
115 sub my_system {
116 my @Cmd = @_;
117 my $cmd_txt = join(" ", @Cmd);
118 print("======== $progname: Executing \"$cmd_txt\"... ========\n");
119 system(@Cmd);
120 return;
123 sub print_version {
124 # Print program version {{{
125 print("$progname v$VERSION\n");
126 # }}}
127 } # print_version()
129 sub usage {
130 # Send the help message to stdout {{{
131 my $Retval = shift;
133 if ($Opt{'verbose'}) {
134 print("\n");
135 print_version();
137 print(<<END);
139 Usage: $progname type directory
141 Options:
143 -h, --help
144 Show this help.
145 -n, --no-svn
146 Don’t use Subversion commands (svn add, etc)
147 -v, --verbose
148 Increase level of verbosity. Can be repeated.
149 --version
150 Print version information.
151 --debug
152 Print debugging messages.
154 Supported types:
156 article
157 DocBook article.
160 exit($Retval);
161 # }}}
162 } # usage()
164 sub msg {
165 # Print a status message to stderr based on verbosity level {{{
166 my ($verbose_level, $Txt) = @_;
168 if ($Opt{'verbose'} >= $verbose_level) {
169 print(STDERR "$progname: $Txt\n");
171 # }}}
172 } # msg()
174 sub D {
175 # Print a debugging message {{{
176 $Debug || return;
177 my @call_info = caller;
178 chomp(my $Txt = shift);
179 my $File = $call_info[1];
180 $File =~ s#\\#/#g;
181 $File =~ s#^.*/(.*?)$#$1#;
182 print(STDERR "$File:$call_info[2] $$ $Txt\n");
183 return("");
184 # }}}
185 } # D()
187 __END__
189 # Plain Old Documentation (POD) {{{
191 =pod
193 =head1 NAME
197 =head1 SYNOPSIS
199 [options] [file [files [...]]]
201 =head1 DESCRIPTION
205 =head1 OPTIONS
207 =over 4
209 =item B<-h>, B<--help>
211 Print a brief help summary.
213 =item B<-v>, B<--verbose>
215 Increase level of verbosity. Can be repeated.
217 =item B<--version>
219 Print version information.
221 =item B<--debug>
223 Print debugging messages.
225 =back
227 =head1 BUGS
231 =head1 AUTHOR
233 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
235 =head1 COPYRIGHT
237 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
238 This is free software; see the file F<COPYING> for legalese stuff.
240 =head1 LICENCE
242 This program is free software: you can redistribute it and/or modify it
243 under the terms of the GNU General Public License as published by the
244 Free Software Foundation, either version 2 of the License, or (at your
245 option) any later version.
247 This program is distributed in the hope that it will be useful, but
248 WITHOUT ANY WARRANTY; without even the implied warranty of
249 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
250 See the GNU General Public License for more details.
252 You should have received a copy of the GNU General Public License along
253 with this program.
254 If not, see L<http://www.gnu.org/licenses/>.
256 =head1 SEE ALSO
258 =cut
260 # }}}
262 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :