sys_lib_detector 0.1.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +69 -5
- data/lib/sys_lib_detector/cli.rb +43 -1
- data/lib/sys_lib_detector/displayer.rb +26 -26
- data/lib/sys_lib_detector/installer.rb +66 -0
- data/lib/sys_lib_detector/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b16819c07104381fe0fcf416ed83a3921debe96
|
4
|
+
data.tar.gz: f2918a512c5715223c5b16e162501f1c18189dc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3393ecec1ff8f6f9f2eba899e15d8663c169638f25781853f15ab4d7a9cab4b13d73b6c6d15cc68e5b37ef80362cb0968835cb796e1d66687e192e9a5a9869c2
|
7
|
+
data.tar.gz: 24ce55003c607d2c10da9ff7b6c7ec66e9a81c7b4dbaa2f534159444bb54dae581bbf124f68ea5b1d5d5dd3a61aed7d42b707e916bfcc11ba3860fd333ccbe37
|
data/README.md
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
# SysLibDetector
|
2
2
|
|
3
|
-
|
3
|
+
SysLibDetector helps in solving an irritating issue, which is ruby gems requiring native system dependencies, such as 'nokogiri' gem, as if you don't know upfront that you need to install ‘zlib1g-dev’ and ‘liblzma-dev’ you will be hit with an exception about a missing system library, and you won't be able to know this till checking Nokogiri's website.
|
4
4
|
|
5
|
-
|
5
|
+
## How SysLibDetector works
|
6
|
+
|
7
|
+
SysLibDetector collects your project's local gems and your system's operating system information and make an API request with this information to a web-service https://sys-libraries.herokuapp.com, which retrieves the **possibly found** system native libraries required for correct installation and usage of your project's gems.
|
8
|
+
|
9
|
+
## Dependencies
|
10
|
+
|
11
|
+
* [Json](https://rubygems.org/gems/json): for parsing json responses from the web-service.
|
12
|
+
* [System](https://rubygems.org/gems/system): for system's operating system detection
|
13
|
+
* [Thor](https://rubygems.org/gems/thor): for building a command-line interface.
|
14
|
+
* [RestClient](https://rubygems.org/gems/rest-client): a rest client for the web-service communication
|
6
15
|
|
7
16
|
## Installation
|
8
17
|
|
@@ -22,17 +31,72 @@ Or install it yourself as:
|
|
22
31
|
|
23
32
|
## Usage
|
24
33
|
|
25
|
-
|
34
|
+
* Show the available methods
|
35
|
+
|
36
|
+
$ sys-lib-detector help
|
37
|
+
|
38
|
+
* List your project's gems
|
39
|
+
|
40
|
+
$ sys-lib-detector list_all_gems
|
41
|
+
|
42
|
+
* List the **available** required system libraries for your project's gems
|
43
|
+
|
44
|
+
$ sys-lib-detector list_sys_libs
|
45
|
+
|
46
|
+
*Note: The web-service is continuously updated with gem's system libraries dependencies upon the contribution of different contributors, and you among those! Check the contribution part below.
|
47
|
+
|
48
|
+
* Install the **available** required system libraries for your project's gems
|
49
|
+
|
50
|
+
$ sys-lib-detector install_sys_libs
|
51
|
+
|
52
|
+
*Note: Supported operating systems are Linux and OS X, with package managers `APT` and `Homebrew` respectively.
|
26
53
|
|
27
54
|
## Development
|
28
55
|
|
29
56
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
57
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
58
|
## Contributing
|
34
59
|
|
60
|
+
### Adding new gem's system libraries
|
61
|
+
|
62
|
+
You can contribute yourself in order for making the whole process more reliable and more useful by adding gems' system dependencies.
|
63
|
+
|
64
|
+
This can be done by making a simple POST API request to the web-service (contributing endpoint) https://sys-libraries.herokuapp.com/contribute_requests including your email, gem's information (name and version) and the system libraries dependencies, as in this example
|
65
|
+
```
|
66
|
+
{
|
67
|
+
"email": "you@example.com",
|
68
|
+
"ruby_gem": {
|
69
|
+
"name": "nokogiri",
|
70
|
+
"version": "1.8.2"
|
71
|
+
},
|
72
|
+
"libraries": [
|
73
|
+
{
|
74
|
+
"platform": "linux",
|
75
|
+
"name": "zlib1g-dev"
|
76
|
+
},
|
77
|
+
{
|
78
|
+
"platform": "linux",
|
79
|
+
"name": "liblzma-dev"
|
80
|
+
},
|
81
|
+
{
|
82
|
+
"platform": "osx",
|
83
|
+
"name": "libxml2"
|
84
|
+
}
|
85
|
+
]
|
86
|
+
}
|
87
|
+
```
|
88
|
+
***NOTE:** You can leave `version` field in `ruby_gems` attributes empty
|
89
|
+
|
90
|
+
***NOTE:** `platform` field in `libraries` attributes can be any of those: 'linux', 'osx' or 'windows'
|
91
|
+
|
92
|
+
### SysLibDetector gem
|
35
93
|
Bug reports and pull requests are welcome on GitHub at https://github.com/HusseinReda/sys_lib_detector.
|
94
|
+
The project is always welcoming for contributions.
|
95
|
+
|
96
|
+
## Future Plans
|
97
|
+
|
98
|
+
* Adding Windows to supported operating systems.
|
99
|
+
* Automating the manual review of the contribution requests of adding gems' dependencies.
|
36
100
|
|
37
101
|
## License
|
38
102
|
|
data/lib/sys_lib_detector/cli.rb
CHANGED
@@ -24,15 +24,50 @@ module SysLibDetector
|
|
24
24
|
def list_sys_libs
|
25
25
|
gems = get_gems
|
26
26
|
os = get_os_name
|
27
|
+
|
27
28
|
begin
|
28
29
|
web_service_handler = get_web_service_handler
|
29
|
-
response = web_service_handler.retrieve_sys_libraries(gems, os)
|
30
30
|
|
31
|
+
response = web_service_handler.retrieve_sys_libraries(gems, os)
|
31
32
|
response = clean_response(response)
|
32
33
|
|
33
34
|
Displayer::diplay_list_sys_libs(response, gems)
|
35
|
+
|
36
|
+
rescue Exception::NoInternetConnection
|
37
|
+
abort "Please check your internet connectivity"
|
38
|
+
rescue => e
|
39
|
+
abort e.message
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "install_sys_libs", "Installing the required gems' dependant system libraries "
|
44
|
+
# Installing the required system libraries for the project's local gems via
|
45
|
+
# sending the retrieval request to the web-service, and then installing the
|
46
|
+
# system libraries included in the response
|
47
|
+
def install_sys_libs
|
48
|
+
gems = get_gems
|
49
|
+
os = get_os_name
|
50
|
+
|
51
|
+
begin
|
52
|
+
web_service_handler = get_web_service_handler
|
53
|
+
|
54
|
+
response = web_service_handler.retrieve_sys_libraries(gems, os)
|
55
|
+
response = clean_response(response)
|
56
|
+
|
57
|
+
libraries = get_libraries(response)
|
58
|
+
|
59
|
+
Displayer::display_header(response, gems)
|
60
|
+
|
61
|
+
# if count == 0 message is already handled in the diplay header
|
62
|
+
if(libraries.count > 0)
|
63
|
+
installer = SysLibDetector::Installer.new
|
64
|
+
installer.install(libraries)
|
65
|
+
end
|
66
|
+
|
34
67
|
rescue Exception::NoInternetConnection
|
35
68
|
abort "Please check your internet connectivity"
|
69
|
+
rescue => e
|
70
|
+
abort e.message
|
36
71
|
end
|
37
72
|
end
|
38
73
|
|
@@ -59,5 +94,12 @@ module SysLibDetector
|
|
59
94
|
def clean_response(json_object)
|
60
95
|
return json_object.delete_if {|key, value| value.nil? || value.empty?}
|
61
96
|
end
|
97
|
+
|
98
|
+
# private method for extracting the system libraries from the reponse
|
99
|
+
# @param response [Json] The json response of web-service
|
100
|
+
def get_libraries(response)
|
101
|
+
return response.values.flatten
|
102
|
+
end
|
103
|
+
|
62
104
|
end
|
63
105
|
end
|
@@ -16,38 +16,38 @@ module SysLibDetector
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
display_footer if response.count > 0
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
# Displaying the header message after recieving the web-service response
|
23
|
+
# @param response [Json] The json response of web-service
|
24
|
+
# in format { gem_1: [a,b,c], gem_2: [x,y,z] }
|
25
|
+
# @param gems [Array] The current project's gems' names
|
26
|
+
def self.display_header(response, gems)
|
27
|
+
gems_found_count = gems_with_libraries_count(response)
|
28
|
+
all_found = gems_found_count == gems.count
|
29
|
+
|
30
|
+
if(gems_found_count == 0)
|
31
|
+
puts "No system libraries found for your gems, you can contribute by adding libraries!"
|
32
|
+
puts "For more details check https://github.com/HusseinReda/SysLibDetectorGem#contributing"
|
33
|
+
return
|
34
|
+
end
|
23
35
|
|
24
|
-
|
25
|
-
|
36
|
+
if(all_found)
|
37
|
+
puts "Required system libraries found for all your gems!"
|
38
|
+
else
|
39
|
+
puts "Required system libraries found for gems: #{response.keys.join(", ")}"
|
26
40
|
end
|
41
|
+
end
|
27
42
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# @param gems [Array] The current project's gems' names
|
32
|
-
def self.display_header(response, gems)
|
33
|
-
gems_found_count = gems_with_libraries_count(response)
|
34
|
-
all_found = gems_found_count == gems.count
|
35
|
-
|
36
|
-
if(gems_found_count == 0)
|
37
|
-
puts "No system libraries found for your gems, you can contribute by adding libraries!"
|
38
|
-
puts "For more details check https://github.com/HusseinReda/SysLibDetectorGem#contributing"
|
39
|
-
return
|
40
|
-
end
|
43
|
+
def self.display_footer
|
44
|
+
puts "\nTo install the required system libraries listed, run 'sys-lib-detector install-sys-libs'"
|
45
|
+
end
|
41
46
|
|
42
|
-
|
43
|
-
puts "Required system libraries found for all your gems!"
|
44
|
-
else
|
45
|
-
puts "Required system libraries found for gems: #{response.keys.join(", ")}"
|
46
|
-
end
|
47
|
-
end
|
47
|
+
private
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
def self.gems_with_libraries_count(response)
|
50
|
+
return response.keys.count
|
51
|
+
end
|
52
52
|
end
|
53
53
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "sys_lib_detector"
|
2
|
+
|
3
|
+
module SysLibDetector
|
4
|
+
# Class responsible for installing the retrieved system libraries
|
5
|
+
class Installer
|
6
|
+
# Available operating systems for installing the libraries are
|
7
|
+
# linux and macos only.
|
8
|
+
AVAILABLE_OS = [:linux, :osx]
|
9
|
+
|
10
|
+
# Initializing the installer object with the current os
|
11
|
+
def initialize
|
12
|
+
@os_name = get_os_name
|
13
|
+
end
|
14
|
+
|
15
|
+
# Installing the required system libraries, packager specified
|
16
|
+
# according to the current operating system, showing info about the
|
17
|
+
# status of the libraries, whether installed or not
|
18
|
+
# @param libraries [Array] Retrieved required system libraries
|
19
|
+
def install(libraries)
|
20
|
+
# Abort with a friendly message if the running OS is not supported yet
|
21
|
+
abort "We're sorry but currently we don't support #{@os_name} package installation" if(!is_os_available?(@os_name))
|
22
|
+
|
23
|
+
# Message shown handled by the displayer already
|
24
|
+
abort if libraries.count == 0
|
25
|
+
installed_libraries = []
|
26
|
+
failed_libraries = []
|
27
|
+
|
28
|
+
libraries.each do |library|
|
29
|
+
installed = self.send("#{@os_name}_installer", library)
|
30
|
+
if(installed == true)
|
31
|
+
installed_libraries << library
|
32
|
+
else
|
33
|
+
failed_libraries << library
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if(failed_libraries.count > 0)
|
38
|
+
abort "#{failed_libraries.count} libraries failed to be installed: #{failed_libraries}"
|
39
|
+
else
|
40
|
+
abort "#{installed_libraries.count} libraries installed successfully!"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
# private method for getting the running operating system's name
|
46
|
+
def get_os_name
|
47
|
+
return SystemDetector.get_os_name
|
48
|
+
end
|
49
|
+
|
50
|
+
# private method for checking the availability of the operating system
|
51
|
+
def is_os_available?(os_name)
|
52
|
+
return AVAILABLE_OS.include?(os_name)
|
53
|
+
end
|
54
|
+
|
55
|
+
# private method for running linux (apt) installing command
|
56
|
+
def linux_installer(package)
|
57
|
+
system("sudo apt-get -y install #{package}")
|
58
|
+
end
|
59
|
+
|
60
|
+
# private method for running MacOS (homebrew) installing command
|
61
|
+
def osx_installer(package)
|
62
|
+
system("brew install #{package}")
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|