xs 0.0.1

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.
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2009-10-05
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,11 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ bin/xs
7
+ lib/xs.rb
8
+ lib/xs/apt_cache.rb
9
+ script/console
10
+ script/destroy
11
+ script/generate
@@ -0,0 +1,7 @@
1
+
2
+ For more information on xs, see http://xs.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
@@ -0,0 +1,48 @@
1
+ = xs
2
+
3
+ * http://github.com/#{github_username}/#{project_name}
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2009 FIXME full name
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/xs'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'xs' do
14
+ self.developer 'David Cuadrado', 'krawek@gmail.coom'
15
+ # self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
27
+
data/bin/xs ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Author: David Cuadrado <krawek at gmaREMOVEil dot com>
4
+ # License: MIT
5
+
6
+ $:.unshift File.dirname(__FILE__)+"/../lib"
7
+
8
+ require 'open3'
9
+ require 'xs'
10
+ require 'optparse'
11
+
12
+ options = { :section => false, :description => false, :complete => false, :compact => false }
13
+
14
+ optparser = OptionParser.new do |opts|
15
+ opts.banner = "Usage: #{$0} [options] <pattern>"
16
+
17
+ opts.on("-a", "--all", "Perform a complete search") do |o|
18
+ options[:complete] = true
19
+ end
20
+
21
+ opts.on("-d", "--description", "Search in description") do |o|
22
+ options[:description] = true
23
+ end
24
+
25
+ opts.on("-s", "--section", "Search in section") do |o|
26
+ options[:section] = true
27
+ end
28
+
29
+ opts.on("-c", "--compact", "Compact output") do |o|
30
+ options[:compact] = true
31
+ end
32
+
33
+ opts.on_tail("-h", "--help", "Show this help message.") do
34
+ puts opts
35
+ exit
36
+ end
37
+ end
38
+
39
+ args = []
40
+ begin
41
+ args = optparser.parse!
42
+ if args.empty?
43
+ raise StandardError, "Missing pattern"
44
+ end
45
+ rescue => e
46
+ $stderr.puts e
47
+ $stderr.puts optparser
48
+ exit 0
49
+ end
50
+
51
+ target = args.first
52
+ begin
53
+ Regexp.compile(target)
54
+ rescue RegexpError
55
+ target = Regexp.escape(target)
56
+ end
57
+
58
+ options[:pattern] = target
59
+
60
+ APT_SEARCH = "apt-cache search #{target}"
61
+
62
+ begin
63
+ Open3.popen3(APT_SEARCH) { |stdin, stdout, stderr|
64
+ matches = 0
65
+ stdout.each { |line|
66
+ matches += 1 if AptCache.parse(line, options)
67
+ }
68
+
69
+ puts "Found #{matches} matches"
70
+ }
71
+ rescue Interrupt
72
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'xs/apt_cache'
5
+
6
+ module Xs
7
+ VERSION = '0.0.1'
8
+ end
@@ -0,0 +1,83 @@
1
+ class AptCache
2
+ def self.parse(pkgdesc, options = {})
3
+ if pkgdesc =~ /([\w\-\_\.\+]+)\s-\s(.+)$/
4
+ pkgname = $1
5
+ description = $2
6
+ pattern = options[:pattern]
7
+
8
+ if options[:complete] or options[:section]
9
+ return AptCache.show(pkgname, options)
10
+ elsif options[:description]
11
+ return AptCache.show(pkgname, options) if description =~ /#{pattern}/
12
+ else
13
+ return AptCache.show(pkgname, options) if pkgname =~ /#{pattern}/
14
+ end
15
+ end
16
+
17
+ false
18
+ end
19
+
20
+ def self.show(pkg, options)
21
+ compact = options[:compact]
22
+
23
+ Open3.popen3("apt-cache show #{pkg}") { |stdin, stdout, stderr|
24
+ hash = {}
25
+ stdout.each { |line|
26
+ if line =~ /([\w\-]+):\s(.+)$/
27
+ hash[$1.downcase.to_sym] = $2
28
+ end
29
+ }
30
+
31
+ if hash.empty?
32
+ puts "FAILED: #{pkg}"
33
+ end
34
+
35
+ if options[:section]
36
+ return if not hash[:section] =~ /#{options[:pattern]}/
37
+ end
38
+
39
+ installed = AptCache.installed?(pkg)
40
+
41
+ if not compact
42
+ print " \033[92m*\033[00m #{hash[:section]}/\033[01m#{hash[:package]}\033[00m "
43
+ if installed
44
+ puts "[\033[01;32mINSTALLED\033[00m]"
45
+ else
46
+ puts ""
47
+ end
48
+ puts " \033[32mVersion:\033[00m \033[96m#{hash[:version]}\033[00m"
49
+
50
+ if hash.has_key? :homepage
51
+ puts " \033[32mHomepage:\033[00m #{hash[:homepage]}"
52
+ end
53
+
54
+ puts " \033[32mDescription:\033[00m #{hash[:description]}"
55
+ puts " \033[32mDownload size:\033[00m #{((hash[:size].to_i + 1023) / 1024)} KiB"
56
+ else
57
+ print " \033[92m*\033[00m #{hash[:section]}/\033[01m#{hash[:package]}\033[00m (\033[32m#{hash[:version]}\033[00m): #{hash[:description]} "
58
+ if installed
59
+ print "[\033[01;32mINSTALLED\033[00m]"
60
+ else
61
+ print ""
62
+ end
63
+ end
64
+ puts ""
65
+ return true
66
+ }
67
+
68
+ false
69
+ end
70
+
71
+
72
+ def self.installed?(pkg)
73
+ Open3.popen3("dpkg -l #{pkg}") { |stdin, stdout, stderr|
74
+ stdout.each { |line|
75
+ if line =~ /^ii\s+#{Regexp.escape(pkg)}\s+/
76
+ return true
77
+ end
78
+ }
79
+ }
80
+
81
+ false
82
+ end
83
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/xs.rb'}"
9
+ puts "Loading xs gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Cuadrado
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-05 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.3
24
+ version:
25
+ description: FIX (describe your package)
26
+ email:
27
+ - krawek@gmail.coom
28
+ executables:
29
+ - xs
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - PostInstall.txt
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - PostInstall.txt
40
+ - README.rdoc
41
+ - Rakefile
42
+ - bin/xs
43
+ - lib/xs.rb
44
+ - lib/xs/apt_cache.rb
45
+ - script/console
46
+ - script/destroy
47
+ - script/generate
48
+ has_rdoc: true
49
+ homepage: http://github.com/#{github_username}/#{project_name}
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --main
55
+ - README.rdoc
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project: xs
73
+ rubygems_version: 1.3.5
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: FIX (describe your package)
77
+ test_files: []
78
+