atk_toolbox 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7be1f743af7afd55414c41e1a58373c22b922e891766d41a08027ca91c85662b
4
+ data.tar.gz: 9957d137a35201bb5f6b9302b4618f80a23af7535bdcd80f04729148be349674
5
+ SHA512:
6
+ metadata.gz: c778630a2ffd8c94d494a6b913ae5b207e4d78624b0f56a8806cdd133526f8ecbf9229406232658d830b4b36f438594706185e1c1df7c22b068f48abb2701451
7
+ data.tar.gz: 933bb35bb46fb63e677aa2f1e600dc81a58b2bfd20acd6a54ac5e43f79195b475906863f8d8164e9283cd7807037766d80da6326060dd82d31bb495b149ad727
data/lib/atk/cmd.rb ADDED
@@ -0,0 +1,7 @@
1
+ class String
2
+ # add a - operator to strings that makes it behave like a system() call
3
+ # but it shows stderr
4
+ def -@
5
+ return Process.wait(Process.spawn(self))
6
+ end
7
+ end
@@ -0,0 +1,39 @@
1
+ def download(input_1=nil, from:nil, url:nil, as:nil)
2
+ require 'open-uri'
3
+ # argument checking
4
+ # if only one argument, either input_1 or url
5
+ if ((input_1!=nil) != (url!=nil)) && (from==nil) && (as==nil)
6
+ # this covers:
7
+ # download 'site.com/file'
8
+ the_url = url || input_1
9
+ file_name = the_url.match /(?<=\/)[^\/]+\z/
10
+ file_name = file_name[0]
11
+ elsif (as != nil) && ((input_1!=nil)!=(url!=nil))
12
+ # this covers:
13
+ # download 'site.com/file' as:'file'
14
+ # download url:'site.com/file' as:'file'
15
+ the_url = url || input_1
16
+ file_name = as
17
+ elsif ((from!=nil) != (url!=nil)) && input_1!=nil
18
+ # this covers:
19
+ # download 'file' from:'site.com/file'
20
+ # download 'file' url:'site.com/file'
21
+ the_url = from || url
22
+ file_name = input_1
23
+ else
24
+ message_ = "I'm not sure how you're using the download function.\n"
25
+ message_ << "Please use one of the following methods:\n"
26
+ message_ << " download 'site.com/file'\n"
27
+ message_ << " download 'site.com/file', as:'file'\n"
28
+ message_ << " download url:'site.com/file', as:'file'\n"
29
+ message_ << " download 'file', from:'site.com/file'\n"
30
+ message_ << " download 'file', url:'site.com/file'\n"
31
+ raise message_
32
+ end#if
33
+ #end argument checking
34
+
35
+ # actually download the file
36
+ open(file_name, 'wb') do |file|
37
+ file << open(the_url).read
38
+ end
39
+ end
data/lib/atk/os.rb ADDED
@@ -0,0 +1,72 @@
1
+ # every OS version is a perfect heirarchy of versions and sub verisons that may or may not be chronological
2
+ # every OS gets it's own custom heirarchy since there are issues like x86 support and "student edition" etc
3
+ # the plan is to release this heirarchy on its own repo, and to get pull requests for anyone who wants to add their own OS
4
+ os_heirarchy = {
5
+ "windows" => {
6
+ "10" => {},
7
+ "8.1" => {},
8
+ "8" => {},
9
+ "7" => {},
10
+ "vista" => {},
11
+ "xp" => {},
12
+ "95" => {},
13
+ },
14
+ "mac" => {
15
+ "mojave" => {},
16
+ "high sierra" => {},
17
+ "sierra" => {},
18
+ "el capitan" => {},
19
+ "yosemite" => {},
20
+ "mavericks" => {},
21
+ "mountain lion" => {},
22
+ "lion" => {},
23
+ "snow leopard" => {},
24
+ "leopard" => {},
25
+ "tiger" => {},
26
+ "panther" => {},
27
+ "jaguar" => {},
28
+ "puma" => {},
29
+ "cheetah" => {},
30
+ "kodiak" => {},
31
+ },
32
+ "ubuntu" => {},
33
+ "arch" => {},
34
+ "manjaro" => {},
35
+ "deepin" => {},
36
+ "centos" => {},
37
+ "debian" => {},
38
+ "fedora" => {},
39
+ "elementary" => {},
40
+ "zorin" => {},
41
+ "raspian" => {},
42
+ "android" => {},
43
+ }
44
+
45
+ #
46
+ # Groups
47
+ #
48
+ # the groups are the pratical side of the OS, they describe the OS rather than fit it prefectly into a heirarchy
49
+ module OS
50
+ # TODO: have the version pick one of the verions in the os_heirarchy according to the current OS
51
+ def self.version
52
+ raise "not yet implemented"
53
+ end
54
+
55
+ def self.is?(adjective)
56
+ # summary:
57
+ # this is a function created for convenience, so it doesn't have to be perfect
58
+ # you can use it to ask about random qualities of the current OS and get a boolean response
59
+ # convert to string (if its a symbol)
60
+ adjective = adjective.to_s
61
+ case adjective
62
+ when 'windows'
63
+ return (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
64
+ when 'mac'
65
+ return (/darwin/ =~ RUBY_PLATFORM) != nil
66
+ when 'linux'
67
+ return (not OS.is?(:windows)) && (not OS.is?(:mac))
68
+ when 'unix'
69
+ return OS.is?(:windows) || OS.is?(:mac)
70
+ end
71
+ end
72
+ end
data/lib/atk/output.rb ADDED
@@ -0,0 +1,5 @@
1
+ # Functions to be used for consistent output to the user
2
+
3
+ module ATKIO
4
+
5
+ end
@@ -0,0 +1,111 @@
1
+ class PackageManager
2
+ def self.installed?(app_name, version=nil)
3
+ puts 'This has not been implemented yet'
4
+ end
5
+
6
+ def self.install(app_name, version=nil)
7
+ puts 'This has not been implemented yet'
8
+ end
9
+
10
+ def self.uninstall(app_name, version=nil)
11
+ puts 'This has not been implemented yet'
12
+ end
13
+
14
+ def self.update_app(app_name)
15
+ puts 'This has not been implemented yet'
16
+ end
17
+ end
18
+
19
+ class Scoop < PackageManager
20
+
21
+ @@scoop_dir = ENV['SCOOP'] or '#{Dir.home}/scoop'
22
+ @@scoop_global_dir = ENV['SCOOP_GLOBAL'] or '#{ENV["ProgramData"]}/scoop'
23
+
24
+ def self.base_dir(global=false)
25
+ return global ? @@scoop_global_dir : @@scoop_dir
26
+ end
27
+
28
+ def self.apps_dir(global=false)
29
+ root = base_dir(global)
30
+ return '#{root}/apps'
31
+ end
32
+
33
+ def self.app_dir(app_name, global=false)
34
+ root = apps_dir(global)
35
+ return '#{root}/#{app_name}'
36
+ end
37
+
38
+ def self.add_bucket(bucket_name, bucket_location=nil)
39
+ if (bucket_location == nil)
40
+ `scoop bucket add #{bucket_name}`
41
+ else
42
+ `scoop bucket add #{bucket_name} #{bucket_location}`
43
+ end
44
+ end
45
+
46
+ def self.switch_app_version(app_name, version=nil)
47
+ if(version == nil)
48
+ `scoop reset #{app_name}`
49
+ else
50
+ `scoop reset #{app_name}@#{version}`
51
+ end
52
+ end
53
+
54
+ # Overriden Methods
55
+
56
+ def self.installed?(app_name, version=nil)
57
+ # if(global == nil) { return (installed?(app_name, true) or installed? (app_name, false)) }
58
+ # Dependencies of the format "bucket/dependency" install in a directory of form
59
+ # "dependency". So we need to extract the bucket from the name and only give the app
60
+ # name to is_directory
61
+ # TODO: add support for checking if version is installed
62
+ app_name = app_name.split("/")[-1]
63
+ return File.directory?(File.expand_path(app_dir(app_name)))
64
+ end
65
+
66
+ def self.install(app_name, version=nil)
67
+ if(installed?(app_name))
68
+ puts 'You already have #{app_name} installed'
69
+ return
70
+ end
71
+
72
+ if(version == nil)
73
+ `scoop install #{app_name}`
74
+ else
75
+ `scoop install #{app_name}@#{version}`
76
+ end
77
+ end
78
+
79
+ def self.uninstall(app_name, version=nil)
80
+ if(app_name == 'scoop')
81
+ puts 'You are trying to uninstall scoop which is a dependency for ATK. We will not let you uninstall Scoop through ATK'
82
+ return
83
+ end
84
+
85
+ if(version == nil)
86
+ `scoop uninstall #{app_name}`
87
+ else
88
+ `scoop uninstall #{app_name}@#{version}`
89
+ end
90
+ end
91
+
92
+ def self.update_app(app_name)
93
+ `scoop update #{app_name}`
94
+ end
95
+ end
96
+
97
+ class Homebrew < PackageManager
98
+
99
+ end
100
+
101
+ class Apt < PackageManager
102
+
103
+ end
104
+
105
+ class Pacman < PackageManager
106
+
107
+ end
108
+
109
+ class Yum < PackageManager
110
+
111
+ end
@@ -0,0 +1,248 @@
1
+ #!/usr/bin/ruby
2
+ require "yaml"
3
+ require_relative './cmd'
4
+ require_relative './os'
5
+
6
+ #
7
+ # Create loaders for ruby code literal and console code literal
8
+ #
9
+ class Code
10
+ @@tags = {}
11
+ def self.tags
12
+ return @@tags
13
+ end
14
+
15
+ def self.register_as(yaml_tag_name)
16
+ YAML.add_tag(yaml_tag_name, self.class)
17
+ Code.tags[yaml_tag_name] = self.class
18
+ end
19
+
20
+ def init_with(coder)
21
+ @value = coder.scalar
22
+ end
23
+
24
+ def run
25
+ # TODO: improve this error message
26
+ raise "This needs to be overloaded"
27
+ end
28
+
29
+ def to_s
30
+ puts @value
31
+ end
32
+ end
33
+
34
+ #
35
+ # Ruby Code/Evaluation
36
+ #
37
+ class RubyCode < Code
38
+ def run
39
+ eval(@value)
40
+ end
41
+ end
42
+ RubyCode.register_as('!language/ruby')
43
+ # add an evaluater for ruby code
44
+ ruby_evaluation_tag = 'evaluate/ruby'
45
+ Code.tags[ruby_evaluation_tag] = "evaluate"
46
+ YAML.add_domain_type("", ruby_evaluation_tag) do |type, value|
47
+ if value.is_a? String
48
+ eval(value)
49
+ else
50
+ value
51
+ end
52
+ end
53
+
54
+ #
55
+ # Console Code
56
+ #
57
+ # TODO: add support for console code
58
+ class ConsoleCode < Code
59
+ def run
60
+ -"#{@value}"
61
+ end
62
+ end
63
+ ConsoleCode.register_as('!language/console')
64
+ #
65
+ # project info (specific to operating sytem)
66
+ #
67
+ # setting/getting values via an object (instead of opening/closing a file)
68
+ class Info
69
+ # main keys
70
+ # (using_atk_version)
71
+ # (project)
72
+ # (advanced_setup)
73
+ # any-level project detail keys:
74
+ # (dependencies)
75
+ # (project_commands)
76
+ # (structures)
77
+ # (local_package_managers)
78
+ # (put_new_dependencies_under)
79
+ # (environment_variables)
80
+
81
+ # TODO: figure out a way of adding write access to the info.yaml
82
+ # TODO: if there is no (using_atk_version), then add one with the current version
83
+ # TODO:
84
+ # if there is no (project) or no (advanced_setup), then assume its not an ATK setup
85
+ # (quit somehow depending on how this code was invoked)
86
+ # TODO:
87
+ # if there are ()'s in a key inside of the (project)
88
+ # but the key isn't part of the standard keys
89
+ # then issue a warning, and give them a suggestion to the next-closest key
90
+
91
+ @@data = nil
92
+ @@valid_variables = ['context', 'os']
93
+ @@valid_operators = ['is']
94
+
95
+ # TODO: write tests for this function
96
+ def self.parse_when_statment(statement)
97
+ # remove the 'when' and paraentheses
98
+ expression = statement.sub( /when\((.*)\)/, "\\1" )
99
+ # create the pattern for finding variables
100
+ variable_pattern = /\A\s*--(?<variable>#{@@valid_variables.join('|')})\s+(?<operator>#{@@valid_operators.join('|')})\s+(?<value>.+)/
101
+ groups = expression.match(variable_pattern)
102
+ if groups == nil
103
+ raise "\n\nIn the info.yaml file\nI couldn't any of the variables in #{statement}\nMake sure the format is:\n when( --VARIABLE *space* OPERATOR *space* VALUE )\nvalid variables are: #{valid_variables}\nvalid operators are: #{valid_operators}"
104
+ end
105
+ value = groups['value'].strip
106
+
107
+ substitutions = ->(value) do
108
+ value.gsub!( /\\'/, "'" )
109
+ value.gsub!( /\\"/, '"' )
110
+ value.gsub!( /\\n/, "\n" )
111
+ value.gsub!( /\\t/, "\t" )
112
+ end
113
+
114
+ # if it has single quotes
115
+ if value =~ /'.+'/
116
+ value.sub!( /'(.+)'/, "\\1" )
117
+ substitutions[value]
118
+ # if double quotes
119
+ elsif value =~ /".+"/
120
+ value.sub!( /"(.+)"/, "\\1" )
121
+ substitutions[value]
122
+ else
123
+ raise "\n\nIn the info.yaml file\nthe value: #{value} in the statment:\n#{statement}\n\nwas invalid. It probably needs single or double quotes around it"
124
+ end
125
+
126
+ return {
127
+ variable: groups['variable'],
128
+ operator: groups['operator'],
129
+ value: value
130
+ }
131
+ end
132
+
133
+ def self.evaluate_when_condition(data)
134
+ case data[:variable]
135
+ when 'context'
136
+ raise "\n\ncontext functionality has not been implemented yet"
137
+ when 'os'
138
+ case data[:operator]
139
+ when 'is'
140
+ return OS.is?(data[:value])
141
+ else
142
+ raise "unknown operator: #{data[:operator]}"
143
+ end
144
+ else
145
+ raise "\n\nunknown variable: #{data[:variable]}"
146
+ end
147
+ end
148
+
149
+ # def self.parse_language_evaluations(value)
150
+ # if value.is_a?(Evaluation)
151
+ # return Info.parse_language_evaluations(value.run())
152
+ # elsif value.is_a?(Hash)
153
+ # new_hash = {}
154
+ # for each_key, each_value in value
155
+ # new_hash[each_key] = Info.parse_language_evaluations(each_value)
156
+ # end
157
+ # return new_hash
158
+ # elsif value.is_a?(Array)
159
+ # new_array = []
160
+ # for each in value
161
+ # new_array.push(Info.parse_language_evaluations(each))
162
+ # end
163
+ # return new_array
164
+ # else
165
+ # return value
166
+ # end
167
+ # end
168
+
169
+ def self.parse_advanced_setup(unchecked_hashmap, current_project_settings)
170
+ for each_key, each_value in unchecked_hashmap.clone()
171
+ case
172
+ # check for yaml-when statements
173
+ when each_key =~ /\Awhen\(.*\)\z/ && each_value.is_a?(Hash)
174
+ statement_data = Info.parse_when_statment(each_key)
175
+ # if the when condition was true
176
+ if Info.evaluate_when_condition(statement_data)
177
+ # recursively parse the tree
178
+ Info.parse_advanced_setup(each_value, current_project_settings)
179
+ end
180
+ # transfer all the normal keys to the current_project_settings
181
+ else
182
+ current_project_settings[each_key] = each_value
183
+ end
184
+ end
185
+ end
186
+
187
+ def self.load_if_needed
188
+ # if the data hasn't been loaded then load it first
189
+ if @@data == nil
190
+ Info.load_from_yaml
191
+ end
192
+ end
193
+
194
+ def self.load_from_yaml
195
+ # this function sets up:
196
+ # @@data
197
+ # @@project
198
+ # @@settings
199
+ # and also
200
+ # @@dependencies
201
+ # @@project_commands
202
+ # @@structures
203
+ # @@local_package_managers
204
+ # @@put_new_dependencies_under
205
+ # @@environment_variables
206
+
207
+ # get the local yaml file
208
+ # TODO: have this search the parent dir's to find it
209
+ @@data = YAML.load_file("./info.yaml")
210
+ @@project = @@data['(project)']
211
+ if @@project == nil
212
+ # TODO: maybe change this to be optional in the future and have default settings
213
+ raise "\n\nThere is no (project): key in the info.yaml\n(so ATK is unable to parse the project settings)"
214
+ end
215
+ # TODO: remove this
216
+ # @@project = Info.parse_language_evaluations(@@project)
217
+
218
+ @@settings = @@project['(advanced_setup)']
219
+ if @@settings == nil
220
+ # TODO: maybe change this to be optional in the future and have default settings
221
+ 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)"
222
+ end
223
+ Info.parse_advanced_setup(@@settings, @@settings)
224
+ @@dependencies = @@settings['(dependencies)']
225
+ @@project_commands = @@settings['(project_commands)']
226
+ @@structures = @@settings['(structures)']
227
+ @@local_package_managers = @@settings['(local_package_managers)']
228
+ @@put_new_dependencies_under = @@settings['(put_new_dependencies_under)']
229
+ @@environment_variables = @@settings['(environment_variables)']
230
+ end
231
+
232
+ # accessors
233
+ def self.data() Info.load_if_needed; return @@data end
234
+ def self.project() Info.load_if_needed; return @@project end
235
+ def self.settings() Info.load_if_needed; return @@settings end
236
+ def self.dependencies() Info.load_if_needed; return @@dependencies end
237
+ def self.project_commands() Info.load_if_needed; return @@project_commands end
238
+ def self.structures() Info.load_if_needed; return @@structures end
239
+ def self.local_package_managers() Info.load_if_needed; return @@local_package_managers end
240
+ def self.put_new_dependencies_under() Info.load_if_needed; return @@put_new_dependencies_under end
241
+ def self.environment_variables() Info.load_if_needed; return @@environment_variables end
242
+
243
+ # read access to the yaml file
244
+ def self.[](element)
245
+ Info.load_if_needed
246
+ return @@data[element.to_s]
247
+ end
248
+ end
@@ -0,0 +1,6 @@
1
+ require_relative './atk/cmd'
2
+ require_relative './atk/download'
3
+ require_relative './atk/os'
4
+ require_relative './atk/output'
5
+ require_relative './atk/package_managers'
6
+ require_relative './atk/yaml_info_parser'
data/test/info.yaml ADDED
@@ -0,0 +1,68 @@
1
+ # Example of Project settings
2
+ (using_atk_version): 1.0
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
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
24
+ # 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
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'):
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
+
59
+ # # caveats for a different context
60
+ # when(--context is 'testing'):
61
+ # (environment_variables):
62
+ # CMAKE_LIB: "testing"
63
+ # (project_commands):
64
+ # run: node tests.rb
65
+
66
+ # when(--os is 'windows'):
67
+ # (environment_variables):
68
+ # CMAKE_LIB: "C:\\testing"
data/test/main.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'atk_toolbox'
2
+
3
+ Dir.chdir __dir__
4
+
5
+ p Info.project_commands
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atk_toolbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Hykin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-06-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ''
14
+ email: jeff.hykin@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/atk/cmd.rb
20
+ - lib/atk/download.rb
21
+ - lib/atk/os.rb
22
+ - lib/atk/output.rb
23
+ - lib/atk/package_managers.rb
24
+ - lib/atk/yaml_info_parser.rb
25
+ - lib/atk_toolbox.rb
26
+ - test/info.yaml
27
+ - test/main.rb
28
+ homepage: http://github.com//atk-toolbox
29
+ licenses:
30
+ - CC-BY-ND-4.0
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.7.3
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: The Ruby gem for all the standard tools ATK uses internally
52
+ test_files: []