Created
May 6, 2010 08:54
-
-
Save aanoaa/391937 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Template; | |
use XML::Smart; | |
use Pod::Usage; | |
use Getopt::Long; | |
use Data::Dump qw/dump/; | |
use List::Util qw/first/; | |
use DBI; | |
my %options; | |
GetOptions(\%options, "--help", "--dir=s"); | |
run(\%options, @ARGV); | |
sub run { | |
my ($opts, @args) = @_; | |
if ($opts->{help}) { | |
pod2usage(0); | |
} | |
my $dir = setup_dir($opts, @args); | |
my $rows = parsing($dir); | |
#print dump($rows); | |
my $template = Template->new(); | |
my $file = "mkslide.tt"; | |
$template->process($file, {rows=>$rows}) || die "Template process failed: ", $template->error(), "\n"; | |
} | |
sub setup_dir { | |
my ($opts, @args) = @_; | |
if (@args == 0 or not -e $args[0]) { | |
return 'p1'; | |
} else { | |
return $args[0]; | |
} | |
} | |
sub parsing { | |
my ($directory) = @_; | |
my $xml = XML::Smart->new(); | |
my %root; | |
opendir my $dh, $directory or die "can't opendir $directory: $!"; | |
my @files = sort { substr($a, 0, 2) <=> substr($b, 0, 2) } grep { -f "$directory/$_" } readdir($dh); | |
closedir $dh; | |
for my $file (@files) { | |
open(my $fh, '<', "$directory/$file") or die "can't open $directory/$file: $!"; | |
my $content = do { local $/; <$fh> }; | |
$content =~ s/\r//g; | |
$content =~ s/\n$//; | |
$content =~ s{\"}{\\"}g; | |
$content =~ s{\'}{\\'}g; | |
close($fh); | |
my @ext = $file =~ m/\.(\w+)$/; | |
my $ext = shift @ext; # need exception | |
my $id = substr $file, 0, 2; | |
$root{"id_$id"}{$ext} = $content; | |
} | |
return \%root; | |
} | |
__END__ | |
=head1 NAME | |
mkslide - 생략 | |
=head1 SYNOPSIS | |
mkslide.pl --help show this message | |
mkslide.pl --dir=/path/to specify content directory | |
mkslide.pl default dir is ./p1 | |
=head1 AUTHOR | |
hshong | |
=cut |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE screen ( | |
id INTEGER PRIMARY KEY AUTOINCREMENT, | |
part_id INTEGER NOT NULL REFERENCES part(id), | |
label TEXT NOT NULL, | |
text TEXT NOT NULL, | |
sec INTEGER NOT NULL, | |
mp3 TEXT NOT NULL, | |
countdown INTEGER NOT NULL, -- boolean | |
dialog INTEGER NOT NULL, -- boolean | |
rec INTEGER NOT NULL -- boolean | |
); | |
INSERT INTO screen (part_id, label, text, sec, mp3, countdown, dialog, rec) VALUES(1, "", "", 0, "", 0, 0, 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[% FOREACH row IN rows.keys.sort -%] | |
INSERT INTO screen (part_id, label, text, sec, mp3, countdown, dialog, rec) VALUES(1, "[% rows.$row.lab %]", "[% rows.$row.txt || rows.$row.pops %]", [% rows.$row.time || rows.$row.hold || rows.$row.rec || 0 %], "[% rows.$row.link %]", [% IF rows.$row.time || rows.$row.rec %] 1 [% ELSE %] 0 [% END %], [% IF rows.$row.pops %] 1 [% ELSE %] 0 [% END %], [% IF rows.$row.rec %] 1 [% ELSE %] 0 [% END %]); | |
[% END %] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment