atk_toolbox 0.0.106 → 0.0.107

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92a0b43317388c1747b105aa93b15f70a20c829ad86d439120300c8604856284
4
- data.tar.gz: 2ce1e06771e1b7cc4900269f5275ba87f32f7ca4d8afb93a236a64ba293ab36a
3
+ metadata.gz: 4e9e896c1f401e8b333baeaed5ab2f4f437a8a2201cede3d94932b1eb73fe139
4
+ data.tar.gz: 0a08f89770bf3115820d63a19670d903eef053455d5970770a5f21c361554c79
5
5
  SHA512:
6
- metadata.gz: 24a92ce26535d23bbe3b38cad85d7d2b72fcab80af72d33fd6c9d1bda2471ee4ae0e1e0f1531cebb6f1ab22ce89448aeb928125f4940b65f3218bdc1d72f885c
7
- data.tar.gz: 672dcb0e0bd74af7dac51904f298fa85ceb67a7297135b3ea0d0d78c2b091904481655c83a8ccf96187c2500887c088a45c06bf090b85c1c31e2f94e17a093ef
6
+ metadata.gz: 11a4ab36e04ac6fadaa8305400d70fc94412798abf2898d6ee724405dd2b21c32d1289e6703dba73441fc41305c200bcb534b94eb645bdc2eef43eae9f92931f
7
+ data.tar.gz: d5fa4fde8e79e2cb8b3e13fff7df7f75c7ba679a47da5fce87c8479cd9aebc188c546207c5700e555e0ff61dad7bf48800be752af1a65b68073bf15cb490d856
data/lib/atk/atk_info.rb CHANGED
@@ -17,7 +17,7 @@ class AtkPaths
17
17
  when 'info'
18
18
  return HOME/"info.yaml"
19
19
  when 'ruby'
20
- atk_path_settings = ATK.info["paths"]
20
+ atk_path_settings = Atk.info["paths"]
21
21
  if atk_path_settings.is_a?(Hash) and atk_path_settings["ruby"].is_a?(String)
22
22
  ruby_path = atk_path_settings["ruby"]
23
23
  elsif OS.is?(:mac)
@@ -38,18 +38,25 @@ class AtkPaths
38
38
  return HOME/"atk"/"installers.yaml"
39
39
  when 'installers_folder'
40
40
  return HOME/"atk"/"installers"
41
+ when 'repos'
42
+ return HOME/"atk"/"repos"
41
43
  end
42
44
  end
43
45
  end
44
46
 
45
- module ATK
47
+ module Atk
46
48
  @@atk_settings_key = "atk_settings"
49
+ def self.version
50
+ require_relative '../atk_toolbox/version.rb'
51
+ return AtkToolbox::VERSION
52
+ end
53
+
47
54
  def self.paths
48
55
  return AtkPaths
49
56
  end
50
57
 
51
58
  def self.temp_path(filename)
52
- new_path = ATK.paths[:temp]/filename
59
+ new_path = Atk.paths[:temp]/filename
53
60
  # make sure the path is empty
54
61
  FS.write("", to: new_path)
55
62
  FS.delete(new_path)
@@ -57,7 +64,7 @@ module ATK
57
64
  end
58
65
 
59
66
  def self.info
60
- settings_path = ATK.paths[:info]
67
+ settings_path = Atk.paths[:info]
61
68
  # if it doesn't exist then create it
62
69
  if not FS.exist?(settings_path)
63
70
  FS.write("#{@@atk_settings_key}: {}", to: settings_path)
@@ -75,59 +82,23 @@ module ATK
75
82
  end
76
83
 
77
84
  def self.save_info(new_hash)
78
- settings_path = ATK.paths[:info]
79
- current_settings = ATK.info
85
+ settings_path = Atk.paths[:info]
86
+ current_settings = Atk.info
80
87
  updated_settings = current_settings.merge(new_hash)
81
88
 
82
- info_data = YAML.load_file(ATK.paths[:info])
89
+ info_data = YAML.load_file(Atk.paths[:info])
83
90
  if info_file.is_a?(Hash)
84
91
  info_data[@@atk_settings_key] = updated_settings
85
92
  else
86
93
  info_data = { @@atk_settings_key => updated_settings }
87
94
  end
88
95
 
