cejo 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +0 -0
  5. data/.rufo +3 -0
  6. data/.travis.yml +6 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +6 -0
  9. data/INSTALL +2 -0
  10. data/LICENSE +674 -0
  11. data/README.org +23 -0
  12. data/README.rdoc +28 -0
  13. data/Rakefile +6 -0
  14. data/annotations/legacy.org +11 -0
  15. data/annotations/todo.org +54 -0
  16. data/bin/console +14 -0
  17. data/bin/setup +9 -0
  18. data/cejo.gemspec +50 -0
  19. data/cejo.rdoc +5 -0
  20. data/exe/cejo +298 -0
  21. data/lib/cejo.rb +42 -0
  22. data/lib/cejo/distro/base.rb +52 -0
  23. data/lib/cejo/distro/commands.rb +26 -0
  24. data/lib/cejo/distro/current_packager.rb +18 -0
  25. data/lib/cejo/distro/help.rb +9 -0
  26. data/lib/cejo/distro/need.rb +32 -0
  27. data/lib/cejo/distro/parsed_commands.rb +23 -0
  28. data/lib/cejo/distro/translate_action.rb +11 -0
  29. data/lib/cejo/floss/archive.rb +49 -0
  30. data/lib/cejo/floss/core.rb +55 -0
  31. data/lib/cejo/floss/grab.rb +44 -0
  32. data/lib/cejo/floss/project_info.rb +28 -0
  33. data/lib/cejo/media/get.rb +54 -0
  34. data/lib/cejo/media/play.rb +45 -0
  35. data/lib/cejo/ops/brightness.rb +37 -0
  36. data/lib/cejo/ops/dots.rb +98 -0
  37. data/lib/cejo/ops/homey.rb +76 -0
  38. data/lib/cejo/ops/screenshot.rb +78 -0
  39. data/lib/cejo/ops/sysinfo.rb +27 -0
  40. data/lib/cejo/ops/volume/sound_manager.rb +45 -0
  41. data/lib/cejo/ops/volume/volume.rb +117 -0
  42. data/lib/cejo/projects/builder.rb +138 -0
  43. data/lib/cejo/projects/dwm.rb +23 -0
  44. data/lib/cejo/projects/emacs.rb +23 -0
  45. data/lib/cejo/projects/ruby.rb +23 -0
  46. data/lib/cejo/projects/st.rb +23 -0
  47. data/lib/cejo/services/folders.rb +21 -0
  48. data/lib/cejo/services/utils.rb +54 -0
  49. data/lib/cejo/version.rb +5 -0
  50. data/lib/tasks/list.rake +7 -0
  51. data/lib/tasks/man.rake +7 -0
  52. data/lib/tasks/spec.rake +5 -0
  53. data/lib/tasks/test.rake +7 -0
  54. data/man/cejo.1.ronn +0 -0
  55. data/spec/distro/action_spec.rb +21 -0
  56. data/spec/distro/base_spec.rb +67 -0
  57. data/spec/distro/commands_spec.rb +22 -0
  58. data/spec/distro/current_packager_spec.rb +17 -0
  59. data/spec/distro/need_spec.rb +22 -0
  60. data/spec/floss/archive_spec.rb +1 -0
  61. data/spec/floss/core_spec.rb +1 -0
  62. data/spec/floss/grab_spec.rb +1 -0
  63. data/spec/media/get_spec.rb +20 -0
  64. data/spec/media/play_spec.rb +41 -0
  65. data/spec/ops/ops_brightness_spec.rb +16 -0
  66. data/spec/ops/ops_volume_spec.rb +22 -0
  67. data/spec/spec_helper.rb +96 -0
  68. data/spec/utils_spec.rb +18 -0
  69. data/test/test_cejo.rb +16 -0
  70. data/test/test_distro_base.rb +13 -0
  71. data/test/test_floss.rb +13 -0
  72. data/test/test_media_get.rb +0 -0
  73. data/test/test_media_play.rb +0 -0
  74. data/test/test_ops_brightness.rb +0 -0
  75. data/test/test_ops_dots.rb +0 -0
  76. data/test/test_ops_homer.rb +0 -0
  77. data/test/test_ops_oss.rb +18 -0
  78. data/test/test_ops_screenshot.rb +0 -0
  79. data/test/test_ops_sysinfo.rb +0 -0
  80. data/test/test_ops_volume.rb +0 -0
  81. data/test/test_projects_builder.rb +0 -0
  82. data/test/test_projects_emacs.rb +0 -0
  83. metadata +468 -0
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Cejo
6
+ # Build Floss Projects
7
+ module Projects
8
+ # Build Projects
9
+ class Builder
10
+ attr_reader :cejo_config, :local_folder, :utils, :project
11
+
12
+ def initialize(folders, utils, project)
13
+ @cejo_config = folders.cejo_config
14
+ @local_folder = folders.local
15
+ @utils = utils
16
+ @project = project
17
+ end
18
+
19
+ def project_folder
20
+ cejo_config.join('projects')
21
+ end
22
+
23
+ def project_info
24
+ utils.parse_folder(project_folder)[project.to_sym]
25
+ .transform_keys(&:to_sym)
26
+ end
27
+
28
+ def url
29
+ project_info[:url]
30
+ end
31
+
32
+ def root
33
+ build_folder.join(project_info[:name])
34
+ end
35
+
36
+ def grab
37
+ Floss::Grab.new(utils, root, url, self.show_info).run
38
+ end
39
+
40
+ def tag
41
+ project_info[:tag]
42
+ end
43
+
44
+ def patch
45
+ project_info[:patch]
46
+ end
47
+
48
+ def repo
49
+ require 'git'
50
+ Git.open(root)
51
+ end
52
+
53
+ def checkout_tag
54
+ return if tag.empty?
55
+ repo.checkout(tag)
56
+ end
57
+
58
+ def commands
59
+ project_info[:commands]
60
+ end
61
+
62
+ def build_folder
63
+ Pathname.new(File.join(Dir.home, 'Builds'))
64
+ end
65
+
66
+ def install
67
+ Dir.chdir(root) do
68
+ commands.each do |command|
69
+ command.gsub!('{0}', local_folder.to_s)
70
+ system command
71
+ end
72
+ end
73
+ end
74
+
75
+ def project_patches
76
+ cejo_config.join('patches')
77
+ .join(project_info[:name])
78
+ end
79
+
80
+ # none, or exclusively these ones.
81
+ def apply_patches
82
+ tasks = project_info[:patch]
83
+ return if tasks == 'none'
84
+
85
+ patches = project_patches.children
86
+
87
+ Dir.chdir(root) do
88
+ patches.each do |patch|
89
+ next unless tasks.include? patch.basename.to_s
90
+ puts "Patched: #{patch.to_path}" # all
91
+ repo.apply patch.to_path
92
+ end
93
+ end
94
+ end
95
+
96
+ def purge
97
+ project_info[:purge]
98
+ end
99
+
100
+ def default
101
+ project_info[:default]
102
+ end
103
+
104
+ def cleaning
105
+ repo.reset_hard
106
+ repo.checkout default
107
+
108
+ Dir.chdir(root) do
109
+ purge.each { |command| system command }
110
+ end
111
+ end
112
+
113
+ public
114
+
115
+ def show_info
116
+ <<~EOF
117
+ ❯ Building Project
118
+
119
+ Name: #{project.capitalize}
120
+ Url: #{url}
121
+ Default: #{default}
122
+ Tag: #{tag}
123
+ Patch: #{patch}
124
+ Folder: #{root}
125
+ EOF
126
+ end
127
+ alias to_s show_info
128
+
129
+ def run
130
+ grab
131
+ checkout_tag
132
+ apply_patches
133
+ install # TODO: raise Git::GitExecuteError
134
+ cleaning
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Cejo
6
+ module Projects
7
+ # Suckless Dwm
8
+ class Dwm
9
+ attr_reader :builder, :services
10
+
11
+ def initialize(services)
12
+ @services = services
13
+ @builder = Builder.new(services.resolve(:folders), services.resolve(:utils), 'dwm')
14
+ end
15
+
16
+ public
17
+
18
+ def run
19
+ builder.run
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Cejo
6
+ module Projects
7
+ # GNU Emacs Editor
8
+ class Emacs
9
+ attr_reader :builder, :services
10
+
11
+ def initialize(services)
12
+ @services = services
13
+ @builder = Builder.new(services.resolve(:folders), services.resolve(:utils), 'emacs')
14
+ end
15
+
16
+ public
17
+
18
+ def run
19
+ builder.run
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Cejo
6
+ module Projects
7
+ # Ruby Programming language
8
+ class Ruby
9
+ attr_reader :builder, :services
10
+
11
+ def initialize(services)
12
+ @services = services
13
+ @builder = Builder.new(services.resolve(:folders), services.resolve(:utils), 'ruby')
14
+ end
15
+
16
+ public
17
+
18
+ def run
19
+ builder.run
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Cejo
6
+ module Projects
7
+ # Suckless Terminal
8
+ class St
9
+ attr_reader :builder, :services
10
+
11
+ def initialize(services)
12
+ @services = services
13
+ @builder = Builder.new(services.resolve(:folders), services.resolve(:utils), 'st')
14
+ end
15
+
16
+ public
17
+
18
+ def run
19
+ builder.run
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Cejo
6
+ module Services
7
+ # System Folders
8
+ class Folders
9
+ attr_reader :cejo_config, :downloads, :pictures, :local
10
+
11
+ def initialize
12
+ home = Dir.home
13
+ xdg_config_home = Pathname.new(File.join(home, '.config'))
14
+ @cejo_config = Pathname.new(File.join(xdg_config_home, 'cejo'))
15
+ @downloads = Pathname.new(File.join(home, 'Downloads'))
16
+ @pictures = Pathname.new(File.join(home, 'Pictures'))
17
+ @local = Pathname.new(File.join(home, '.local'))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tty-spinner'
4
+
5
+ require 'yaml'
6
+
7
+ module Cejo
8
+ module Services
9
+ # General Utilities.
10
+ class Utils
11
+ def spin(msg)
12
+ warning = 'status:'
13
+
14
+ require 'tty-spinner'
15
+ spinner = TTY::Spinner.new("#{warning} #{msg.downcase} :spinner ", format: :dots_6)
16
+ spinner.auto_spin
17
+
18
+ yield
19
+ spinner.success
20
+ end
21
+
22
+ # Load file with famous serialization formats
23
+ def load_this(file, ext)
24
+ case ext # TODO: load lazily per time. enumerator?
25
+ when 'yaml'
26
+ require 'yaml'
27
+ YAML.load_file(file, symbolize_names: true)
28
+ when 'json'
29
+ require 'json'
30
+ JSON.parse(file, symbolize_names: true)
31
+ end
32
+ end
33
+
34
+ # Parse Folder with serialization files
35
+ def parse_folder(folder, ext = 'yaml')
36
+ projects = {}
37
+
38
+ folder.each_child do |file|
39
+ name = file.basename.sub_ext('').to_s.to_sym
40
+ projects[name] = load_this(file, ext)
41
+ end
42
+
43
+ projects
44
+ end
45
+
46
+ # Is the executable available?
47
+ def which?(executable)
48
+ ENV['PATH'].split(File::PATH_SEPARATOR).any? do |directory|
49
+ File.executable?(File.join(directory, executable.to_s))
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cejo
4
+ VERSION = '0.0.5'
5
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :backup do
4
+ task :create do
5
+ # ...
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :docs do
4
+ task :man do
5
+ gem man '/man/cejo.1.ronn'
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ end
data/man/cejo.1.ronn ADDED
File without changes
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cejo'
4
+
5
+ require 'spec_helper'
6
+
7
+ RSpec.describe 'The marvelous Distro' do
8
+ context 'Current Packager' do
9
+ let(:action) { Cejo::Distro::TranslateAction.new }
10
+
11
+ it 'has the real action' do
12
+ commands = {
13
+ apt: { autoremove: 'autoremove' },
14
+ dnf: { autoremove: 'autoremove' },
15
+ }
16
+ real_action = action.real_action(commands, :dnf, :autoremove)
17
+
18
+ expect(real_action).to eq('autoremove')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cejo'
4
+
5
+ require 'spec_helper'
6
+
7
+ RSpec.describe 'The marvelous Distro' do
8
+ context 'Current Packager' do
9
+ let(:base) { Cejo::Distro::Base.new(folders, utils) }
10
+ let(:arguments) { 'fonts-hack' }
11
+ let(:folders) { Pathname.new '/home/engels/.config/cejo' }
12
+
13
+ let(:utils) {
14
+ Class.new do
15
+ def which?(x)
16
+ true
17
+ end
18
+
19
+ def parse_folder(x)
20
+ { apt: { install: 'install' } }
21
+ end
22
+ end.new
23
+ }
24
+
25
+ it 'has action argument as symbol' do
26
+ base.action = :search
27
+ base.arguments = 'fonts-hack'
28
+ expect(base.action).to eq(:search)
29
+ end
30
+
31
+ it 'has string arguments' do
32
+ base.action = :install
33
+ base.arguments = arguments
34
+ expect(base.arguments).to eq(arguments)
35
+ end
36
+
37
+ it 'has does not have arguments' do
38
+ base.action = :update
39
+ base.arguments = nil
40
+ expect(base.arguments).to eq(nil)
41
+ end
42
+
43
+ it 'has the translated action' do
44
+ base.action = :install
45
+ base.arguments = arguments
46
+ expect(base.real_action).to eq('install')
47
+ end
48
+
49
+ it 'has the commands' do
50
+ base.action = :install
51
+ base.arguments = arguments
52
+ expect(base.commands).to eq(base.utils.parse_folder(''))
53
+ end
54
+
55
+ it 'use the correct pakager' do
56
+ base.action = :install
57
+ base.arguments = arguments
58
+ expect(base.packager).to eq(:apt)
59
+ end
60
+
61
+ it 'has the final_command' do
62
+ base.action = :install
63
+ base.arguments = arguments
64
+ expect(base.final_command).to eq('sudo apt install fonts-hack')
65
+ end
66
+ end
67
+ end