apti 0.6

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,103 @@
1
+ # encoding: utf-8
2
+ #===============================================================================
3
+ #
4
+ # This file is part of Apti.
5
+ #
6
+ # Copyright (C) 2013-2014 by Florent Lévigne <florent.levigne at mailoo dot com>
7
+ # Copyright (C) 2013-2014 by Julien Rosset <jul.rosset at gmail dot com>
8
+ #
9
+ #
10
+ # Apti is free software: you can redistribute it and/or modify
11
+ # it under the terms of the GNU General Public License as published by
12
+ # the Free Software Foundation, either version 3 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # Apti is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
22
+ #
23
+ #===============================================================================
24
+
25
+ module Apti
26
+
27
+ # Debian package.
28
+ class Package
29
+ #
30
+ # @!attribute name
31
+ # @return [String] Name of the package.
32
+ #
33
+ # @!attribute parameter
34
+ # @return [String] Aptitude's information : a, u, p, i, ...
35
+ #
36
+ # @!attribute version_old
37
+ # @return [String] Old / current version of the package.
38
+ #
39
+ # @!attribute version_new
40
+ # @return [String] New version of the package.
41
+ #
42
+ # @!attribute size_before_decimal
43
+ # @return [String] Size of the package, before the decimal.
44
+ #
45
+ # @!attribute size_after_decimal
46
+ # @return [String] Size of the package, after the decimal.
47
+ #
48
+ # @!attribute size_unit
49
+ # @return [String] Size's unit (B, kB, ...).
50
+ #
51
+ # @!attribute description
52
+ # @return [String] Description of the package.
53
+ attr_accessor :name, :parameter, :version_static, :version_old, :version_new,
54
+ :size_before_decimal, :size_after_decimal, :size_unit,
55
+ :description
56
+
57
+ # Return all the versions of the package as follow : version_old -> version_new (if version_new not nil).
58
+ #
59
+ # @return [String] Version(s) of the package.
60
+ def version_all
61
+ version_all = version_static + version_old
62
+
63
+ if !version_new.empty?
64
+ version_all += " -> #{version_new}"
65
+ end
66
+
67
+ version_all
68
+ end
69
+
70
+ # Test the existence of the package.
71
+ #
72
+ # @return [Boolean] True if the package exist.
73
+ def exist?
74
+ # Name without architecture and version informations (ex: foo for foo:amd64 or foo=3.2).
75
+ name_cleaned = name.split(':').first.split('=').first
76
+
77
+ pkg = `apt-cache show #{name} 2>/dev/null | grep "Package: #{name_cleaned}"`
78
+
79
+ if pkg.include?(name_cleaned)
80
+ return true
81
+ end
82
+
83
+ false
84
+ end
85
+
86
+ # Test if the package is installed.
87
+ #
88
+ # @return [Boolean] True if the package is installed.
89
+ def is_installed?
90
+ # If the package does not have information about architecture.
91
+ pkg = `dpkg --get-selections | grep -v deinstall | cut -f 1 | grep ^#{name}$`.chomp
92
+ # If the package has information about architecture (foo:amd64).
93
+ pkg_arch = `dpkg --get-selections | grep -v deinstall | cut -f 1 | grep ^#{name}:`.chomp.split(':').first
94
+
95
+ if [pkg, pkg_arch].include?(name)
96
+ return true
97
+ end
98
+
99
+ false
100
+ end
101
+ end
102
+
103
+ end
@@ -0,0 +1,223 @@
1
+ # encoding: utf-8
2
+ #===============================================================================
3
+ #
4
+ # This file is part of Apti.
5
+ #
6
+ # Copyright (C) 2013-2014 by Florent Lévigne <florent.levigne at mailoo dot com>
7
+ # Copyright (C) 2013-2014 by Julien Rosset <jul.rosset at gmail dot com>
8
+ #
9
+ #
10
+ # Apti is free software: you can redistribute it and/or modify
11
+ # it under the terms of the GNU General Public License as published by
12
+ # the Free Software Foundation, either version 3 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # Apti is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
22
+ #
23
+ #===============================================================================
24
+
25
+ module Apti
26
+
27
+ module Config
28
+
29
+ class Color
30
+ #
31
+ # @!attribute COLOR_END [r]
32
+ # @return [Fixnum] Shell color id for stopping color style.
33
+ STYLE_END = 0
34
+
35
+ #
36
+ # @!attribute COLOR_BLACK [r]
37
+ # @return [Fixnum] Shell text color id for black.
38
+ #
39
+ # @!attribute COLOR_RED [r]
40
+ # @return [Fixnum] Shell text color id for red.
41
+ #
42
+ # @!attribute COLOR_GREEN [r]
43
+ # @return [Fixnum] Shell text color id for green.
44
+ #
45
+ # @!attribute COLOR_ORANGE [r]
46
+ # @return [Fixnum] Shell text color id for orange.
47
+ #
48
+ # @!attribute COLOR_BLUE [r]
49
+ # @return [Fixnum] Shell text color id for blue.
50
+ #
51
+ # @!attribute COLOR_MAGENTA [r]
52
+ # @return [Fixnum] Shell text color id for magenta.
53
+ #
54
+ # @!attribute COLOR_CYAN [r]
55
+ # @return [Fixnum] Shell text color id for cyan.
56
+ #
57
+ # @!attribute COLOR_WHITE [r]
58
+ # @return [Fixnum] Shell text color id for white.
59
+ TEXT_BLACK = 30
60
+ TEXT_RED = 31
61
+ TEXT_GREEN = 32
62
+ TEXT_ORANGE = 33
63
+ TEXT_BLUE = 34
64
+ TEXT_MAGENTA = 35
65
+ TEXT_CYAN = 36
66
+ TEXT_WHITE = 37
67
+
68
+ #
69
+ # @!attribute BACKGROUND_BLACK [r]
70
+ # @return [Fixnum] Shell background color id for black.
71
+ #
72
+ # @!attribute BACKGROUND_RED [r]
73
+ # @return [Fixnum] Shell background color id for red.
74
+ #
75
+ # @!attribute BACKGROUND_GREEN [r]
76
+ # @return [Fixnum] Shell background color id for green.
77
+ #
78
+ # @!attribute BACKGROUND_ORANGE [r]
79
+ # @return [Fixnum] Shell background color id for orange.
80
+ #
81
+ # @!attribute BACKGROUND_BLUE [r]
82
+ # @return [Fixnum] Shell background color id for blue.
83
+ #
84
+ # @!attribute BACKGROUND_MAGENTA [r]
85
+ # @return [Fixnum] Shell background color id for magenta.
86
+ #
87
+ # @!attribute BACKGROUND_CYAN [r]
88
+ # @return [Fixnum] Shell background color id for cyan.
89
+ #
90
+ # @!attribute BACKGROUND_WHITE [r]
91
+ # @return [Fixnum] Shell background color id for white.
92
+ BACKGROUND_BLACK = 40
93
+ BACKGROUND_RED = 41
94
+ BACKGROUND_GREEN = 42
95
+ BACKGROUND_ORANGE = 43
96
+ BACKGROUND_BLUE = 44
97
+ BACKGROUND_MAGENTA = 45
98
+ BACKGROUND_CYAN = 46
99
+ BACKGROUND_WHITE = 47
100
+
101
+ #
102
+ # @!attribute EFFECT_NORMAL [r]
103
+ # @return [Fixnum] Shell effect id for normal text.
104
+ #
105
+ # @!attribute EFFECT_BOLD [r]
106
+ # @return [Fixnum] Shell effect id for bold text.
107
+ #
108
+ # @!attribute EFFECT_UNDERLINE [r]
109
+ # @return [Fixnum] Shell effect id for underlined text.
110
+ #
111
+ # @!attribute EFFECT_BLINK [r]
112
+ # @return [Fixnum] Shell effect id for blink text.
113
+ #
114
+ # @!attribute EFFECT_HIGHLIGHT [r]
115
+ # @return [Fixnum] Shell effect id for highlighted text.
116
+ #
117
+ #
118
+ # @!attribute EFFECT_DARK [r]
119
+ # @return [Fixnum] Shell effect id for dark color text (alias of EFFECT_NORMAL).
120
+ #
121
+ # @!attribute EFFECT_LIGHT [r]
122
+ # @return [Fixnum] Shell effect id for light color text (alias of EFFECT_BOLD).
123
+ EFFECT_NORMAL = 0
124
+ EFFECT_BOLD = 1
125
+ EFFECT_UNDERLINE = 4
126
+ EFFECT_BLINK = 5
127
+ EFFECT_HIGHLIGHT = 7
128
+
129
+ EFFECT_DARK = EFFECT_NORMAL
130
+ EFFECT_LIGHT = EFFECT_BOLD
131
+
132
+ #
133
+ # @!attribute text [r]
134
+ # @return Shell text color id.
135
+ #
136
+ # @!attribute background [r]
137
+ # @return Shell background color id.
138
+ #
139
+ # @!attribute effect [r]
140
+ # @return Shell effect id.
141
+ attr_reader :text, :background, :effect
142
+
143
+ # Initialize color to default.
144
+ #
145
+ # @param text [Fixnum] Shell text color id.
146
+ # @param background [Fixnum] Shell background color id.
147
+ # @param effect [Fixnum] Shell effect id.
148
+ def initialize(text = TEXT_BLACK, background = nil, effect = EFFECT_NORMAL)
149
+ @text = text
150
+ @background = background
151
+ @effect = effect
152
+ end
153
+
154
+ # Read a color from a YAML configuration (itself from a configuration file).
155
+ #
156
+ # @param color [String, Fixnum, Hash{String => String, Fixnum}] YAML color part.
157
+ def read_from (color)
158
+ if color.nil?
159
+ return
160
+ end
161
+
162
+ if color.class == String || color.class == Integer
163
+ @text = read_property('text', color, @text)
164
+ else
165
+ @text = read_property('text', color['text'], @text)
166
+ @background = read_property('background', color['background'], @background)
167
+ @effect = read_property('effect', color['effect'], @effect)
168
+ end
169
+ end
170
+
171
+ # Get Shell notation for the color.
172
+ #
173
+ # @return [String] Shell notation.
174
+ def to_shell_color
175
+ if @text == STYLE_END
176
+ return "\e[#{@text}m";
177
+ end
178
+
179
+ color = "\e[#{@effect};#{@text}"
180
+
181
+ if !@background.nil?
182
+ color = color + ";#{@background}"
183
+ end
184
+
185
+ color + "m"
186
+ end
187
+
188
+ private
189
+
190
+ # Get correct value of a "color" from YAML configuration (cf. read_from).
191
+ #
192
+ # @note If *property* is a String, Color will try to convert it to a shell id using "COLOR_*", "BACKGROUND_*" or "EFFECT_*" constants (according to *type* parameter).
193
+ #
194
+ # @param type [String] The "type" of property to read. Must only be "color", "background" or "effect".
195
+ # @param property [String, Fixnum] The value to read.
196
+ # @param default_value [Fixnum] The default value to use if *property* is not valid.
197
+ #
198
+ # @return [Fixnum] The correct shell id.
199
+ def read_property(type, property, default_value)
200
+ if property.nil?
201
+ return default_value
202
+ end
203
+
204
+ # If property is a number (always between 0 and 255 inclusive).
205
+ if property.class == Integer || !(property.to_s =~ /^[[:digit:]]{1,3}$/).nil?
206
+ return property
207
+ end
208
+
209
+ property_constant = "#{type.upcase}_#{property.upcase}"
210
+ if Color.const_defined?(property_constant, false)
211
+ return Color.const_get(property_constant, false)
212
+ end
213
+
214
+ print "Configuration: Unable to get property #{type} from \"#{property}\"\n"
215
+ default_value
216
+ end
217
+
218
+ end
219
+
220
+ end
221
+
222
+ end
223
+
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+ #===============================================================================
3
+ #
4
+ # This file is part of Apti.
5
+ #
6
+ # Copyright (C) 2013-2014 by Florent Lévigne <florent.levigne at mailoo dot com>
7
+ # Copyright (C) 2013-2014 by Julien Rosset <jul.rosset at gmail dot com>
8
+ #
9
+ #
10
+ # Apti is free software: you can redistribute it and/or modify
11
+ # it under the terms of the GNU General Public License as published by
12
+ # the Free Software Foundation, either version 3 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # Apti is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
22
+ #
23
+ #===============================================================================
24
+
25
+ module Apti
26
+
27
+ module Config
28
+
29
+ # Colors to use in apti.
30
+ class Colors
31
+
32
+ #
33
+ # @!attribute install [r]
34
+ # @return [Apti::Config::Color] Color of install.
35
+ #
36
+ # @!attribute upgrade [r]
37
+ # @return [Apti::Config::ColorsUpgrade] Colors of upgrade.
38
+ #
39
+ # @!attribute remove [r]
40
+ # @return [Apti::Config::Color] Color of remove.
41
+ #
42
+ # @!attribute description [r]
43
+ # @return [Apti::Config::Color] Color of description.
44
+ #
45
+ # @!attribute size [r]
46
+ # @return [Apti::Config::Color] Color of size.
47
+ #
48
+ # @!attribute text [r]
49
+ # @return [Apti::Config::Color] Color of text (operation, confirmation, ...).
50
+ attr_reader :install, :upgrade, :remove, :description, :size, :text
51
+
52
+ # Initialize colors to default.
53
+ def initialize
54
+ require_relative 'Color'
55
+ require_relative 'ColorsUpgrade'
56
+
57
+ @install = Color.new(Color::TEXT_GREEN, nil, Color::EFFECT_BOLD)
58
+ @upgrade = ColorsUpgrade.new
59
+ @remove = Color.new(Color::TEXT_RED, nil, Color::EFFECT_BOLD)
60
+ @description = Color.new(Color::TEXT_BLACK, nil, Color::EFFECT_BOLD)
61
+ @size = Color.new(Color::TEXT_BLACK, nil, Color::EFFECT_BOLD)
62
+ @text = Color.new(Color::TEXT_WHITE, nil, Color::EFFECT_BOLD)
63
+ end
64
+
65
+ # Read colors from a YAML configuration (itself from a configuration file).
66
+ #
67
+ # @param colors [Hash{String => String, Fixnum}] YAML colors part.
68
+ def read_from(colors)
69
+ if colors.nil?
70
+ return
71
+ end
72
+
73
+ @install.read_from(colors['install'])
74
+ @upgrade.read_from(colors['upgrade'])
75
+ @remove.read_from(colors['remove'])
76
+ @description.read_from(colors['description'])
77
+ @size.read_from(colors['size'])
78
+ @text.read_from(colors['text'])
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+ #===============================================================================
3
+ #
4
+ # This file is part of Apti.
5
+ #
6
+ # Copyright (C) 2014 by Florent Lévigne <florent.levigne at mailoo dot com>
7
+ # Copyright (C) 2014 by Julien Rosset <jul.rosset at gmail dot com>
8
+ #
9
+ #
10
+ # Apti is free software: you can redistribute it and/or modify
11
+ # it under the terms of the GNU General Public License as published by
12
+ # the Free Software Foundation, either version 3 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # Apti is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
22
+ #
23
+ #===============================================================================
24
+
25
+ module Apti
26
+
27
+ module Config
28
+
29
+ # Colors to use in apti.
30
+ class ColorsUpgrade
31
+
32
+ #
33
+ # @!attribute revision [r]
34
+ # @return [Apti::Config::ColorsUpgradeRevision] Colors of upgrade (revision).
35
+ #
36
+ # @!attribute version [r]
37
+ # @return [Apti::Config::ColorsUpgradeVersion] Colors of upgrade (version).
38
+ attr_reader :revision, :version
39
+
40
+ # Initialize colors to default.
41
+ def initialize
42
+ require_relative 'ColorsUpgradeRevision'
43
+ require_relative 'ColorsUpgradeVersion'
44
+
45
+ @revision = ColorsUpgradeRevision.new
46
+ @version = ColorsUpgradeVersion.new
47
+ end
48
+
49
+ # Read upgrade colors from a YAML configuration (itself from a configuration file).
50
+ #
51
+ # @param upgrade [Hash{String => String, Fixnum}] YAML colors part.
52
+ def read_from(upgrade)
53
+ if upgrade.nil?
54
+ return
55
+ end
56
+
57
+ @revision.read_from(upgrade['revision'])
58
+ @version.read_from(upgrade['version'])
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
65
+ end