89
- FS.save(info_data, to: ATK.paths[:info], as: :yaml )
90
- end
91
-
92
- def self.simplify_package_name(source)
93
- source = source.strip
94
- # if its starts with "atk/", just remove that part
95
- source = source.sub( /^atk\//, "" )
96
- # if it starts with "https://github.com/", just remove that part
97
- source = source.sub( /^https:\/\/github.com\//, "" )
98
- return source
99
- end
100
-
101
- def self.package_name_to_url(package_name)
102
- # if its starts with "atk/", just remove that part
103
- package_name = ATK.simplify_package_name(package_name)
104
- # if the package name does not have a slash in it, then assume it is a core / approved installer
105
- if not (package_name =~ /.*\/.*/)
106
- # TODO: turn this into a check for is_core_repo?(package_name)
107
- # path_to_core_listing = ATK.paths[:core_yaml]
108
- # core = YAML.load_file(path_to_core_listing)
109
- # if core[package_name] == nil
110
- # puts "I don't see that package in the core, let me make sure I have the latest info"
111
- # download("https://raw.githubusercontent.com/aggie-tool-kit/atk/master/interface/core.yaml", as: path_to_core_listing)
112
- # core = YAML.load_file(path_to_core_listing)
113
- # end
114
- # if core[package_name] != nil
115
- # repo_url = core[package_name]["source"]
116
- # else
117
- raise "That package doesn't seem to be a core package"
118
- # end
119
- # if it does have a slash, and isn't a full url, then assume its a github repo
120
- elsif not package_name.start_with?(/https?:\/\//)
121
- repo_url = "https://github.com/"+package_name
122
- else
123
- repo_url = package_name
124
- end
125
- return repo_url
96
+ FS.save(info_data, to: Atk.paths[:info], as: :yaml )
126
97
  end
127
98
 
128
99
  def self.setup(package_name, arguments)
129
- repo_url = ATK.package_name_to_url(package_name)
130
- project_folder = ATK.info["project_folder"]
100
+ repo_url = AtkPackage.new(package_name).url
101
+ project_folder = Atk.info["project_folder"]
131
102
  # if there's no project folder
132
103
  if not project_folder
133
104
  # then use the current folder
@@ -147,11 +118,7 @@ module ATK
147
118
  if setup_command.is_a?(Code)
148
119
  setup_command.run(arguments)
149
120
  else
150
- safe_arguments = arguments.map do |each|
151
- "'"+Console.single_quote_escape(each)+"'"
152
- end
153
- console_line = setup_command+' '+(safe_arguments.join(' '))
154
- system(console_line)
121
+ system(setup_command + Console.make_arguments_appendable(arguments))
155
122
  end
156
123
  end
157
124
  puts "\n\n\n\n============================================================"
@@ -162,7 +129,145 @@ module ATK
162
129
  end
163
130
  end
164
131
 
165
- def not_yet_implemented()
132
+ def self.run(package_name, arguments=[])
133
+ the_package = AtkPackage.new(package_name)
134
+ the_package.run(arguments)
135
+ end
136
+
137
+ def self.not_yet_implemented()
166
138
  puts "Sorry, this feature is still under development"
167
139
  end
140
+ end
141
+
142
+
143
+
144
+ class AtkPackage
145
+ def initialize(package_name)
146
+ @init_name = package_name
147
+ end
148
+
149
+ def simple_name
150
+ if @simple_name == nil
151
+ source = @init_name.strip
152
+ # if its starts with "atk/", just remove that part
153
+ source = source.sub( /^atk\//, "" )
154
+ # if it starts with "https://github.com/", just remove that part
155
+ @simple_name = source.sub( /^https:\/\/github.com\//, "" )
156
+ end
157
+ return @simple_name
158
+ end
159
+
160
+ def url
161
+ if @url == nil
162
+ simple_name = self.simple_name()
163
+ # if the package name does not have a slash in it, then assume it is a core / approved installer
164
+ if not (simple_name =~ /.*\/.*/)
165
+ # TODO: turn this into a check for is_core_repo?(package_name)
166
+ # path_to_core_listing = Atk.paths[:core_yaml]
167
+ # core = YAML.load_file(path_to_core_listing)
168
+ # if core[package_name] == nil
169
+ # puts "I don't see that package in the core, let me make sure I have the latest info"
170
+ # download("https://raw.githubusercontent.com/aggie-tool-kit/atk/master/interface/core.yaml", as: path_to_core_listing)
171
+ # core = YAML.load_file(path_to_core_listing)
172
+ # end
173
+ # if core[package_name] != nil
174
+ # repo_url = core[package_name]["source"]
175
+ # else
176
+ raise "That package #{@init_name} doesn't seem to be a core package"
177
+ # end
178
+ # if it does have a slash, and isn't a full url, then assume its a github repo
179
+ elsif not simple_name.start_with?(/https?:\/\//)
180
+ repo_url = "https://github.com/"+simple_name
181
+ else
182
+ repo_url = simple_name
183
+ end
184
+ @url = repo_url
185
+ end
186
+ return @url
187
+ end
188
+
189
+ def cache_name()
190
+ if @cache_name == nil
191
+ repo_url = self.url()
192
+ require 'digest'
193
+ repo_hash = Digest::MD5.hexdigest(repo_url)
194
+ repo_name = Git.repo_name(repo_url)
195
+ @cache_name = repo_name+"_"+repo_hash
196
+ end
197
+ return @cache_name
198
+ end
199
+
200
+ def cache_location()
201
+ if @cache_location == nil
202
+ @cache_location = Atk.paths['repos']/self.cache_name
203
+ end
204
+ return @cache_location
205
+ end
206
+
207
+ def ensure_cached()
208
+ if @is_cached == nil
209
+ Git.ensure_cloned_and_up_to_date(self.cache_location, self.url)
210
+ @is_cached = true
211
+ end
212
+ end
213
+
214
+ def run(arguments)
215
+ # make sure the repo is downloaded
216
+ self.ensure_cached()
217
+ FS.in_dir(self.cache_location) do
218
+ run_command = nil
219
+ begin
220
+ run_command = Info["(installer)"]["(commands)"]["(run)"]
221
+ rescue
222
+ end
223
+ if run_command.is_a?(String)
224
+ system(run_command + Console.make_arguments_appendable(arguments))
225
+ else
226
+ #
227
+ # refine the error message
228
+ #
229
+ custom_message = ""
230
+ if run_command != nil && ( !run_command.is_a?(String) )
231
+ custom_message = "✖ the (run) command wasn't a string".red
232
+ else
233
+ yaml_exists = File.exist?(self.cache_location()/"info.yaml")
234
+
235
+ if not yaml_exists
236
+ custom_message = "✖ there was no info.yaml for this package".red
237
+ else
238
+ error_loading_yaml = false
239
+ begin
240
+ YAML.load_file("./info.yaml")
241
+ rescue
242
+ error_loading_yaml = true
243
+ end
244
+ if error_loading_yaml
245
+ custom_message = "✖ there was an issue loading the info.yaml for this package".red
246
+ else
247
+ if run_command["(installer)"] == nil
248
+ custom_message = "✖ there wasn't an (installer) key with a run command".red
249
+ end
250
+ end
251
+ end
252
+ end
253
+
254
+ # throw error for command not being runable
255
+ raise <<-HEREDOC.remove_indent
256
+
257
+
258
+ #{custom_message}
259
+
260
+ For the repository to be runnable
261
+ 1. There needs to be an #{"info.yaml".blue}
262
+ 2. The info.yaml needs to be in the root directory/folder
263
+ 3. It needs to contain:
264
+ #{"
265
+ (installer):
266
+ (commands):
267
+ (run): \"a commandline command\"
268
+ ".blue}
269
+ HEREDOC
270
+ end
271
+ end
272
+ end
168
273
  end
@@ -1,6 +1,6 @@
1
1
  require_relative '../atk_info'
2
2
 
3
- module ATK
3
+ module Atk
4
4
  def self.project(args)
5
5
  # TODO: check to make sure project exists
6
6
  if args.length == 0
@@ -159,7 +159,7 @@ module ATK
159
159
  end
160
160
  else
161
161
  puts "I don't recognized that command\nhere's the `project --help` which might get you what you're looking for:"
162
- ATK.project(["help"])
162
+ Atk.project(["help"])
163
163
  end
164
164
  end
165
165
  end
data/lib/atk/console.rb CHANGED
@@ -61,6 +61,14 @@ class TTY::Prompt
61
61
  def single_quote_escape(string)
62
62
  string.gsub(/'/, "'\"'\"'")
63
63
  end
64
+
65
+ def make_arguments_appendable(arguments)
66
+ # TODO: make sure this works on windows
67
+ safe_arguments = arguments.map do |each|
68
+ " '"+Console.single_quote_escape(each)+"'"
69
+ end
70
+ return safe_arguments.join('')
71
+ end
64
72
  end
65
73
 
66
74
  Console = TTY::Prompt.new
data/lib/atk/file_sys.rb CHANGED
@@ -200,7 +200,7 @@ module FileSys
200
200
 
201
201
  def self.path_pieces(path)
202
202
  # use this function like this:
203
- # *path, filename, extension = FS.path_peices('/Users/jeffhykin/Desktop/place1/file1.pdf')
203
+ # *path, filename, extension = FS.path_pieces('/Users/jeffhykin/Desktop/place1/file1.pdf')
204
204
  pieces = Pathname(path).each_filename.to_a
205
205
  extname = File.extname(pieces[-1])
206
206
  basebasename = pieces[-1][0...(pieces[-1].size - extname.size)]
data/lib/atk/git.rb CHANGED
@@ -18,4 +18,10 @@ module Git
18
18
  # TODO: make this a force pull
19
19
  git_repo.pull
20
20
  end
21
+
22
+ def self.repo_name(url)
23
+ require_relative './file_sys'
24
+ *folders, name, extension = FS.path_pieces('https://stackoverflow.com/questions/19072070/how-to-find-where-gem-files-are-installed')
25
+ return name
26
+ end
21
27
  end
@@ -12,9 +12,9 @@ class TTY::Prompt
12
12
  def set_command(name, code)
13
13
  if OS.is?("unix")
14
14
  exec_path = "/usr/local/bin/#{name}"
15
- local_place = ATK.temp_path(name)
15
+ local_place = Atk.temp_path(name)
16
16
  # add the hash bang
17
- hash_bang = "#!#{ATK.paths[:ruby]}\n"
17
+ hash_bang = "#!#{Atk.paths[:ruby]}\n"
18
18
  # create the file
19
19
  FS.write(hash_bang+code, to: local_place)
20
20
  # copy to command folder
@@ -239,22 +239,22 @@ class Info
239
239
  HEREDOC
240
240
  end
241
241
  rescue => exception
242
- puts "\n\nI'm having trouble loading the info.yaml file. Here's the error:\n"
242
+ puts "\n\nI'm having trouble loading the info.yaml file. Here's the error:\n".red
243
243
  raise exception
244
244
  end
245
245
  else
246
- raise "\n\nCouldn't find an info.yaml file in #{Dir.pwd}"
246
+ raise "\n\nCouldn't find an info.yaml file in #{Dir.pwd}".red
247
247
  end
248
248
  @@project = @@data['(project)']
249
249
  if @@project == nil
250
250
  # TODO: maybe change this to be optional in the future and have default settings
251
- raise "\n\nThere is no (project): key in the info.yaml\n(so ATK is unable to parse the project settings)"
251
+ raise "\n\nThere is no (project): key in the info.yaml\n(so ATK is unable to parse the project settings)".red
252
252
  end
253
253
 
254
254
  @@settings = @@project['(advanced_setup)']
255
255
  if @@settings == nil
256
256
  # TODO: maybe change this to be optional in the future and have default settings
257
- raise "\n\nThere is no (advanced_setup): key in the (project) of the info.yaml\n(so ATK is unable to parse the project settings)"
257
+ raise "\n\nThere is no (advanced_setup): key in the (project) of the info.yaml\n(so ATK is unable to parse the project settings)".red
258
258
  end
259
259
  Info.parse_advanced_setup(@@settings, @@settings)
260
260
  @@dependencies = @@settings['(dependencies)']
@@ -309,7 +309,7 @@ class Info
309
309
  loop do
310
310
  # if all folders exhausted
311
311
  if folders.size == 0
312
- raise <<-HEREDOC.remove_indent
312
+ raise <<-HEREDOC.remove_indent.red
313
313
 
314
314
  Couldn't find an info.yaml in the current directory or any parent directory
315
315
  #{Dir.pwd}
@@ -1,3 +1,3 @@
1
1
  module AtkToolbox
2
- VERSION = '0.0.106'
2
+ VERSION = '0.0.107'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atk_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.106
4
+ version: 0.0.107
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Hykin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-07 00:00:00.000000000 Z
11
+ date: 2019-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zip
@@ -105,7 +105,6 @@ files:
105
105
  - lib/atk/git.rb
106
106
  - lib/atk/online.rb
107
107
  - lib/atk/os.rb
108
- - lib/atk/output.rb
109
108
  - lib/atk/package_managers.rb
110
109
  - lib/atk/remove_indent.rb
111
110
  - lib/atk/set_command.rb
data/lib/atk/output.rb DELETED
@@ -1,5 +0,0 @@
1
- # Functions to be used for consistent output to the user
2
-
3
- module ATKIO
4
-
5
- end