gsg 2.9 KB

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