1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Getopt::Long qw(GetOptions);
7 use Log::Log4perl qw(:easy);
8 use lib "/usr/local/lib";
9 use Shellex::Shellex qw(shellex findBin);
10 use Gsg::ConfigParse qw(parse_gsg_config);
11 use Gsg::Gather qw(get_file_tree get_projects trim_project_paths);
12 use Gsg::Html qw(write_file append_file write_root_index clean_web_root write_project_content);
13
14 my $start_time = time();
15
16 # TODO set this in config file?
17 my $log_file = "gsg.log";
18 sub get_log_name { return $log_file; };
19 my $log_conf = q(
20 log4perl.rootLogger = ERROR, LOG1, screen
21 log4perl.appender.LOG1 = Log::Log4perl::Appender::File
22 log4perl.appender.LOG1.filename = sub { get_log_name(); }
23 log4perl.appender.LOG1.mode = append
24 log4perl.appender.LOG1.layout = Log::Log4perl::Layout::PatternLayout
25 log4perl.appender.LOG1.layout.ConversionPattern = %d %p >> %m %n
26
27 log4perl.appender.screen = Log::Log4perl::Appender::Screen
28 log4perl.appender.screen.stderr = 0
29 log4perl.appender.screen.layout = PatternLayout
30 log4perl.appender.screen.layout.ConversionPattern = %d %p >> %m %n
31 );
32
33 Log::Log4perl::init(\$log_conf);
34 my $logger = get_logger();
35
36 # Args processing: TODO
37 my %args;
38 GetOptions(
39 \%args,
40 "config-file=s",
41 "version",
42 );
43
44 my $version = "0.1";
45 if ( defined $args{'version'} ) {
46 print "git-site-gen: Version $version\n";
47 exit 0;
48 }
49 # Read config
50 my $config_file;
51 if ( ! defined $args{'config-file'} ) {
52 $config_file = "config.default";
53 } else {
54 $config_file = $args{'config-file'};
55 }
56
57 my %config = parse_gsg_config($config_file,$logger);
58
59 # Set default vars
60 my $web_root = $config{'WebRoot'};
61 my $web_projects_dir = $web_root . "/projects/";
62 my $root_index = $web_root . "/" . "index.html";
63
64 # Really just here for testing right now
65 sub dump_config {
66 foreach my $key ( keys %config ) {
67 if ( $key eq "IgnoredProjects" ) {
68 print "$key contains:\n";
69 foreach my $val ( @{$config{$key}} ) {
70 print "$val\n";
71 }
72 } else {
73 print "Key is $key and val is $config{$key}\n";
74 }
75 }
76 }
77
78 dump_config();
79
80 # Get projects list
81 my $git_projects_ref = get_projects($config{'GitHome'},$config{'IgnoredProjects'},$logger);
82 foreach my $p ( @$git_projects_ref ) {
83 print "Generating for $p\n";
84 }
85
86 # Get trimmed (name only) git projects
87 my $trimmed_git_projects_ref = trim_project_paths($git_projects_ref,$logger);
88
89 # Clean webroot if there is anything we no longer want to display
90 # clean_web_root($web_projects_dir,$trimmed_git_projects_ref,$logger);
91
92 # Write root index
93 write_root_index($root_index,$trimmed_git_projects_ref,$web_projects_dir,$logger);
94
95 # Write project contents
96 my $clone_path;
97 if ( $config{'CloneEnabled'} eq "yes" ) {
98 $clone_path = $config{'ClonePath'};
99 } else {
100 $clone_path = "Disabled";
101 }
102
103 write_project_content($git_projects_ref,$trimmed_git_projects_ref,$web_projects_dir,$clone_path,$logger);
104 my $end_time = time();
105 my $run_time = $end_time - $start_time;
106 print "Took $run_time seconds\n";
107 $logger->info("Done");