falkorlib 0.6.19 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +88 -0
  4. data/.travis.yml +56 -4
  5. data/Gemfile +4 -4
  6. data/Gemfile.lock +55 -27
  7. data/Rakefile +12 -8
  8. data/Vagrantfile +68 -0
  9. data/completion/_falkor +55 -7
  10. data/falkorlib.gemspec +14 -12
  11. data/lib/falkorlib.rb +22 -21
  12. data/lib/falkorlib/bootstrap.rb +5 -1
  13. data/lib/falkorlib/bootstrap/base.rb +385 -693
  14. data/lib/falkorlib/bootstrap/git.rb +137 -0
  15. data/lib/falkorlib/bootstrap/latex.rb +186 -0
  16. data/lib/falkorlib/bootstrap/link.rb +108 -96
  17. data/lib/falkorlib/bootstrap/ruby.rb +102 -0
  18. data/lib/falkorlib/cli.rb +82 -26
  19. data/lib/falkorlib/cli/config.rb +8 -8
  20. data/lib/falkorlib/cli/link.rb +8 -9
  21. data/lib/falkorlib/cli/new.rb +25 -39
  22. data/lib/falkorlib/common.rb +425 -425
  23. data/lib/falkorlib/config.rb +114 -110
  24. data/lib/falkorlib/error.rb +27 -16
  25. data/lib/falkorlib/gem_tasks.rb +12 -11
  26. data/lib/falkorlib/git.rb +3 -4
  27. data/lib/falkorlib/git/base.rb +439 -396
  28. data/lib/falkorlib/git/flow.rb +163 -165
  29. data/lib/falkorlib/git_tasks.rb +31 -31
  30. data/lib/falkorlib/loader.rb +1 -1
  31. data/lib/falkorlib/puppet.rb +3 -5
  32. data/lib/falkorlib/puppet/base.rb +10 -15
  33. data/lib/falkorlib/puppet/modules.rb +367 -365
  34. data/lib/falkorlib/puppet_tasks.rb +11 -8
  35. data/lib/falkorlib/tasks.rb +51 -54
  36. data/lib/falkorlib/tasks/gem.rake +42 -43
  37. data/lib/falkorlib/tasks/gem.rb +12 -11
  38. data/lib/falkorlib/tasks/git.rake +101 -107
  39. data/lib/falkorlib/tasks/git.rb +31 -31
  40. data/lib/falkorlib/tasks/gitflow.rake +131 -141
  41. data/lib/falkorlib/tasks/puppet.rb +11 -8
  42. data/lib/falkorlib/tasks/puppet_modules.rake +143 -154
  43. data/lib/falkorlib/tasks/rspec.rake +94 -59
  44. data/lib/falkorlib/tasks/yard.rake +35 -39
  45. data/lib/falkorlib/version.rb +55 -55
  46. data/lib/falkorlib/versioning.rb +169 -167
  47. data/spec/falkorlib/bootstrap_helpers_spec.rb +106 -56
  48. data/spec/falkorlib/bootstrap_latex_spec.rb +145 -0
  49. data/spec/falkorlib/bootstrap_link_spec.rb +137 -0
  50. data/spec/falkorlib/bootstrap_ruby_spec.rb +118 -0
  51. data/spec/falkorlib/bootstrap_spec.rb +112 -129
  52. data/spec/falkorlib/git_spec.rb +94 -22
  53. data/spec/falkorlib/gitflow_spec.rb +54 -42
  54. data/spec/falkorlib/puppet_modules_spec.rb +35 -26
  55. data/spec/falkorlib/versioning_puppet_module_spec.rb +94 -90
  56. data/spec/falkorlib_spec.rb +5 -0
  57. data/spec/spec_helper.rb +88 -47
  58. data/templates/latex/article-ieee/main.tex.erb +509 -0
  59. data/templates/latex/article/_abstract.tex.erb +19 -0
  60. data/templates/latex/article/_acronyms.tex.erb +116 -0
  61. data/templates/latex/article/_conclusion.tex.erb +25 -0
  62. data/templates/latex/article/_context.tex.erb +17 -0
  63. data/templates/latex/article/_experiments.tex.erb +27 -0
  64. data/templates/latex/article/_implem.tex.erb +17 -0
  65. data/templates/latex/article/_introduction.tex.erb +39 -0
  66. data/templates/latex/article/_related_works.tex.erb +19 -0
  67. data/templates/latex/article/biblio.bib.erb +28 -0
  68. data/templates/latex/article/template.tex.erb +16 -0
  69. data/templates/latex/ieee/IEEEtran.bst +2409 -0
  70. data/templates/latex/ieee/IEEEtran.cls +6347 -0
  71. data/templates/motd/motd.erb +2 -1
  72. metadata +82 -2
@@ -1,7 +1,7 @@
1
1
  #compdef falkor
2
2
  ########################################################################################
3
3
  # -*- mode:sh; -*-
4
- # Time-stamp: <Sat 2016-10-15 22:20 svarrette>
4
+ # Time-stamp: <Mon 2016-11-14 15:24 svarrette>
5
5
  #
6
6
  # ZSH completion for [FalkorLib](https://github.com/Falkor/falkorlib)
7
7
  #
@@ -17,7 +17,12 @@
17
17
  ########################################################################################
18
18
  # You can inspired from the (unfortunately buggy) automatic generation of the ZSH
19
19
  # completion file (see https://github.com/labocho/thor-zsh_completion) using:
20
+ #
20
21
  # bundle exec falkor zsh-completion > completion/_falkor.autogen
22
+ #
23
+ # Test modification in live in your shell:
24
+ #
25
+ # unfunction _falkor && autoload -U _falkor
21
26
 
22
27
  typeset -A opt_args
23
28
 
@@ -35,7 +40,9 @@ _falkor()
35
40
  _falkor_cmds=(
36
41
  'config:Print the current configuration of FalkorLib'
37
42
  'help:Describe available commands or one specific command'
38
- 'link:link:Initialize a special symlink (.root, .makefile.d etc.)'
43
+ 'init:Bootstrap a Git Repository the falkor way'
44
+ 'link:Initialize a special symlink (.root, .makefile.d etc.)'
45
+ 'motd:bootstrap a Message of the Day (motd) file'
39
46
  'new:Initialize the directory PATH with one of Falkors template(s)'
40
47
  'version:Prints the FalkorLib version information'
41
48
  )
@@ -63,10 +70,14 @@ _falkor()
63
70
  ;;
64
71
  (config)
65
72
  __falkor_config && ret=0 ;;
66
- (new)
67
- __falkor_new && ret=0 ;;
73
+ (init)
74
+ __falkor_init && ret=0 ;;
68
75
  (link)
69
76
  __falkor_link && ret=0 ;;
77
+ (motd)
78
+ __falkor_motd && ret=0 ;;
79
+ (new)
80
+ __falkor_new && ret=0 ;;
70
81
  (version|*)
71
82
  _nothing
72
83
  ;;
@@ -112,8 +123,8 @@ __falkor_new()
112
123
  (letter)
113
124
  _arguments -C \
114
125
  '(-n --name)'{-n,--name}'[Name of the LaTeX project]' \
115
- '(-d --dir)'{-d,--dir=}':Project directory (relative to the git root directory):_directories' && ret=0
116
- ;;
126
+ '(-d --dir)'{-d,--dir}':Project directory (relative to the git root directory):_directories' && ret=0
127
+ ;;
117
128
  (repo)
118
129
  _arguments -C \
119
130
  '(--no-git-flow)--git-flow[Bootstrap the repository with Git-flow]' \
@@ -130,7 +141,7 @@ __falkor_new()
130
141
  case "$state" in
131
142
  (path)
132
143
  _directories ;;
133
- esac
144
+ esac
134
145
  ;;
135
146
  esac
136
147
  ;;
@@ -200,4 +211,41 @@ __falkor_config() {
200
211
  }
201
212
 
202
213
 
