atk_toolbox 0.0.126 → 0.0.127

Sign up to get free protection for your applications and to get access to all the features.
data/lib/atk/os.rb CHANGED
@@ -19,11 +19,11 @@ end
19
19
  #
20
20
  # Groups
21
21
  #
22
- # the groups are the pratical side of the OS, they describe the OS rather than fit it prefectly into a heirarchy
23
22
  module OS
24
- # TODO: have the version pick one of the verions in the os_heirarchy according to the current OS
25
- def self.version
26
- raise "not yet implemented"
23
+
24
+ # create a singleton class
25
+ class << (OS::CACHE = Object.new)
26
+ attr_accessor :is_windows, :is_mac, :is_linux, :is_unix, :is_debian, :is_ubuntu
27
27
  end
28
28
 
29
29
  def self.is?(adjective)
@@ -34,17 +34,35 @@ module OS
34
34
  adjective = adjective.to_s.downcase
35
35
  case adjective
36
36
  when 'windows'
37
- return (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
37
+ if OS::CACHE::is_windows == nil
38
+ OS::CACHE::is_windows = (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
39
+ end
40
+ return OS::CACHE::is_windows
38
41
  when 'mac'
39
- return (/darwin/ =~ RUBY_PLATFORM) != nil
42
+ if OS::CACHE::is_mac == nil
43
+ OS::CACHE::is_mac = (/darwin/ =~ RUBY_PLATFORM) != nil
44
+ end
45
+ return OS::CACHE::is_mac
40
46
  when 'linux'
41
- return (not OS.is?(:windows)) && (not OS.is?(:mac))
47
+ if OS::CACHE::is_linux == nil
48
+ OS::CACHE::is_linux = (not OS.is?(:windows)) && (not OS.is?(:mac))
49
+ end
50
+ return OS::CACHE::is_linux
42
51
  when 'unix'
43
- return not( OS.is?(:windows))
52
+ if OS::CACHE::is_unix == nil
53
+ OS::CACHE::is_unix = not(OS.is?(:windows))
54
+ end
55
+ return OS::CACHE::is_unix
44
56
  when 'debian'
45
- return File.file?('/etc/debian_version')
57
+ if OS::CACHE::is_debian == nil
58
+ OS::CACHE::is_debian = File.file?('/etc/debian_version')
59
+ end
60
+ return OS::CACHE::is_debian
46
61
  when 'ubuntu'
47
- return OS.has_command('lsb_release') && `lsb_release -a`.match(/Distributor ID:[\s\t]*Ubuntu/)
62
+ if OS::CACHE::is_ubuntu == nil
63
+ OS::CACHE::is_ubuntu = OS.has_command('lsb_release') && `lsb_release -a`.match(/Distributor ID:[\s\t]*Ubuntu/)
64
+ end
65
+ return OS::CACHE::is_ubuntu
48
66
  end
49
67
  end
50
68
 
@@ -59,7 +77,7 @@ module OS
59
77
  end
60
78
  return version
61
79
  elsif OS.is?("debian")
62
- # TODO: support debian version
80
+ # FUTURE: support debian version
63
81
  return nil
64
82
  elsif OS.is?('mac')
65
83
  version = Version.extract_from(`system_profiler SPSoftwareDataType`)
@@ -1,4 +1,4 @@
1
- require_relative './file_sys'
1
+ require_relative './file_system'
2
2
  require_relative './os'
3
3
  require_relative './atk_info'
4
4
 
@@ -11,7 +11,7 @@ require_relative './atk_info'
11
11
  class TTY::Prompt
12
12
  def set_command(name, code)
13
13
  if OS.is?("unix")
14
- exec_path = "/usr/local/bin/#{name}"
14
+ exec_path = "#{Atk.paths[:commands]}/#{name}"
15
15
  local_place = Atk.temp_path(name)
16
16
  # add the hash bang
17
17
  hash_bang = "#!#{Atk.paths[:ruby]}\n"
@@ -23,11 +23,16 @@ class TTY::Prompt
23
23
  elsif OS.is?("windows")
24
24
  # check for invalid file paths, see https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
25
25
  if name =~ /[><:"\/\\|?*]/
26
- puts "Sorry #{name} isn't a valid file path on windows"
27
- return ""
26
+ raise <<-HEREDOC.remove_indent
27
+
28
+
29
+ When using the ATK Console.set_command(name)
30
+ The name: #{name}
31
+ is not a valid file path on windows
32
+ which means it cannot be a command
33
+ HEREDOC
28
34
  end
29
- username = FS.username
30
- exec_path = "C:\\Users\\#{username}\\AppData\\local\\Microsoft\\WindowsApps\\#{name}"
35
+ exec_path = "#{Atk.paths[:commands]}\\#{name}"
31
36
 
32
37
  # create the code
33
38
  IO.write(exec_path+".rb", code)
@@ -1,3 +1,3 @@
1
1
  module AtkToolbox
2
- VERSION = '0.0.126'
2
+ VERSION = '0.0.127'
3
3
  end
@@ -0,0 +1,104 @@
1
+ class String
2
+ style_wrap = ->(name, number) do
3
+ # reset: \\e\\[0m
4
+ # some number of resets: (?:\\e\\[0m)+
5
+ # any ansi style/color: \\e\\[([;0-9]+)m
6
+ # some number of ansi-style/colors: ((?:\\e\\[([;0-9]+)m)*)
7
+ eval(<<-HEREDOC)
8
+ def #{name}()
9
+ # fix nested
10
+ self.gsub!(/(\\e\\[0m)(?:\\e\\[0m)*((?:\\e\\[([;0-9]+)m)*)/, '\\1\\2\e[#{number}m')
11
+ # inject start
12
+ self.sub!(/^((?:\\e\\[([;0-9]+)m)*)/, '\\1'+"\\e[#{number}m")
13
+ # append reset
14
+ self.replace("\#{self}\\e[0m")
15
+ end
16
+ HEREDOC
17
+ end
18
+
19
+ #
20
+ # generate foreground/background methods
21
+ #
22
+ @@colors = {
23
+ default: 39,
24
+ black: 30,
25
+ red: 31,
26
+ green: 32,
27
+ yellow: 33,
28
+ blue: 34,
29
+ magenta: 35,
30
+ cyan: 36,
31
+ white: 37,
32
+ light_black: 90,
33
+ light_red: 91,
34
+ light_green: 92,
35
+ light_yellow: 93,
36
+ light_blue: 94,
37
+ light_magenta: 95,
38
+ light_cyan: 96,
39
+ light_white: 97,
40
+ }
41
+ for each_key, each_value in @@colors
42
+ # foreground
43
+ style_wrap[each_key, each_value]
44
+ # background
45
+ style_wrap["on_#{each_key}", each_value+10]
46
+ end
47
+
48
+ #
49
+ # generate style methods
50
+ #
51
+ styles = {
52
+ normal: "21;22;23;24;25;27;28;29", # reset all non-color changes
53
+ bold: 1,
54
+ dim: 2,
55
+ italic: 3,
56
+ underline: 4,
57
+ blink: 5,
58
+ flash: 6,
59
+ invert: 7,
60
+ hide: 8,
61
+ }
62
+ for each_key, each_value in styles
63
+ style_wrap[each_key, each_value]
64
+ end
65
+
66
+ def unstyle
67
+ self.gsub!(/\e\[([;0-9]+)m/,"")
68
+ end
69
+
70
+ def self.color_samples
71
+ for background, foreground in @@colors.keys.permutation(2)
72
+ eval("puts ' #{foreground} on_#{background} '.rjust(32).#{foreground}.on_#{background}")
73
+ end
74
+ end
75
+ end
76
+
77
+
78
+ #
79
+ # Theme
80
+ #
81
+ class String
82
+ def color_as(kind)
83
+ case kind
84
+ when :error
85
+ " #{self} ".white.on_red
86
+ when :code
87
+ " #{self} ".light_blue.on_black
88
+ when :key_term
89
+ " #{self} ".yellow.on_black
90
+ when :title
91
+ " #{self} ".green.on_black
92
+ when :argument, :message
93
+ " #{self} ".cyan.on_black
94
+ when :optional
95
+ " #{self} ".light_magenta.on_black
96
+ when :good
97
+ " #{self} ".green.on_black
98
+ when :bad
99
+ " #{self} ".red.on_black
100
+ else
101
+ " #{self} ".cyan.on_black
102
+ end
103
+ end
104
+ end
@@ -1,3 +1,18 @@
1
+ # NOTES:
2
+ #
3
+ # this is the ideal replacement for the "after_gem_update.rb"
4
+ # however it (the ruby gem API) does not work as intended and has very *VERY* little documentation
5
+ # there may be a way to get it working, however the name of this file and the following code are required
6
+ # and finding their names in the ruby documentation is difficult (which is why dead code is living here)
7
+ # the issue is something along the lines of:
8
+ # - if gem 0.0.1 is already installed
9
+ # - then gem install atk_toolbox (upgrading to atk_toolbox 0.0.2)
10
+ # - will run the 0.0.1 version of this file instead of the 0.0.2 version
11
+ # (even durning post_install)
12
+ # I'm unsure of the initial behavior (aka assuming no atk_toolbox was installed)
13
+ # this needs to be further tested/explored before replacing "after_gem_update.rb"
14
+
15
+
1
16
  # #
2
17
  # # right before gem install
3
18
  # #
metadata CHANGED
@@ -1,55 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atk_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.126
4
+ version: 0.0.127
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-22 00:00:00.000000000 Z
11
+ date: 2020-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: zip
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.0'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 2.0.2
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '2.0'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 2.0.2
33
- - !ruby/object:Gem::Dependency
34
- name: git
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: 1.5.0
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 1.5.0
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: 1.5.0
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 1.5.0
53
13
  - !ruby/object:Gem::Dependency
54
14
  name: tty-prompt
55
15
  requirement: !ruby/object:Gem::Requirement
@@ -70,26 +30,6 @@ dependencies:
70
30
  - - ">="
71
31
  - !ruby/object:Gem::Version
72
32
  version: 0.19.0
73
- - !ruby/object:Gem::Dependency
74
- name: colorize
75
- requirement: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - "~>"
78
- - !ruby/object:Gem::Version
79
- version: 0.8.1
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 0.8.1
83
- type: :runtime
84
- prerelease: false
85
- version_requirements: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 0.8.1
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: 0.8.1
93
33
  description: ''
94
34
  email: jeff.hykin@gmail.com
95
35
  executables: []
@@ -102,19 +42,16 @@ files:
102
42
  - lib/atk/commands/project.rb
103
43
  - lib/atk/console.rb
104
44
  - lib/atk/default_info.yaml
105
- - lib/atk/extra_yaml.rb
106
- - lib/atk/file_sys.rb
45
+ - lib/atk/file_system.rb
107
46
  - lib/atk/git.rb
108
- - lib/atk/online.rb
47
+ - lib/atk/info.rb
109
48
  - lib/atk/os.rb
110
- - lib/atk/package_managers.rb
111
49
  - lib/atk/remove_indent.rb
112
50
  - lib/atk/set_command.rb
113
51
  - lib/atk/version.rb
114
- - lib/atk/yaml_info_parser.rb
115
- - lib/atk/zip.rb
116
52
  - lib/atk_toolbox.rb
117
53
  - lib/atk_toolbox/version.rb
54
+ - lib/console_colors.rb
118
55
  - lib/rubygems_plugin.rb
119
56
  - test/info.yaml
120
57
  - test/main.rb
@@ -1,147 +0,0 @@
1
- require_relative './remove_indent'
2
- require_relative './version'
3
- require 'json'
4
- require 'yaml'
5
-
6
- # how the new parser should work
7
- # turn every meaninful peice of the yaml file into data that is represented in ruby
8
- # reference objects instead of actually replacing the reference with the value
9
- # reference insertion keys instead of actually performing the <<:
10
- # save the style data (like 0x00 vs 0) to every peice of data
11
- # save whether or not the data must be single-line
12
- # tokenize the yaml recursively with the base case of scalar values
13
- # HARD: detect when values must be single-line or multiline
14
- # non-complex keys are single-line
15
- # anything inside of a JSON-like list or array must be single line
16
- # everything else I know of can be multiline
17
- # have both an inline and multiline conversion function for every data type
18
- # when changing data, convert the new data into a single-line or multiline form based on the parent token
19
- # if multiline, add the correct amount of indentation
20
-
21
- #
22
- #
23
- # JSON method
24
- #
25
- #
26
- # example:
27
- # doc = <<-HEREDOC
28
- # (dependencies):
29
- # python: 3.6.7
30
- # gcc: 8.0.0
31
- # HEREDOC
32
- # document = YamlEdit.new(string:doc)
33
- # document["(dependencies)"]["python"].replace_value_with(value: "200")
34
- # puts document.string
35
- # # creates:
36
- # doc = <<-HEREDOC
37
- # (dependencies):
38
- # python: "200"
39
- # gcc: 8.0.0
40
- # HEREDOC
41
-
42
- def inject_string(string, middle_part, start_line, start_column, end_line, end_column)
43
- lines = string.split("\n")
44
- untouched_begining_lines = lines[0...start_line]
45
- untouched_ending_lines = lines[end_line+1..-1]
46
- middle_lines = []
47
-
48
- before_part = lines[start_line][0...start_column]
49
- after_part = lines[end_line][end_column..-1]
50
-
51
- return (untouched_begining_lines + [ before_part + middle_part + after_part ] + untouched_ending_lines).join("\n")
52
- end
53
-
54
- class YamlEdit
55
- attr_accessor :string
56
-
57
- def initialize(string:nil, file:nil)
58
- self.init(string:string, file: file)
59
- end
60
-
61
- def init(string:nil, file:nil)
62
- if string == nil
63
- string = IO.read(file)
64
- end
65
- @root_node = YAML.parse(string).children[0]
66
- @string = string
67
- self.attach_to_all_children(@root_node, self)
68
- end
69
-
70
- def attach_to_all_children(node, original_document)
71
- if node.respond_to?(:children)
72
- if node.children.is_a?(Array)
73
- for each in node.children
74
- self.attach_to_all_children(each, original_document)
75
- end
76
- end
77
- end
78
- node.document = original_document
79
- end
80
-
81
- def [](key)
82
- return @root_node[key]
83
- end
84
-
85
- def save_to(file)
86
- IO.write(file, @string)
87
- end
88
- end
89
-
90
- class Psych::Nodes::Node
91
- attr_accessor :document
92
- def anchor_and_tag(anchor:nil, tag:nil)
93
- anchor = @anchor if anchor == nil
94
- tag = @tag if tag == nil
95
-
96
- string = ""
97
- if anchor
98
- string += "&#{anchor} "
99
- end
100
-
101
- if tag
102
- string += "!#{tag} "
103
- end
104
- return string
105
- end
106
-
107
- # saving this for later once the JSON method can be replaced
108
- def indent_level
109
- if self.respond_to?(:children)
110
- if self.children.size > 0
111
- return self.children[0].start_column
112
- end
113
- end
114
- return 4 + self.start_column
115
- end
116
-
117
- def [](key)
118
- previous = nil
119
- # for seq
120
- if key.is_a?(Integer)
121
- return self.children[key]
122
- end
123
- # for maps
124
- for each in self.children.reverse
125
- if each.respond_to?(:value) && each.value == key
126
- return previous
127
- end
128
- previous = each
129
- end
130
- end
131
-
132
- def replace_value_with(value:nil, literal:nil, anchor: nil, tag:nil)
133
- # check version
134
- if VERSION_OF_RUBY < "2.5.0"
135
- raise "\n\nSomewhere, replace_value_with() is being called, which is related to editing yaml\nthe problem is this function needs ruby >= 2.5.0\nbut the code is being run with ruby #{RUBY_VERSION}"
136
- end
137
-
138
- if literal == nil
139
- new_value = value.to_json
140
- else
141
- new_value = literal
142
- end
143
- middle_part = self.anchor_and_tag(anchor:anchor, tag:tag) + new_value
144
- new_string = inject_string(@document.string, middle_part, @start_line, @start_column, @end_line, @end_column)
145
- @document.init( string: new_string )
146
- end
147
- end