dcs-debian 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 196051d55c2132d2324c9a032f1944183f766a07
4
+ data.tar.gz: de29432ca948d6453e6f4be9ea35e0d4bee6e410
5
+ SHA512:
6
+ metadata.gz: 3115eaf85d8cb58b3378071d5145820ed23cac43ec8836c0f783ecced144ce5aa14abbd4c45d60eced247235cb63d2b1a1b74186610087732087c890129edca3
7
+ data.tar.gz: 2701943a0d02cf5cbd2531187d0cc1544cc87c8ff1222244dd63da8dab03a7d4ce94dbe69829c21aa78398b5a2454ed3979d5f28dddf435e070fdc36795fc6b7
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dcs-debian.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 HAYASHI Kentaro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Dcs::Debian
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dcs-debian'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dcs-debian
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/dcs-debian/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/dcs-debian ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.dirname(__FILE__) + "/../lib")
4
+
5
+ require 'dcs/debian'
6
+
7
+ Dcs::Debian::Command.start
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dcs/debian/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dcs-debian"
8
+ spec.version = Dcs::Debian::VERSION
9
+ spec.authors = ["HAYASHI Kentaro"]
10
+ spec.email = ["kenhys@gmail.com"]
11
+ spec.summary = %q{Command line tool to search debian/ files.}
12
+ spec.description = %q{Search keyword from http://codesearch.debian.net by command line.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "thor", "~> 0.19.1"
22
+ spec.add_runtime_dependency "colored", "~> 1.2"
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
data/lib/dcs/debian.rb ADDED
@@ -0,0 +1,49 @@
1
+ require "thor"
2
+ require "open-uri"
3
+ require "nokogiri"
4
+ require "colored"
5
+ require "dcs/debian/version"
6
+ require "dcs/debian/helper"
7
+
8
+ module Dcs
9
+ module Debian
10
+ # Your code goes here...
11
+
12
+ class Command < Thor
13
+
14
+ desc "control [KEYWORDS]", ""
15
+ def control(arg)
16
+ client = Searcher.new
17
+ client.pagination("control", arg) do |context|
18
+ puts sprintf("%s (%s)",
19
+ context[:path].bold.white_on_green,
20
+ context[:url].white_on_blue)
21
+ puts context[:pre].gsub(/#{arg}/, '\&'.red_on_yellow)
22
+ end
23
+ end
24
+
25
+ desc "changelog [KEYWORDS]", ""
26
+ def changelog(arg)
27
+ client = Searcher.new
28
+ client.pagination("changelog", arg) do |context|
29
+ puts sprintf("%s (%s)",
30
+ context[:path].bold.white_on_green,
31
+ context[:url].white_on_blue)
32
+ puts context[:pre].gsub(/#{arg}/, '\&'.red_on_yellow)
33
+ end
34
+ end
35
+
36
+ desc "rules [KEYWORDS]", ""
37
+ def rules(arg)
38
+ client = SearchClient.new
39
+ client.pagination("rules", arg) do |context|
40
+ puts sprintf("%s (%s)",
41
+ context[:path].bold.white_on_green,
42
+ context[:url].white_on_blue)
43
+ puts context[:pre].gsub(/#{arg}/, '\&'.red_on_yellow)
44
+ end
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,101 @@
1
+ module Dcs
2
+ module Debian
3
+
4
+ class Searcher
5
+
6
+ attr_accessor :page_limit
7
+ attr_accessor :n_limit
8
+
9
+ BASE_URL = "http://codesearch.debian.net"
10
+
11
+ def initialize
12
+ @page_limit = 10
13
+ @n_limit = 10
14
+ end
15
+
16
+ def pagination(target, keyword)
17
+ next_uri = nil
18
+
19
+ data = []
20
+ unless next_uri
21
+ next_uri = sprintf("%s/search?q=%s+path%%3Adebian%%2F%s",
22
+ BASE_URL, keyword, target)
23
+ end
24
+
25
+ page = 1
26
+ n = 1
27
+ until next_uri.nil? or n > @n_limit or page > @page_limit
28
+ html = open(next_uri, "r:utf-8").read
29
+ Nokogiri.parse(html) do |doc|
30
+ doc.xpath("//ul[@id='results']/li").each do |li|
31
+ entry = extract_entry(li, target)
32
+ unless entry.empty?
33
+ if entry[:pre].include?(keyword)
34
+ n = n + 1
35
+ yield(entry)
36
+ end
37
+ end
38
+ end
39
+ next_uri = extract_next_page_uri(doc)
40
+ end
41
+ page = page + 1
42
+ end
43
+ end
44
+
45
+ def extract_next_page_uri(node)
46
+ next_uri = nil
47
+ node.xpath("//div[@id='pagination']").each do |div|
48
+ div.xpath("a").each do |a|
49
+ case a.text
50
+ when "Next page"
51
+ next_uri = BASE_URL + a.attribute("href").text
52
+ end
53
+ end
54
+ end
55
+ next_uri
56
+ end
57
+
58
+ def extract_entry(node, target)
59
+ url = BASE_URL + node.xpath("a").attribute("href").text
60
+ raw = node.xpath("a/code").text
61
+ raw =~ /(.+)debian\/(.+):(.+)/
62
+ package = $1
63
+ file = $2
64
+ line = $3
65
+ entry = {}
66
+ case file
67
+ when target
68
+ entry[:path] = raw
69
+ entry[:url] = url
70
+ entry[:package] = package
71
+ entry[:file] = file
72
+ entry[:line] = line
73
+ node.xpath("pre").each do |pre|
74
+ data = []
75
+ pre.children.each do |cnode|
76
+ if cnode.kind_of?(Nokogiri::XML::Element)
77
+ case cnode.attribute("name")
78
+ when "br"
79
+ when "strong"
80
+ data << indent + cnode.text
81
+ end
82
+ else
83
+ data << indent + cnode.text
84
+ end
85
+ end
86
+ entry[:pre] = data.join("\n")
87
+ end
88
+ else
89
+ #p file
90
+ #p line
91
+ end
92
+ entry
93
+ end
94
+
95
+ def indent
96
+ " " * 2
97
+ end
98
+
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,5 @@
1
+ module Dcs
2
+ module Debian
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dcs-debian
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - HAYASHI Kentaro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: colored
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Search keyword from http://codesearch.debian.net by command line.
70
+ email:
71
+ - kenhys@gmail.com
72
+ executables:
73
+ - dcs-debian
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - bin/dcs-debian
83
+ - dcs-debian.gemspec
84
+ - lib/dcs/debian.rb
85
+ - lib/dcs/debian/helper.rb
86
+ - lib/dcs/debian/version.rb
87
+ homepage: ''
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Command line tool to search debian/ files.
111
+ test_files: []