bowie 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a1627386c87e3785efd62c3c32e9a2e05a89863
4
- data.tar.gz: 961ca9b6ee29c6a7db3ce15a50741119b83985b2
3
+ metadata.gz: ececbde1cb3bb56582f6aa35aea67de68231f8b6
4
+ data.tar.gz: 46f9875461219c7b698b91f9806db72bd7096b1e
5
5
  SHA512:
6
- metadata.gz: 2b17b0c8664ad75cf4b12ca14b3a5799096e4f35382530075ea8be0d2fa50f4e0d388e844ae0800466171a071a3330cc1e400aa8433435b1fc2a7eeb0eb07eda
7
- data.tar.gz: 15b9cac6ae41dca43c96b1c60c882c3cb2f1c4c8fe2fe009758c986938ed8c082151ce984608113def20924d444fafd2c90d09f305d0f252920f61af737dfc89
6
+ metadata.gz: 6a727b62aa104ca86b9935f8574c910abd3c23d5361e0eb9a63ddac494774c224c366599ba18842173a0e8c1696d16b8708791eabd5888ff5768a32171c6b6df
7
+ data.tar.gz: 6605c234da1ce24f14ea541f910fcd554e292a4ca89b6b1fa9713b82823ca1977e0ec06b8d810947f17519467fc9c089744859ad51a84caed90cc03d2da496a1
data/bin/bowie CHANGED
@@ -1,45 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bowie'
4
- require 'thor'
5
4
 
6
- class BowieCLI < Thor
7
-
8
- Bowie.get_songs
9
- Bowie.get_local_songs
10
- Bowie.get_local_lyrics
11
-
12
- desc "install [song]", "install the selected package"
13
- def install(*songs)
14
- Bowie.install(*songs)
15
- end
16
-
17
- desc "update [song]", "update the selected package"
18
- def update(*songs)
19
- Bowie.update(*songs)
20
- end
21
-
22
- desc "uninstall [song]", "remove the selected package"
23
- def uninstall(*songs)
24
- Bowie.uninstall(*songs)
25
- end
26
-
27
- desc "search [song]", "list all availables packages matching [song]"
28
- def search(song)
29
- results = Bowie.search(song)
30
- results.each { |key, values| puts "#{values['name']}:\n #{values['description']}" }
31
- end
32
-
33
- desc "prune", "remove all the packages not included in songs.yml"
34
- def prune
35
- Bowie.prune
36
- end
37
-
38
- desc "list", "list all the installed packages"
39
- def list
40
- results = Bowie.list
41
- results.each { |key, values| puts "#{values['name']}:\n #{values['description']}" }
42
- end
43
- end
44
-
45
- BowieCLI.start(ARGV)
5
+ Bowie::CLI.start(ARGV)
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
23
24
 
24
25
  spec.add_runtime_dependency "git"
25
26
  spec.add_runtime_dependency "thor"
@@ -4,166 +4,8 @@ require "open-uri"
4
4
  require "fileutils"
5
5
  require "git"
6
6
  require "logger"
7
+ require "semver/semver"
7
8
  require "bowie/utils"