214
+ ##################
215
+ __falkor_init() {
216
+ local curcontext=$curcontext state line ret=1
217
+ declare -A opt_args
218
+
219
+ _arguments -C \
220
+ {--git-flow,--no-git-flow}'[Bootstrap the repository with (or without) Git-flow]' \
221
+ {-i,--interactive}'[Interactive mode, in particular to confirm Gitflow branch names]' \
222
+ {-r,--remote-sync}'[Operate a git remote synchronization with remote. By default, all commits stay local]' \
223
+ '--master[Master Branch name for production releases]' \
224
+ {-b,--branch,--devel,--develop}'[Branch name for development commits]' \
225
+ '--make[Use a Makefile to pilot the repository actions (default)]' \
226
+ '--rake[Use a Rakefile (and FalkorLib) to pilot the repository actions]' \
227
+ '*:directory:_directories'
228
+ }
229
+
230
+
231
+ ##################
232
+ __falkor_motd() {
233
+ local curcontext=$curcontext state line ret=1
234
+ declare -A opt_args
235
+
236
+ _arguments -C \
237
+ {--file,-f}'[File storing the message of the day]:filename:_files' \
238
+ {--width,-w}'[Width for the text]:[0-9]#' \
239
+ {--title,-t}'[Title to be placed in the motd (using asciify or figlet)]:title' \
240
+ '--subtitle[Eventual subtitle to place below the title]:subtitle' \
241
+ '--hostname[Hostname]:hostname' \
242
+ {--support,-s}"[Support/Contact mail]:email:($(git config user.email) hpc-sysadmins@uni.lu)" \
243
+ {--desc,-d}'[Short Description of the host]:desc' \
244
+ {--nodemodel,-n}'[Node Model]:model' \
245
+ '*:directory:_files -/'
246
+ }
247
+
248
+
249
+
250
+
203
251
  _falkor "$@"
@@ -1,11 +1,11 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
3
  require "falkorlib/version"
4
- $version = FalkorLib::Version.to_s
4
+ #$version = FalkorLib::Version.to_s
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "falkorlib"
8
- s.version = $version
8
+ s.version = FalkorLib::Version.to_s #$version
9
9
  s.date = Time.now.strftime('%Y-%m-%d')
10
10
  s.summary = "Sebastien Varrette aka Falkor's Common library to share Ruby code and {rake,cap} tasks"
11
11
  s.description = "This is my personal library I use to share the Ruby tidbits and Rake tasks I made it for my various projects, and also to bootstrap easily several element of my daily workflow (new git repository, new beamer slides etc.).\nThis is also my first gem so any comments on the code/organization are welcome, I'm a newbie in this domain. \nNote that I used [Noe](https://github.com/blambeau/noe) to bootstrap this project and get a fully documented environment."
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
38
38
  s.test_files = Dir["test/**/*"] + Dir["spec/**/*"]
39
39
 
40
40
  # Alternative:
41
- s.files = `git ls-files`.split("\n")
41
+ s.files = `git ls-files`.split("\n")
42
42
  #s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
43
43
  #s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
44
44
 
@@ -46,7 +46,7 @@ Gem::Specification.new do |s|
46
46
  #
47
47
  #s.bindir = "bin"
48
48
 
49
- s.executables = (Dir["bin/*"]).collect{|f| File.basename(f)}
49
+ s.executables = (Dir["bin/*"]).collect { |f| File.basename(f) }
50
50
 
51
51
  ################################################################### REQUIREMENTS & INSTALL
52
52
  # Remember the gem version requirements operators and schemes:
@@ -83,9 +83,12 @@ Gem::Specification.new do |s|
83
83
  s.add_runtime_dependency("thor", '>= 0.19')
84
84
  s.add_runtime_dependency("artii", '>= 2.1')
85
85
  s.add_runtime_dependency("facter", '~> 2.4.1')
86
-
86
+ s.add_runtime_dependency("thor-zsh_completion", '>= 0')
87
+ s.add_runtime_dependency("activesupport", '~> 4.0')
88
+ #s.add_runtime_dependency("benchmark", '~> 4.0')
87
89
  #s.add_runtime_dependency("mercenary", '>= 0.3.5')
88
90
 
91
+
89
92
  #
90
93
  #
91
94
  # One call to add_dependency('gem_name', 'gem version requirement') for each
@@ -94,15 +97,15 @@ Gem::Specification.new do |s|
94
97
  # for each development dependency. These gems are required for developers
95
98
  #
96
99
  #s.add_development_dependency("rake", ">= 10.1.0") #"~> 0.9.2")
97
- s.add_development_dependency("bundler", "~> 1.0")
98
- s.add_development_dependency 'rspec', '~> 3.0' #, '>= 2.7.0'
100
+ s.add_development_dependency("bundler", "~> 1.0")
101
+ s.add_development_dependency 'rspec', '~> 3.0' #, '>= 2.7.0'
99
102
  s.add_development_dependency("pry", "~> 0.9")
100
103
  s.add_development_dependency("yard", "~> 0.8")
101
- #s.add_development_dependency("minitest", "~> 5.3")
102
- s.add_development_dependency("rubygems-tasks", "~> 0.2")
104
+ s.add_development_dependency('rubocop', '~> 0.45.0')
105
+ s.add_development_dependency("rubygems-tasks", "~> 0.2")
103
106
  s.add_development_dependency("travis", "~> 1.6")
104
107
  s.add_development_dependency("travis-lint", "~> 1.8")
105
-
108
+ s.add_development_dependency('simplecov', '~> 0.12.0')
106
109
  s.add_development_dependency("codeclimate-test-reporter", '~> 0') #, group: :test, require: nil)
107
110
  #s.add_development_dependency("bluecloth", "~> 2.2.0")
108
111
  #s.add_development_dependency("wlang", "~> 0.10.2")
@@ -130,7 +133,7 @@ Gem::Specification.new do |s|
130
133
  s.extensions = []
131
134
 
132
135
  # External (to RubyGems) requirements that must be met for this gem to work.
133
- # Its simply information for the user.
136
+ # It's simply information for the user.
134
137
  #
135
138
  s.requirements = nil
136
139
 
@@ -163,5 +166,4 @@ Gem::Specification.new do |s|
163
166
  # Extra files to add to RDoc such as README
164
167
  #
165
168
  s.extra_rdoc_files = Dir["README.md"] + Dir["CHANGELOG.md"] + Dir["LICENCE.md"]
166
-
167
169
  end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Mar 2015-01-13 21:24 svarrette>
3
+ # Time-stamp: <Mon 2016-11-07 22:06 svarrette>
4
4
  ################################################################################
5
5
  # _____ _ _ _ _ _
6
6
  # | ___|_ _| | | _____ _ __| | (_) |__
@@ -15,15 +15,17 @@
15
15
  # * [Official Gem](https://rubygems.org/gems/falkorlib)
16
16
  ################################################################################
17
17
 
18
- require "awesome_print"
18
+ require 'awesome_print'
19
+ # require 'active_support' # provides so many nice extensions
20
+ require 'active_support/core_ext/hash'
19
21
 
20
22
  begin
21
- require 'term/ansicolor'
22
- COLOR = true
23
- rescue Exception => e
24
- puts "/!\\ cannot find the 'term/ansicolor' library"
25
- puts " Consider installing it by 'gem install term-ansicolor'"
26
- COLOR = false
23
+ require 'term/ansicolor'
24
+ COLOR = true
25
+ rescue LoadError
26
+ puts "/!\\ cannot find the 'term/ansicolor' library"
27
+ puts " Consider installing it by 'gem install term-ansicolor'"
28
+ COLOR = false
27
29
  end
28
30
 
29
31
  require 'yaml'
@@ -32,21 +34,20 @@ require 'yaml'
32
34
  # and `{rake,cap}` tasks
33
35
  module FalkorLib
34
36
 
35
- # Return the root directory of the gem
36
- def self.root
37
- File.expand_path '../..', __FILE__
38
- end
37
+ # Return the root directory of the gem
38
+ def self.root
39
+ File.expand_path '../..', __FILE__
40
+ end
39
41
 
40
- def self.lib
41
- File.join root, 'lib'
42
- end
42
+ def self.lib
43
+ File.join root, 'lib'
44
+ end
43
45
 
44
- def self.templates
45
- File.join root, 'templates'
46
- end
46
+ def self.templates
47
+ File.join root, 'templates'
48
+ end
47
49
 
48
50
  end # module FalkorLib
49
51
 
50
-
51
- require "falkorlib/version"
52
- require "falkorlib/loader"
52
+ require 'falkorlib/version'
53
+ require 'falkorlib/loader'
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Sun 2016-03-27 23:21 svarrette>
3
+ # Time-stamp: <Tue 2016-11-01 10:05 svarrette>
4
4
  ################################################################################
5
5
  # Management of Bootstrapping operations
6
6
 
@@ -12,4 +12,8 @@ end # module FalkorLib
12
12
 
13
13
  require "falkorlib/bootstrap/base"
14
14
  require "falkorlib/bootstrap/link"
15
+ require "falkorlib/bootstrap/ruby"
16
+ require "falkorlib/bootstrap/git"
17
+ require "falkorlib/bootstrap/latex"
18
+
15
19
  #require "falkorlib/bootstrap/repo"
