bluto

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

to_python.pl (2542B)


      1 #!/usr/bin/perl
      2 
      3 use warnings;
      4 use strict;
      5 
      6 # standard imports
      7 use Getopt::Long qw/ :config auto_help /;
      8 use File::Temp qw/ tempdir /;
      9 use File::Spec qw/ catfile /;
     10 use File::Basename qw/ dirname /;
     11 use Cwd qw/ getcwd abs_path /;
     12 
     13 # external imports
     14 use Config::Simple;
     15 
     16 # local imports
     17 use lib dirname(abs_path($0));
     18 use Log::Term::Ansi qw/error info debug warn trace/;
     19 
     20 my $ini_dir = File::Spec->catfile(getcwd, '.bluto');
     21 GetOptions(
     22 	'd:s', \$ini_dir,
     23 );
     24 $ini_dir = abs_path($ini_dir);
     25 
     26 info("using ini dir " . $ini_dir . "\n");
     27 
     28 my $fn = File::Spec->catfile($ini_dir, 'bluto.ini');
     29 Config::Simple->import_from($fn, \my %config);
     30 
     31 $fn = File::Spec->catfile($ini_dir, 'bluto.py.ini');
     32 Config::Simple->import_from($fn, \my %config_py);
     33 
     34 my $r;
     35 
     36 my $d = tempdir( CLEANUP => 1 );
     37 $fn = File::Spec->catfile($d, 'config_py.ini');
     38 my $fh;
     39 open($fh, '>', $fn);
     40 print $fh "[metadata]\n";
     41 close($fh);
     42 
     43 our %py_first_author = (
     44 	name => undef,
     45 	email => undef,
     46 );
     47 
     48 our $py_first_url;
     49 our $py_first_license;
     50 for my $k (keys %config) {
     51 	my @p = split(/:/, $k, 2);
     52 	if ($p[0] eq 'author' && ! defined $py_first_author{'name'}) {
     53 		my @n = split(/\./, $p[1]);
     54 		my $name =  $config{'author:' . $n[0] . '.name'};
     55 		$py_first_author{'name'} = $name;
     56 		my $email = $config{'author:' . $n[0] . '.email'};
     57 		if (defined $email) {
     58 			$py_first_author{'email'} = $email;
     59 		}
     60 	} elsif ($p[0] eq 'locate' && ! defined $py_first_url) {
     61 		$py_first_url = $config{$k};
     62 	}
     63 
     64 	@p = split(/\./, $p[0], 2);
     65 	if ($p[0] eq 'license' && ! defined $py_first_license) {
     66 		$py_first_license = $p[1] . $config{$k};
     67 	}
     68 }
     69 
     70 our @py_tags;
     71 our @py_classifiers;
     72 my $fh_tag;
     73 $r = open($fh_tag, '<', 'bluto.tag');
     74 if ($r) {
     75 	while (<$fh_tag>) {
     76 		my $v = $_;
     77 		chomp($v);
     78 		my @p = split(/ :: /, $v);
     79 		if ($#p > 0) {
     80 			push(@py_classifiers, $v);
     81 		} else {
     82 			push(@py_tags, $v);
     83 		}
     84 	}
     85 }
     86 
     87 my $py_cfg = new Config::Simple($fn);
     88 $py_cfg->param('metadata.author_email', $py_first_author{email});
     89 $py_cfg->param('metadata.author', $py_first_author{name});
     90 $py_cfg->param('metadata.description', $config{'main.summary'});
     91 $py_cfg->param('metadata.url', $py_first_url);
     92 $py_cfg->param('metadata.version', $config{'main.version'});
     93 $py_cfg->param('metadata.name', $config{'main.name'});
     94 $py_cfg->param('metadata.license', $py_first_license);
     95 print $py_cfg->as_string();
     96 
     97 if ($#py_tags > -1) {
     98 	print "keywords =\n";
     99 	for my $v (@py_tags) {
    100 		print "\t" . $v . "\n";
    101 	}
    102 }
    103 
    104 if ($#py_classifiers > -1) {
    105 	print "classifiers =\n";
    106 	for my $v (@py_classifiers) {
    107 		print "\t" . $v . "\n";
    108 	}
    109 }