File: stag-template2bin.pl

package info (click to toggle)
libdbix-dbstag-perl 0.12-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,420 kB
  • sloc: perl: 6,152; sql: 588; xml: 221; lisp: 59; makefile: 20
file content (48 lines) | stat: -rwxr-xr-x 1,034 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/local/bin/perl

# cjm@fruitfly.org

use strict;
use Carp;
use Getopt::Long;

my $bindir = $ENV{DBSTAG_TEMPLATE_BINDIR};
my $force;
my $quiet;
my $chmod = "777";
GetOptions("bindir|b=s"=>\$bindir,
	   "force"=>\$force,
	   "quiet|q"=>\$quiet,
	   "chmod=s"=>\$chmod,
	  );

if (!$bindir) {
    $bindir = "/usr/local/bin";
    unless ($force) {
	print "You did not specify -b (path to template generated binaries) on the command line\n or in \$DBSTAG_TEMPLATE_BINDIR";
	print "I will use this: $bindir\n";
	print "\nOK? [yes/no] ";
	my $ok = <STDIN>;
	if ($ok !~ /^y/i) {
	    print "Bye!\n";
	    exit 0;
	}
    }
}

foreach my $f (@ARGV) {
    my @parts = split(/\//, $f);
    my $name = $parts[-1];
    if ($name =~ s/\.stg$//) {
	my $bin = "$bindir/$name";
	open(F, ">$bin") || die("can't write to $bin");
	print F "#!/bin/sh\n";
	print F "selectall_xml.pl -t $name \$\@\n";
	close(F);
	system("chmod $chmod $bin");
	print "$bin\n" unless $quiet;
    }
    else {
	"$f doesn't look like a template (no .stg suffix)";
    }
}