atk_toolbox 0.0.35 → 0.0.36

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: 4f919029a07ca905076c275a25b5095c8e51bfeab821cdc41c2992dd4b121c5b
4
- data.tar.gz: 2075c6ba4538e2fe0f78e33ff4a3ad0f60bb0c67cbb72c8426bfc1dd0318abf8
3
+ metadata.gz: '05948ecaeb302fe7fac8223a0c9236c506c6f42b5f61f70ae599a337de1f1a82'
4
+ data.tar.gz: 332cdebeb6df4e8b3ed5d36078b1b9ec327b82c0dd2d6336f22509ed3a9d8226
5
5
  SHA512:
6
- metadata.gz: 3c94d50770aaa1215b2283091f2b94c4eb5e490c3b6e84c96ec666e107ae9b0a122bbe993cf31a6f7cd4c4674e74f2d3a042a6f1a609e548191dc9c256a48273
7
- data.tar.gz: 3dab6e99578a1b3f7d4212e9bbcebee9559acbd0e7b5ffd2acd14af17d348cdafcfdf1106c38b65635feed28437a1cd7c48e909ab5695df6233c9370702175a4
6
+ metadata.gz: f1b9926571e1a245bedaa1f5af9dbe40e07d41c05daf2128cb775e7e4cf0a5f97899252a877937c8fb683d1c4e29fa2f4f183966ddfcc461b370c30df1314f5f
7
+ data.tar.gz: 1ef3ed00db4fa1ac0d59c79b42983684939b212f8d2a6a4777d179293193505f46d41833165b41c400e03444e3d6c33da53daaf5857ccf2f1718ad31b37f817d
@@ -2,6 +2,8 @@
2
2
  require "yaml"
3
3
  require_relative './cmd'
4
4
  require_relative './os'
5
+ require_relative './extra_file_utils'
6
+ require_relative '../yaml_edit/yaml_edit.rb'
5
7
  require 'fileutils'
6
8
 
7
9
  #
@@ -97,7 +99,7 @@ class Info
97
99
 
98
100
  def self.init
99
101
  # copy the default yaml to the current dir
100
- FileUtils.cp(File.join(__dir__, "default_info.yaml"), File.join(Dir.pwd, "info.yaml"))
102
+ FileUtils.cp(__dir__/"default_info.yaml", Dir.pwd/"info.yaml")
101
103
  end
102
104
 
103
105
  # TODO: write tests for this function
@@ -215,7 +217,7 @@ class Info
215
217
  # get the local yaml file
216
218
  # TODO: have this search the parent dir's to find it
217
219
  begin
218
- @@data = YAML.load_file("./info.yaml")
220
+ @@data = YAML.load_file(Info.source_path)
219
221
  rescue => exception
220
222
  puts "Couldn't find an info.yaml file in #{Dir.pwd}"
221
223
  exit
@@ -256,4 +258,18 @@ class Info
256
258
  Info.load_if_needed
257
259
  return @@data[element.to_s]
258
260
  end
259
- end
261
+
262
+ def self.source_path()
263
+ return "."/"info.yaml"
264
+ end
265
+
266
+ def self.set_key(key_list, new_value)
267
+ path = Info.source_path
268
+ IO.write(path, YAML.set_key(IO.read(path), key_list, new_value))
269
+ end
270
+
271
+ def self.remove_key(key_list, new_value)
272
+ path = Info.source_path
273
+ IO.write(path, YAML.remove_key(IO.read(path), key_list))
274
+ end
275
+ end
@@ -1,3 +1,3 @@
1
1
  module AtkToolbox
2
- VERSION = '0.0.35'
2
+ VERSION = '0.0.36'
3
3
  end
@@ -2,6 +2,7 @@ require_relative '../atk/os'
2
2
  require_relative '../atk/remove_indent'
3
3
  require 'open3'
4
4
  require 'json'
5
+ require 'yaml'
5
6
 
6
7
  def execute_with_local_python(python_file_path, *args)
7
8
  # save the current directory
@@ -15,22 +16,31 @@ def execute_with_local_python(python_file_path, *args)
15
16
  return [stdout_str, stderr_str, status]
16
17
  end
17
18
 
18
- def set_key(yaml_string, key_list, new_value)
19
- # run the python file with the virtual environment
20
- stdout_str, stderr_str, status = execute_with_local_python('set_key.py', yaml_string, key_list.to_json, new_value.to_json)
21
- if not status.success?
22
- raise "\n\nFailed to set key in yaml file:\n#{stderr_str}"
19
+ module YAML
20
+ def set_key(yaml_string, key_list, new_value)
21
+ if not key_list.is_a?(Array)
22
+ raise "when using YAML.set_key, the second argument needs to be a list of keys"
23
+ end
24
+ # run the python file with the virtual environment
25
+ stdout_str, stderr_str, status = execute_with_local_python('set_key.py', yaml_string, key_list.to_json, new_value.to_json)
26
+ if not status.success?
27
+ raise "\n\nFailed to set key in yaml file:\n#{stderr_str}"
28
+ end
29
+ return stdout_str
23
30
  end
24
- return stdout_str
25
- end
26
31
 
27
- def remove_key(yaml_string, key_list)
28
- # run the python file with the virtual environment
29
- stdout_str, stderr_str, status = execute_with_local_python('remove_key.py', yaml_string, key_list.to_json)
30
- if not status.success?
31
- raise "\n\nFailed to remove key in yaml file:\n#{stderr_str}"
32
+ def remove_key(yaml_string, key_list)
33
+ if not key_list.is_a?(Array)
34
+ raise "when using YAML.remove_key, the second argument needs to be a list of keys"
35
+ end
36
+ # run the python file with the virtual environment
37
+ stdout_str, stderr_str, status = execute_with_local_python('remove_key.py', yaml_string, key_list.to_json)
38
+ if not status.success?
39
+ raise "\n\nFailed to remove key in yaml file:\n#{stderr_str}"
40
+ end
41
+ return stdout_str
32
42
  end