@@ -1,718 +1,410 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Sat 2016-10-15 23:44 svarrette>
3
+ # Time-stamp: <Sat 2016-11-12 09:21 svarrette>
4
4
  ################################################################################
5
5
  # Interface for the main Bootstrapping operations
6
6
  #
7
7
 
8
8
  require "falkorlib"
9
9
  require "falkorlib/common"
10
- require 'erb' # required for module generation
10
+ require "falkorlib/bootstrap"
11
+
12
+ require 'erb' # required for module generation
11
13
  require 'artii'
12
14
  require 'facter'
13
15
 
14
16
  include FalkorLib::Common
15
17
 
16
- module FalkorLib #:nodoc:
17
- module Config
18
+ module FalkorLib #:nodoc:
19
+ module Config
20
+ # Default configuration for Bootstrapping processes
21
+ module Bootstrap
22
+
23
+ DEFAULTS =
24
+ {
25
+ :motd => {
26
+ :file => 'motd',
27
+ :hostname => `hostname -f`.chomp,
28
+ :title => "Title",
29
+ :desc => "Brief server description",
30
+ :support => `git config user.email`.chomp,
31
+ :width => 80
32
+ },
33
+ :latex => {
34
+ :name => '',
35
+ :author => `git config user.name`.chomp,
36
+ :mail => `git config user.email`.chomp,
37
+ :title => 'Title',
38
+ :subtitle => 'Overview and Open Challenges',
39
+ :image => 'images/logo_ULHPC.pdf',
40
+ :logo => 'images/logo_UL.pdf',
41
+ :url => 'http://csc.uni.lu/sebastien.varrette'
42
+ },
43
+ :letter => {
44
+ :author_title => 'PhD',
45
+ :institute => 'University of Luxembourg',
46
+ :department => 'Parallel Computing and Optimization Group',
47
+ :department_acro => 'PCOG',
48
+ :address => '7, rue Richard Coudenhove-Kalergie',
49
+ :zipcode => 'L-1359',
50
+ :location => 'Luxembourg',
51
+ :phone => '(+352) 46 66 44 6600',
52
+ :twitter => 'svarrette',
53
+ :linkedin => 'svarrette',
54
+ :skype => 'sebastien.varrette',
55
+ :scholar => '6PTStIcAAAAJ'
56
+ },
57
+ :metadata => {
58
+ :name => '',
59
+ :type => [],
60
+ :by => (ENV['USER']).to_s,
61
+ :author => `git config user.name`.chomp,
62
+ :mail => `git config user.email`.chomp,
63
+ :summary => "rtfm",
64
+ :description => '',
65
+ :forge => '',
66
+ :source => '',
67
+ :project_page => '',
68
+ :origin => '',
69
+ :license => '',
70
+ :issues_url => '',
71
+ :tags => []
72
+ },
73
+ :trashdir => '.Trash',
74
+ :types => [ :none, :latex, :gem, :octopress, :puppet_module, :rvm, :pyenv ],
75
+ :licenses => {
76
+ "none" => {},
77
+ "Apache-2.0" => {
78
+ :url => "http://www.apache.org/licenses/LICENSE-2.0",
79
+ :logo => "https://www.apache.org/images/feather-small.gif"
80
+ },
81
+ "BSD" => {
82
+ :url => "http://www.linfo.org/bsdlicense.html",
83
+ :logo => "http://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/License_icon-bsd.svg/200px-License_icon-bsd.svg.png"
84
+ },
85
+ "CC by-nc-sa" => {
86
+ :name => "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International",
87
+ :url => "http://creativecommons.org/licenses/by-nc-sa/4.0",
88
+ :logo => "https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png"
89
+ },
90
+ "GPL-2.0" => {
91
+ :url => "http://www.gnu.org/licenses/gpl-2.0.html",
92
+ :logo => "https://licensebuttons.net/l/GPL/2.0/88x62.png"
93
+ },
94
+ "GPL-3.0" => {
95
+ :url => "http://www.gnu.org/licenses/gpl-3.0.html",
96
+ :logo => "https://www.gnu.org/graphics/gplv3-88x31.png"
97
+ },
98
+ "LGPL-2.1" => {
99
+ :url => "https://www.gnu.org/licenses/lgpl-2.1.html",
100
+ :logo => "https://licensebuttons.net/l/LGPL/2.1/88x62.png"
101
+ },
102
+ "LGPL-3.0" => {
103
+ :url => "https://www.gnu.org/licenses/lgpl.html",
104
+ :logo => "https://www.gnu.org/graphics/lgplv3-88x31.png"
105
+ },
106
+ "MIT" => {
107
+ :url => "http://opensource.org/licenses/MIT",
108
+ :logo => "http://upload.wikimedia.org/wikipedia/commons/thumb/0/0b/License_icon-mit-2.svg/200px-License_icon-mit-2.svg.png"
109
+ }
110
+ },
111
+ :puppet => {},
112
+ :forge => {
113
+ :none => { :url => '', :name => "None" },
114
+ :gforge => { :url => 'gforge.uni.lu', :name => 'GForge @ Uni.lu' },
115
+ :github => { :url => 'github.com', :name => 'Github', :login => (`whoami`.chomp.capitalize).to_s },
116
+ :gitlab => { :url => 'gitlab.uni.lu', :name => 'Gitlab @ Uni.lu', :login => (`whoami`.chomp.capitalize).to_s }
117
+ }
118
+ }
18
119
 
19
- # Default configuration for Bootstrapping processes
20
- module Bootstrap
21
- DEFAULTS =
22
- {
23
- :motd => {
24
- :title => "Title",
25
- :support => "#{ENV['GIT_AUTHOR_EMAIL']}",
26
- :width => 80,
27
- :hostname => "`hostname -f`",
28
- },
29
- :latex => {
30
- :name => '',
31
- :author => %x( git config user.name ).chomp,
32
- :mail => %x( git config user.email ).chomp,
33
- :title => 'Title',
34
- :subtitle => 'Overview and Open Challenges',
35
- :image => 'images/logo_ULHPC.pdf',
36
- :logo => 'images/logo_UL.pdf',
37
- :url => 'http://csc.uni.lu/sebastien.varrette'
38
- },
39
- :letter => {
40
- :author_title => 'PhD',
41
- :institute => 'University of Luxembourg',
42
- :department => 'Parallel Computing and Optimization Group',
43
- :department_acro => 'PCOG',
44
- :address => '7, rue Richard Coudenhove-Kalergie',
45
- :zipcode => 'L-1359',
46
- :location => 'Luxembourg',
47
- :phone => '(+352) 46 66 44 6600',
48
- :twitter => 'svarrette',
49
- :linkedin => 'svarrette',
50
- :skype => 'sebastien.varrette',
51
- :scholar => '6PTStIcAAAAJ'
52
- },
53
- :metadata => {
54
- :name => '',
55
- :type => [],
56
- :by => "#{ENV['USER']}",
57
- :author => "#{ENV['GIT_AUTHOR_NAME']}",
58
- :mail => "#{ENV['GIT_AUTHOR_EMAIL']}",
59
- :summary => "rtfm",
60
- :description => '',
61
- :forge => '',
62
- :source => '',
63
- :project_page => '',
64
- :origin => '',
65
- :license => '',
66
- :issues_url => '',
67
- :tags => []
68
- },
69
- :trashdir => '.Trash',
70
- :types => [ :none, :latex, :gem, :octopress, :puppet_module, :rvm, :pyenv ],
71
- :licenses => {
72
- "none" => {},
73
- "Apache-2.0" => {
74
- :url => "http://www.apache.org/licenses/LICENSE-2.0",
75
- :logo => "https://www.apache.org/images/feather-small.gif"
76
- },
77
- "BSD" => {
78
- :url => "http://www.linfo.org/bsdlicense.html",
79
- :logo => "http://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/License_icon-bsd.svg/200px-License_icon-bsd.svg.png"
80
- },
81
- "CC by-nc-sa" => {
82
- :name => "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International",
83
- :url => "http://creativecommons.org/licenses/by-nc-sa/4.0",
84
- :logo => "https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png"
85
- },
86
- "GPL-2.0" => {
87
- :url => "http://www.gnu.org/licenses/gpl-2.0.html",
88
- :logo => "https://licensebuttons.net/l/GPL/2.0/88x62.png"
89
- },
90
- "GPL-3.0" => {
91
- :url => "http://www.gnu.org/licenses/gpl-3.0.html",
92
- :logo => "https://www.gnu.org/graphics/gplv3-88x31.png",
93
- },
94
- "LGPL-2.1" => {
95
- :url => "https://www.gnu.org/licenses/lgpl-2.1.html",
96
- :logo => "https://licensebuttons.net/l/LGPL/2.1/88x62.png",
97
- },
98
- "LGPL-3.0" => {
99
- :url => "https://www.gnu.org/licenses/lgpl.html",
100
- :logo => "https://www.gnu.org/graphics/lgplv3-88x31.png",
101
- },
102
- "MIT" => {
103
- :url => "http://opensource.org/licenses/MIT",
104
- :logo => "http://upload.wikimedia.org/wikipedia/commons/thumb/0/0b/License_icon-mit-2.svg/200px-License_icon-mit-2.svg.png"
105
- },
106
- },
107
- :puppet => {},
108
- :forge => {
109
- :none => { :url => '', :name => "None"},
110
- :gforge => { :url => 'gforge.uni.lu', :name => 'GForge @ Uni.lu' },
111
- :github => { :url => 'github.com', :name => 'Github', :login => "#{`whoami`.chomp.capitalize}" },
112
- :gitlab => { :url => 'gitlab.uni.lu', :name => 'Gitlab @ Uni.lu', :login => "#{`whoami`.chomp.capitalize}" },
113
- },
114
- }
115
- end
116
120
  end
