thug 0.1.2 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51ad4ca9848297c0fcb3f03f44857c01ef3d3561
4
- data.tar.gz: d10724e6e952e4b79c80ed697364307fd7363f99
3
+ metadata.gz: f2f51e917bb4972ca4099565696f516b4b27ad6a
4
+ data.tar.gz: 9b83c8f28d1129902434ae98fdac09581fa5ac0f
5
5
  SHA512:
6
- metadata.gz: 13ace429ecfb28f6018b69cbb1d6b84d6a70580b8411ce7d0c6799a16ab61ea191fe654f260b23bb9bac7c4012a35702200a4fc839bb8ffb5ab24d6d4cfe8398
7
- data.tar.gz: f9a90cfc4c58af359d9b95ee83c32418d80e780331fc3142391257417c31d3eba7bab323560a5795005d4b4d8c3d04581bc1d13889afacbb217e303440474454
6
+ metadata.gz: c4fa6be44aa5e01cfe24ec591309446b53adf34d95a8cdc3528b9712e9ce331ff78517a70a8a79d8d2e3ac09776623bbb033c9aa0dd8d8d45a93d96a7634f970
7
+ data.tar.gz: 15611a8f02cce23f1b80bd9ebedb6da5790b1fd3c592a7b2a03e54a551f6dff8acd432e6b789ba5fcbaa3ba2fbe8da1b618a2aee88b9a3eb77a429efa772b664
data/README.md CHANGED
@@ -1,38 +1,39 @@
1
1
  # Thug
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/thug`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Thug resolves all the system level dependencies for you project, by generating the "Gemfile.lock" it fetches the needed dependencies and proceeds to install it.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ # Dependencies
6
6
 
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
7
+ * [Json](https://rubygems.org/gems/json): for parsing json responses.
8
+ * [Ohai](https://github.com/opscode/ohai): to detect platform, platform version.
9
+ * [Thor](https://github.com/erikhuda/thor): for command-line utlilties.
10
10
 
11
- ```ruby
12
- gem 'thug'
13
- ```
14
11
 
15
- And then execute:
16
-
17
- $ bundle
12
+ ## Installation
18
13
 
19
- Or install it yourself as:
14
+ Install the gem via terminal using:
20
15
 
21
16
  $ gem install thug
22
17
 
23
18
  ## Usage
24
19
 
25
- TODO: Write usage instructions here
20
+ Navigate to ruby project then run thug list to list all needed system dependencies:
21
+
22
+ $ thug list
23
+
24
+ To install dependencies run
25
+
26
+ $ thug install
26
27
 
27
28
  ## Development
28
29
 
29
- 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
+ Checkout the project and run
30
31
 
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
+ $ gem build thug.gemspec
32
33
 
33
34
  ## Contributing
34
35
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/thug. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+ Thug gem relies on users to keep its system dependencies list up to date, Bug reports and pull requests are welcome on here. or you can [Sign up](http://13.15.15.166:1337/register) at [Thug-Gem](http://13.15.15.166:1337)Thug-gem and start adding gems/dependencies.
36
37
 
37
38
  ## License
38
39
 
@@ -40,4 +41,4 @@ The gem is available as open source under the terms of the [MIT License](http://
40
41
 
41
42
  ## Code of Conduct
42
43
 
43
- Everyone interacting in the Thug project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/thug/blob/master/CODE_OF_CONDUCT.md).
44
+ Everyone interacting in the Thug project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sherifalaa55/thug/blob/master/CODE_OF_CONDUCT.md).
@@ -1,5 +1 @@
1
1
  require "thug/version"
2
-
3
- module Thug
4
- # Your code goes here...
5
- end
@@ -10,12 +10,12 @@ module Thug
10
10
  default_task :list
11
11
 
12
12
  desc 'thug list', 'lists system dependencies in current project'
13
- def list(*entry_names)
13
+ def list()
14
14
  # detect gem file and create/update gem .lock file
15
15
  gem_detector = Thug::GemDetector.new
16
16
 
17
17
  unless gem_detector.has_gem?
18
- raise Exception.new("No Gemfile was found in the current directory")
18
+ raise "No Gemfile was found in the current directory"
19
19
  end
20
20
 
21
21
  # list gems in current project
@@ -39,9 +39,62 @@ module Thug
39
39
 
40
40
  end
41
41
 
42
+ if !dependencies.empty?
43
+ puts "The following system packages are required by your project."
44
+ puts dependencies
45
+ else
46
+ puts "No system packages are needed."
47
+ end
48
+
49
+
50
+ rescue => ex
51
+ $stderr.puts ex.message
52
+ end
53
+
54
+ desc 'thug install', 'lists system dependencies in current project and installs them via package manager'
55
+ def install()
56
+ # detect gem file and create/update gem .lock file
57
+ gem_detector = Thug::GemDetector.new
58
+
59
+ unless gem_detector.has_gem?
60
+ raise "No Gemfile was found in the current directory"
61
+ end
62
+
63
+ # list gems in current project
64
+ current_gems = gem_detector.list_gems
65
+
66
+ # detect current os, platform and package manager
67
+ platform_detector = Thug::PlatformDetector.new
68
+
69
+ platform = platform_detector.get_platform
70
+ os = platform_detector.get_os
71
+
72
+ # check internet
73
+ utils = Thug::Utils.new
74
+
75
+ if utils.internet?
76
+ # if connected, request system dependencies
77
+ client = Thug::HttpClient.new
78
+ dependencies = client.get_dependencies platform, current_gems
79
+ else
80
+ # if not, get system dependencies from local file
81
+
82
+ end
83
+
84
+ if !dependencies.empty?
85
+ puts "The following system packages are required by your project."
86
+ puts dependencies
87
+ else
88
+ puts "No system packages are needed."
89
+ end
90
+
42
91
  # run install command to install dependencies
92
+ pkg_manager = platform_detector.get_package_manager platform
43
93
  installer = Thug::Installer.new
44
- installer.install_dependencies dependencies
94
+ puts "installing dependencies via #{pkg_manager}"
95
+
96
+ installer.install_dependencies(pkg_manager, dependencies)
97
+
45
98
  rescue => ex
46
99
  $stderr.puts ex.message
47
100
  end
@@ -21,7 +21,7 @@ module Thug
21
21
 
22
22
  # lists gems in current project
23
23
  def list_gems
24
- # self.update_lock
24
+ self.update_lock
25
25
 
26
26
  @gemfile_path = File.expand_path(@gemfile_path)
27
27
 
@@ -5,7 +5,7 @@ module Thug
5
5
  class HttpClient
6
6
 
7
7
  def get_dependencies platform, gems
8
- uri = URI('http://localhost:1337/dependencies')
8
+ uri = URI('http://13.95.24.166:1337/dependencies')
9
9
  res = Net::HTTP.post_form(uri, 'gems[]' => gems, 'platform' => platform)
10
10
  deps = JSON.parse(res.body)
11
11
  dependencies = deps.map do |dep|
@@ -1,10 +1,10 @@
1
1
  module Thug
2
2
  class Installer
3
3
 
4
- def install_dependencies dependencies
5
- dependencies.each do |dep|
6
- puts `sudo apt-get install #{dep}`
7
- end
4
+ def install_dependencies (pkg, dependencies)
5
+ deps = dependencies.join(" ")
6
+
7
+ puts `sudo #{pkg} install #{deps}`
8
8
  end