8
- require "bowie/semver"
9
-
10
- module Bowie
11
-
12
- # Retrive the online registry of available songs
13
- def self.get_songs
14
- begin
15
- YAML.parse(open("https://raw.github.com/axyz/bowie-songs/master/songs.yml")).to_ruby
16
- rescue
17
- puts "ERROR: Cannot connect to github.com"
18
- end
19
- end
20
-
21
- # Retrive the local registry of installed songs
22
- def self.get_local_songs
23
- begin
24
- YAML.load_file('songs.yml')? YAML.load_file('songs.yml') : Array.new
25
- rescue
26
- begin
27
- FileUtils.mkdir 'bowie_songs'
28
- rescue
29
- end
30
- FileUtils.touch 'songs.yml'
31
- return Array.new
32
- end
33
- end
34
-
35
- # Retrive the local lyrics file
36
- def self.get_local_lyrics
37
- begin
38
- YAML.load_file('bowie_songs/lyrics.yml')? YAML.load_file('songs.yml') : Hash.new
39
- rescue
40
- begin
41
- FileUtils.mkdir 'bowie_songs'
42
- rescue
43
- end
44
- FileUtils.touch 'bowie_songs/lyrics.yml'
45
- return Hash.new
46
- end
47
- end
48
-
49
- # Return a printable list of available packages matching the [query]
50
- def self.search(query)
51
- @songs = self.get_songs
52
- @songs.select { |el| /.*#{query}.*/ =~ el }
53
- end
54
-
55
- # Install the selected [song] in the bowie_songs directory
56
- def self.install(*songs)
57
- @songs = self.get_songs
58
- @local_songs = self.get_local_songs
59
-
60
- if songs.length > 0
61
- songs.each do |song|
62
- name = Utils.parse_song_name song
63
- version = Semver.new(Utils.parse_song_version song)
64
- url = @songs[name]['url']
65
- path = "bowie_songs/#{name}"
66
-
67
- if File.directory? path
68
- self.update(name)
69
- else
70
- FileUtils.mkdir_p(path)
71
- Git.clone(url, path)
72
- if version.major != nil
73
- g = Git.open(path)
74
- begin
75
- g.checkout(version.to_s)
76
- rescue
77
- begin
78
- g.checkout(version.to_s :v => true)
79
- rescue
80
- end
81
- end
82
- end
83
- end
84
-
85
- unless @local_songs.include? name or @local_songs.include? name+'#'+version.to_s
86
- version.major ? @local_songs.push(name+'#'+version.to_s) : @local_songs.push(name)
87
- end
88
- File.open("songs.yml", "w"){|f| YAML.dump(@local_songs, f)}
89
- end
90
- else
91
- @local_songs.each {|song| self.install(song)}
92
- end
93
- end
94
-
95
- # Remove the selected package
96
- def self.uninstall(*songs)
97
- @songs = self.get_songs
98
- @local_songs = self.get_local_songs
99
-
100
- songs.each do |song|
101
- name = Utils.parse_song_name song
102
- version = Semver.new(Utils.parse_song_version song)
103
- path = "bowie_songs/#{name}"
104
-
105
- FileUtils.rm_rf(path) # use remove_entry_secure for security reasons?
106
-
107
- if version.major != nil
108
- @local_songs.delete "#{name}##{version}"
109
- else
110
- @local_songs.delete_if {|el| not (el =~ /^#{name}#/).nil?}
111
- end
112
- File.open("songs.yml", "w"){|f| YAML.dump(@local_songs, f)}
113
- end
114
- end
115
-
116
- # Update the selected package
117
- def self.update(*songs)
118
- @songs = self.get_songs
119
- @local_songs = self.get_local_songs
120
-
121
- if songs.length > 0
122
- songs.each do |song|
123
- name = Utils.parse_song_name song
124
- version = Semver.new(Utils.parse_song_version song)
125
- path = "bowie_songs/#{name}"
126
-
127
- g = Git.open(path, :log => Logger.new(STDOUT))
128
- g.reset_hard('HEAD')
129
- g.pull
130
- unless version.major.nil?
131
- begin
132
- g.checkout(version.to_s)
133
- rescue
134
- begin
135
- g.checkout(version.to_s :v => true)
136
- rescue
137
- end
138
- end
139
- end
140
- @local_songs.delete name
141
- @local_songs.delete_if {|el| not (el =~ /^#{name}#/).nil?}
142
- version.major ? @local_songs.push(name+'#'+version.to_s) : @local_songs.push(name)
143
- File.open("songs.yml", "w"){|f| YAML.dump(@local_songs, f)}
144
- end
145
- else
146
- @local_songs.each {|song| self.update(song)}
147
- end
148
- end
149
-
150
- # Remove all the packages not included in songs.yml
151
- def self.prune
152
- @local_songs = self.get_local_songs
153
-
154
- Utils.get_songs_dirs.each do |dir|
155
- unless @local_songs.include? dir
156
- FileUtils.rm_rf("bowie_songs/#{dir}")
157
- end
158
- end
159
- end
160
-
161
- # List all the installed packages
162
- def self.list
163
- @local_songs = self.get_local_songs
164
- @songs = self.get_songs
165
-
166
- @songs.select {|el| @local_songs.include? el}
167
- end
168
-
169
- end
9
+ require "semver/semver"
10
+ require "bowie/actions"
11
+ require "bowie/cli"
@@ -0,0 +1,7 @@
1
+ require 'bowie/song_utils'
2
+ require 'bowie/actions/install'
3
+ require 'bowie/actions/list'
4
+ require 'bowie/actions/prune'
5
+ require 'bowie/actions/search'
6
+ require 'bowie/actions/uninstall'
7
+ require 'bowie/actions/update'
@@ -0,0 +1,42 @@
1
+ module Bowie
2
+ module Actions
3
+ def self.install(*songs)
4
+ @songs = SongUtils.get_songs
5
+ @local_songs = SongUtils.get_local_songs
6
+
7
+ if songs.length > 0
8
+ songs.each do |song|
9
+ name = SongUtils.parse_song_name song
10
+ version = Semver.new(SongUtils.parse_song_version song)
11
+ url = @songs[name]['url']
12
+ path = "bowie_songs/#{name}"
13
+
14
+ if File.directory? path
15
+ self.update(name)
16
+ else
17
+ FileUtils.mkdir_p(path)
18
+ Git.clone(url, path)
19
+ if version.major != nil
20
+ g = Git.open(path)
21
+ begin
22
+ g.checkout(version.to_s)
23
+ rescue
24
+ begin
25
+ g.checkout(version.to_s :v => true)
26
+ rescue
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ unless @local_songs.include? name or @local_songs.include? name+'#'+version.to_s
33
+ version.major ? @local_songs.push(name+'#'+version.to_s) : @local_songs.push(name)
34
+ end
35
+ File.open("songs.yml", "w"){|f| YAML.dump(@local_songs, f)}
36
+ end
37
+ else
38
+ @local_songs.each {|song| self.install(song)}
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ module Bowie
2
+ module Actions
3
+ # List all the installed packages
4
+ def self.list
5
+ @local_songs = SongUtils.get_local_songs
6
+ @songs = SongUtils.get_songs
7
+
8
+ @songs.select {|el| @local_songs.include? el}
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module Bowie
2
+ module Actions
3
+ # Remove all the packages not included in songs.yml
4
+ def self.prune
5
+ @local_songs = SongUtils.get_local_songs
6
+
7
+ SongUtils.get_songs_dirs.each do |dir|
8
+ unless @local_songs.include? dir
9
+ FileUtils.rm_rf("bowie_songs/#{dir}")
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module Bowie
2
+ module Actions
3
+ # Return a printable list of available packages matching the [query]
4
+ def self.search(query)
5
+ @songs = SongUtils.get_songs
6
+ @songs.select { |el| /.*#{query}.*/ =~ el }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ module Bowie
2
+ module Actions
3
+ # Remove the selected package
4
+ def self.uninstall(*songs)
5
+ @songs = SongUtils.get_songs
6
+ @local_songs = SongUtils.get_local_songs
7
+
8
+ songs.each do |song|
9
+ name = SongUtils.parse_song_name song
10
+ version = Semver.new(SongUtils.parse_song_version song)
11
+ path = "bowie_songs/#{name}"
12
+
13
+ FileUtils.rm_rf(path) # use remove_entry_secure for security reasons?
14
+
15
+ if version.major != nil
16
+ @local_songs.delete "#{name}##{version}"
17
+ else
18
+ @local_songs.delete_if {|el| not (el =~ /^#{name}#/).nil?}
19
+ end
20
+ File.open("songs.yml", "w"){|f| YAML.dump(@local_songs, f)}
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ module Bowie
2
+ module Actions
3
+ # Update the selected package
4
+ def self.update(*songs)
5
+ @songs = SongUtils.get_songs
6
+ @local_songs = SongUtils.get_local_songs
7
+
8
+ if songs.length > 0
9
+ songs.each do |song|
10
+ name = SongUtils.parse_song_name song
11
+ version = Semver.new(SongUtils.parse_song_version song)
12
+ path = "bowie_songs/#{name}"
13
+
14
+ g = Git.open(path, :log => Logger.new(STDOUT))
15
+ g.reset_hard('HEAD')
16
+ g.pull
17
+ unless version.major.nil?
18
+ begin
19
+ g.checkout(version.to_s)
20
+ rescue
21
+ begin
22
+ g.checkout(version.to_s :v => true)
23
+ rescue
24
+ end
25
+ end
26
+ end
27
+ @local_songs.delete name
28
+ @local_songs.delete_if {|el| not (el =~ /^#{name}#/).nil?}
29
+ version.major ? @local_songs.push(name+'#'+version.to_s) : @local_songs.push(name)
30
+ File.open("songs.yml", "w"){|f| YAML.dump(@local_songs, f)}
31
+ end
32
+ else
33
+ @local_songs.each {|song| self.update(song)}
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,42 @@
1
+ require 'thor'
2
+
3
+ module Bowie
4
+ class CLI < Thor
5
+
6
+ SongUtils.get_songs
7
+ SongUtils.get_local_songs
8
+ SongUtils.get_local_lyrics
9
+
10
+ desc "install [song]", "install the selected package"
11
+ def install(*songs)
12
+ Actions.install(*songs)
13
+ end
14
+
15
+ desc "update [song]", "update the selected package"
16
+ def update(*songs)
17
+ Actions.update(*songs)
18
+ end
19
+
20
+ desc "uninstall [song]", "remove the selected package"
21
+ def uninstall(*songs)
22
+ Actions.uninstall(*songs)
23
+ end
24
+
25
+ desc "search [song]", "list all availables packages matching [song]"
26
+ def search(song)
27
+ results = Bowi::Actions.search(song)
28
+ results.each { |key, values| puts "#{values['name']}:\n #{values['description']}" }
29
+ end
30
+
31
+ desc "prune", "remove all the packages not included in songs.yml"
32
+ def prune
33
+ Actions.prune
34
+ end
35
+
36
+ desc "list", "list all the installed packages"
37
+ def list
38
+ results = Actions.list
39
+ results.each { |key, values| puts "#{values['name']}:\n #{values['description']}" }
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,61 @@
1
+ module Bowie
2
+ module SongUtils
3
+ # Retrive the online registry of available songs
4
+ def self.get_songs
5
+ begin
6
+ YAML.parse(open("https://raw.github.com/axyz/bowie-songs/master/songs.yml")).to_ruby
7
+ rescue
8
+ puts "ERROR: Cannot connect to github.com"
9
+ end
10
+ end
11
+
12
+ # Retrive the local registry of installed songs
13
+ def self.get_local_songs
14
+ begin
15
+ YAML.load_file('songs.yml')? YAML.load_file('songs.yml') : Array.new
16
+ rescue
17
+ begin
18
+ FileUtils.mkdir 'bowie_songs'
19
+ rescue
20
+ end
21
+ FileUtils.touch 'songs.yml'
22
+ return Array.new
23
+ end
24
+ end
25
+
26
+ # Retrive the local lyrics file
27
+ def self.get_local_lyrics
28
+ begin
29
+ YAML.load_file('bowie_songs/lyrics.yml')? YAML.load_file('songs.yml') : Hash.new
30
+ rescue
31
+ begin
32
+ FileUtils.mkdir 'bowie_songs'
33
+ rescue
34
+ end
35
+ FileUtils.touch 'bowie_songs/lyrics.yml'
36
+ return Hash.new
37
+ end
38
+ end
39
+
40
+ # Return an array with all the direcotry inside bowye_songs
41
+ def self.get_songs_dirs
42
+ result = []
43
+ Dir.foreach('bowie_songs') do |el|
44
+ unless (el == "." or el == ".." or el == "lyrics.yml")
45
+ result.push el
46
+ end
47
+ end
48
+ result
49
+ end
50
+
51
+ # Parse the name of a package in the form name#version
52
+ def self.parse_song_name(s)
53
+ s.split("#")[0]
54
+ end
55
+
56
+ # Parse the version of a package in the form name#version
57
+ def self.parse_song_version(s)
58
+ s.split("#")[1]
59
+ end
60
+ end
61
+ end
@@ -3,27 +3,6 @@ require "git"
3
3
  module Bowie
4
4
  module Utils
5
5
 
6
- # Return an array with all the direcotry inside bowye_songs
7
- def self.get_songs_dirs
8
- result = []
9
- Dir.foreach('bowie_songs') do |el|
10
- unless (el == "." or el == ".." or el == "lyrics.yml")
11
- result.push el
12
- end
13
- end
14
- result
15
- end
16
-
17
- # Parse the name of a package in the form name#version
18
- def self.parse_song_name(s)
19
- s.split("#")[0]
20
- end
21
-
22
- # Parse the version of a package in the form name#version
23
- def self.parse_song_version(s)
24
- s.split("#")[1]
25
- end
26
-
27
6
  def self.get_git_tags(path)
28
7
  result = Array.new
29
8
  g = Git.open(path)
@@ -1,3 +1,3 @@
1
1
  module Bowie
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
File without changes
@@ -0,0 +1,5 @@
1
+ require 'rspec'
2
+ require './lib/bowie'
3
+
4
+ Describe Bowie do
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bowie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrea Moretti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-14 00:00:00.000000000 Z
11
+ date: 2013-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: git
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -82,9 +96,19 @@ files:
82
96
  - bin/bowie
83
97
  - bowie.gemspec
84
98
  - lib/bowie.rb
85
- - lib/bowie/semver.rb
99
+ - lib/bowie/actions.rb
100
+ - lib/bowie/actions/install.rb
101
+ - lib/bowie/actions/list.rb
102
+ - lib/bowie/actions/prune.rb
103
+ - lib/bowie/actions/search.rb
104
+ - lib/bowie/actions/uninstall.rb
105
+ - lib/bowie/actions/update.rb
106
+ - lib/bowie/cli.rb
107
+ - lib/bowie/song_utils.rb
86
108
  - lib/bowie/utils.rb
87
109
  - lib/bowie/version.rb
110
+ - lib/semver/semver.rb
111
+ - spec/bowie_spec.rb
88
112
  homepage: http://axyz.github.io/bowie/
89
113
  licenses:
90
114
  - MIT
@@ -109,4 +133,5 @@ rubygems_version: 2.0.3
109
133
  signing_key:
110
134
  specification_version: 4
111
135
  summary: The White Duke rules them all
112
- test_files: []
136
+ test_files:
137
+ - spec/bowie_spec.rb