appifier 0.1.0 → 0.1.2
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +56 -2
- data/Gemfile +3 -1
- data/Rakefile +27 -15
- data/VERSION +1 -1
- data/appifier.gemspec +20 -19
- data/bin/console +4 -3
- data/config/appifier.registry +9 -0
- data/config/settings.yml +59 -0
- data/exe/appifier +2 -1
- data/lib/appifier/actors/collector.rb +67 -0
- data/lib/appifier/actors/generator.rb +92 -100
- data/lib/appifier/actors/init.rb +3 -1
- data/lib/appifier/actors/retriever.rb +35 -35
- data/lib/appifier/cli/configuration.rb +13 -14
- data/lib/appifier/cli/templates.rb +28 -8
- data/lib/appifier/cli.rb +108 -49
- data/lib/appifier/components/Appifile.rb +35 -0
- data/lib/appifier/components/init.rb +3 -0
- data/lib/appifier/components/templates.rb +34 -0
- data/lib/appifier/helpers/archives.rb +29 -31
- data/lib/appifier/helpers/datasets.rb +36 -0
- data/lib/appifier/helpers/gem.rb +31 -30
- data/lib/appifier/helpers/init.rb +3 -1
- data/lib/appifier/helpers/user.rb +29 -31
- data/lib/appifier/services/finisher.rb +52 -0
- data/lib/appifier/services/init.rb +3 -0
- data/lib/appifier/setup.rb +11 -7
- data/lib/appifier/version.rb +2 -0
- data/lib/appifier.rb +34 -23
- data/samples/dummy/Appifile +12 -0
- data/samples/{skeleton → dummy/skeleton}/%%APPNAME.downcase%%/.rspec +0 -0
- data/samples/{skeleton → dummy/skeleton}/%%APPNAME.downcase%%/Rakefile +0 -0
- data/samples/{skeleton → dummy/skeleton}/%%APPNAME.downcase%%/config.ru +0 -0
- data/samples/{skeleton → dummy/skeleton}/%%APPNAME.downcase%%/exe/%%APPNAME.downcase%% +0 -0
- data/samples/{skeleton → dummy/skeleton}/%%APPNAME.downcase%%/lib/%%APPNAME.downcase%%.rb +0 -0
- data/samples/{skeleton → dummy/skeleton}/%%APPNAME.downcase%%/spec/%%APPNAME.downcase%%_spec.rb +0 -0
- data/samples/dummy.tgz +0 -0
- metadata +53 -30
@@ -1,18 +1,17 @@
|
|
1
|
-
|
2
|
-
module CLI
|
3
|
-
module Subcommands
|
4
|
-
class Configuration < ::Thor
|
5
|
-
# Thor method : running of Appifier sanitycheck
|
6
|
-
desc "sanitycheck", "Verify installation of Appifier for user"
|
7
|
-
def sanitycheck
|
8
|
-
end
|
1
|
+
# frozen_string_literal: true
|
9
2
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
module Appifier
|
4
|
+
module CLI
|
5
|
+
module Subcommands
|
6
|
+
class Configuration < ::Thor
|
7
|
+
# Thor method : running of Appifier sanitycheck
|
8
|
+
desc 'sanitycheck', 'Verify installation of Appifier for user'
|
9
|
+
def sanitycheck; end
|
14
10
|
|
15
|
-
|
16
|
-
|
11
|
+
# Thor method : Getting the current Appifier version
|
12
|
+
desc 'version', 'Display current Appifier version'
|
13
|
+
def version; end
|
14
|
+
end
|
17
15
|
end
|
16
|
+
end
|
18
17
|
end
|
@@ -1,14 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Appifier
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module CLI
|
5
|
+
module Subcommands
|
6
|
+
class Templates < ::Thor
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
super
|
10
|
+
@output = Carioca::Registry.get.get_service name: :output
|
11
|
+
@finisher = Carioca::Registry.get.get_service name: :finisher
|
12
|
+
end
|
9
13
|
|
14
|
+
# Thor method : list availables templates in user bundle
|
15
|
+
desc 'ls', 'list templates availables in user bundle'
|
16
|
+
def ls
|
17
|
+
Appifier::Components::Templates::list
|
18
|
+
@finisher.terminate exit_case: :error_exit
|
19
|
+
end
|
10
20
|
|
11
|
-
|
21
|
+
# Thor method : remove a template from user bundle
|
22
|
+
desc 'rm', 'rm templates from user bundle'
|
23
|
+
def rm(template)
|
24
|
+
begin
|
25
|
+
Appifier::Components::Templates::rm(template)
|
26
|
+
rescue RuntimeError => e
|
27
|
+
@output.error e.message
|
28
|
+
@finisher.terminate exit_case: :error_exit
|
29
|
+
end
|
12
30
|
end
|
31
|
+
end
|
13
32
|
end
|
33
|
+
end
|
14
34
|
end
|
data/lib/appifier/cli.rb
CHANGED
@@ -1,67 +1,126 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
2
3
|
require 'appifier'
|
3
4
|
require 'thor'
|
4
5
|
|
5
|
-
Dir[File.dirname(__FILE__)
|
6
|
-
|
7
|
-
|
6
|
+
Dir["#{File.dirname(__FILE__)}/cli/*.rb"].sort.each { |file| require file }
|
8
7
|
|
9
8
|
module Appifier
|
9
|
+
module CLI
|
10
|
+
# The CLI Command structure for Thor
|
11
|
+
class MainCommand < Thor
|
10
12
|
|
11
|
-
module CLI
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
def initialize(*args)
|
15
|
+
super
|
16
|
+
@output = Carioca::Registry.get.get_service name: :output
|
17
|
+
@finisher = Carioca::Registry.get.get_service name: :finisher
|
18
|
+
end
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
# callback for managing ARGV errors
|
21
|
+
def self.exit_on_failure?
|
22
|
+
true
|
23
|
+
end
|
20
24
|
|
21
|
-
|
25
|
+
desc 'templates SUBCOMMAND ...ARGS', 'Managing apps templates'
|
26
|
+
subcommand 'templates', Subcommands::Templates
|
22
27
|
|
23
|
-
|
24
|
-
|
28
|
+
desc 'configuration SUBCOMMAND ...ARGS', 'Configuration commands for Appifier'
|
29
|
+
subcommand 'configuration', Subcommands::Configuration
|
25
30
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# Thor method : running of Appifier generate
|
32
|
-
desc "generate TEMPLATE [TARGET]", "Generate application from bundled template"
|
33
|
-
long_desc <<-LONGDESC
|
31
|
+
# Thor method : running of Appifier generate
|
32
|
+
desc 'generate TEMPLATE [TARGET]', 'Generate application from bundled template'
|
33
|
+
long_desc <<-LONGDESC
|
34
34
|
Generate application from bundled template\n
|
35
|
-
with --simulate, only simulate folders and files installed
|
36
|
-
with --force, force regeneration of application, remove old files [DANGER]
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
35
|
+
with --simulate, only simulate folders and files installed
|
36
|
+
with --force, force regeneration of application, remove old files [DANGER]
|
37
|
+
LONGDESC
|
38
|
+
option :simulate, type: :boolean, aliases: '-s'
|
39
|
+
option :force, type: :boolean, aliases: '-F'
|
40
|
+
def generate(template, target = '.')
|
41
|
+
root = "#{File.expand_path(Appifier::DEFAULT_TEMPLATES_PATH)}/#{template}"
|
42
|
+
source = "#{root}/skeleton"
|
43
|
+
|
44
|
+
if File::exist? File::expand_path("#{DEFAULT_DATASETS_PATH}/#{template}.yml") then
|
45
|
+
dataset = open_dataset(template: template)
|
46
|
+
@output.info "Dataset file found for #{template}"
|
47
|
+
else
|
48
|
+
@output.ko "Dataset file not found for #{template}"
|
49
|
+
@finisher.terminate exit_case: :error_exit
|
50
|
+
end
|
49
51
|
|
52
|
+
begin
|
53
|
+
generator = Appifier::Actors::Generator.new src_root: source, target_root: File.expand_path(target), dataset: dataset
|
54
|
+
generator.generate dry_run: options[:simulate], force: options[:force]
|
55
|
+
@finisher.terminate exit_case: :quiet_exit
|
56
|
+
rescue RuntimeError => e
|
57
|
+
@output.error e.message
|
58
|
+
@finisher.terminate exit_case: :error_exit
|
59
|
+
end
|
60
|
+
end
|
50
61
|
|
51
|
-
|
52
|
-
|
53
|
-
|
62
|
+
# Thor method : running of Appifier retreive
|
63
|
+
desc 'retrieve ORIGIN', 'Retrieve an application template in user templates bundle'
|
64
|
+
long_desc <<-LONGDESC
|
54
65
|
Retrieve an application template in user templates bundle\n
|
55
|
-
with --type [RETRIEVER], precise retrieving type ex,builtin [:git,:archive]
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
66
|
+
with --type [RETRIEVER], precise retrieving type ex,builtin [:git,:archive] DEFAULT : :git
|
67
|
+
LONGDESC
|
68
|
+
option :type, type: :string, aliases: '-t', default: 'git'
|
69
|
+
def retrieve(origin)
|
70
|
+
begin
|
71
|
+
type = options[:type].to_sym
|
72
|
+
retriever = Appifier::Actors::Retriever.new type: type, origin: origin
|
73
|
+
retriever.get
|
74
|
+
@finisher.terminate exit_case: :quiet_exit
|
75
|
+
rescue RuntimeError => e
|
76
|
+
@output.error e.message
|
77
|
+
@finisher.terminate exit_case: :error_exit
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Thor method : running of Appifier Dataset Collector
|
82
|
+
desc 'collect TEMPLATE', 'Collect dataset for an application template in user templates bundle'
|
83
|
+
long_desc <<-LONGDESC
|
84
|
+
Collect dataset for an application template in user templates bundle\n
|
85
|
+
with --force => force collect, and destroy previous Dataset [DANGER]
|
86
|
+
with --file FILENAME get data from à YAML File
|
87
|
+
with --stdin get data from STDIN
|
88
|
+
|
89
|
+
LONGDESC
|
90
|
+
option :force, type: :boolean, aliases: '-F'
|
91
|
+
option :stdin, type: :boolean, aliases: '-S'
|
92
|
+
option :file, type: :string, aliases: '-f'
|
93
|
+
def collect(template)
|
94
|
+
data = nil
|
95
|
+
begin
|
96
|
+
raise "Options incompatibles --file and --stdin" if options[:stdin] and options[:file]
|
97
|
+
@output.info "Force mode, rewrite dataset if exist" if options[:force]
|
98
|
+
if options[:file]
|
99
|
+
Appifier::Actors::Collector.new template: template, dataset: open_yaml(filename: options[:file]), force: options[:force]
|
100
|
+
@output.info "Getting Dataset from file : #{options[:file]} for #{template}"
|
101
|
+
elsif options[:stdin]
|
102
|
+
@output.info "Getting Dataset from STDIN for #{template}"
|
103
|
+
begin
|
104
|
+
data = STDIN.readlines.join
|
105
|
+
rescue Interrupt
|
106
|
+
@output.error "Dataset input from STDIN cancelled"
|
107
|
+
@finisher.terminate exit_case: :interrupt
|
108
|
+
end
|
109
|
+
Appifier::Actors::Collector.new template: template, dataset: YAML::load(data), force: options[:force]
|
110
|
+
else
|
111
|
+
@output.info "Beginning interactive Dataset input for #{template}"
|
112
|
+
collector = Appifier::Actors::Collector.new template: template, force: options[:force]
|
113
|
+
collector.collect
|
114
|
+
end
|
115
|
+
@finisher.terminate exit_case: :quiet_exit
|
116
|
+
rescue RuntimeError => e
|
117
|
+
@output.error e.message
|
118
|
+
@finisher.terminate exit_case: :error_exit
|
119
|
+
rescue
|
120
|
+
|
64
121
|
end
|
122
|
+
end
|
65
123
|
|
66
124
|
end
|
67
|
-
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Appifier
|
2
|
+
module Components
|
3
|
+
class Appifile
|
4
|
+
|
5
|
+
attr_reader :content
|
6
|
+
|
7
|
+
def initialize(path:)
|
8
|
+
@path = path
|
9
|
+
@content = {}
|
10
|
+
openfile
|
11
|
+
end
|
12
|
+
|
13
|
+
def dataset_rules
|
14
|
+
@content[:template][:dataset]
|
15
|
+
end
|
16
|
+
|
17
|
+
def actions
|
18
|
+
@content[:actions]
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def openfile
|
23
|
+
raise 'Appifile not foud' unless File::exist? @path
|
24
|
+
begin
|
25
|
+
@content = YAML.load_file(@path)
|
26
|
+
rescue StandardError => e
|
27
|
+
raise e.message
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Appifier
|
4
|
+
module Components
|
5
|
+
class Templates
|
6
|
+
|
7
|
+
extend Carioca::Injector
|
8
|
+
inject service: :output
|
9
|
+
|
10
|
+
def self.list
|
11
|
+
output.info "List of avaible templates for user : #{current_user} :"
|
12
|
+
template_path = File.expand_path(Appifier::DEFAULT_TEMPLATES_PATH)
|
13
|
+
Dir.glob("#{template_path}/*").map { |item| item.delete_prefix("#{template_path}/") }.each do |template|
|
14
|
+
output.item "#{template}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.rm(template)
|
19
|
+
output.info "Removing template #{template} for user : #{current_user} :"
|
20
|
+
template_path = File.expand_path(Appifier::DEFAULT_TEMPLATES_PATH)
|
21
|
+
begin
|
22
|
+
if File::exist? "#{template_path}/#{template}"
|
23
|
+
FileUtils.rm_rf "#{template_path}/#{template}"
|
24
|
+
output.ok "Template #{template} deleted of bundle for user #{current_user}"
|
25
|
+
else
|
26
|
+
raise "Template #{template} not found in bundle for user #{current_user}"
|
27
|
+
end
|
28
|
+
rescue Errno::ENOENT
|
29
|
+
raise "Template #{template} not found in bundle for user #{current_user}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,40 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rubygems/package'
|
2
4
|
require 'zlib'
|
3
5
|
require 'open-uri'
|
4
6
|
|
5
7
|
module Appifier
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
if entry.full_name == '././@LongLink'
|
17
|
-
dest = File.join destination, entry.read.strip
|
18
|
-
next
|
19
|
-
end
|
20
|
-
dest ||= File.join destination, entry.full_name
|
21
|
-
if entry.directory?
|
22
|
-
File.delete dest if File.file? dest
|
23
|
-
FileUtils.mkdir_p dest, :mode => entry.header.mode, :verbose => false
|
24
|
-
elsif entry.file?
|
25
|
-
FileUtils.rm_rf dest if File.directory? dest
|
26
|
-
File.open dest, "wb" do |f|
|
27
|
-
f.print entry.read
|
28
|
-
end
|
29
|
-
FileUtils.chmod entry.header.mode, dest, :verbose => false
|
30
|
-
elsif entry.header.typeflag == '2' #Symlink!
|
31
|
-
File.symlink entry.header.linkname, dest
|
32
|
-
end
|
33
|
-
dest = nil
|
34
|
-
end
|
35
|
-
end
|
8
|
+
module Helpers
|
9
|
+
module Archives
|
10
|
+
def untar_gz(archive:, destination:)
|
11
|
+
source = open archive
|
12
|
+
::Gem::Package::TarReader.new(Zlib::GzipReader.new(source)) do |tar|
|
13
|
+
dest = nil
|
14
|
+
tar.each do |entry|
|
15
|
+
if entry.full_name == '././@LongLink'
|
16
|
+
dest = File.join destination, entry.read.strip
|
17
|
+
next
|
36
18
|
end
|
37
|
-
|
19
|
+
dest ||= File.join destination, entry.full_name
|
20
|
+
if entry.directory?
|
21
|
+
File.delete dest if File.file? dest
|
22
|
+
FileUtils.mkdir_p dest, mode: entry.header.mode, verbose: false
|
23
|
+
elsif entry.file?
|
24
|
+
FileUtils.rm_rf dest if File.directory? dest
|
25
|
+
File.open dest, 'wb' do |f|
|
26
|
+
f.print entry.read
|
27
|
+
end
|
28
|
+
FileUtils.chmod entry.header.mode, dest, verbose: false
|
29
|
+
elsif entry.header.typeflag == '2' # Symlink!
|
30
|
+
File.symlink entry.header.linkname, dest
|
31
|
+
end
|
32
|
+
dest = nil
|
33
|
+
end
|
38
34
|
end
|
35
|
+
end
|
39
36
|
end
|
37
|
+
end
|
40
38
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Appifier
|
4
|
+
module Helpers
|
5
|
+
module Datasets
|
6
|
+
def open_dataset(template:)
|
7
|
+
path = File::expand_path("#{DEFAULT_DATASETS_PATH}/#{template}.yml")
|
8
|
+
raise 'Dataset not found' unless File::exist? path
|
9
|
+
begin
|
10
|
+
return YAML.load_file(path)
|
11
|
+
rescue StandardError => e
|
12
|
+
raise e.message
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def check_dataset_defined?(template:)
|
17
|
+
return File::exist? File::expand_path("#{DEFAULT_DATASETS_PATH}/#{template}.yml")
|
18
|
+
end
|
19
|
+
|
20
|
+
def write_dataset(template:, data:)
|
21
|
+
path = File::expand_path("#{DEFAULT_DATASETS_PATH}/#{template}.yml")
|
22
|
+
File.open(path, 'w') { |file| file.write(data.to_yaml) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def open_yaml(filename:)
|
26
|
+
raise 'File not found' unless File::exist? filename
|
27
|
+
begin
|
28
|
+
return YAML.load_file(filename)
|
29
|
+
rescue StandardError => e
|
30
|
+
raise e.message
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/appifier/helpers/gem.rb
CHANGED
@@ -1,35 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Appifier
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
else
|
23
|
-
res = ::Gem.searcher.lib_dirs_for(spec).split('/')
|
24
|
-
end
|
25
|
-
res.pop
|
26
|
-
services_path = res.join('/').concat("/#{_file}")
|
27
|
-
return services_path if File::exist?(services_path)
|
28
|
-
return false
|
4
|
+
module Helpers
|
5
|
+
module Gem
|
6
|
+
# facility to find a file in gem path
|
7
|
+
# @param [String] _gem a Gem name
|
8
|
+
# @param [String] _file a file relative path in the gem
|
9
|
+
# @return [String] the path of the file, if found.
|
10
|
+
# @return [False] if not found
|
11
|
+
def search_file_in_gem(_gem, _file)
|
12
|
+
if ::Gem::Specification.respond_to?(:find_by_name)
|
13
|
+
begin
|
14
|
+
spec = ::Gem::Specification.find_by_name(_gem)
|
15
|
+
rescue LoadError
|
16
|
+
spec = nil
|
17
|
+
end
|
18
|
+
else
|
19
|
+
spec = ::Gem.searcher.find(_gem)
|
20
|
+
end
|
21
|
+
if spec
|
22
|
+
res = if ::Gem::Specification.respond_to?(:find_by_name)
|
23
|
+
spec.lib_dirs_glob.split('/')
|
29
24
|
else
|
30
|
-
|
25
|
+
::Gem.searcher.lib_dirs_for(spec).split('/')
|
31
26
|
end
|
32
|
-
|
27
|
+
res.pop
|
28
|
+
services_path = res.join('/').concat("/#{_file}")
|
29
|
+
return services_path if File.exist?(services_path)
|
30
|
+
|
33
31
|
end
|
32
|
+
false
|
33
|
+
end
|
34
34
|
end
|
35
|
-
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,38 +1,36 @@
|
|
1
|
-
|
2
|
-
module Helpers
|
3
|
-
module User
|
4
|
-
|
5
|
-
# return the 'root' name
|
6
|
-
# @return [String] name
|
7
|
-
def user_root
|
8
|
-
return Etc.getpwuid(0).name
|
9
|
-
end
|
1
|
+
# frozen_string_literal: true
|
10
2
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def group_root
|
20
|
-
return Etc.getgrgid(0).name
|
21
|
-
end
|
3
|
+
module Appifier
|
4
|
+
module Helpers
|
5
|
+
module User
|
6
|
+
# return the 'root' name
|
7
|
+
# @return [String] name
|
8
|
+
def user_root
|
9
|
+
Etc.getpwuid(0).name
|
10
|
+
end
|
22
11
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
return true
|
29
|
-
else
|
30
|
-
return false
|
31
|
-
end
|
32
|
-
end
|
12
|
+
# return the current user name
|
13
|
+
# @return [String] name
|
14
|
+
def current_user
|
15
|
+
Etc.getpwuid(Process.uid).name
|
16
|
+
end
|
33
17
|
|
18
|
+
# return the 'root' group name : root or wheel
|
19
|
+
# @return [String] name
|
20
|
+
def group_root
|
21
|
+
Etc.getgrgid(0).name
|
22
|
+
end
|
34
23
|
|
24
|
+
# facility to verifying if the active process run as root
|
25
|
+
# @return [Bool] status
|
26
|
+
def is_root?
|
27
|
+
case Process.uid
|
28
|
+
when 0
|
29
|
+
true
|
30
|
+
else
|
31
|
+
false
|
35
32
|
end
|
33
|
+
end
|
36
34
|
end
|
35
|
+
end
|
37
36
|
end
|
38
|
-
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash namespace
|
4
|
+
module Appifier
|
5
|
+
|
6
|
+
module Services
|
7
|
+
# Exiter namespace
|
8
|
+
class Finisher
|
9
|
+
|
10
|
+
extend Carioca::Injector
|
11
|
+
inject service: :configuration
|
12
|
+
inject service: :logger
|
13
|
+
|
14
|
+
EXIT_MAP= configuration.settings.exit_cases
|
15
|
+
|
16
|
+
|
17
|
+
def self.terminate(return_case: nil, exit_case: nil, more: nil )
|
18
|
+
raise "Case must a return or an exit" if return_case and exit_case
|
19
|
+
do_exit( exit_case: exit_case, more: more) if exit_case
|
20
|
+
do_return(return_case: return_case, more: more) if return_case
|
21
|
+
end
|
22
|
+
|
23
|
+
# exiter wrapper
|
24
|
+
# @param [Hash] options
|
25
|
+
# @option options [Symbol] :case an exit case
|
26
|
+
# @option options [String] :more a complementary string to display
|
27
|
+
def self.do_exit(exit_case: :quiet_exit, more: nil )
|
28
|
+
|
29
|
+
mess = ""
|
30
|
+
mess = EXIT_MAP[exit_case][:message] if EXIT_MAP[exit_case].include? :message
|
31
|
+
mess << " : " unless mess.empty? or not more
|
32
|
+
mess << "#{more}" if more
|
33
|
+
if EXIT_MAP[exit_case][:code] == 0 then
|
34
|
+
logger.success mess unless mess.empty?
|
35
|
+
exit 0
|
36
|
+
else
|
37
|
+
logger.fatal mess unless mess.empty?
|
38
|
+
exit EXIT_MAP[exit_case][:code]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.do_return(return_case: :status_ok, more: nil )
|
43
|
+
|
44
|
+
data = EXIT_MAP[return_case].clone
|
45
|
+
data[:status] = (data[:code]>0)? :failure : :success
|
46
|
+
data[:more] = more if more
|
47
|
+
return data
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/appifier/setup.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Appifier
|
2
4
|
class Configuration
|
3
5
|
def self.setup(force: false)
|
4
|
-
|
5
|
-
|
6
|
-
puts 'Appifier already configured'
|
6
|
+
if File.exist?(File.expand_path(Appifier::DEFAULT_CONFIG_PATH)) && !force
|
7
|
+
puts 'Appifier already configured'
|
7
8
|
else
|
8
|
-
config_file = search_file_in_gem('appifier','config/settings.yml')
|
9
|
+
config_file = search_file_in_gem('appifier', 'config/settings.yml')
|
9
10
|
path = File.expand_path(Appifier::DEFAULT_TEMPLATES_PATH)
|
10
|
-
|
11
|
-
|
11
|
+
[Appifier::DEFAULT_TEMPLATES_PATH, Appifier::DEFAULT_LOGS_PATH, Appifier::DEFAULT_CONFIG_PATH, Appifier::DEFAULT_DATASETS_PATH].each do |path|
|
12
|
+
FileUtils.mkdir_p File.expand_path(path)
|
13
|
+
end
|
14
|
+
File.open(File.expand_path("#{Appifier::DEFAULT_LOGS_PATH}/#{Appifier::DEFAULT_LOG_FILENAME}"), 'w') { |file| file.write("# Appifier : beginning of log file") }
|
15
|
+
FileUtils.cp config_file, File.expand_path(Appifier::DEFAULT_CONFIG_PATH)
|
12
16
|
puts '[OK] Building config folder and initialize settings'
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
16
|
-
end
|
20
|
+
end
|