Module: FalkorLib::Bootstrap

Defined in:
lib/falkorlib/bootstrap/git.rb,
lib/falkorlib/bootstrap/base.rb,
lib/falkorlib/bootstrap/link.rb,
lib/falkorlib/bootstrap/ruby.rb,
lib/falkorlib/bootstrap/latex.rb,
lib/falkorlib/bootstrap/mkdocs.rb,
lib/falkorlib/bootstrap/python.rb,
lib/falkorlib/bootstrap/vagrant.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Link

Class Method Summary collapse

Class Method Details

.get_badge(subject, status, color = 'blue', options = {}) ⇒ Object

get_badge ###### Return a Markdown-formatted string for a badge to display, typically in a README. Based on shields.io/ Supported options:

* :style [string] style of the badge, Elligible: ['plastic', 'flat', 'flat-square']


550
551
552
553
554
555
# File 'lib/falkorlib/bootstrap/base.rb', line 550

def get_badge(subject, status, color = 'blue', options = {})
  st = status.gsub(/-/, '--').gsub(/_/, '__')
  res = "https://img.shields.io/badge/#{subject}-#{st}-#{color}.svg"
  res += "?style=#{options[:style]}" if options[:style]
  res
end

.get_project_name(dir = Dir.pwd, _options = {}) ⇒ Object

get_project_name ###### Return a “reasonable” project name from a given [sub] directory i.e. its basename



560
561
562
563
564
# File 'lib/falkorlib/bootstrap/base.rb', line 560

def get_project_name(dir = Dir.pwd, _options = {})
  path = normalized_path(dir)
  path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path)
  File.basename(path)
end

.gitcrypt(dir = Dir.pwd, options = {}) ⇒ Object

gitcrypt ###### Initialize git-crypt in the current directory Supported options:

* :force       [boolean] force overwritting
* :owner       [string]  owner (GPG ID or email)
* :keys        [array]   List of GPG IDs allowed to unlock the repository
* :ulhpc       [boolean] setup the repository for the ULHPC team


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/falkorlib/bootstrap/git.rb', line 133