121
+ end
117
122
  end
118
123
 
119
124
 
120
125
 
121
126
  module FalkorLib
122
- module Bootstrap
123
- module_function
124
-
125
- ###
126
- # Initialize a trash directory in path
127
- ##
128
- def trash(path = Dir.pwd, dirname = FalkorLib.config[:templates][:trashdir], options = {})
129
- #args = method(__method__).parameters.map { |arg| arg[1].to_s }.map { |arg| { arg.to_sym => eval(arg) } }.reduce Hash.new, :merge
130
- #ap args
131
- exit_status = 0
132
- trashdir = File.join(path, dirname)
133
- if Dir.exists?(trashdir)
134
- warning "The trash directory '#{dirname}' already exists"
135
- return 1
136
- end
137
- Dir.chdir(path) do
138
- info "creating the trash directory '#{dirname}'"
139
- exit_status = run %{
127
+ module Bootstrap #:nodoc:
128
+
129
+ module_function
130
+
131
+ ###
132
+ # Initialize a trash directory in path
133
+ ##
134
+ def trash(path = Dir.pwd, dirname = FalkorLib.config[:templates][:trashdir], _options = {})
135
+ #args = method(__method__).parameters.map { |arg| arg[1].to_s }.map { |arg| { arg.to_sym => eval(arg) } }.reduce Hash.new, :merge
136
+ #ap args
137
+ exit_status = 0
138
+ trashdir = File.join(File.realpath(path), dirname)
139
+ if Dir.exist?(trashdir)
140
+ warning "The trash directory '#{dirname}' already exists"
141
+ return 1
142
+ end
143
+ Dir.chdir(path) do
144
+ info "creating the trash directory '#{dirname}'"
145
+ exit_status = run %(
140
146
  mkdir -p #{dirname}
141
147
  echo '*' > #{dirname}/.gitignore
142
- }
143
- if FalkorLib::Git.init?(path)
144
- exit_status = FalkorLib::Git.add(File.join(path, dirname, '.gitignore' ),
145
- 'Add Trash directory',
146
- { :force => true } )
147
- end
148
- end
149
- exit_status.to_i
150
- end # trash
151
-
152
- ###### rvm ######
153
- # Initialize RVM in the current directory
154
- # Supported options:
155
- # * :force [boolean] force overwritting
156
- # * :ruby [string] Ruby version to configure for RVM
157
- # * :versionfile [string] Ruby Version file
158
- # * :gemset [string] RVM Gemset to configure
159
- # * :gemsetfile [string] RVM Gemset file
160
- # * :commit [boolean] Commit the changes NOT YET USED
161
- ##
162
- def rvm(dir = Dir.pwd, options = {})
163
- info "Initialize Ruby Version Manager (RVM)"
164
- ap options if options[:debug]
165
- path = normalized_path(dir)
166
- use_git = FalkorLib::Git.init?(path)
167
- rootdir = use_git ? FalkorLib::Git.rootdir(path) : path
168
- files = {}
169
- exit_status = 1
170
- [:versionfile, :gemsetfile].each do |type|
171
- f = options[type.to_sym].nil? ? FalkorLib.config[:rvm][type.to_sym] : options[type.to_sym]
172
- if File.exists?( File.join( rootdir, f ))
173
- content = `cat #{File.join( rootdir, f)}`.chomp
174
- warning "The RVM file '#{f}' already exists (and contains '#{content}')"
175
- next unless options[:force]
176
- warning "... and it WILL BE overwritten"
177
- end
178
- files[type.to_sym] = f
179
- end
180
- # ==== Ruby version ===
181
- unless files[:versionfile].nil?
182
- file = File.join(rootdir, files[:versionfile])
183
- v =
184
- options[:ruby] ?
185
- options[:ruby] :
186
- select_from(FalkorLib.config[:rvm][:rubies],
187
- "Select RVM ruby to configure for this directory",
188
- 1)
189
- info " ==> configuring RVM version file '#{files[:versionfile]}' for ruby version '#{v}'"
190
- File.open(file, 'w') do |f|
191
- f.puts v
192
- end
193
- exit_status = (File.exists?(file) and `cat #{file}`.chomp == v) ? 0 : 1
194
- FalkorLib::Git.add(File.join(rootdir, files[:versionfile])) if use_git
195
- end
196
- # === Gemset ===
197
- if files[:gemsetfile]
198
- file = File.join(rootdir, files[:gemsetfile])
199
- default_gemset = File.basename(rootdir)
200
- default_gemset = `cat #{file}`.chomp if File.exists?( file )
201
- g = options[:gemset] ? options[:gemset] : ask("Enter RVM gemset name for this directory", default_gemset)
202
- info " ==> configuring RVM gemset file '#{files[:gemsetfile]}' with content '#{g}'"
203
- File.open( File.join(rootdir, files[:gemsetfile]), 'w') do |f|
204
- f.puts g
205
- end
206
- exit_status = (File.exists?(file) and `cat #{file}`.chomp == g) ? 0 : 1
207
- FalkorLib::Git.add(File.join(rootdir, files[:gemsetfile])) if use_git
208
- end
209
- # ==== Gemfile ===
210
- gemfile = File.join(rootdir, 'Gemfile')
211
- unless File.exists?( gemfile )
212
- # Dir.chdir(rootdir) do
213
- # run %{ bundle init }
214
- # end
215
- info " ==> configuring Gemfile with Falkorlib"
216
- File.open( gemfile, 'a') do |f|
217
- f.puts "source 'https://rubygems.org'"
218
- f.puts ""
219
- f.puts "gem 'falkorlib' #, :path => '~/git/github.com/Falkor/falkorlib'"
220
- end
221
- FalkorLib::Git.add(gemfile) if use_git
222
- end
223
- exit_status
224
- end # rvm
225
-
226
- ###### repo ######
227
- # Initialize a Git repository for a project with my favorite layout
228
- # Supported options:
229
- # * :no_interaction [boolean]: do not interact
230
- # * :gitflow [boolean]: bootstrap with git-flow
231
- # * :interactive [boolean] Confirm Gitflow branch names
232
- # * :master [string] Branch name for production releases
233
- # * :develop [string] Branch name for development commits
234
- # * :make [boolean] Use a Makefile to pilot the repository actions
235
- # * :rake [boolean] Use a Rakefile (and FalkorLib) to pilot the repository action
236
- # * :remote_sync [boolean] Operate a git remote synchronization
237
- # * :latex [boolean] Initiate a LaTeX project
238
- # * :gem [boolean] Initiate a Ruby gem project
239
- # * :rvm [boolean] Initiate a RVM-based Ruby project
240
- # * :pyenv [boolean] Initiate a pyenv-based Python project
241
- # * :octopress [boolean] Initiate an Octopress web site
242
- ##
243
- def repo(name, options = {})
244
- ap options if options[:debug]
245
- path = normalized_path(name)
246
- project = File.basename(path)
247
- use_git = FalkorLib::Git.init?(path)
248
- if options[:rake]
249
- options[:make] = false
250
- options[:rvm] = true
251
- end
252
- info "Bootstrap a [Git] repository for the project '#{project}'"
253
- if use_git
254
- warning "Git is already initialized for the repository '#{name}'"
255
- really_continue? unless options[:force]
256
- end
257
- if options[:git_flow]
258
- info " ==> initialize Git flow in #{path}"
259
- FalkorLib::GitFlow.init(path, options)
260
- gitflow_branches = {}
261
- [ :master, :develop ].each do |t|
262
- gitflow_branches[t.to_sym] = FalkorLib::GitFlow.branches(t, path)
263
- end
264
- else
265
- FalkorLib::Git.init(path, options)
266
- end
267
- # === prepare Git submodules ===
268
- info " ==> prepare the relevant Git submodules"
269
- submodules = {}
270
- #'gitstats' => { :url => 'https://github.com/hoxu/gitstats.git' }
271
- # }
272
- if options[:make]
273
- submodules['Makefiles'] = {
274
- :url => 'https://github.com/Falkor/Makefiles.git',
275
- :branch => 'devel'
276
- }
277
- end
278
- FalkorLib::Git.submodule_init(path, submodules)
279
- # === Prepare root [M|R]akefile ===
280
- if options[:make]
281
- info " ==> prepare Root Makefile"
282
- makefile = File.join(path, "Makefile")
283
- unless File.exist?( makefile )
284
- src_makefile = File.join(path, FalkorLib.config.git[:submodulesdir],
285
- 'Makefiles', 'repo', 'Makefile')
286
- FileUtils.cp src_makefile, makefile
287
- info "adapting Makefile to the gitflow branches"
288
- Dir.chdir( path ) do
289
- run %{
290
- sed -i '' \
291
- -e \"s/^GITFLOW_BR_MASTER=production/GITFLOW_BR_MASTER=#{gitflow_branches[:master]}/\" \
292
- -e \"s/^GITFLOW_BR_DEVELOP=devel/GITFLOW_BR_DEVELOP=#{gitflow_branches[:develop]}/\" \
293
- Makefile
294
- }
295
- end
296
- FalkorLib::Git.add(makefile, 'Initialize root Makefile for the repo')
297
- else
298
- puts " ... not overwriting the root Makefile which already exists"
299
- end
300
- end
301
- if options[:rake]
302
- info " ==> prepare Root Rakefile"
303
- rakefile = File.join(path, "Rakefile")
304
- unless File.exist?( rakefile )
305
- templatedir = File.join( FalkorLib.templates, 'Rakefile')
306
- erbfiles = [ 'header_rakefile.erb' ]
307
- erbfiles << 'rakefile_gitflow.erb' if FalkorLib::GitFlow.init?(path)
308
- erbfiles << 'footer_rakefile.erb'
309
- write_from_erb_template(erbfiles, rakefile, {}, { :srcdir => "#{templatedir}" })
310
- end
311
- end
312
-
313
- # === VERSION file ===
314
- FalkorLib::Bootstrap.versionfile(path, :tag => 'v0.0.0')
315
-
316
- # === RVM ====
317
- FalkorLib::Bootstrap.rvm(path, options) if options[:rvm]
318
-
319
- # === README ===
320
- FalkorLib::Bootstrap.readme(path, options)
321
-
322
- #===== remote synchro ========
323
- if options[:remote_sync]
324
- remotes = FalkorLib::Git.remotes(path)
325
- if remotes.include?( 'origin' )
326
- info "perform remote synchronization"
327
- [ :master, :develop ].each do |t|
328
- FalkorLib::Git.publish(gitflow_branches[t.to_sym], path, 'origin')
329
- end
330
- else
331
- warning "no Git remote 'origin' found, thus no remote synchronization performed"
332
- end
333
- end
334
-
335
- end # repo
336
-
337
- ###### versionfile ######
338
- # Bootstrap a VERSION file at the root of a project
339
- # Supported options:
340
- # * :file [string] filename
341
- # * :version [string] version to mention in the file
342
- ##
343
- def versionfile(dir = Dir.pwd, options = {})
344
- file = options[:file] ? options[:file] : 'VERSION'
345
- version = options[:version] ? options[:version] : '0.0.0'
346
- info " ==> bootstrapping a VERSION file"
347
- path = normalized_path(dir)
348
- path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path)
349
- unless Dir.exists?( path )
350
- warning "The directory #{path} does not exists and will be created"
351
- really_continue?
352
- FileUtils.mkdir_p path
353
- end
354
- versionfile = File.join(path, file)
355
- unless File.exists?( versionfile )
356
- FalkorLib::Versioning.set_version(version, path, {
357
- :type => 'file',
358
- :source => { :filename => file }
359
- })
360
- Dir.chdir( path ) do
361
- run %{ git tag #{options[:tag]} } if options[:tag]
362
- end
363
- else
364
- puts " ... not overwriting the #{file} file which already exists"
365
- end
366
-
367
- # unless File.exists?( versionfile )
368
- # run %{ echo "#{version}" > #{versionfile} }
369
- # if FalkorLib::Git.init?(path)
370
- # FalkorLib::Git.add(versionfile, "Initialize #{file} file")
371
- # Dir.chdir( path ) do
372
- # run %{ git tag #{options[:tag]} } if options[:tag]
373
- # end
374
- # end
375
- # else
376
- # puts " ... not overwriting the #{file} file which already exists"
377
- # end
378
- end # versionfile
379
-
380
-
381
- ###### motd ######
382
- # Generate a new motd (Message of the Day) file
383
- # Supported options:
384
- # * :force [boolean] force action
385
- ##
386
- def motd(dir = Dir.pwd, options = {})
387
- config = FalkorLib::Config::Bootstrap::DEFAULTS[:motd].merge!(options)
388
- path = normalized_path(dir)
389
- erbfile = File.join( FalkorLib.templates, 'motd', 'motd.erb')
390
- outfile = (options[:file] =~ /^\//) ? options[:file] : File.join(path, options[:file])
391
- info "Generate a motd (Message of the Day) file '#{outfile}'"
392
- config[:os] = Facter.value(:lsbdistdescription) if Facter.value(:lsbdistdescription)
393
- config[:os] = "Mac " + Facter.value(:sp_os_version) if Facter.value(:sp_os_version)
394
- write_from_erb_template(erbfile, outfile, config, options)
395
- end # motd
396
-
397
-
398
-
399
- ###### readme ######
400
- # Bootstrap a README file for various context
401
- # Supported options:
402
- # * :no_interaction [boolean]: do not interact
403
- # * :force [boolean] force overwritting
404
- # * :latex [boolean] describe a LaTeX project
405
- # * :octopress [boolean] octopress site
406
- ##
407
- def readme(dir = Dir.pwd, options = {})
408
- info "Bootstrap a README file for this project"
409
- # get the local configuration
410
- local_config = FalkorLib::Config.get(dir)
411
- config = FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].clone
412
- name = get_project_name(dir)
413
- if local_config[:project]
414
- config.deep_merge!( local_config[:project])
415
- else
416
- config[:name] = ask("\tProject name: ", name) unless options[:name]
417
- end
418
- if options[:rake]
419
- options[:make] = false
420
- options[:rvm] = true
421
- end
422
- config[:type] << :rvm if options[:rake]
423
- # Type of project
424
- config[:type] << :latex if options[:latex]
425
- if config[:type].empty?
426
- t = select_from( FalkorLib::Config::Bootstrap::DEFAULTS[:types],
427
- 'Select the type of project to describe:', 1)
428
- config[:type] << t
429
- config[:type] << [ :ruby, :rvm ] if [ :gem, :rvm, :octopress, :puppet_module ].include?( t )
430
- config[:type] << :python if t == :pyenv
431
- end
432
- config[:type].uniq!
433
- ap config
434
- config[:type] = config[:type].uniq.flatten
435
- # Apply options (if provided)
436
- [ :name, :forge ].each do |k|
437
- config[k.to_sym] = options[k.to_sym] if options[k.to_sym]
438
- end
439
- path = normalized_path(dir)
440
- config[:filename] = options[:filename] ? options[:filename] : File.join(path, 'README.md')
441
- if ( FalkorLib::Git.init?(dir) && FalkorLib::Git.remotes(dir).include?( 'origin' ))
442
- config[:origin] = FalkorLib::Git.config('remote.origin.url')
443
- if config[:origin] =~ /((gforge|gitlab|github)[\.\w_-]+)[:\d\/]+(\w*)/
444
- config[:forge] = $2.to_sym
445
- config[:by] = $3
446
- end
447
- else
448
- config[:forge] = select_forge(config[:forge]).to_sym if config[:forge].empty?
449
- end
450
- forges = FalkorLib::Config::Bootstrap::DEFAULTS[:forge][ config[:forge].to_sym ]
451
- #ap config
452
- default_source = case config[:forge]
453
- when :gforge
454
- 'https://' + forges[:url] + "/projects/" + name.downcase
455
- when :github, :gitlab
456
- 'https://' + forges[:url] + "/" + config[:by] + "/" + name.downcase
457
- else
458
- ""
459
- end
460
- FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].each do |k,v|
461
- next if v.kind_of?(Array) or [ :license, :forge ].include?( k )
462
- next if k == :name and ! config[:name].empty?
463
- next if k == :issues_url and ! [ :github, :gitlab ].include?( config[:forge] )
464
- #next unless [ :name, :summary, :description ].include?(k.to_sym)
465
- default_answer = case k
466
- when :author
467
- (config[:by] == 'ULHPC') ? 'UL HPC Management Team' : config[:author]
468
- when :mail
469
- (config[:by] == 'ULHPC') ? 'hpc-sysadmins@uni.lu' : config[:mail]
470
- when :description
471
- config[:description].empty? ? "#{config[:summary]}" : "#{config[:description]}"
472
- when :source
473
- config[:source].empty? ? default_source : "#{config[:source]}"
474
- when :project_page
475
- config[:source].empty? ? v : config[:source]
476
- when :issues_url
477
- config[:project_page].empty? ? v : "#{config[:project_page]}/issues"
478
- else
479
- config[k.to_sym].empty? ? v : config[k.to_sym]
480
- end
481
- config[k.to_sym] = ask( "\t" + sprintf("Project %-20s", "#{k}"), default_answer)
482
- end
483
- tags = ask("\tKeywords (comma-separated list of tags)", config[:tags].join(','))
484
- config[:tags] = tags.split(',')
485
- config[:license] = select_licence() if config[:license].empty?
486
- # stack the ERB files required to generate the README
487
- templatedir = File.join( FalkorLib.templates, 'README')
488
- erbfiles = [ 'header_readme.erb', ]
489
- [ :latex ].each do |type|
490
- erbfiles << "readme_#{type}.erb" if options[type.to_sym] and File.exist?( File.join(templatedir, "readme_#{type}.erb"))
491
- end
492
- erbfiles << "readme_issues.erb"
493
- erbfiles << "readme_git.erb" if FalkorLib::Git.init?(dir)
494
- erbfiles << "readme_gitflow.erb" if FalkorLib::GitFlow.init?(dir)
495
- erbfiles << "readme_rvm.erb" if config[:type].include?(:rvm)
496
- erbfiles << "footer_readme.erb"
497
-
498
- content = ""
499
- erbfiles.each do |f|
500
- erbfile = File.join(templatedir, f)
501
- content += ERB.new(File.read("#{erbfile}"), nil, '<>').result(binding)
502
- end
503
- show_diff_and_write(content, config[:filename], options)
504
-
505
- # Eventually save/upgrade local config
506
- info "=> saving customization of the FalkorLib configuration in #{FalkorLib.config[:config_files][:local]}"
507
- really_continue?
508
- FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].keys.each do |k|
509
- local_config[:project] = {} unless local_config[:project]
510
- local_config[:project][k.to_sym] = config[k.to_sym]
511
- end
512
- if FalkorLib::GitFlow.init?(dir)
513
- local_config[:gitflow] = {} unless local_config[:gitflow]
514
- local_config[:gitflow][:branches] = FalkorLib.config[:gitflow][:branches].clone unless local_config[:gitflow][:branches]
515
- [ :master, :develop ].each do |b|
516
- local_config[:gitflow][:branches][b.to_sym] = FalkorLib::GitFlow.branches(b.to_sym)
517
- end
518
- end
519
- FalkorLib::Config.save(dir, local_config, :local)
520
- #
521
- end # readme
522
-
523
-
524
-
525
- ###### latex ######
526
- # Bootstrap a LaTeX sub-project of type <type> within a given repository <dir>.
527
- # Supported types:
528
- # * :beamer LaTeX Beamer Slides
529
- # * :article LaTeX article
530
- # * :letter LaTeX Letter
531
- # Supported options:
532
- # * :force [boolean] force action
533
- ##
534
- def latex(dir = Dir.pwd, type = :beamer, options = {})
535
- ap options if options[:debug]
536
- print_error_and_exit "Unsupported type" unless [ :beamer, :article, :letter ].include?( type )
537
- path = normalized_path(dir)
538
- config = FalkorLib::Config::Bootstrap::DEFAULTS[:latex].clone
539
- if type == :letter
540
- config.merge!(FalkorLib::Config::Bootstrap::DEFAULTS[:letter].clone)
541
- [ :title, :subtitle, :image ].each { |k| config.delete k }
542
- end
543
- config.deep_merge!(FalkorLib::Config::Bootstrap::DEFAULTS[:letter].clone) if type == :letter
544
- # initiate the repository if needed
545
- unless File.directory?( path )
546
- warn "The directory '#{path}' does not exists and will be created"
547
- really_continue? unless options[:force]
548
- run %{ mkdir -p #{path} }
549
- end
550
- repo(path, options) unless FalkorLib::Git.init?(path)
551
- rootdir = FalkorLib::Git.rootdir(path)
552
- info "Initiate a LaTeX #{type} project from the Git root directory: '#{rootdir}'"
553
- really_continue? unless options[:force]
554
- relative_path_to_root = (Pathname.new( FalkorLib::Git.rootdir(dir) ).relative_path_from Pathname.new( File.realpath(path))).to_s
555
- config[:name] = options[:name] ? options[:name] : ask("\tEnter the name of the #{type} LaTeX project: ", File.basename(path))
556
- raise FalkorLib::ExecError "Empty project name" if config[:name].empty?
557
- default_project_dir = (Pathname.new( File.realpath(path) ).relative_path_from Pathname.new( FalkorLib::Git.rootdir(dir))).to_s
558
- if relative_path_to_root == '.'
559
- default_project_dir = case type
560
- when :article
561
- "articles/#{Time.now.year}/#{config[:name]}"
562
- when :beamer
563
- "slides/#{Time.now.year}/#{config[:name]}"
564
- when :bookchapter
565
- "chapters/#{config[:name]}"
566
- when :letter
567
- "letters/#{Time.now.year}/#{config[:name]}"
568
- else
569
- "#{config[:name]}"
570
- end
571
- else
572
- default_project_dir += "/#{config[:name]}" unless default_project_dir =~ /#{config[:name]}$/
573
- end
574
- project_dir = options[:dir] ? options[:dir] : ask("\tLaTeX Sources directory (relative to the Git root directory)", "#{default_project_dir}")
575
- raise FalkorLib::ExecError "Empty project directory" if project_dir.empty?
576
- src_project_dir = File.join(project_dir, 'src')
577
- srcdir = File.join(rootdir, src_project_dir)
578
- if File.exists?(File.join(srcdir, '.root'))
579
- warn "The directory '#{project_dir}' seems to have been already initialized"
580
- really_continue? unless options[:force]
581
- end
582
- FalkorLib::GitFlow.start('feature', config[:name], rootdir) if FalkorLib::GitFlow.init?(rootdir)
583
- # === prepare Git submodules ===
584
- info " ==> prepare the relevant Git submodules"
585
- submodules = {}
586
- submodules['Makefiles'] = { :url => 'https://github.com/Falkor/Makefiles.git',
587
- :branch => 'devel'
588
- } if [ :article, :beamer, :bookchapter].include?(type)
589
- submodules['beamerthemeFalkor'] = { :url => 'https://github.com/Falkor/beamerthemeFalkor' } if type == :beamer
590
- FalkorLib::Git.submodule_init(rootdir, submodules)
591
- info "bootstrapping the #{type} project sources in '#{src_project_dir}'"
592
- # Create the project directory
593
- Dir.chdir( rootdir ) do
594
- run %{ mkdir -p #{src_project_dir}/images } unless File.directory?("#{srcdir}/images")
595
- end
596
- info "populating '#{src_project_dir}'"
597
- #FalkorLib::Bootstrap::Link.root(srcdir, { :verbose => true} )
598
- FalkorLib::Bootstrap::Link.makefile(srcdir, { :no_interaction => true })
599
- [ '_style.sty', '.gitignore' ].each do |f|
600
- Dir.chdir( srcdir ) do
601
- dst = ".makefile.d/latex/#{f}"
602
- run %{ ln -s #{dst} #{f} } unless File.exist?( File.join(srcdir, f) )
603
- end
604
- end
605
- if type == :beamer
606
- f = 'beamerthemeFalkor.sty'
607
- dst = "#{FalkorLib.config[:git][:submodulesdir]}/beamerthemeFalkor/#{f}"
608
- Dir.chdir( srcdir ) do
609
- run %{ ln -s .root/#{dst} #{f} } unless File.exist?( File.join(srcdir, f) )
610
- end
611
- end
612
-
613
- # Bootstrap the directory
614
- templatedir = File.join( FalkorLib.templates, 'latex', "#{type}")
615
- unless File.exists?( File.join(srcdir, "#{config[:name]}.tex"))
616
- info "gathering information for the LaTeX templates"
617
- prefix = case type
618
- when :article
619
- 'Article '
620
- when :beamer
621
- 'Slides '
622
- when :bookchapter
623
- 'Book Chapter '
624
- when :letter
625
- 'Letter '
148
+ )
149
+ if FalkorLib::Git.init?(path)
150
+ exit_status = FalkorLib::Git.add(File.join(trashdir.to_s, '.gitignore' ),
151
+ 'Add Trash directory',
152
+ :force => true )
153
+ end
154
+ end
155
+ exit_status.to_i
156
+ end # trash
157
+
158
+ ###### versionfile ######
159
+ # Bootstrap a VERSION file at the root of a project
160
+ # Supported options:
161
+ # * :file [string] filename
162
+ # * :version [string] version to mention in the file
163
+ ##
164
+ def versionfile(dir = Dir.pwd, options = {})
165
+ file = (options[:file]) ? options[:file] : 'VERSION'
166
+ version = (options[:version]) ? options[:version] : '0.0.0'
167
+ info " ==> bootstrapping a VERSION file"
168
+ path = normalized_path(dir)
169
+ path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path)
170
+ unless Dir.exist?( path )
171
+ warning "The directory #{path} does not exists and will be created"
172
+ really_continue?
173
+ FileUtils.mkdir_p path
174
+ end
175
+ versionfile = File.join(path, file)
176
+ if File.exist?( versionfile )
177
+ puts " ... not overwriting the #{file} file which already exists"
178
+ else
179
+ FalkorLib::Versioning.set_version(version, path, :type => 'file',
180
+ :source => { :filename => file })
181
+ Dir.chdir( path ) do
182
+ run %( git tag #{options[:tag]} ) if options[:tag]
183
+ end
184
+ end
185
+
186
+ # unless File.exists?( versionfile )
187
+ # run %{ echo "#{version}" > #{versionfile} }
188
+ # if FalkorLib::Git.init?(path)
189
+ # FalkorLib::Git.add(versionfile, "Initialize #{file} file")
190
+ # Dir.chdir( path ) do
191
+ # run %{ git tag #{options[:tag]} } if options[:tag]
192
+ # end
193
+ # end
194
+ # else
195
+ # puts " ... not overwriting the #{file} file which already exists"
196
+ # end
197
+ end # versionfile
198
+
199
+
200
+ ###### motd ######
201
+ # Generate a new motd (Message of the Day) file
202
+ # Supported options:
203
+ # * :force [boolean] force action
204
+ # * :title [string] title of the motd (in figlet)
205
+ # * :support [string] email address to use for getting support
206
+ # * :hostname [string] hostname of the server to mention in the motd
207
+ # * :width [number] width of the line used
208
+ ##
209
+ def motd(dir = Dir.pwd, options = {})
210
+ config = FalkorLib::Config::Bootstrap::DEFAULTS[:motd].merge!(::ActiveSupport::HashWithIndifferentAccess.new(options).symbolize_keys)
211
+ path = normalized_path(dir)
212
+ erbfile = File.join( FalkorLib.templates, 'motd', 'motd.erb')
213
+ outfile = (config[:file] =~ /^\//) ? config[:file] : File.join(path, config[:file])
214
+ info "Generate a motd (Message of the Day) file '#{outfile}'"
215
+ FalkorLib::Config::Bootstrap::DEFAULTS[:motd].keys.each do |k|
216
+ next if [:file, :width].include?(k)
217
+ config[k.to_sym] = ask( "\t" + format("Message of the Day (MotD) %-10s", k.to_s), config[k.to_sym]) unless options[:no_interaction]
218
+ end
219
+ config[:os] = Facter.value(:lsbdistdescription) if Facter.value(:lsbdistdescription)
220
+ config[:os] = "Mac " + Facter.value(:sp_os_version) if Facter.value(:sp_os_version)
221
+ unless options[:nodemodel]
222
+ config[:nodemodel] = Facter.value(:sp_machine_name) if Facter.value(:sp_machine_name)
223
+ config[:nodemodel] += " (#{Facter.value(:sp_cpu_type)}" if Facter.value(:sp_cpu_type)
224
+ config[:nodemodel] += " " + Facter.value(:sp_current_processor_speed) if Facter.value(:sp_current_processor_speed)
225
+ config[:nodemodel] += " #{Facter.value(:sp_number_processors)} cores )" if Facter.value(:sp_number_processors)
226
+ end
227
+ config[:nodemodel] = Facter.value(:sp_machine_name) unless options[:nodemodel]
228
+ write_from_erb_template(erbfile, outfile, config, options)
229
+ end # motd
230
+
231
+
232
+
233
+ ###### readme ######
234
+ # Bootstrap a README file for various context
235
+ # Supported options:
236
+ # * :no_interaction [boolean]: do not interact
237
+ # * :force [boolean] force overwritting
238
+ # * :latex [boolean] describe a LaTeX project
239
+ # * :octopress [boolean] octopress site
240
+ ##
241
+ def readme(dir = Dir.pwd, options = {})
242
+ info "Bootstrap a README file for this project"
243
+ # get the local configuration
244
+ local_config = FalkorLib::Config.get(dir)
245
+ config = FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].clone
246
+ name = get_project_name(dir)
247
+ if local_config[:project]
248
+ config.deep_merge!( local_config[:project])
249
+ else
250
+ config[:name] = ask("\tProject name: ", name) unless options[:name]
251
+ end
252
+ if options[:rake]
253
+ options[:make] = false
254
+ options[:rvm] = true
255
+ end
256
+ config[:type] << :rvm if options[:rake]
257
+ # Type of project
258
+ config[:type] << :latex if options[:latex]
259
+ if config[:type].empty?
260
+ t = select_from( FalkorLib::Config::Bootstrap::DEFAULTS[:types],
261
+ 'Select the type of project to describe:', 1)
262
+ config[:type] << t
263
+ config[:type] << [ :ruby, :rvm ] if [ :gem, :rvm, :octopress, :puppet_module ].include?( t )
264
+ config[:type] << :python if t == :pyenv
265
+ end
266
+ config[:type].uniq!
267
+ ap config
268
+ config[:type] = config[:type].uniq.flatten
269
+ # Apply options (if provided)
270
+ [ :name, :forge ].each do |k|
271
+ config[k.to_sym] = options[k.to_sym] if options[k.to_sym]
272
+ end
273
+ path = normalized_path(dir)
274
+ config[:filename] = (options[:filename]) ? options[:filename] : File.join(path, 'README.md')
275
+ if ( FalkorLib::Git.init?(dir) && FalkorLib::Git.remotes(dir).include?( 'origin' ))
276
+ config[:origin] = FalkorLib::Git.config('remote.origin.url')
277
+ if config[:origin] =~ /((gforge|gitlab|github)[\.\w_-]+)[:\d\/]+(\w*)/
278
+ config[:forge] = Regexp.last_match(2).to_sym
279
+ config[:by] = Regexp.last_match(3)
280
+ end
281
+ elsif config[:forge].empty?
282
+ config[:forge] = select_forge(config[:forge]).to_sym
283
+ end
284
+ forges = FalkorLib::Config::Bootstrap::DEFAULTS[:forge][ config[:forge].to_sym ]
285
+ #ap config
286
+ default_source = case config[:forge]
287
+ when :gforge
288
+ 'https://' + forges[:url] + "/projects/" + name.downcase
289
+ when :github, :gitlab
290
+ 'https://' + forges[:url] + "/" + config[:by] + "/" + name.downcase
291
+ else
292
+ ""
293
+ end
294
+ FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].each do |k, v|
295
+ next if v.is_a?(Array) || [ :license, :forge ].include?( k )
296
+ next if (k == :name) && !config[:name].empty?
297
+ next if (k == :issues_url) && ![ :github, :gitlab ].include?( config[:forge] )
298
+ #next unless [ :name, :summary, :description ].include?(k.to_sym)
299
+ default_answer = case k
300
+ when :author
301
+ (config[:by] == 'ULHPC') ? 'UL HPC Management Team' : config[:author]
302
+ when :mail
303
+ (config[:by] == 'ULHPC') ? 'hpc-sysadmins@uni.lu' : config[:mail]
304
+ when :description
305
+ (config[:description].empty?) ? (config[:summary]).to_s : (config[:description]).to_s
306
+ when :source
307
+ (config[:source].empty?) ? default_source : (config[:source]).to_s
308
+ when :project_page
309
+ (config[:source].empty?) ? v : config[:source]
310
+ when :issues_url
311
+ (config[:project_page].empty?) ? v : "#{config[:project_page]}/issues"
626
312
  else
627
- ''
313
+ (config[k.to_sym].empty?) ? v : config[k.to_sym]
628
314
  end
629
- config.each do |k,v|
630
- next if k == :name
631
- config[k.to_sym] = ask( "\t" + sprintf("%-20s", "#{prefix}#{k.capitalize}"), v)
632
- end
633
- init_from_template(templatedir, srcdir, config, {:no_interaction => true,
634
- :no_commit => true })
635
- # Rename the main file
636
- Dir.chdir( srcdir ) do
637
- run %{ mv main.tex #{config[:name]}.tex }
638
- end
639
- end
640
- # Create the trash directory
641
- trash(srcdir)
642
-
643
- # populate the images/ directory
644
- baseimages = File.join( FalkorLib.templates, 'latex', 'images')
645
- #images_makefile_src = "#{FalkorLib.config[:git][:submodulesdir]}/Makefiles/generic/Makefile.insrcdir"
646
- images = File.join(srcdir, 'images')
647
- info "populating the image directory"
648
- Dir.chdir( images ) do
649
- run %{ rsync -avzu #{baseimages}/ . }
650
- run %{ ln -s ../.root .root } unless File.exists?(File.join(images, '.root'))
651
- #run %{ ln -s .root/#{images_makefile_src} Makefile } unless File.exists?(File.join(images, 'Makefile'))
652
- end
653
- FalkorLib::Bootstrap::Link.makefile(images, { :images => true, :no_interaction => true } )
654
-
655
- # Prepare the src/ directory
656
- FalkorLib::Bootstrap::Link.makefile(File.join(rootdir, project_dir), { :src => true, :no_interaction => true } )
657
-
658
-
659
- # default_project_dir = case type
660
- # when :beamer
661
- # "slides/#{Time.new.yea}"
662
- # end
663
- end # project
664
-
665
-
666
- ###
667
- # Select the forge (gforge, github, etc.) hosting the project sources
668
- ##
669
- def select_forge(default = :gforge, options = {})
670
- forge = FalkorLib::Config::Bootstrap::DEFAULTS[:forge]
671
- #ap forge
672
- default_idx = forge.keys.index(default)
673
- default_idx = 0 if default_idx.nil?
674
- v = select_from(forge.map{ |k,v| v[:name] },
675
- "Select the Forge hosting the project sources",
676
- default_idx+1,
677
- forge.keys)
678
- v
679
- end # select_forge
680
-
681
- ###### select_licence ######
682
- # Select a given licence for the project
683
- ##
684
- def select_licence(default_licence = FalkorLib::Config::Bootstrap::DEFAULTS[:metadata][:license],
685
- options = {})
686
- list_license = FalkorLib::Config::Bootstrap::DEFAULTS[:licenses].keys
687
- idx = list_license.index(default_licence) unless default_licence.nil?
688
- select_from(list_license,
689
- 'Select the license index for this project:',
690
- idx.nil? ? 1 : idx + 1)
691
- #licence
692
- end # select_licence
693
-
694
- ###### get_badge ######
695
- # Return a Markdown-formatted string for a badge to display, typically in a README.
696
- # Based on http://shields.io/
697
- # Supported options:
698
- # * :style [string] style of the badge, Elligible: ['plastic', 'flat', 'flat-square']
699
- ##
700
- def get_badge(subject, status, color = 'blue', options = {})
701
- st = status.gsub(/-/, '--').gsub(/_/, '__')
702
- res = "https://img.shields.io/badge/#{subject}-#{st}-#{color}.svg"
703
- res += "?style=#{options[:style]}" if options[:style]
704
- res
705
- end # get_licence_badge
706
-
707
- ###### get_project_name ######
708
- # Return a "reasonable" project name from a given [sub] directory i.e. its basename
709
- ##
710
- def get_project_name(dir = Dir.pwd, options = {})
711
- path = normalized_path(dir)
712
- path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path)
713
- File.basename(path)
714
- end # get_project_name
715
-
716
-
717
- end # module Bootstrap
315
+ config[k.to_sym] = ask( "\t" + Kernel.format("Project %-20s", k.to_s), default_answer)
316
+ end
317
+ tags = ask("\tKeywords (comma-separated list of tags)", config[:tags].join(','))
318
+ config[:tags] = tags.split(',')
319
+ config[:license] = select_licence if config[:license].empty?
320
+ # stack the ERB files required to generate the README
321
+ templatedir = File.join( FalkorLib.templates, 'README')
322
+ erbfiles = [ 'header_readme.erb' ]
323
+ [ :latex ].each do |type|
324
+ erbfiles << "readme_#{type}.erb" if options[type.to_sym] && File.exist?( File.join(templatedir, "readme_#{type}.erb"))
325
+ end
326
+ erbfiles << "readme_issues.erb"
327
+ erbfiles << "readme_git.erb" if FalkorLib::Git.init?(dir)
328
+ erbfiles << "readme_gitflow.erb" if FalkorLib::GitFlow.init?(dir)
329
+ erbfiles << "readme_rvm.erb" if config[:type].include?(:rvm)
330
+ erbfiles << "footer_readme.erb"
331
+
332
+ content = ""
333
+ erbfiles.each do |f|
334
+ erbfile = File.join(templatedir, f)
335
+ content += ERB.new(File.read(erbfile.to_s), nil, '<>').result(binding)
336
+ end
337
+ show_diff_and_write(content, config[:filename], options)
338
+
339
+ # Eventually save/upgrade local config
340
+ info "=> saving customization of the FalkorLib configuration in #{FalkorLib.config[:config_files][:local]}"
341
+ really_continue?
342
+ FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].keys.each do |k|
343
+ local_config[:project] = {} unless local_config[:project]
344
+ local_config[:project][k.to_sym] = config[k.to_sym]
345
+ end
346
+ if FalkorLib::GitFlow.init?(dir)
347
+ local_config[:gitflow] = {} unless local_config[:gitflow]
348
+ local_config[:gitflow][:branches] = FalkorLib.config[:gitflow][:branches].clone unless local_config[:gitflow][:branches]
349
+ [ :master, :develop ].each do |b|
350
+ local_config[:gitflow][:branches][b.to_sym] = FalkorLib::GitFlow.branches(b.to_sym)
351
+ end
352
+ end
353
+ FalkorLib::Config.save(dir, local_config, :local)
354
+ #
355
+ end # readme
356
+
357
+
358
+ ###
359
+ # Select the forge (gforge, github, etc.) hosting the project sources
360
+ ##
361
+ def select_forge(default = :gforge, _options = {})
362
+ forge = FalkorLib::Config::Bootstrap::DEFAULTS[:forge]
363
+ #ap forge
364
+ default_idx = forge.keys.index(default)
365
+ default_idx = 0 if default_idx.nil?
366
+ v = select_from(forge.map { |_k, u| u[:name] },
367
+ "Select the Forge hosting the project sources",
368
+ default_idx + 1,
369
+ forge.keys)
370
+ v
371
+ end # select_forge
372
+
373
+ ###### select_licence ######
374
+ # Select a given licence for the project
375
+ ##
376
+ def select_licence(default_licence = FalkorLib::Config::Bootstrap::DEFAULTS[:metadata][:license],
377
+ _options = {})
378
+ list_license = FalkorLib::Config::Bootstrap::DEFAULTS[:licenses].keys
379
+ idx = list_license.index(default_licence) unless default_licence.nil?
380
+ select_from(list_license,
381
+ 'Select the license index for this project:',
382
+ (idx.nil?) ? 1 : idx + 1)
383
+ #licence
384
+ end # select_licence
385
+
386
+ ###### get_badge ######
387
+ # Return a Markdown-formatted string for a badge to display, typically in a README.
388
+ # Based on http://shields.io/
389
+ # Supported options:
390
+ # * :style [string] style of the badge, Elligible: ['plastic', 'flat', 'flat-square']
391
+ ##
392
+ def get_badge(subject, status, color = 'blue', options = {})
393
+ st = status.gsub(/-/, '--').gsub(/_/, '__')
394
+ res = "https://img.shields.io/badge/#{subject}-#{st}-#{color}.svg"
395
+ res += "?style=#{options[:style]}" if options[:style]
396
+ res
397
+ end # get_licence_badge
398
+
399
+ ###### get_project_name ######
400
+ # Return a "reasonable" project name from a given [sub] directory i.e. its basename
401
+ ##
402
+ def get_project_name(dir = Dir.pwd, _options = {})
403
+ path = normalized_path(dir)
404
+ path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path)
405
+ File.basename(path)
406
+ end # get_project_name
407
+
408
+
409
+ end # module Bootstrap
718
410
  end # module FalkorLib