cpee-frames 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/ruby
  2. #
  3. # This file is part of CPEE-FRAMES.
  4. #
  5. # CPEE-FRAMES is free software: you can redistribute it and/or modify it under
  6. # the terms of the GNU Lesser General Public License as published by the Free
  7. # Software Foundation, either version 3 of the License, or (at your option) any
  8. # later version.
  9. #
  10. # CPEE-FRAMES is distributed in the hope that it will be useful, but WITHOUT
  11. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  13. # details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public License
  16. # along with CPEE-FRAMES (file LICENSE in the main directory). If not, see
  17. # <http://www.gnu.org/licenses/>.
  18. curpath = __dir__
  19. require 'rubygems'
  20. require 'optparse'
  21. require 'fileutils'
  22. require 'xml/smart'
  23. require 'yaml'
  24. require 'typhoeus'
  25. require 'stringio'
  26. def wrap(s, width=78, indent=18, extra_indent=4) #{{{
  27. lines = []
  28. line, s = s[0..indent-2], s[indent..-1]
  29. s.split(/\n/).each do |ss|
  30. ss.split(/[ \t]+/).each do |word|
  31. if line.size + word.size >= width
  32. lines << line
  33. line = (" " * (indent + extra_indent)) + word
  34. else
  35. line << " " << word
  36. end
  37. end
  38. lines << line if line
  39. line = (" " * (indent-1))
  40. end
  41. return lines.join "\n"
  42. end #}}}
  43. exname = File.basename($0)
  44. ARGV.options { |opt|
  45. opt.summary_indent = ' ' * 2
  46. opt.summary_width = 15
  47. opt.banner = "Usage:\n#{opt.summary_indent}#{exname} new [DIR] | newui [DIR]\n"
  48. opt.on("Options:")
  49. opt.on("--help", "-h", "This text") { puts opt; exit }
  50. opt.on("")
  51. opt.on(wrap("new [DIR] scaffolds a sample logging service. Add a handler to a cpee instance to experience the pleasure.",78,18,0))
  52. opt.on("")
  53. opt.on(wrap("newui [DIR] scaffolds css/js directors that are use by the UI into your webserver dir."))
  54. opt.parse!
  55. }
  56. if (ARGV.length != 2)
  57. puts ARGV.options
  58. exit
  59. else
  60. command = ARGV[0]
  61. dir = ARGV[1]
  62. end
  63. if command == 'new'
  64. if !File.exist?(dir)
  65. FileUtils.cp_r(File.join(curpath,'..','server'),dir)
  66. FileUtils.mkdir(File.join(dir,'data')) rescue nil
  67. else
  68. puts 'Directory already exists.'
  69. end
  70. elsif command == 'newui'
  71. if !File.exist?(dir)
  72. FileUtils.cp_r(File.join(curpath,'..','ui'),dir)
  73. else
  74. puts 'Directory already exists.'
  75. end
  76. else
  77. puts ARGV.options
  78. end