33
- return stdout_str
43
+ module_function :remove_key, :set_key
34
44
  end
35
45
 
36
46
  # yaml_test_string = <<-HEREDOC
data/test/info.yaml CHANGED
@@ -1,68 +1,67 @@
1
1
  # Example of Project settings
2
2
  (using_atk_version): 1.0
3
3
  (project):
4
- name: The ATK Repo
5
- description: Blah
6
- homepage: www.blah.com
7
-
8
- auto_generated_commands: &auto_generated_commands !evaluate/ruby |
9
- commands = {}
10
- # check for a scripts directory
11
- script_file_paths = Dir["scripts/*"]
12
- for each in script_file_paths
13
- commands[File.basename(each, ".*")] = "./#{each}"
14
- end
15
- commands
16
-
17
- basic_setup: &basic_setup_reference
18
- (project_commands): &basic_commands
4
+ name: The ATK Repo
5
+ description: Blah
6
+ homepage: www.blah.com
7
+
8
+ auto_generated_commands: &auto_generated_commands !evaluate/ruby |
9
+ commands = {}
10
+ # check for a scripts directory
11
+ script_file_paths = Dir["scripts/*"]
12
+ for each in script_file_paths
13
+ commands[File.basename(each, ".*")] = "./#{each}"
14
+ end
15
+ commands
16
+
17
+ basic_setup: &basic_setup_reference
18
+ (project_commands): &basic_commands
19
19
  # auto-insert the !lang/console if they dont put one
20
- run: !language/ruby
21
- puts "hi"
22
- stop: \`pkill node`
23
- compile: gcc *.cpp
20
+ run: !language/ruby puts "hi"
21
+ stop: \`pkill node`
22
+ compile: gcc *.cpp
24
23
  # TODO: add inline support for doing things like auto-generating commands
25
- ? !inline [ *auto_generated_commands ]
26
- (environment_variables):
27
- JAVA_VERSION: "8.9"
28
- (structures):
29
- npm-package: v1.0.0
30
- vs-code-package: v1.0.0
31
- git-repo: v1.0.0
32
- (dependencies): &base_dependencies
33
- python3: v3.7.0
34
- node: v11.11.0
35
- npm: v6.7.0
36
- git: v2.21.0
37
-
38
- (advanced_setup):
39
- (local_package_managers): ['npm', 'pip'] # by default the local package managers are always here
40
- (put_new_dependencies_under): [ '(project)', 'basic_info', '(dependencies)' ]
41
- <<: *basic_setup_reference # this injects all the (basic_setup) here
24
+ [*auto_generated_commands]:
25
+ (environment_variables):
26
+ JAVA_VERSION: '8.9'
27
+ (structures):
28
+ npm-package: v1.0.0
29
+ vs-code-package: v1.0.0
30
+ git-repo: v1.0.0
31
+ (dependencies): &base_dependencies
32
+ python3: v3.7.0
33
+ node: v11.11.0
34
+ npm: v6.7.0
35
+ git: v2.21.0
36
+
37
+ (advanced_setup):
38
+ (local_package_managers): [npm, pip] # by default the local package managers are always here
39
+ (put_new_dependencies_under): [(project), basic_info, (dependencies)]
40
+ <<: *basic_setup_reference
41
+ # this injects all the (basic_setup) here
42
42
  # caveats for a specific OS
43
- when(--os is 'mac'):
44
- (dependencies):
45
- <<: *base_dependencies
46
- python2: v2.7
47
-
48
- when(--os is 'windows'):
49
- (project_commands):
50
- <<: *basic_commands
51
- show_files: dir # this is a custom command specific to windows
52
- when(--os is 'linux'):
43
+ when(--os is 'mac'):
44
+ (dependencies):
45
+ <<: *base_dependencies
46
+ python2: v2.7
47
+
48
+ when(--os is 'windows'):
49
+ (project_commands):
50
+ <<: *basic_commands
51
+ show_files: dir # this is a custom command specific to windows
52
+ when(--os is 'linux'):
53
53
  # caveats for a specific OS sub-version
54
- when(--os is 'arch'):
55
- (project_commands):
56
- <<: *basic_commands # this injects all the (project_commands) here
57
- my_ip_address: "ip" # this is a custom command specific to arch linux
58
-
54
+ when(--os is 'arch'):
55
+ (project_commands):
56
+ <<: *basic_commands
57
+ # this injects all the (project_commands) here
58
+ my_ip_address: ip # this is a custom command specific to arch linux
59
59
  # # caveats for a different context
60
60
  # when(--context is 'testing'):
61
61
  # (environment_variables):
62
62
  # CMAKE_LIB: "testing"
63
63
  # (project_commands):
64
64
  # run: node tests.rb
65
-
66
65
  # when(--os is 'windows'):
67
66
  # (environment_variables):
68
67
  # CMAKE_LIB: "C:\\testing"
data/test/main.rb CHANGED
@@ -2,4 +2,4 @@ require_relative '../lib/atk_toolbox'
2
2
 
3
3
  Dir.chdir __dir__
4
4
 
5
- p Info.project_commands
5
+ Info.set_key(["test"], "it worked?")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atk_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.35
4
+ version: 0.0.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Hykin