gsg 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 = INFO, 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. # Get projects list
  66. my $git_projects_ref = get_projects($config{'GitHome'},$config{'IgnoredProjects'},$logger);
  67. foreach my $p ( @$git_projects_ref ) {
  68. print "$p\n";
  69. }
  70. # Get trimmed (name only) git projects
  71. my $trimmed_git_projects_ref = trim_project_paths($git_projects_ref,$logger);
  72. # Clean webroot if there is anything we no longer want to display
  73. # clean_web_root($web_projects_dir,$trimmed_git_projects_ref,$logger);
  74. # Write root index
  75. write_root_index($root_index,$trimmed_git_projects_ref,$web_projects_dir,$logger);
  76. # Write project contents
  77. write_project_content($git_projects_ref,$trimmed_git_projects_ref,$web_projects_dir,$logger);
  78. $logger->info("Done");