123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #!/usr/bin/perl
- use strict;
- use warnings;
- use Getopt::Long qw(GetOptions);
- use Log::Log4perl qw(:easy);
- use lib "/usr/local/lib";
- use Shellex::Shellex qw(shellex findBin);
- use Gsg::ConfigParse qw(parse_gsg_config);
- use Gsg::Gather qw(get_file_tree get_projects trim_project_paths);
- use Gsg::Html qw(write_file append_file write_root_index clean_web_root write_project_content);
- my $start_time = time();
- # TODO set this in config file?
- my $log_file = "gsg.log";
- sub get_log_name { return $log_file; };
- my $log_conf = q(
- log4perl.rootLogger = ERROR, LOG1, screen
- log4perl.appender.LOG1 = Log::Log4perl::Appender::File
- log4perl.appender.LOG1.filename = sub { get_log_name(); }
- log4perl.appender.LOG1.mode = append
- log4perl.appender.LOG1.layout = Log::Log4perl::Layout::PatternLayout
- log4perl.appender.LOG1.layout.ConversionPattern = %d %p >> %m %n
- log4perl.appender.screen = Log::Log4perl::Appender::Screen
- log4perl.appender.screen.stderr = 0
- log4perl.appender.screen.layout = PatternLayout
- log4perl.appender.screen.layout.ConversionPattern = %d %p >> %m %n
- );
- Log::Log4perl::init(\$log_conf);
- my $logger = get_logger();
- # Args processing: TODO
- my %args;
- GetOptions(
- \%args,
- "config-file=s",
- "version",
- );
- my $version = "0.1";
- if ( defined $args{'version'} ) {
- print "git-site-gen: Version $version\n";
- exit 0;
- }
- # Read config
- my $config_file;
- if ( ! defined $args{'config-file'} ) {
- $config_file = "config.default";
- } else {
- $config_file = $args{'config-file'};
- }
- my %config = parse_gsg_config($config_file,$logger);
- # Set default vars
- my $web_root = $config{'WebRoot'};
- my $web_projects_dir = $web_root . "/projects/";
- my $root_index = $web_root . "/" . "index.html";
- # Really just here for testing right now
- sub dump_config {
- foreach my $key ( keys %config ) {
- if ( $key eq "IgnoredProjects" ) {
- print "$key contains:\n";
- foreach my $val ( @{$config{$key}} ) {
- print "$val\n";
- }
- } else {
- print "Key is $key and val is $config{$key}\n";
- }
- }
- }
- dump_config();
- # Get projects list
- my $git_projects_ref = get_projects($config{'GitHome'},$config{'IgnoredProjects'},$logger);
- foreach my $p ( @$git_projects_ref ) {
- print "Generating for $p\n";
- }
- # Get trimmed (name only) git projects
- my $trimmed_git_projects_ref = trim_project_paths($git_projects_ref,$logger);
- # Clean webroot if there is anything we no longer want to display
- # clean_web_root($web_projects_dir,$trimmed_git_projects_ref,$logger);
- # Write root index
- write_root_index($root_index,$trimmed_git_projects_ref,$web_projects_dir,$logger);
- # Write project contents
- my $clone_path;
- if ( $config{'CloneEnabled'} eq "yes" ) {
- $clone_path = $config{'ClonePath'};
- } else {
- $clone_path = "Disabled";
- }
- write_project_content($git_projects_ref,$trimmed_git_projects_ref,$web_projects_dir,$clone_path,$logger);
- my $end_time = time();
- my $run_time = $end_time - $start_time;
- print "Took $run_time seconds\n";
- $logger->info("Done");
|