def gitcrypt(dir = Dir.pwd, options = {})
  path = normalized_path(dir)
  unless File.directory?(path)
    warning "The directory '#{path}' does not exist yet."
    warning 'Do you want to create (and git init) this directory?'
    really_continue?
    run %(mkdir -p #{path})
    FalkorLib::Git.init(path)
  end
  error "Not a git-ready directory" unless FalkorLib::Git.init?(path)
  rootdir = FalkorLib::Git.rootdir(path)
  config =  FalkorLib::Config::Bootstrap::DEFAULTS[:gitcrypt].clone
  info "about to initialize Git crypt for the repository '#{rootdir}'"
  really_continue?
  config[:owner] = (options[:owner]) ? options[:owner] :  ask("\tEmail or (better) GPG ID of the owner of the git-crypt (root) vault", config[:owner])
  [ :hooksdir ].each do |k|
    config[k] = (options[k]) ? options[k] : ask("\t#{k.capitalize}", config[k])
  end
  #puts config.to_yaml
  if File.exists?(File.join(rootdir, '.git/git-crypt/keys/default'))
    warning "git-crypt has already been initialised in '#{rootdir}'"
  else
    Dir.chdir( rootdir ) do
      run %( git crypt init )
      if config[:owner]
        info "setup owner of the git-crypt vault to '#{config[:owner]}'"
        run %( gpg --list-key  #{config[:owner]} | grep uid| head -n1)
        run %( git crypt add-gpg-user #{config[:owner]} )
      end
    end
  end
  # Bootstrap the directory
  gitattributes = File.join(rootdir, '.gitattributes')
  if File.exists?(gitattributes)
    puts "  ... '.gitattributes' file already exists"
  else
    templatedir = File.join( FalkorLib.templates, 'git-crypt')
    init_from_template(templatedir, rootdir, {},
                       :no_interaction => true,
                       :no_commit => false)
    FalkorLib::Git.add(gitattributes, 'Initialize .gitattributes for git-crypt')
  end

  git_hooksdir       = File.join(rootdir, '.git', 'hooks')
  precommit_hook     = File.join(git_hooksdir, 'pre-commit')
  src_git_hooksdir   = File.join(rootdir, config[:hooksdir])
  src_precommit_hook = File.join(src_git_hooksdir, config[:hook])
  if File.exists?(File.join(rootdir, config[:hook]))
    Dir.chdir( rootdir ) do
      run %(mkdir -p #{config[:hooksdir]} )
      unless File.exists?(src_precommit_hook)
        run %(mv #{config[:hook]} #{config[:hooksdir]}/ )
        run %(chmod +x #{config[:hooksdir]}/#{config[:hook]})
        FalkorLib::Git.add(src_precommit_hook, 'pre-commit hook for git-crypt')
      end
      run %(rm -f #{config[:hook]} ) if File.exists?(File.join(rootdir, config[:hook]))
    end
  end
  # Pre-commit hook
  unless File.exist?(precommit_hook)
    info "=> bootstrapping special Git pre-commit hook for git-crypt"
    relative_src_hooksdir = Pathname.new( File.realpath( src_git_hooksdir )).relative_path_from Pathname.new( git_hooksdir )
    Dir.chdir( git_hooksdir ) do
      run %(ln -s #{relative_src_hooksdir}/#{config[:hook]} pre-commit)
    end
  end
  gpgkeys = []
  gpgkeys = config[:ulhpc] if options[:ulhpc]
  gpgkeys = options[:keys] if options[:keys]
  unless gpgkeys.empty?
    warning "About to allow the following GPG IDs to unlock the git-crypt vault"
    puts gpgkeys.to_yaml
    really_continue?
  end
  gpgkeys.each do |k|
    Dir.chdir( rootdir ) do
      info "allow GPG ID '#{k}' to unlock the git-crypt vault"
      run %( gpg --list-key  #{k} | grep uid| head -n1)
      run %( git crypt add-gpg-user #{k} )
    end
  end




end

.guess_project_config(dir = Dir.pwd, options = {}) ⇒ Object

guess_project_config ###### Guess the project configuration



499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/falkorlib/bootstrap/base.rb', line 499

def guess_project_config(dir = Dir.pwd, options = {})
  path = normalized_path(dir)
  use_git = FalkorLib::Git.init?(path)
  rootdir = (use_git) ? FalkorLib::Git.rootdir(path) : path
  local_config = FalkorLib::Config.get(rootdir, :local)
  return local_config[:project] if local_config[:project]
  # Otherwise, guess the rest of the configuration
  config = FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].clone
  # Apply options (if provided)
  [ :name, :forge ].each do |k|
    config[k.to_sym] = options[k.to_sym] if options[k.to_sym]
  end
  config[:name] = ask("\tProject name: ", get_project_name(dir)) if config[:name].empty?
  if (use_git)
    config[:origin] = FalkorLib::Git.config('remote.origin.url')
    if config[:origin] =~ /((gforge|gitlab|github)[\.\w_-]+)[:\d\/]+(\w*)/
      config[:forge] = Regexp.last_match(2).to_sym
      config[:by]    = Regexp.last_match(3)
    elsif config[:forge].empty?
      config[:forge] = select_forge(config[:forge]).to_sym
    end
  end
  forges = FalkorLib::Config::Bootstrap::DEFAULTS[:forge][ config[:forge].to_sym ]
  default_source = case config[:forge]
                   when :gforge
                     'https://' + forges[:url] + "/projects/" + config[:name].downcase
                   when :github, :gitlab
                     'https://' + forges[:url] + "/" + config[:by] + "/" + config[:name].downcase
                   else
                     ""
                   end
  config[:source] = config[:project_page] = default_source
  config[:issues_url] =  "#{config[:project_page]}/issues"
  config[:license] = select_licence if config[:license].empty?
  [ :summary  ].each do |k|
    config[k.to_sym] = ask( "\t" + Kernel.format("Project %-20s", k.to_s))
  end
  config[:description] = config[:summary]
  config[:gitflow] = FalkorLib::GitFlow.guess_gitflow_config(rootdir)
  config[:make] = File.exists?(File.join(rootdir, 'Makefile'))
  config[:rake] = File.exists?(File.join(rootdir, 'Rakefile'))
  config
end

.latex(dir = Dir.pwd, type = :beamer, options = {}) ⇒ Object

latex ###### Bootstrap a LaTeX sub-project of type <type> within a given repository <dir>.

* :beamer      LaTeX Beamer Slides
* :article     LaTeX article
* :letter      LaTeX Letter
* :bookchapter LaTeX Book chapter

Supported options:

* :force [boolean] force action
* :no_interaction [boolean]: do not interact
* :ieee      LaTeX IEEE conference article
* :ieee_jnl  LaTeX IEEE journal                     **NOT YET IMPLEMENTED**
* :llncs     LaTeX Springer LNCS conference article
* :acm       LaTeX ACM conference article


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/falkorlib/bootstrap/latex.rb', line 38

def latex(dir = Dir.pwd, type = :beamer, options = {})
  ap options if options[:debug]
  error "Unsupported type" unless [ :beamer, :article, :letter, :bookchapter ].include?( type )
  path   = normalized_path(dir)
  config = FalkorLib::Config::Bootstrap::DEFAULTS[:latex].clone
  if type == :letter
    config.merge!(FalkorLib::Config::Bootstrap::DEFAULTS[:letter].clone)
    [ :title, :subtitle, :image ].each { |k| config.delete k }
  end
  config.deep_merge!(FalkorLib::Config::Bootstrap::DEFAULTS[:letter].clone) if type == :letter
  # initiate the repository if needed
  unless File.directory?( path )
    warn "The directory '#{path}' does not exists and will be created"
    really_continue? unless options[:no_interaction]
    run %( mkdir -p #{path} )
  end
  repo(path, options) unless FalkorLib::Git.init?(path)
  rootdir = FalkorLib::Git.rootdir(path)
  info "Initiate a LaTeX #{type} project from the Git root directory: '#{rootdir}'"
  really_continue? unless options[:no_interaction]
  relative_path_to_root = (Pathname.new( FalkorLib::Git.rootdir(dir) ).relative_path_from Pathname.new( File.realpath(path))).to_s
  config[:name] = (options[:name]) ? options[:name] : ask("\tEnter the name of the LaTeX project (which will serve as basename for the main LaTeX file): ", File.basename(path))
  raise FalkorLib::ExecError "Empty project name" if config[:name].empty?
  default_project_dir = (Pathname.new( File.realpath(path) ).relative_path_from Pathname.new( FalkorLib::Git.rootdir(dir))).to_s
  if relative_path_to_root == '.'
    default_project_dir = case type
                          when :article
                            "articles/#{Time.now.year}/#{config[:name]}"
                          when :beamer
                            "slides/#{Time.now.year}/#{config[:name]}"
                          when :bookchapter
                            "chapters/#{config[:name]}"
                          when :letter
                            "letters/#{Time.now.year}/#{config[:name]}"
                          else
                            (config[:name]).to_s
                          end
  else
    default_project_dir += "/#{config[:name]}" unless default_project_dir =~ /#{config[:name]}$/
  end
  project_dir = (options[:dir]) ? options[:dir] : default_project_dir
  project_dir = ask("\tLaTeX Sources directory (relative to the Git root directory)", project_dir.to_s) unless options[:no_interaction]
  raise FalkorLib::ExecError "Empty project directory" if project_dir.empty?
  src_project_dir = File.join(project_dir, 'src')
  srcdir = File.join(rootdir, src_project_dir)
  if File.exist?(File.join(srcdir, '.root'))
    warn "The directory '#{project_dir}' seems to have been already initialized"
    really_continue? unless options[:no_interaction]
  end
  FalkorLib::GitFlow.start('feature', config[:name], rootdir) if FalkorLib::GitFlow.init?(rootdir)
  # === prepare Git submodules ===
  info " ==> prepare the relevant Git submodules"
  submodules = {}
  submodules['Makefiles'] = { :url => 'https://github.com/Falkor/Makefiles.git', :branch => 'devel' }
  submodules['beamerthemeFalkor'] = { :url => 'https://github.com/Falkor/beamerthemeFalkor' } if type == :beamer
  FalkorLib::Git.submodule_init(rootdir, submodules)

  info "bootstrapping the #{type} project sources in '#{src_project_dir}'"
  # Create the project directory
  Dir.chdir( rootdir ) do
    run %( mkdir -p #{src_project_dir}/images ) unless File.directory?("#{srcdir}/images")
  end
  info "populating '#{src_project_dir}'"
  #FalkorLib::Bootstrap::Link.root(srcdir, { :verbose => true} )
  FalkorLib::Bootstrap::Link.makefile(srcdir, :no_interaction => true)
  [ '_style.sty', '.gitignore' ].each do |f|
    Dir.chdir( srcdir ) do
      dst = ".makefile.d/latex/#{f}"
      run %( ln -s #{dst} #{f} ) unless File.exist?( File.join(srcdir, f) )
    end
  end
  if type == :beamer
    f = 'beamerthemeFalkor.sty'
    dst = "#{FalkorLib.config[:git][:submodulesdir]}/beamerthemeFalkor/#{f}"
    Dir.chdir( srcdir ) do
      run %( ln -s .root/#{dst} #{f} ) unless File.exist?( File.join(srcdir, f) )
    end
  end

  # Bootstrap the directory
  src_templatedir = File.join( FalkorLib.templates, 'latex')
  unless File.exist?( File.join(srcdir, "#{config[:name]}.tex"))
    info "gathering information for the LaTeX templates (type #{type})"
    prefix = case type
             when :article
                  'Article '
             when :ieee_journal
               'IEEE Journal '
             when :beamer
               'Slides '
             when :bookchapter
               'Book Chapter '
             when :letter
               'Letter '
             end
    prefix.prepend("LLNCS ")        if options[:llncs]
    prefix.prepend("IEEE ")         if options[:ieee]
    prefix.prepend("ACM ")          if options[:acm]
    prefix.prepend("IEEE Journal ") if options[:ieee_journal]
    config.each do |k, v|
      next if k == :name
      next if (type == :article and [ :image, :logo, :url].include?(k) )
      config[k.to_sym] = ask( "\t" + Kernel.format("%-20s", "#{prefix}#{k.capitalize}"), v) unless options[:no_interaction]
    end
    templates = [ File.join(src_templatedir, type.to_s) ]
    if (type == :article)
      style = :ieee  # default style
      [ :llncs, :acm ].each { |s| style = s if options[ s.to_sym ]  }
      templates << File.join(src_templatedir, "article-#{style}")
      templates << File.join(src_templatedir, "#{style}")
    end
    templates.each do |templatedir|
      info "**** using templatedir = #{templatedir}"
      init_from_template(templatedir, srcdir, config, :no_interaction => true,
                         :no_commit => true)
    end
    # Rename the main file
    Dir.chdir( srcdir ) do
      run %( mv main.tex #{config[:name]}.tex )
    end
  end
  # Create the trash directory
  trash(srcdir)

  # populate the images/ directory
  baseimages = File.join( FalkorLib.templates, 'latex', 'images')
  #images_makefile_src = "#{FalkorLib.config[:git][:submodulesdir]}/Makefiles/generic/Makefile.insrcdir"
  images = File.join(srcdir, 'images')
  info "populating the image directory"
  Dir.chdir( images ) do
    run %( rsync -avzu #{baseimages}/ . )
    run %( ln -s ../.root .root ) unless File.exist?(File.join(images, '.root'))
    #run %{ ln -s .root/#{images_makefile_src} Makefile } unless File.exists?(File.join(images, 'Makefile'))
  end
  FalkorLib::Bootstrap::Link.makefile(images, :images => true, :no_interaction => true )

  # Prepare the src/ directory
  FalkorLib::Bootstrap::Link.makefile(File.join(rootdir, project_dir), :src => true, :no_interaction => true )

end

.license(dir = Dir.pwd, license = , authors = '', options = { :filename => 'LICENSE' }) ⇒ Object

license ###### Generate the licence file

Supported options:

* :force    [boolean] force action
* :filename [string]  License file name
* :organization [string]  Organization


477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/falkorlib/bootstrap/base.rb', line 477

def license(dir = Dir.pwd,
            license = FalkorLib::Config::Bootstrap::DEFAULTS[:metadata][:license],
            authors = '',
            options = {
              :filename     => 'LICENSE'
            })
  return if ((license.empty?) or (license == 'none') or (license =~ /^CC/))
  return unless FalkorLib::Config::Bootstrap::DEFAULTS[:licenses].keys.include?( license )
  info "Generate the #{license} licence file"
  path = normalized_path(dir)
  use_git = FalkorLib::Git.init?(path)
  rootdir = (use_git) ? FalkorLib::Git.rootdir(path) : path
  Dir.chdir( rootdir ) do
    run %( licgen #{license.downcase} #{authors} )
    run %( mv LICENSE #{options[:filename]} ) if( options[:filename] and options[:filename] != 'LICENSE')
  end
end

.makefile(dir = Dir.pwd, options = {}) ⇒ Object

makefile ###### Supported options:

  • :master [string] git flow master/production branch

  • :develop [string] git flow development branch

  • :force [boolean] for overwritting

.….….….….….….….….…..



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/falkorlib/bootstrap/base.rb', line 165

def makefile(dir = Dir.pwd, options = {})
  path = normalized_path(dir)
  path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path)
  info "=> Setup a root repository makefile in '#{dir}'"
  # Preparing submodule
  submodules = {}
  submodules['Makefiles'] = {
    :url    => 'https://github.com/Falkor/Makefiles.git',
    :branch => 'devel'
  }
  FalkorLib::Git.submodule_init(path, submodules)
  makefile = File.join(path, "Makefile")
  if File.exist?( makefile )
    puts "  ... not overwriting the root Makefile which already exists"
  else
    src_makefile = File.join(path, FalkorLib.config.git[:submodulesdir],
                             'Makefiles', 'repo', 'Makefile')
    FileUtils.cp src_makefile, makefile
    gitflow_branches = FalkorLib::Config::GitFlow::DEFAULTS[:branches]
    if FalkorLib::GitFlow.init?(path)
      [ :master, :develop ].each do |b|
        gitflow_branches[b.to_sym] = FalkorLib::GitFlow.branches(b.to_sym)
      end
    end
    unless options.nil?
      [ :master, :develop ].each do |b|
        gitflow_branches[b.to_sym] = options[b.to_sym] if options[b.to_sym]
      end
    end
    info "adapting Makefile to the gitflow branches"
    Dir.chdir( path ) do
      run %(
   sed -i '' \
    -e \"s/^GITFLOW_BR_MASTER=production/GITFLOW_BR_MASTER=#{gitflow_branches[:master]}/\" \
    -e \"s/^GITFLOW_BR_DEVELOP=devel/GITFLOW_BR_DEVELOP=#{gitflow_branches[:develop]}/\" \
    Makefile
                    )
    end
    FalkorLib::Git.add(makefile, 'Initialize root Makefile for the repo')
  end
end

.mkdocs(dir = Dir.pwd, options = {}) ⇒ Object

mkdocs ###### Initialize MkDocs in the current directory Supported options:

* :force       [boolean] force overwritting


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/falkorlib/bootstrap/mkdocs.rb', line 28

def mkdocs(dir = Dir.pwd, options = {})
  info "Initialize MkDocs (see http://www.mkdocs.org/)"
  path = normalized_path(dir)
  use_git = FalkorLib::Git.init?(path)
  rootdir = (use_git) ? FalkorLib::Git.rootdir(path) : path
  templatedir = File.join( FalkorLib.templates, 'mkdocs')
  config = guess_project_config(rootdir, options)
  config[:sitename] = ask("\tSite name: ", config[:name].capitalize)
  puts config.to_yaml
  #FalkorLib::GitFlow.start('feature', 'mkdocs', rootdir) if (use_git && FalkorLib::GitFlow.init?(rootdir))
  init_from_template(templatedir, rootdir, config,
                     :no_interaction => true,
                     :no_commit => true)
  Dir.chdir( File.join(rootdir, 'docs')) do
    run %(ln -s README.md index.md )
    run %(ln -s README.md contributing/index.md )
    run %(ln -s README.md setup/index.md )
  end
  #exit_status.to_i
end

.motd(dir = Dir.pwd, options = {}) ⇒ Object

motd ###### Generate a new motd (Message of the Day) file Supported options:

* :force    [boolean] force action
* :title    [string]  title of the motd (in figlet)
* :support  [string]  email address to use for  getting support
* :hostname [string]  hostname of the server to mention in the motd
* :width    [number]  width of the line used


286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/falkorlib/bootstrap/base.rb', line 286

def motd(dir = Dir.pwd, options = {})
  config = FalkorLib::Config::Bootstrap::DEFAULTS[:motd].merge!(::ActiveSupport::HashWithIndifferentAccess.new(options).symbolize_keys)
  path = normalized_path(dir)
  erbfile = File.join( FalkorLib.templates, 'motd', 'motd.erb')
  outfile = (config[:file] =~ /^\//) ? config[:file] : File.join(path, config[:file])
  info "Generate a motd (Message of the Day) file '#{outfile}'"
  FalkorLib::Config::Bootstrap::DEFAULTS[:motd].keys.each do |k|
    next if [:file, :width].include?(k)
    config[k.to_sym] = ask( "\t" + format("Message of the Day (MotD) %-10s", k.to_s), config[k.to_sym]) unless options[:no_interaction]
  end
  config[:os] = Facter.value(:lsbdistdescription) if Facter.value(:lsbdistdescription)
  config[:os] = "Mac " + Facter.value(:sp_os_version) if Facter.value(:sp_os_version)
  unless options[:nodemodel]
    config[:nodemodel] = Facter.value(:sp_machine_name) if Facter.value(:sp_machine_name)
    config[:nodemodel] += " (#{Facter.value(:sp_cpu_type)}" if Facter.value(:sp_cpu_type)
    config[:nodemodel] += " " + Facter.value(:sp_current_processor_speed) if Facter.value(:sp_current_processor_speed)
    config[:nodemodel] += " #{Facter.value(:sp_number_processors)} cores )" if Facter.value(:sp_number_processors)
  end
  config[:nodemodel] = Facter.value(:sp_machine_name) unless options[:nodemodel]
  write_from_erb_template(erbfile, outfile, config, options)
end

.pyenv(dir = Dir.pwd, options = {}) ⇒ Object

pyenv ###### Initialize pyenv/direnv in the current directory Supported options:

* :force          [boolean] force overwritting
* :python         [string]  Python version to configure for pyenv
* :virtualenv     [string]  Python virtualenv name to configure
* :versionfile    [string]  Python Version file
* :virtualenvfile [string]  Python virtualenv file (specifying its name)
* :direnvfile     [string]  Direnv configuration file
* :commit         [boolean] Commit the changes NOT YET USED
* :global         [boolean] Also configure the global direnv configuration
.                           in ~/.config/direnv


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/falkorlib/bootstrap/python.rb', line 38

def pyenv(dir = Dir.pwd, options = {})
  info "Initialize Pyenv-virtualenv and direnv setup in '#{dir}'"
  ap options if options[:debug]
  path = normalized_path(dir)
  unless File.directory?(path)
    warning "The directory '#{path}' does not exist yet."
    warning 'Do you want to create (and git init) this directory?'
    really_continue?
    run %(mkdir -p #{path})
  end
  use_git = FalkorLib::Git.init?(path)
  rootdir = (use_git) ? FalkorLib::Git.rootdir(path) : path
  config =  FalkorLib::Config::DEFAULTS[:pyenv].clone
  files = {}   # list of files to create
  exit_status = 1
  # Specialize configuration
  [:versionfile, :virtualenvfile, :direnvfile].each do |k|
    #config[k] =  (options[k]) ? options[k] : ask("\t" + Kernel.format("%-20s", "#{k.to_s.capitalize.gsub!(/file/, ' filename')}"), config[k])
    config[k] = options[k] if options[k]
    if File.exist?( File.join( rootdir, config[k] ))
      content = `cat #{File.join( rootdir, config[k])}`.chomp
      warning "The python/pyenv file '#{config[k]}' already exists"
      warning "    (with content '#{content}')" unless k == :direnvfile
      next unless options[:force]
      warning "... and it WILL BE overwritten"
    end
    files[k] = config[k]
  end
  # ==== Python version ===
  unless files[:versionfile].nil?
    file = File.join(rootdir, config[:versionfile])
    config[:version] = FalkorLib.config[:pyenv][:version]
    if options[:python]
      config[:version] = options[:python]
    else
      config[:version] = select_from(FalkorLib.config[:pyenv][:versions],
                                     "Select Python pyenv version to configure for this directory",
                                     (FalkorLib.config[:pyenv][:versions].find_index(FalkorLib.config[:pyenv][:version]) + 1))
    end
    info " ==>  configuring pyenv version file '#{config[:versionfile]}' for python version '#{config[:version]}'"
    File.open(file, 'w') do |f|
      f.puts config[:version]
    end
    exit_status = (File.exist?(file) && (`cat #{file}`.chomp == config[:version])) ? 0 : 1
    FalkorLib::Git.add( file ) if use_git
  end
  # === Virtualenv ===
  if files[:virtualenvfile]
    file = File.join(rootdir, files[:virtualenvfile])
    default_virtualenv = File.basename(rootdir)
    default_virtualenv = `cat #{file}`.chomp if File.exist?( file )
    g = (options[:virtualenv]) ? options[:virtualenv] : ask("Enter virtualenv name for this directory", default_virtualenv)
    info " ==>  configuring virtualenv file '#{files[:virtualenvfile]}' with content '#{g}'"
    File.open( File.join(rootdir, files[:virtualenvfile]), 'w') do |f|
      f.puts g
    end
    exit_status = (File.exist?(file) && (`cat #{file}`.chomp == g)) ? 0 : 1
    FalkorLib::Git.add(File.join(rootdir, files[:virtualenvfile])) if use_git
  end
  # ==== Global direnvrc ====
  if options and options[:global]
    direnvrc     = config[:direnvrc]
    direnvrc_dir = File.dirname( direnvrc )
    unless File.directory?( direnvrc_dir )
      warning "The directory '#{direnvrc_dir}' meant for hosting the globa direnv settings does not exist"
      warning "About to create this directory"
      really_continue?
      run %(mkdir -p #{direnvrc_dir})
    end
    if (!File.exists?(direnvrc) or options[:force])
      templatedir = File.join( FalkorLib.templates, 'direnv')
      info " ==> configuring Global direnvrc #{files[:direnvrc]}"
      init_from_template(templatedir, direnvrc_dir, config,
                         :no_interaction => true,
                         :no_commit      => true,
                        )
    end
  end
  # ==== Local Direnv setup and .envrc ===
  if files[:direnvfile]
    envrc = File.join(rootdir, files[:direnvfile])
    setup = File.join(rootdir, 'setup.sh')
    if (!File.exists?(setup) or options[:force])
      templatedir = File.join( FalkorLib.templates, 'python')
      info " ==> configuring local direnv setup and #{files[:direnvfile]}"
      init_from_template(templatedir, rootdir, config,
                         :no_interaction => true,
                         :no_commit => true,
                        )
    end
    if (!File.exists?(envrc) or options[:force])
      run %(ln -s setup.sh #{envrc})
    end
    FalkorLib::Git.add( envrc ) if use_git
    FalkorLib::Git.add( setup ) if use_git
  end
  # Last motd
  warning <<-MOTD

----------------------------------------------------------------------------
Direnv/Pyenv configured for #{path}.
For more detailed instructions, see
 https://varrette.gforge.uni.lu/tutorials/pyenv.html

Now you probably need to perform the following actions:

cd #{path}
direnv allow .
# Eventually install the pyenv version
pyenv install #{config[:version]}

You can then enjoy your newly configured sand-boxed environment

pip list
pip install numpy scipy matplotlib
pip install jupyter ipykernel
python -m ipykernel install --user --name=$(head .python-virtualenv)
jupyter notebook

To freeze your environment to pass it around

pip freeze -l  # List all the pip packages used in the virtual environment
pip freeze -l > requirements.txt  # Dump it to a requirements file
git add requirements.txt
git commit -s -m 'Python package list' requirements.txt

MOTD
  exit_status.to_i
end

.readme(dir = Dir.pwd, options = {}) ⇒ Object

readme ###### Bootstrap a README file for various context Supported options:

* :no_interaction [boolean]: do not interact
* :force          [boolean] force overwritting
* :license     [string]  License to use
* :licensefile [string]  License filename (default: LICENSE)
* :latex          [boolean] describe a LaTeX project
* :octopress      [boolean] octopress site


320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/falkorlib/bootstrap/base.rb', line 320

def readme(dir = Dir.pwd, options = {})
  info "Bootstrap a README file for this project"
  # get the local configuration
  local_config = FalkorLib::Config.get(dir)
  config = FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].clone
  name = get_project_name(dir)
  if local_config[:project]
    config.deep_merge!( local_config[:project])
  else
    config[:name] = ask("\tProject name: ", name) unless options[:name]
  end
  if options[:rake]
    options[:make] = false
    options[:rvm]  = true
  end
  config[:license] = options[:license] if options[:license]
  config[:type] << :rvm if options[:rake]
  # Type of project
  config[:type] << :latex if options[:latex]
  if config[:type].empty?
    t = select_from( FalkorLib::Config::Bootstrap::DEFAULTS[:types],
                     'Select the type of project to describe:', 1)
    config[:type] << t
    config[:type] << [ :ruby, :rvm ] if [ :gem, :rvm, :octopress, :puppet_module ].include?( t )
    config[:type] << :python if t == :pyenv
  end
  config[:type].uniq!
  #ap config
  config[:type] = config[:type].uniq.flatten
  # Apply options (if provided)
  [ :name, :forge ].each do |k|
    config[k.to_sym] = options[k.to_sym] if options[k.to_sym]
  end
  path = normalized_path(dir)
  config[:filename] = (options[:filename]) ? options[:filename] : File.join(path, 'README.md')
  if ( FalkorLib::Git.init?(dir) && FalkorLib::Git.remotes(dir).include?( 'origin' ))
    config[:origin] = FalkorLib::Git.config('remote.origin.url')
    if config[:origin] =~ /((gforge|gitlab|github)[\.\w_-]+)[:\d\/]+(\w*)/
      config[:forge] = Regexp.last_match(2).to_sym
      config[:by]    = Regexp.last_match(3)
    end
  elsif config[:forge].empty?
    config[:forge] = select_forge(config[:forge]).to_sym
  end
  forges = FalkorLib::Config::Bootstrap::DEFAULTS[:forge][ config[:forge].to_sym ]
  #ap config
  default_source = case config[:forge]
                   when :gforge
                     'https://' + forges[:url] + "/projects/" + name.downcase
                   when :github, :gitlab
                     'https://' + forges[:url] + "/" + config[:by] + "/" + name.downcase
                   else
                     ""
                   end
  FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].each do |k, v|
    next if v.is_a?(Array) || [ :license, :forge ].include?( k )
    next if (k == :name) && !config[:name].empty?
    next if (k == :issues_url) && ![ :github, :gitlab ].include?( config[:forge] )
    #next unless [ :name, :summary, :description ].include?(k.to_sym)
    default_answer = case k
                     when :author
                       (config[:by] == 'ULHPC') ? 'UL HPC Team' : config[:author]
                     when :mail
                       (config[:by] == 'ULHPC') ? '[email protected]'   : config[:mail]
                     when :description
                       (config[:description].empty?) ? (config[:summary]).to_s : (config[:description]).to_s
                     when :source
                       (config[:source].empty?) ? default_source : (config[:source]).to_s
                     when :project_page
                       (config[:source].empty?) ? v : config[:source]
                     when :issues_url
                       (config[:project_page].empty?) ? v : "#{config[:project_page]}/issues"
                     else
                       (config[k.to_sym].empty?) ? v : config[k.to_sym]
                     end
    config[k.to_sym] = ask( "\t" + Kernel.format("Project %-20s", k.to_s), default_answer)
  end
  tags = ask("\tKeywords (comma-separated list of tags)", config[:tags].join(','))
  config[:tags]    = tags.split(',')
  config[:license] = select_licence if config[:license].empty?
  # stack the ERB files required to generate the README
  templatedir = File.join( FalkorLib.templates, 'README')
  erbfiles = [ 'header_readme.erb' ]
  [ :latex ].each do |type|
    erbfiles << "readme_#{type}.erb" if options[type.to_sym] && File.exist?( File.join(templatedir, "readme_#{type}.erb"))
  end
  erbfiles << "readme_issues.erb"
  erbfiles << "readme_git.erb"     if FalkorLib::Git.init?(dir)
  erbfiles << "readme_gitflow.erb" if FalkorLib::GitFlow.init?(dir)
  erbfiles << "readme_rvm.erb"     if config[:type].include?(:rvm)
  erbfiles << "readme_mkdocs.erb"  if options[:mkdocs]
  erbfiles << "footer_readme.erb"

  content = ""
  ap options
  ap config
  erbfiles.each do |f|
    erbfile = File.join(templatedir, f)
    content += ERB.new(File.read(erbfile.to_s), nil, '<>').result(binding)
  end
  show_diff_and_write(content, config[:filename], options)

  # Force save/upgrade local config
  info "=> saving customization of the FalkorLib configuration in #{FalkorLib.config[:config_files][:local]}"
  # really_continue?
  FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].keys.each do |k|
    local_config[:project] = {} unless local_config[:project]
    local_config[:project][k.to_sym] = config[k.to_sym]
  end
  if FalkorLib::GitFlow.init?(dir)
    local_config[:gitflow] = {} unless local_config[:gitflow]
    local_config[:gitflow][:branches] = FalkorLib.config[:gitflow][:branches].clone unless local_config[:gitflow][:branches]
    [ :master, :develop ].each do |b|
      local_config[:gitflow][:branches][b.to_sym] = FalkorLib::GitFlow.branches(b.to_sym)
    end
  end
  FalkorLib::Config.save(dir, local_config, :local)
  #
end

.repo(name, options = {}) ⇒ Object

repo ###### Initialize a Git repository for a project with my favorite layout Supported options:

  • :no_interaction [boolean]: do not interact

  • :gitflow [boolean]: bootstrap with git-flow

  • :license [string] License to use

  • :licensefile [string] License filename (default: LICENSE)

  • :interactive [boolean] Confirm Gitflow branch names

  • :master [string] Branch name for production releases

  • :develop [string] Branch name for development commits

  • :make [boolean] Use a Makefile to pilot the repository actions

  • :rake [boolean] Use a Rakefile (and FalkorLib) to pilot the repository action

  • :remote_sync [boolean] Operate a git remote synchronization

  • :latex [boolean] Initiate a LaTeX project **NOT YET IMPLEMENTED**

  • :gem [boolean] Initiate a Ruby gem project **NOT YET IMPLEMENTED**

  • :mkdocs [boolean] Initiate MkDocs within your project

  • :rvm [boolean] Initiate a RVM-based Ruby project

  • :pyenv [boolean] Initiate a pyenv-based Python project **NOT YET IMPLEMENTED**

  • :octopress [boolean] Initiate an Octopress web site **NOT YET IMPLEMENTED**



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/falkorlib/bootstrap/git.rb', line 44

def repo(name, options = {})
  ap options if options[:debug]
  path    = normalized_path(name)
  project = File.basename(path)
  use_git = FalkorLib::Git.init?(path)
  if options[:rake]
    options[:make] = false
    options[:rvm]  = true
  end
  info "Bootstrap a [Git] repository for the project '#{project}'"
  if use_git
    warning "Git is already initialized for the repository '#{name}'"
    really_continue? unless options[:force]
  end
  if options[:git_flow]
    info " ==> initialize Git flow in #{path}"
    FalkorLib::GitFlow.init(path, options)
    gitflow_branches = {}
    [ :master, :develop ].each do |t|
      gitflow_branches[t.to_sym] = FalkorLib::GitFlow.branches(t, path)
    end
  else
    FalkorLib::Git.init(path, options)
  end
  # === prepare Git submodules ===
  submodules = {}
  #'gitstats' => { :url => 'https://github.com/hoxu/gitstats.git' }
  unless submodules.empty?
    info " ==> prepare the relevant Git submodules"
    FalkorLib::Git.submodule_init(path, submodules)
  end
  # === Prepare root [M|R]akefile ===
  FalkorLib::Bootstrap.makefile(path, gitflow_branches) if options[:make]
  if options[:rake]
    info " ==> prepare Root Rakefile"
    rakefile = File.join(path, "Rakefile")
    unless File.exist?( rakefile )
      templatedir = File.join( FalkorLib.templates, 'Rakefile')
      erbfiles = [ 'header_rakefile.erb' ]
      erbfiles << 'rakefile_gitflow.erb' if FalkorLib::GitFlow.init?(path)
      erbfiles << 'footer_rakefile.erb'
      write_from_erb_template(erbfiles, rakefile, {}, :srcdir => templatedir.to_s)
    end
  end

  # === VERSION file ===
  FalkorLib::Bootstrap.versionfile(path, :tag => 'v0.0.0') unless options[:gem]

  # === RVM ====
  FalkorLib::Bootstrap.rvm(path, options) if options[:rvm]

  # === README ===
  FalkorLib::Bootstrap.readme(path, options) # This should also save the project configuration
  # collect the set options
  local_config = FalkorLib::Config.get(path)

  # === MkDocs ===
  FalkorLib::Bootstrap.mkdocs(path, options) if options[:mkdocs]

  # === Licence ===
  if (local_config[:project] and local_config[:project][:license])
    author  = local_config[:project][:author] ? local_config[:project][:author] : FalkorLib::Config::Bootstrap::DEFAULTS[:metadata][:author]
    FalkorLib::Bootstrap.license(path, local_config[:project][:license], author,  options)
  end
  #


  #===== remote synchro ========
  if options[:remote_sync]
    remotes = FalkorLib::Git.remotes(path)
    if remotes.include?( 'origin' )
      info "perform remote synchronization"
      [ :master, :develop ].each do |t|
        FalkorLib::Git.publish(gitflow_branches[t.to_sym], path, 'origin')
      end
    else
      warning "no Git remote  'origin' found, thus no remote synchronization performed"
    end
  end
end

.rvm(dir = Dir.pwd, options = {}) ⇒ Object

rvm ###### Initialize RVM in the current directory Supported options:

* :force       [boolean] force overwritting
* :ruby        [string]  Ruby version to configure for RVM
* :versionfile [string]  Ruby Version file
* :gemset      [string]  RVM Gemset to configure
* :gemsetfile  [string]  RVM Gemset file
* :commit      [boolean] Commit the changes NOT YET USED


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/falkorlib/bootstrap/ruby.rb', line 35

def rvm(dir = Dir.pwd, options = {})
  info "Initialize Ruby Version Manager (RVM)"
  ap options if options[:debug]
  path = normalized_path(dir)
  use_git = FalkorLib::Git.init?(path)
  rootdir = (use_git) ? FalkorLib::Git.rootdir(path) : path
  files = {}
  exit_status = 1
  [:versionfile, :gemsetfile].each do |type|
    f = (options[type.to_sym].nil?) ? FalkorLib.config[:rvm][type.to_sym] : options[type.to_sym]
    if File.exist?( File.join( rootdir, f ))
      content = `cat #{File.join( rootdir, f)}`.chomp
      warning "The RVM file '#{f}' already exists (and contains '#{content}')"
      next unless options[:force]
      warning "... and it WILL BE overwritten"
    end
    files[type.to_sym] = f
  end
  # ==== Ruby version ===
  unless files[:versionfile].nil?
    file = File.join(rootdir, files[:versionfile])
    v = FalkorLib.config[:rvm][:version]
    if options[:ruby]
      v = options[:ruby]
    else
      select_from(FalkorLib.config[:rvm][:rubies],
                  "Select RVM ruby to configure for this directory",
                  (FalkorLib.config[:rvm][:rubies].find_index(FalkorLib.config[:rvm][:version]) + 1))
    end
    info " ==>  configuring RVM version file '#{files[:versionfile]}' for ruby version '#{v}'"
    File.open(file, 'w') do |f|
      f.puts v
    end
    exit_status = (File.exist?(file) && (`cat #{file}`.chomp == v)) ? 0 : 1
    FalkorLib::Git.add(File.join(rootdir, files[:versionfile])) if use_git
  end
  # === Gemset ===
  if files[:gemsetfile]
    file = File.join(rootdir, files[:gemsetfile])
    default_gemset = File.basename(rootdir)
    default_gemset = `cat #{file}`.chomp if File.exist?( file )
    g = (options[:gemset]) ? options[:gemset] : ask("Enter RVM gemset name for this directory", default_gemset)
    info " ==>  configuring RVM gemset file '#{files[:gemsetfile]}' with content '#{g}'"
    File.open( File.join(rootdir, files[:gemsetfile]), 'w') do |f|
      f.puts g
    end
    exit_status = (File.exist?(file) && (`cat #{file}`.chomp == g)) ? 0 : 1
    FalkorLib::Git.add(File.join(rootdir, files[:gemsetfile])) if use_git
  end
  # ==== Gemfile ===
  gemfile = File.join(rootdir, 'Gemfile')
  unless File.exist?( gemfile )
    # Dir.chdir(rootdir) do
    #     run %{ bundle init }
    # end
    info " ==>  configuring Gemfile with Falkorlib"
    File.open( gemfile, 'a') do |f|
      f.puts "source 'https://rubygems.org'"
      f.puts ""
      f.puts "gem 'falkorlib' #, :path => '~/git/github.com/Falkor/falkorlib'"
    end
    FalkorLib::Git.add(gemfile) if use_git
  end
  exit_status.to_i
end

.select_forge(default = :gforge, _options = {}) ⇒ Object

Select the forge (gforge, github, etc.) hosting the project sources



444
445
446
447
448
449
450
451
452
453
454
# File 'lib/falkorlib/bootstrap/base.rb', line 444

def select_forge(default = :gforge, _options = {})
  forge = FalkorLib::Config::Bootstrap::DEFAULTS[:forge]
  #ap forge
  default_idx = forge.keys.index(default)
  default_idx = 0 if default_idx.nil?
  v = select_from(forge.map { |_k, u| u[:name] },
                  "Select the Forge hosting the project sources",
                  default_idx + 1,
                  forge.keys)
  v
end

.select_licence(default_licence = , _options = {}) ⇒ Object

select_licence ###### Select a given licence for the project



459
460
461
462
463
464
465
466
467
# File 'lib/falkorlib/bootstrap/base.rb', line 459

def select_licence(default_licence = FalkorLib::Config::Bootstrap::DEFAULTS[:metadata][:license],
                   _options = {})
  list_license = FalkorLib::Config::Bootstrap::DEFAULTS[:licenses].keys
  idx = list_license.index(default_licence) unless default_licence.nil?
  select_from(list_license,
              'Select the license index for this project:',
              (idx.nil?) ? 1 : idx + 1)
  #licence
end

.trash(path = Dir.pwd, dirname = , _options = {}) ⇒ Object

Initialize a trash directory in path



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/falkorlib/bootstrap/base.rb', line 211

def trash(path = Dir.pwd, dirname = FalkorLib.config[:templates][:trashdir], _options = {})
  #args = method(__method__).parameters.map { |arg| arg[1].to_s }.map { |arg| { arg.to_sym => eval(arg) } }.reduce Hash.new, :merge
  #ap args
  exit_status = 0
  trashdir = File.join(File.realpath(path), dirname)
  if Dir.exist?(trashdir)
    warning "The trash directory '#{dirname}' already exists"
    return 1
  end
  Dir.chdir(path) do
    info "creating the trash directory '#{dirname}'"
    exit_status = run %(
      mkdir -p #{dirname}
      echo '*' > #{dirname}/.gitignore
            )
    if FalkorLib::Git.init?(path)
      exit_status = FalkorLib::Git.add(File.join(trashdir.to_s, '.gitignore' ),
                                       'Add Trash directory',
                                       :force => true )
    end
  end
  exit_status.to_i
end

.vagrant(dir = Dir.pwd, options = {}) ⇒ Object

vagrant ###### Initialize Vagrant in the current directory Supported options:

* :force       [boolean] force overwritting


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/falkorlib/bootstrap/vagrant.rb', line 28

def vagrant(dir = Dir.pwd, options = {})
  info "Initialize Vagrant (see https://www.vagrantup.com/)"
  path = normalized_path(dir)
  use_git = FalkorLib::Git.init?(path)
  rootdir = (use_git) ? FalkorLib::Git.rootdir(path) : path
  templatedir = File.join( FalkorLib.templates, 'vagrant')
  config = FalkorLib::Config::Bootstrap::DEFAULTS[:vagrant].clone
  if options[:os]
    config[:os] = options[:os]
  else
    config[:os] = select_from(config[:boxes].keys,
                "Select OS to configure within your vagrant boxes by default",
                (config[:boxes].keys.find_index(config[:os]) + 1))
  end
  [ :ram, :vcpus, :domain, :range ].each do |k|
    config[k.to_sym] = ask("\tDefault #{k.capitalize}:", config[k.to_sym])
  end
  puts config.to_yaml
  FalkorLib::GitFlow.start('feature', 'vagrant', rootdir) if (use_git && FalkorLib::GitFlow.init?(rootdir))
  init_from_template(templatedir, rootdir, config,
                     :no_interaction => true,
                     :no_commit => true)
  [ 'bootstrap.sh', 'config.yaml.sample' ].each do |f|
    FalkorLib::Git.add(File.join(rootdir, 'vagrant', "#{f}")) if use_git
  end
  Dir.chdir( rootdir ) do
    run %(git ignore '.vagrant/' )
    #   run %(ln -s README.md index.md )
  #   run %(ln -s README.md contributing/index.md )
  #   run %(ln -s README.md setup/index.md )
  end
  FalkorLib::Git.add(File.join(rootdir, '.gitignore')) if use_git

  #exit_status.to_i
end

.versionfile(dir = Dir.pwd, options = {}) ⇒ Object

versionfile ###### Bootstrap a VERSION file at the root of a project Supported options:

  • :file [string] filename

  • :version [string] version to mention in the file



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/falkorlib/bootstrap/base.rb', line 241

def versionfile(dir = Dir.pwd, options = {})
  file    = (options[:file])    ? options[:file]    : 'VERSION'
  version = (options[:version]) ? options[:version] : '0.0.0'
  info " ==> bootstrapping a VERSION file"
  path = normalized_path(dir)
  path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path)
  unless Dir.exist?( path )
    warning "The directory #{path} does not exists and will be created"
    really_continue?
    FileUtils.mkdir_p path
  end
  versionfile = File.join(path, file)
  if File.exist?( versionfile )
    puts "  ... not overwriting the #{file} file which already exists"
  else
    FalkorLib::Versioning.set_version(version, path, :type => 'file',
                                      :source => { :filename => file })
    Dir.chdir( path ) do
      run %( git tag #{options[:tag]} ) if options[:tag]
    end
  end

  # unless File.exists?( versionfile )
  #     run %{  echo "#{version}" > #{versionfile} }
  #     if FalkorLib::Git.init?(path)
  #         FalkorLib::Git.add(versionfile, "Initialize #{file} file")
  #         Dir.chdir( path ) do
  #             run %{ git tag #{options[:tag]} } if options[:tag]
  #         end
  #     end
  # else
  #     puts "  ... not overwriting the #{file} file which already exists"
  # end
end