gsg 2.8 KB

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