cejo 0.0.5

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.
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
data/lib/cejo.rb ADDED
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # * Root
4
+ require_relative 'cejo/version'
5
+
6
+ # * Services
7
+ require_relative 'cejo/services/folders'
8
+ require_relative 'cejo/services/utils'
9
+
10
+ # * Ops
11
+ require_relative 'cejo/ops/homey'
12
+ require_relative 'cejo/ops/screenshot'
13
+ require_relative 'cejo/ops/volume/volume'
14
+ require_relative 'cejo/ops/volume/sound_manager'
15
+ require_relative 'cejo/ops/brightness'
16
+ require_relative 'cejo/ops/dots'
17
+ require_relative 'cejo/ops/sysinfo'
18
+
19
+ # * Floss
20
+ require_relative 'cejo/floss/core'
21
+ require_relative 'cejo/floss/project_info'
22
+ require_relative 'cejo/floss/archive'
23
+ require_relative 'cejo/floss/grab'
24
+
25
+ # * Distro
26
+ require_relative 'cejo/distro/base'
27
+ require_relative 'cejo/distro/translate_action'
28
+ require_relative 'cejo/distro/parsed_commands'
29
+ require_relative 'cejo/distro/commands'
30
+ require_relative 'cejo/distro/current_packager'
31
+ require_relative 'cejo/distro/need'
32
+
33
+ # * Projects
34
+ require_relative 'cejo/projects/builder'
35
+ require_relative 'cejo/projects/emacs'
36
+ require_relative 'cejo/projects/dwm'
37
+ require_relative 'cejo/projects/st'
38
+ require_relative 'cejo/projects/ruby'
39
+
40
+ # * Media
41
+ require_relative 'cejo/media/play'
42
+ require_relative 'cejo/media/get'
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cejo
4
+ # Distro Front End
5
+ module Distro
6
+ # Base
7
+ class Base
8
+ attr_reader :folder, :utils
9
+ attr_accessor :action, :arguments
10
+
11
+ def initialize(folder, utils)
12
+ @folder = folder
13
+ @utils = utils
14
+ @action = action
15
+ end
16
+
17
+ def commands
18
+ parsed_commands = ParsedCommands.new(utils, folder).found
19
+ commands = Commands.new(parsed_commands)
20
+
21
+ exit unless commands.any?
22
+ commands.all
23
+ end
24
+
25
+ def packager
26
+ current_packager = CurrentPackager.new(utils)
27
+ current_packager.packager(commands.keys)
28
+ end
29
+
30
+ def real_action
31
+ result = TranslateAction.new
32
+ result.real_action(commands, packager, action)
33
+ end
34
+
35
+ def need
36
+ Need.new(action)
37
+ end
38
+
39
+ def final_command
40
+ result = packager, real_action
41
+ result.append(arguments)
42
+ result.prepend('sudo') if need.admin?
43
+ result.join(' ')
44
+ end
45
+
46
+ def run
47
+ system(final_command)
48
+ end
49
+ public :run
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cejo
4
+ module Distro
5
+ # Base
6
+ class Commands
7
+ attr_reader :parsed_commands
8
+
9
+ def initialize(parsed_commands)
10
+ @parsed_commands = parsed_commands
11
+ end
12
+
13
+ def all
14
+ parsed_commands
15
+ end
16
+
17
+ def any?
18
+ parsed_commands.any?
19
+ end
20
+
21
+ def packagers
22
+ all.keys
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cejo
4
+ module Distro
5
+ # Base
6
+ class CurrentPackager
7
+ attr_reader :utils
8
+
9
+ def initialize(utils)
10
+ @utils = utils
11
+ end
12
+
13
+ def packager(keys)
14
+ keys.find { |exec| utils.which? exec }.to_sym
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cejo
4
+ module Distro
5
+ # Provide Commands Information
6
+ class Help
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cejo
4
+ module Distro
5
+ # Base
6
+ class Need
7
+ attr_reader :action
8
+
9
+ ADMIN = %i[install remove purge update upgrade clean autoremove].freeze
10
+ ARGUMENTS = %i[install remove purge dependencies].freeze
11
+ WHATEVER = %i[autoremove].freeze
12
+
13
+ def initialize(action)
14
+ @action = action
15
+ end
16
+
17
+ # Action need to be run with administration level
18
+ def admin?
19
+ true if ADMIN.include?(action)
20
+ end
21
+
22
+ # Action need any argument
23
+ def arguments?
24
+ true if ARGUMENTS.include?(action)
25
+ end
26
+
27
+ def whatever?
28
+ true if WHATEVER.include?(action)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cejo
4
+ module Distro
5
+ # Objectfy commands parsed
6
+ class ParsedCommands
7
+ attr_reader :utils, :folder
8
+
9
+ def initialize(utils, folder)
10
+ @utils = utils
11
+ @folder = folder.join('distro')
12
+ end
13
+
14
+ def found
15
+ utils.parse_folder(folder)
16
+ end
17
+
18
+ def any?
19
+ packagers.any?
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cejo
4
+ module Distro
5
+ class TranslateAction
6
+ def real_action(commands, packager, action)
7
+ commands[packager][action]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Cejo
6
+ module Floss
7
+ # Archive FLOSS Projects
8
+ class Archive
9
+ # FLOSS Projects elected to be archived
10
+ ARCHIVE_THESE = %w[lar cejo rake pry use-package lsp-mode].freeze
11
+
12
+ # Format to be compressed
13
+ FMT = 'tar'
14
+
15
+ # Folder which compressed files will be stored
16
+ ARCHIVED_FOLDER = Pathname.new(File.join(Dir.home, 'Downloads', 'archived'))
17
+
18
+ attr_reader :utils, :archived_filename, :name, :folder, :info
19
+
20
+ def initialize(utils, name, folder, info)
21
+ @utils = utils
22
+ @name = name
23
+ @folder = folder
24
+ @info = info
25
+ @archived_filename = "#{ARCHIVED_FOLDER.join(name)}.#{FMT}"
26
+ end
27
+
28
+ # Archiving FLOSS project
29
+ def do_archive
30
+ require 'git'
31
+
32
+ utils.spin('Archiving') do
33
+ repo = Git.open(folder)
34
+ repo.archive(repo.current_branch, archived_filename, format: FMT) # TODO: fiber/multithread
35
+ end
36
+ puts
37
+ end
38
+
39
+ def run
40
+ return unless ARCHIVE_THESE.include?(name)
41
+
42
+ Dir.mkdir(ARCHIVED_FOLDER) unless ARCHIVED_FOLDER.exist?
43
+
44
+ print info
45
+ do_archive
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Cejo
6
+ # Manage FLOSS Projects
7
+ module Floss
8
+ # Core Management FLOSS Projects
9
+ class Core
10
+ attr_reader :services, :folders, :utils, :command
11
+
12
+ def initialize(folders, utils, command)
13
+ @folders = folders
14
+ @utils = utils
15
+ @command = command
16
+ end
17
+
18
+ def parsed_projects
19
+ folder = folders.cejo_config.join('floss')
20
+ utils.parse_folder(folder)
21
+ end
22
+
23
+ def process_projects
24
+ parsed_projects.each do |language, projects|
25
+ puts "\n❯ #{language.capitalize}"
26
+ puts
27
+
28
+ projects.each do |url|
29
+ project_info = ProjectInfo.new(url, language.to_s)
30
+ yield(project_info)
31
+ end
32
+ end
33
+ end
34
+
35
+ def archive
36
+ process_projects do |info|
37
+ Archive.new(utils, info.name, info.folder, info.to_s).run
38
+ end
39
+ end
40
+ public :archive
41
+
42
+ def grab
43
+ process_projects do |info|
44
+ Grab.new(utils, info.folder, info.url, info.to_s).run
45
+ end
46
+ end
47
+ public :grab
48
+
49
+ def run
50
+ public_send(command)
51
+ end
52
+ public :run
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git'
4
+
5
+ module Cejo
6
+ module Floss
7
+ # Grab FLOSS Projects
8
+ class Grab
9
+ attr_reader :utils, :folder, :url, :info
10
+
11
+ def initialize(utils, folder, url, info)
12
+ @utils = utils
13
+ @folder = folder
14
+ @url = url
15
+ @info = info
16
+ end
17
+
18
+ def do_pull
19
+ utils.spin('Pulling') do
20
+ repo = Git.open(folder)
21
+ repo.pull('origin', repo.current_branch)
22
+ end
23
+ end
24
+
25
+ def do_clone
26
+ utils.spin('Cloning') do
27
+ Git.clone(url, folder)
28
+ end
29
+ end
30
+
31
+ # Cloning/Pulling FLOSS Project
32
+ def run
33
+ puts info.to_s
34
+
35
+ if folder.exist?
36
+ do_pull
37
+ else
38
+ do_clone
39
+ end
40
+ puts
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require 'uri'
5
+
6
+ module Cejo
7
+ module Floss
8
+ # Provides Project Information
9
+ class ProjectInfo
10
+ attr_reader :url, :name, :folder
11
+
12
+ def initialize(url, language)
13
+ @url = URI.parse url
14
+ @language = language
15
+ @name = File.basename(@url.path.split('/').last, '.git')
16
+ projects = Pathname.new(File.join(Dir.home, 'Projects'))
17
+ @folder = projects.join(language, name)
18
+ end
19
+
20
+ def to_s
21
+ <<~EOF
22
+ repository: #{url}
23
+ folder: #{folder}
24
+ EOF
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Cejo
6
+ module Media
7
+ # Get media pointed in url.
8
+ class Get
9
+ GRABBER = 'youtube-dl'
10
+ AUDIO_FORMATS = %w[vorbis flac mp3].freeze
11
+ AUDIO_DIR = Pathname.new(Dir.home).join('Music')
12
+ VIDEO_DIR = Pathname.new(Dir.home).join('Videos')
13
+
14
+ attr_reader :media, :codec
15
+
16
+ def initialize(media, codec = nil)
17
+ @media = media if media
18
+ @codec = codec if codec
19
+ end
20
+
21
+ def current_media
22
+ "\'#{media}\'" unless media
23
+ end
24
+
25
+ def current_dir
26
+ AUDIO_FORMATS.include?(codec) ? AUDIO_DIR : VIDEO_DIR
27
+ end
28
+
29
+ def audio_command
30
+ "--extract-audio --audio-format #{codec} #{media}"
31
+ end
32
+
33
+ def video_command
34
+ media
35
+ end
36
+
37
+ def final_command
38
+ action = AUDIO_FORMATS.include?(codec) ? audio_command : video_command
39
+ "#{GRABBER} #{action}"
40
+ end
41
+
42
+ def show_info
43
+ puts "media: #{media}"
44
+ puts "codec: #{codec}"
45
+ puts
46
+ end
47
+
48
+ def run
49
+ show_info
50
+ Dir.chdir(current_dir) { system(final_command) }
51
+ end
52
+ end
53
+ end
54
+ end