Module: Bowie::Actions
- Defined in:
- lib/bowie/actions/list.rb,
lib/bowie/actions/prune.rb,
lib/bowie/actions/search.rb,
lib/bowie/actions/update.rb,
lib/bowie/actions/install.rb,
lib/bowie/actions/uninstall.rb
Class Method Summary collapse
- .install(*songs) ⇒ Object
-
.list ⇒ Object
List all the installed packages.
-
.prune ⇒ Object
Remove all the packages not included in songs.yml.
-
.search(query) ⇒ Object
Return a printable list of available packages matching the [query].
-
.uninstall(*songs) ⇒ Object
Remove the selected package.
-
.update(*songs) ⇒ Object
Update the selected package.
Class Method Details
.install(*songs) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bowie/actions/install.rb', line 3 def self.install(*songs) @songs = SongUtils.get_songs @local_songs = SongUtils.get_local_songs if songs.length > 0 songs.each do |song| name = SongUtils.parse_song_name song begin version = Semver.new(SongUtils.parse_song_version song) rescue version = false end url = @songs[name]['url'] path = "bowie_songs/#{name}" if File.directory? path self.update(name) else FileUtils.mkdir_p(path) Git.clone(url, path) if version g = Git.open(path) begin g.checkout(version.to_s) rescue begin g.checkout(version.to_s :v => true) rescue end end end end unless @local_songs.include? name or @local_songs.include? name+'#'+version.to_s version ? @local_songs.push(name+'#'+version.to_s) : @local_songs.push(name) end File.open("songs.yml", "w"){|f| YAML.dump(@local_songs, f)} end else @local_songs.each {|song| self.install(song)} end end |
.list ⇒ Object
List all the installed packages
4 5 6 7 8 9 |
# File 'lib/bowie/actions/list.rb', line 4 def self.list @local_songs = SongUtils.get_local_songs @songs = SongUtils.get_songs @songs.select {|el| @local_songs.include? el} end |
.prune ⇒ Object
Remove all the packages not included in songs.yml
4 5 6 7 8 9 10 11 12 |
# File 'lib/bowie/actions/prune.rb', line 4 def self.prune @local_songs = SongUtils.get_local_songs SongUtils.get_songs_dirs.each do |dir| unless @local_songs.include? dir FileUtils.rm_rf("bowie_songs/#{dir}") end end end |
.search(query) ⇒ Object
Return a printable list of available packages matching the [query]
4 5 6 7 |
# File 'lib/bowie/actions/search.rb', line 4 def self.search(query) @songs = SongUtils.get_songs @songs.select { |el| /.*#{query}.*/ =~ el } end |
.uninstall(*songs) ⇒ Object
Remove the selected package
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bowie/actions/uninstall.rb', line 4 def self.uninstall(*songs) @songs = SongUtils.get_songs @local_songs = SongUtils.get_local_songs songs.each do |song| name = SongUtils.parse_song_name song begin version = Semver.new(SongUtils.parse_song_version song) rescue version = false end path = "bowie_songs/#{name}" FileUtils.rm_rf(path) # use remove_entry_secure for security reasons? if version @local_songs.delete "#{name}##{version}" else @local_songs.delete_if {|el| not (el =~ /^#{name}#/).nil?} end File.open("songs.yml", "w"){|f| YAML.dump(@local_songs, f)} end end |
.update(*songs) ⇒ Object
Update the selected package
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bowie/actions/update.rb', line 4 def self.update(*songs) @songs = SongUtils.get_songs @local_songs = SongUtils.get_local_songs if songs.length > 0 songs.each do |song| name = SongUtils.parse_song_name song begin version = Semver.new(SongUtils.parse_song_version song) rescue version = false end path = "bowie_songs/#{name}" g = Git.open(path, :log => Logger.new(STDOUT)) g.reset_hard('HEAD') g.pull unless version begin g.checkout(version.to_s) rescue begin g.checkout(version.to_s :v => true) rescue end end end @local_songs.delete name @local_songs.delete_if {|el| not (el =~ /^#{name}#/).nil?} version ? @local_songs.push(name+'#'+version.to_s) : @local_songs.push(name) File.open("songs.yml", "w"){|f| YAML.dump(@local_songs, f)} end else @local_songs.each {|song| self.update(song)} end end |