bluto

Release package and announcement generator
Info | Log | Files | Refs | README | LICENSE

to_std.pl (2124B)


      1 #!/usr/bin/perl
      2 
      3 use v5.10.1;
      4 use warnings;
      5 use strict;
      6 
      7 # standard imports
      8 use Getopt::Long qw/ :config auto_help /;
      9 #use File::Temp qw/ tempdir /;
     10 use File::Basename qw/ dirname /;
     11 use File::Spec;
     12 use Cwd qw/ getcwd abs_path /;
     13 use lib (dirname(abs_path($0)));
     14 
     15 # external imports
     16 use Config::Simple;
     17 
     18 # bundled external imports
     19 use SemVer;
     20 
     21 # local imports
     22 use Log::Term::Ansi qw/error info debug warn trace/;
     23 use Bluto;
     24 use Bluto::RSS;
     25 
     26 sub croak {
     27 	die(shift);
     28 }
     29 
     30 sub help() {
     31 	print("$0\n\nwould have shown help...\n");
     32 	exit 0;
     33 }
     34 
     35 # TODO: export to perl modules
     36 
     37 my $force_version = undef;
     38 my $loglevel = 0;
     39 my $force_help = 0;
     40 my %env = (
     41 	src_dir => File::Spec->catfile(getcwd, '.bluto'),
     42 	out_dir => File::Spec->catfile(getcwd, 'bluto_build'),
     43 	feed_dir => undef,
     44 	content_dir => getcwd,
     45 	template_path => undef,
     46 	engine => undef,
     47 	readme => undef,
     48 	version => undef,
     49 	loglevel => undef,
     50 );
     51 GetOptions(
     52 	'd:s', \$env{src_dir},
     53 	'o:s', \$env{out_dir},
     54 	'f:s', \$env{feed_dir},
     55 	'c:s', \$env{content_dir},
     56 	'v+', \$loglevel,
     57 	'h+', \$force_help,
     58 	'help+', \$force_help,
     59 	'version=s', \$force_version,
     60 );
     61 
     62 if ($force_help > 0) {
     63 	help;
     64 }
     65 
     66 foreach my $k (keys %env ) {
     67 	if (defined $env{$k}) {
     68 		$env{$k} = abs_path($env{$k});
     69 	}
     70 }
     71 
     72 if (!defined $env{feed_dir}) {
     73 	$env{feed_dir} = $env{out_dir};
     74 }
     75 
     76 if (defined $force_version) {
     77 	$env{version} = SemVer->new($force_version);
     78 }
     79 
     80 $env{loglevel} = $loglevel;
     81 
     82 $env{engine} = 'bluto v' . SemVer->new(Bluto::VERSION). " (perl $^V)";
     83 foreach my $k (keys %env ) {
     84 	if (defined $env{$k}) {
     85 		debug('environment "' . $k . '":  ' . $env{$k});
     86 	}
     87 }
     88 
     89 if (Bluto::check_sanity(\%env)) {
     90 	croak('sanity check fail');
     91 }
     92 
     93 my $fn = File::Spec->catfile($env{src_dir}, 'bluto.ini');
     94 debug("import from " . $fn);
     95 my $cfg = new Config::Simple($fn);
     96 
     97 my $version = Bluto::from_config($cfg, \%env);
     98 if (!defined $version) {
     99 	die("config processing failed");
    100 }
    101 
    102 my $announce = Bluto::create_announce(\%env);
    103 if (!defined $announce) {
    104 	die("announce processing failed");
    105 }
    106 
    107 my $rss = Bluto::create_rss(\%env);
    108 if (!defined $rss) {
    109 	die("rss processing failed");
    110 }
    111 
    112 #my @change = $cfg->vars();