dgh 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,170 @@
1
+ # Treetop grammar for apt-cache policy output
2
+ grammar Policy
3
+ rule package_list
4
+ package_entry+ {
5
+ def content
6
+ elements.map {|e| e.content}
7
+ end
8
+ }
9
+ end
10
+
11
+ rule package_entry
12
+ package_name ":\n"
13
+ " " installed "\n"
14
+ " " candidate "\n"
15
+ version_table {
16
+ def content
17
+ {
18
+ :name => elements[0].content,
19
+ :installed_version => elements[3].content,
20
+ :candidate_version => elements[6].content,
21
+ :versions => elements[8].content
22
+ }
23
+ end
24
+ }
25
+ end
26
+
27
+ rule package_name
28
+ [a-z0-9_.+-]+ {
29
+ def content
30
+ elements.inject("") {|s,e| s << e.text_value}
31
+ end
32
+ }
33
+ end
34
+
35
+ rule installed
36
+ "Installed: " version {
37
+ def content
38
+ elements[1].content
39
+ end
40
+ }
41
+ end
42
+
43
+ rule candidate
44
+ "Candidate: " version {
45
+ def content
46
+ elements[1].content
47
+ end
48
+ }
49
+ end
50
+
51
+ rule version
52
+ ([0-9] ":")? [a-zA-Z0-9_.~+-]+ {
53
+ def content
54
+ text_value
55
+ end
56
+ }
57
+ end
58
+
59
+ rule version_table
60
+ " Version table:\n" version_table_entries {
61
+ def content
62
+ elements[1].content
63
+ end
64
+ }
65
+ end
66
+
67
+ rule version_table_entries
68
+ version_table_entry+ {
69
+ def content
70
+ elements.map {|e| e.content}
71
+ end
72
+ }
73
+ end
74
+
75
+ rule version_table_entry
76
+ (current_mark / not_current_mark) version " " [0-9]+ "\n" source_lines {
77
+ def content
78
+ {
79
+ :version => elements[1].content,
80
+ :current => elements[0].content,
81
+ :sources => elements[5].content
82
+ }
83
+ end
84
+ }
85
+ end
86
+
87
+ rule current_mark
88
+ " *** " {
89
+ def content
90
+ true
91
+ end
92
+ }
93
+ end
94
+
95
+ rule not_current_mark
96
+ " " {
97
+ def content
98
+ false
99
+ end
100
+ }
101
+ end
102
+
103
+ rule source_lines
104
+ source_line+ {
105
+ def content
106
+ elements.map {|e| e.content}
107
+ end
108
+ }
109
+ end
110
+
111
+ rule source_line
112
+ " "+ priority " "+ (status_file / apt_source) "\n" {
113
+ def content
114
+ {
115
+ :priority => elements[1].content,
116
+ :source => elements[3].content
117
+ }
118
+ end
119
+ }
120
+ end
121
+
122
+ rule priority
123
+ [0-9]+ {
124
+ def content
125
+ text_value.to_i
126
+ end
127
+ }
128
+ end
129
+
130
+ rule status_file
131
+ "/var/lib/dpkg/status" {
132
+ def content
133
+ text_value
134
+ end
135
+ }
136
+ end
137
+
138
+ rule apt_source
139
+ url " "+ (section " "+)? (arch " "+)? "Packages" {
140
+ def content
141
+ text_value
142
+ end
143
+ }
144
+ end
145
+
146
+ rule url
147
+ [a-z]+ "://" [^ ]+ {
148
+ def content
149
+ text_value
150
+ end
151
+ }
152
+ end
153
+
154
+ rule section
155
+ [a-z-]+ "/" [a-z-]+ {
156
+ def content
157
+ text_value
158
+ end
159
+ }
160
+ end
161
+
162
+ rule arch
163
+ [a-zA-Z0-9]+ {
164
+ def content
165
+ text_value
166
+ end
167
+ }
168
+ end
169
+ end
170
+ # vim: filetype=ruby
@@ -0,0 +1,74 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ PolicyOutputWithDowngradable = <<EOS
4
+ avahi-autoipd:
5
+ Installed: 0.6.30-3ubuntu1~natty1
6
+ Candidate: 0.6.30-3ubuntu1~natty1
7
+ Version table:
8
+ *** 0.6.30-3ubuntu1~natty1 0
9
+ 100 /var/lib/dpkg/status
10
+ 0.6.30-0ubuntu2 0
11
+ 500 http://fi.archive.ubuntu.com/ubuntu/ natty/main i386 Packages
12
+ libdaemon0:
13
+ Installed: 0.14-2
14
+ Candidate: 0.14-2
15
+ Version table:
16
+ *** 0.14-2 0
17
+ 500 http://fi.archive.ubuntu.com/ubuntu/ natty/main i386 Packages
18
+ 100 /var/lib/dpkg/status
19
+ EOS
20
+
21
+ PolicyOutputWithoutDowngradable = <<EOS
22
+ automake:
23
+ Installed: 1:1.11.1-1ubuntu1
24
+ Candidate: 1:1.11.1-1ubuntu1
25
+ Version table:
26
+ *** 1:1.11.1-1ubuntu1 0
27
+ 500 http://fi.archive.ubuntu.com/ubuntu/ natty/main i386 Packages
28
+ 100 /var/lib/dpkg/status
29
+ autotools-dev:
30
+ Installed: 20100122.1
31
+ Candidate: 20100122.1
32
+ Version table:
33
+ *** 20100122.1 0
34
+ 500 http://fi.archive.ubuntu.com/ubuntu/ natty/main i386 Packages
35
+ 100 /var/lib/dpkg/status
36
+ libqt4-dev:
37
+ Installed: 4:4.7.2-0ubuntu6
38
+ Candidate: 4:4.7.2-0ubuntu6
39
+ Version table:
40
+ *** 4:4.7.2-0ubuntu6 0
41
+ 500 http://fi.archive.ubuntu.com/ubuntu/ natty/main i386 Packages
42
+ 100 /var/lib/dpkg/status
43
+ EOS
44
+
45
+ describe Dgh do
46
+ describe 'parser' do
47
+ it 'parses apt-cache policy output' do
48
+ result = Dgh.parse(PolicyOutputWithDowngradable).content
49
+ result.length.should == 2
50
+ result[0][:name].should == 'avahi-autoipd'
51
+ result[0][:installed_version].should == '0.6.30-3ubuntu1~natty1'
52
+ result[0][:candidate_version].should == '0.6.30-3ubuntu1~natty1'
53
+ result[0][:versions].length.should == 2
54
+ result[0][:versions][0][:version].should == '0.6.30-3ubuntu1~natty1'
55
+ result[0][:versions][0][:current].should == true
56
+ result[0][:versions][0][:sources].length.should == 1
57
+ result[0][:versions][0][:sources][0][:priority].should == 100
58
+ result[0][:versions][0][:sources][0][:source].should == '/var/lib/dpkg/status'
59
+ end
60
+ end
61
+
62
+ describe 'scanner' do
63
+ it 'finds downgradable packages in parse results' do
64
+ result = Dgh.find_downgradable(Dgh.parse(PolicyOutputWithDowngradable).content)
65
+ result.length.should == 1
66
+ result[0][:name].should == "avahi-autoipd"
67
+ end
68
+
69
+ it "doesn't find downgradables where there aren't any" do
70
+ result = Dgh.find_downgradable(Dgh.parse(PolicyOutputWithoutDowngradable).content)
71
+ result.length.should == 0
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'spork'
3
+
4
+ Spork.prefork do
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'rspec'
8
+
9
+ # Requires supporting files with custom matchers and macros, etc,
10
+ # in ./support/ and its subdirectories.
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+ end
15
+ end
16
+
17
+ Spork.each_run do
18
+ require 'dgh'
19
+ end
20
+
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env watchr
2
+ # vim: filetype=ruby
3
+ #
4
+ # Thanks to
5
+ # http://www.stupididea.com/2009/03/15/non-rails-autotest-rspec-libnotify-linux/
6
+ # for inspiration.
7
+
8
+ def have_notify_send?
9
+ case `which notify-send`.empty?
10
+ when true
11
+ false
12
+ else
13
+ true
14
+ end
15
+ end
16
+
17
+ def have_growl?
18
+ @have_growl ||= begin
19
+ require 'growl'
20
+ rescue LoadError
21
+ false
22
+ end
23
+ end
24
+
25
+ def error_icon_name
26
+ "gtk-dialog-error"
27
+ end
28
+
29
+ def success_icon_name
30
+ "gtk-dialog-info"
31
+ end
32
+
33
+ # Rules
34
+ watch('^spec/.+_spec\.rb$') { |md| spec md[0] }
35
+ watch('^lib/.+\.rb$') { |md| spec "spec/#{File.basename(md[0]).gsub(/\..*?$/, '')}_spec.rb" }
36
+ watch('^features/.+\.feature$') { |md| feature md[0] }
37
+ watch('^lib/.+\.treetop$') { |md| treetop md[0]; run_suite }
38
+
39
+ # Notify using notify-send.
40
+ #
41
+ # @param icon [String] name of stock icon to use.
42
+ # @param title [String] title of notification.
43
+ # @param message [String] message for notification body.
44
+ # @return [Boolean] true if the command ran successfully, false
45
+ # otherwise.
46
+ def notify(icon, title, message)
47
+ system("notify-send -t 3000 -i #{icon} \"#{title}\" \"#{message}\"")
48
+ end
49
+
50
+ # Notify of success.
51
+ #
52
+ def notify_success
53
+ puts "Success"
54
+ #if have_notify_send?
55
+ #notify success_icon_name, "All green!", "Now write more tests :)"
56
+ #elsif have_growl?
57
+ #Growl.notify_ok "All green!"
58
+ #end
59
+ end
60
+
61
+ # Notify of failure.
62
+ #
63
+ def notify_failure
64
+ puts "Failure"
65
+ #if have_notify_send?
66
+ #notify error_icon_name, "Something is broken", "Now go fix it :)"
67
+ #elsif have_growl?
68
+ #Growl.notify_error "Something is broken"
69
+ #end
70
+ end
71
+
72
+ # Run a single ruby command. Notify appropriately.
73
+ #
74
+ # @param cmd [String] command to run.
75
+ def run(cmd)
76
+ system('clear')
77
+ puts "Running #{cmd}"
78
+ if system(cmd)
79
+ notify_success
80
+ true
81
+ else
82
+ notify_failure
83
+ false
84
+ end
85
+ end
86
+
87
+ # Run a single spec.
88
+ #
89
+ # @param specfile [String] path to specfile.
90
+ def spec(specfile)
91
+ if run(%Q(rspec #{rspec_opts} #{specfile}))
92
+ if @last_run_failed
93
+ run_all_specs && @last_run_failed = false
94
+ end
95
+ else
96
+ @last_run_failed = true
97
+ end
98
+ end
99
+
100
+ # Run a single feature.
101
+ #
102
+ # @param featurefile [String] path to feature file.
103
+ def feature(featurefile)
104
+ run(%Q(cucumber #{cucumber_opts} #{featurefile}))
105
+ end
106
+
107
+ # Compile a treetop grammar
108
+ #
109
+ # @param grammarfile [String] path to grammar file
110
+ def treetop(grammarfile)
111
+ run(%Q(tt #{grammarfile}))
112
+ end
113
+
114
+ # Options for rspec run
115
+ #
116
+ # @return [String] string with options.
117
+ def rspec_opts
118
+ "--format documentation --color --drb"
119
+ end
120
+
121
+ # Options for cucumber run.
122
+ #
123
+ # @return [String] string with options.
124
+ def cucumber_opts
125
+ "--drb --port 8990"
126
+ end
127
+
128
+ # Run all specs.
129
+ #
130
+ def run_all_specs
131
+ run "rake spec"
132
+ end
133
+
134
+ # Run all features.
135
+ #
136
+ def run_features
137
+ run "rake features"
138
+ end
139
+
140
+ # Run specs and features.
141
+ #
142
+ def run_suite
143
+ run "rake spec features"
144
+ end
145
+
146
+ # Run all specs on Ctrl-\
147
+ Signal.trap('QUIT') { run_all_specs }
148
+
149
+ # Run full suite on one Ctrl-C, quit on two
150
+ @interrupted = false
151
+ Signal.trap('INT') do
152
+ if @interrupted
153
+ abort("\n")
154
+ else
155
+ puts "Interrupt a second time to quit"
156
+ @interrupted = true
157
+ Kernel.sleep 1.5
158
+ run_suite
159
+ @interrupted = false
160
+ end
161
+ end
162
+
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dgh
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.2
6
+ platform: ruby
7
+ authors:
8
+ - Ilkka Laukkanen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-23 00:00:00 +03:00
14
+ default_executable: dgh
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: treetop
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 0.9.0
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 2.6.0
47
+ type: :development
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: yard
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: 0.6.0
58
+ type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: cucumber
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ type: :development
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: bundler
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ version: 1.0.13
80
+ type: :development
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: jeweler
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: 1.5.2
91
+ type: :development
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: spork
95
+ prerelease: false
96
+ requirement: &id008 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
102
+ type: :development
103
+ version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
105
+ name: watchr
106
+ prerelease: false
107
+ requirement: &id009 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: "0"
113
+ type: :development
114
+ version_requirements: *id009
115
+ description: |
116
+ Dgh helps when you have to manually downgrade a large amount of packages.
117
+ It requires the user to generate a file with `apt-cache policy` output for all
118
+ installed packages, which it then reads. It looks for packages that have a
119
+ currently installed version that doesn't exist in any repository, and prints
120
+ those. This includes both locally generated packages that never did exist in
121
+ any repository, and more crucially, packages that have been upgraded from e.g.
122
+ a PPA that has since been removed from the system.
123
+
124
+ email:
125
+ - ilkka.s.laukkanen@gmail.com
126
+ executables:
127
+ - dgh
128
+ extensions: []
129
+
130
+ extra_rdoc_files:
131
+ - LICENSE.txt
132
+ - README.rdoc
133
+ files:
134
+ - .document
135
+ - .gitignore
136
+ - .rspec
137
+ - .rvmrc
138
+ - Gemfile
139
+ - LICENSE.txt
140
+ - README.rdoc
141
+ - Rakefile
142
+ - bin/dgh
143
+ - cucumber.yml
144
+ - dgh.gemspec
145
+ - features/dgh.feature
146
+ - features/step_definitions/dgh_steps.rb
147
+ - features/support/env.rb
148
+ - lib/dgh.rb
149
+ - lib/dgh/version.rb
150
+ - lib/policy.rb
151
+ - lib/policy.treetop
152
+ - spec/dgh_spec.rb
153
+ - spec/spec_helper.rb
154
+ - tests.watchr
155
+ has_rdoc: true
156
+ homepage: http://github.com/ilkka/dgh
157
+ licenses:
158
+ - GPLv3
159
+ post_install_message:
160
+ rdoc_options: []
161
+
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: "0"
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: "0"
176
+ requirements: []
177
+
178
+ rubyforge_project:
179
+ rubygems_version: 1.5.2
180
+ signing_key:
181
+ specification_version: 3
182
+ summary: The Debian/Ubuntu Downgrade Helper
183
+ test_files: []
184
+