9
9
  end
10
10
  end
@@ -3,8 +3,14 @@ module Thug
3
3
 
4
4
  # get platform: ubuntu, debian, centos
5
5
  def get_platform
6
+
7
+ if(/darwin/i =~ RUBY_PLATFORM)
8
+ return "mac"
9
+ end
10
+
6
11
  platform = `ohai platform`
7
12
 
13
+
8
14
  if platform =~ /ubuntu/i
9
15
  platform = "ubuntu"
10
16
  elsif platform =~ /debian/i
@@ -27,7 +33,18 @@ module Thug
27
33
 
28
34
  # returns package manager of current platform
29
35
  def get_package_manager platform
30
-
36
+ case platform
37
+ when "ubuntu"
38
+ pkg = "apt-get"
39
+ when "debian"
40
+ pkg = "apt-get"
41
+ when "centos"
42
+ pkg = "yum"
43
+ when "mac"
44
+ pkg = "brew"
45
+ end
46
+
47
+ pkg
31
48
  end
32
49
 
33
50
 
@@ -1,3 +1,3 @@
1
1
  module Thug
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["sherif"]
10
10
  spec.email = ["sherif.alaa55@gmail.com"]
11
11
 
12
- spec.summary = "A thug gem that does all the system dirty work for you."
12
+ spec.summary = "A thug gem that installs all the system level dependencies for you."
13
13
  spec.description = "lists all the system level dependencies for you ruby project."
14
14
  spec.homepage = "https://www.github.com"
15
15
  spec.license = "MIT"
@@ -37,8 +37,8 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency "rake", "~> 10.0"
38
38
  spec.add_development_dependency "rspec", "~> 3.0"
39
39
 
40
- spec.add_runtime_dependency "ohai"
41
- spec.add_runtime_dependency "thor"
42
- spec.add_runtime_dependency "bundler"
43
- spec.add_runtime_dependency "json"
40
+ spec.add_runtime_dependency "ohai", '~> 13.5'
41
+ spec.add_runtime_dependency "thor", '~> 0.20.0'
42
+ spec.add_runtime_dependency "bundler", '~> 1.15'
43
+ spec.add_runtime_dependency "json", '~> 2.1'
44
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sherif
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-15 00:00:00.000000000 Z
11
+ date: 2017-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,58 +56,58 @@ dependencies:
56
56
  name: ohai
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '13.5'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '13.5'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: thor
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.20.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.20.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '1.15'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '1.15'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: json
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '2.1'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '2.1'
111
111
  description: lists all the system level dependencies for you ruby project.
112
112
  email:
113
113
  - sherif.alaa55@gmail.com
@@ -160,5 +160,5 @@ rubyforge_project:
160
160
  rubygems_version: 2.6.13
161
161
  signing_key:
162
162
  specification_version: 4
163
- summary: A thug gem that does all the system dirty work for you.
163
+ summary: A thug gem that installs all the system level dependencies for you.
164
164
  test_files: []