kgem 0.1.0

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.
data/lib/gemcmddlgs.rb ADDED
@@ -0,0 +1,350 @@
1
+
2
+ #--------------------------------------------------------------------------------
3
+ #
4
+ #
5
+ module InstallOption
6
+ def makeArgs
7
+ args = []
8
+ options = Settings.instance
9
+ if options.installRdocFlag then
10
+ args.push( '--rdoc' )
11
+ else
12
+ args.push( '--no-rdoc' )
13
+ end
14
+ if options.installRiFlag then
15
+ args.push( '--ri' )
16
+ else
17
+ args.push( '--no-ri' )
18
+ end
19
+ if options.installSheBangFlag then
20
+ args.push( '--env-shebang' )
21
+ else
22
+ args.push( '--no-env-shebang' )
23
+ end
24
+ if options.installUnitTestFlag then
25
+ args.push( '--test' )
26
+ else
27
+ args.push( '--no-test' )
28
+ end
29
+ if options.installBinWrapFlag then
30
+ args.push( '--wrappers' )
31
+ else
32
+ args.push( '--no-wrappers' )
33
+ end
34
+ if options.installIgnoreDepsFlag then
35
+ args.push( '--ignore-dependencies' )
36
+ end
37
+ if options.installIncludeDepsFlag then
38
+ args.push( '--include-dependencies' )
39
+ end
40
+ if options.installDevelopmentDepsFlag then
41
+ args.push( '--development' )
42
+ end
43
+ if options.installformatExecutableFlag then
44
+ args.push( '--format-executable' )
45
+ end
46
+ args.push( '-P' )
47
+ args.push( options.installTrustPolicyStr )
48
+
49
+ args
50
+ end
51
+ end
52
+
53
+
54
+ #--------------------------------------------------------------------------------
55
+ #
56
+ #
57
+ class UpdateDlg < Qt::Dialog
58
+ def initialize(parent=nil)
59
+ super(parent)
60
+ self.windowTitle = i18n('Update Gem')
61
+
62
+ @msgLabel = Qt::Label.new(i18n('Update Gem'))
63
+ @okBtn = KDE::PushButton.new(KDE::Icon.new('dialog-ok'), 'OK')
64
+ @cancelBtn = KDE::PushButton.new(KDE::Icon.new('dialog-cancel'), 'Cancel')
65
+ connect(@okBtn, SIGNAL(:clicked), self, SLOT(:accept))
66
+ connect(@cancelBtn, SIGNAL(:clicked), self, SLOT(:reject))
67
+ @versionComboBox = Qt::ComboBox.new
68
+ @allCheckBox = Qt::CheckBox.new(i18n('Update all'))
69
+ @forceCheckBox = Qt::CheckBox.new(i18n('Force gem to install, bypassing dependency checks'))
70
+
71
+ @optionsPage = InstallOptionsPage.new
72
+
73
+ # layout
74
+ @versionWidget = HBoxLayoutWidget.new do |l|
75
+ l.addWidgets('Version :', @versionComboBox, nil)
76
+ end
77
+ @versionEnabled = true
78
+ @mainLayout = Qt::VBoxLayout.new do |l|
79
+ l.addWidget(@msgLabel)
80
+ l.addWidget(@versionWidget)
81
+ l.addWidget(@allCheckBox)
82
+ l.addWidget(@forceCheckBox)
83
+ l.addWidget(@optionsPage)
84
+ l.addWidgets(nil, @okBtn, @cancelBtn)
85
+ end
86
+ setLayout(@mainLayout)
87
+ end
88
+
89
+
90
+ def selectOption(gem)
91
+ @allCheckBox.checked = false
92
+ @allCheckBox.enabled = true
93
+ @versionWidget.visible = true
94
+ @gem = gem
95
+ @versionComboBox.clear
96
+ self.windowTitle = @msgLabel.text = i18n('Update Gem %s') % gem.name
97
+ vers = gem.availableVersions
98
+ return unless vers
99
+ @versionComboBox.addItems(vers)
100
+ @versionComboBox.currentIndex = 0
101
+ Settings.updateWidgets(self)
102
+ @optionsPage.installInSystemVisible = false
103
+ ret = exec == Qt::Dialog::Accepted
104
+ @optionsPage.installInSystemVisible = true
105
+ ret
106
+ end
107
+
108
+ def confirmUpdateAll
109
+ @allCheckBox.checked = true
110
+ @allCheckBox.enabled = false
111
+ @versionWidget.visible = false
112
+ self.windowTitle = @msgLabel.text = i18n('Update All Gems')
113
+
114
+ Settings.updateWidgets(self)
115
+ @optionsPage.installInSystemVisible = false
116
+ ret = exec == Qt::Dialog::Accepted
117
+ @optionsPage.installInSystemVisible = true
118
+ ret
119
+ end
120
+
121
+
122
+ include InstallOption
123
+
124
+ def makeUpdateArgs
125
+ Settings.updateSettings(self)
126
+
127
+ args = [ 'update' ]
128
+ unless @allCheckBox.checked then
129
+ args.push( @gem.package )
130
+ args.push( '-r' )
131
+ if @versionComboBox.currentIndex != @gem.nowVersion then
132
+ args.shift
133
+ args.unshift( 'install' )
134
+ args.push( '-v' )
135
+ args.push( @versionComboBox.currentText )
136
+ end
137
+ end
138
+ if @forceCheckBox.checked then
139
+ args.push( '--force' )
140
+ else
141
+ args.push( '--no-force' )
142
+ end
143
+ args += makeArgs
144
+ end
145
+ end
146
+
147
+ #--------------------------------------------------------------------------------
148
+ #
149
+ #
150
+ class GenerateRdocDlg < Qt::Dialog
151
+ def initialize(parent=nil)
152
+ super(parent)
153
+ self.windowTitle = i18n('Generate RDoc/ri')
154
+
155
+ @msgLabel = Qt::Label.new(i18n('Generate RDoc/ri'))
156
+ @okBtn = KDE::PushButton.new(KDE::Icon.new('dialog-ok'), 'OK')
157
+ @cancelBtn = KDE::PushButton.new(KDE::Icon.new('dialog-cancel'), 'Cancel')
158
+ connect(@okBtn, SIGNAL(:clicked), self, SLOT(:accept))
159
+ connect(@cancelBtn, SIGNAL(:clicked), self, SLOT(:reject))
160
+ @allCheckBox = Qt::CheckBox.new(i18n('Generate RDoc/RI documentation for all'))
161
+ @rdocCheckBox = Qt::CheckBox.new(i18n('Generate RDoc Documentation'))
162
+ @rdocCheckBox.checked = true
163
+ @riCheckBox = Qt::CheckBox.new(i18n('Generate RI Documentation'))
164
+ @riCheckBox.checked = true
165
+ @overwriteCheckBox = Qt::CheckBox.new(i18n('Overwrite installed documents'))
166
+
167
+ # layout
168
+ lo = Qt::VBoxLayout.new do |l|
169
+ l.addWidget(@allCheckBox)
170
+ l.addWidget(@rdocCheckBox)
171
+ l.addWidget(@riCheckBox)
172
+ l.addWidget(@overwriteCheckBox)
173
+ l.addWidgets(nil, @okBtn, @cancelBtn)
174
+ end
175
+ setLayout(lo)
176
+ end
177
+
178
+ def all?
179
+ @allCheckBox.checked
180
+ end
181
+
182
+ def makeRdocArgs(gem)
183
+ args = ['rdoc']
184
+ return nil unless @rdocCheckBox.checked or @riCheckBox.checked
185
+
186
+ args.push(gem.package)
187
+ if @allCheckBox.checked
188
+ args.push('--all')
189
+ end
190
+ if @rdocCheckBox.checked
191
+ args.push('--rdoc')
192
+ else
193
+ args.push('--no-rdoc')
194
+ end
195
+ if @riCheckBox.checked
196
+ args.push('--ri')
197
+ else
198
+ args.push('--no-ri')
199
+ end
200
+ if @overwriteCheckBox.checked
201
+ args.push('--overwrite')
202
+ else
203
+ args.push('--no-overwrite')
204
+ end
205
+ args
206
+ end
207
+ end
208
+
209
+ #--------------------------------------------------------------------------------
210
+ #
211
+ #
212
+ class SelectInstallVerDlg < Qt::Dialog
213
+ def initialize(parent=nil)
214
+ super(parent)
215
+ self.windowTitle = i18n('Install Ruby Gem')
216
+
217
+ @msgLabel = Qt::Label.new
218
+ @msgLabel.wordWrap = true
219
+ @okBtn = KDE::PushButton.new(KDE::Icon.new('dialog-ok'), 'OK')
220
+ @cancelBtn = KDE::PushButton.new(KDE::Icon.new('dialog-cancel'), 'Cancel')
221
+ connect(@okBtn, SIGNAL(:clicked), self, SLOT(:accept))
222
+ connect(@cancelBtn, SIGNAL(:clicked), self, SLOT(:reject))
223
+ @checkOtherVersion = KDE::PushButton.new(i18n("Check Other Version's Availability"))
224
+ connect(@checkOtherVersion , SIGNAL(:clicked), self, SLOT(:checkOtherVersion))
225
+ @versionComboBox = Qt::ComboBox.new
226
+ @skipVersionCheck = Qt::CheckBox.new(i18n('Always Accept Latest Version to Skip This Dialog'))
227
+ @skipVersionCheck.objectName = 'kcfg_installLatestFlag'
228
+ @forceCheckBox = Qt::CheckBox.new(i18n('Force gem to install, bypassing dependency checks'))
229
+
230
+ @optionsPage = InstallOptionsPage.new
231
+
232
+ # layout
233
+ lo = Qt::VBoxLayout.new do |l|
234
+ l.addWidget(@msgLabel)
235
+ l.addWidgets('Version :', @versionComboBox, @checkOtherVersion, nil)
236
+ l.addWidget(@skipVersionCheck)
237
+ l.addWidget(@forceCheckBox)
238
+ l.addWidget(@optionsPage)
239
+ l.addWidgets(nil, @okBtn, @cancelBtn)
240
+ end
241
+ setLayout(lo)
242
+ end
243
+
244
+ slots :checkOtherVersion
245
+ def checkOtherVersion
246
+ @versionComboBox.clear
247
+ vers = @gem.availableVersions
248
+ return unless vers
249
+ @versionComboBox.addItems(vers)
250
+ @versionComboBox.currentIndex = 0
251
+ end
252
+
253
+ def selectVersion(gem)
254
+ @gem = gem
255
+ @versionComboBox.clear
256
+ @versionComboBox.addItem(gem.version)
257
+ @msgLabel.text = 'Install gem ' + gem.name + ' (' + gem.version.strip + ')'
258
+ Settings.updateWidgets(self)
259
+ return true if @skipVersionCheck.checked
260
+ exec == Qt::Dialog::Accepted
261
+ end
262
+
263
+ include InstallOption
264
+ def makeInstallArgs(localFlag)
265
+ Settings.updateSettings(self)
266
+
267
+ args = [ 'install' ]
268
+ if @versionComboBox.currentIndex != 0 then
269
+ args.push( @gem.package )
270
+ args.push( '-r' )
271
+ args.push( '-v' )
272
+ args.push( @versionComboBox.currentText )
273
+ elsif localFlag then
274
+ args.push( @gem.filePath )
275
+ else
276
+ args.push( @gem.package )
277
+ args.push( '-r' )
278
+ end
279
+ if @forceCheckBox.checked then
280
+ args.push( '--force' )
281
+ else
282
+ args.push( '--no-force' )
283
+ end
284
+ args += makeArgs
285
+ end
286
+
287
+ end
288
+
289
+
290
+ #--------------------------------------------------------------------------------
291
+ #
292
+ #
293
+ class SelectDownloadVerDlg < Qt::Dialog
294
+ def initialize(parent=nil)
295
+ super(parent)
296
+ self.windowTitle = i18n('Download Ruby Gem')
297
+
298
+ @msgLabel = Qt::Label.new
299
+ @msgLabel.wordWrap = true
300
+ @okBtn = KDE::PushButton.new(KDE::Icon.new('dialog-ok'), 'OK')
301
+ @cancelBtn = KDE::PushButton.new(KDE::Icon.new('dialog-cancel'), 'Cancel')
302
+ connect(@okBtn, SIGNAL(:clicked), self, SLOT(:accept))
303
+ connect(@cancelBtn, SIGNAL(:clicked), self, SLOT(:reject))
304
+ @checkOtherVersion = KDE::PushButton.new(i18n("Check Other Version's Availability"))
305
+ connect(@checkOtherVersion , SIGNAL(:clicked), self, SLOT(:checkOtherVersion))
306
+ @versionComboBox = Qt::ComboBox.new
307
+ @skipVersionCheck = Qt::CheckBox.new(i18n('Always Accept Latest Version to Skip This Dialog'))
308
+ @skipVersionCheck.objectName = 'kcfg_downloadLatestFlag'
309
+
310
+ # layout
311
+ lo = Qt::VBoxLayout.new do |l|
312
+ l.addWidget(@msgLabel)
313
+ l.addWidgets('Version :', @versionComboBox, @checkOtherVersion, nil)
314
+ l.addWidget(@skipVersionCheck)
315
+ l.addWidgets(nil, @okBtn, @cancelBtn)
316
+ end
317
+ setLayout(lo)
318
+ end
319
+
320
+ slots :checkOtherVersion
321
+ def checkOtherVersion
322
+ @versionComboBox.clear
323
+ vers = @gem.availableVersions
324
+ return unless vers
325
+ @versionComboBox.addItems(vers)
326
+ @versionComboBox.currentIndex = 0
327
+ end
328
+
329
+ def selectVersion(gem)
330
+ @gem = gem
331
+ @versionComboBox.clear
332
+ @versionComboBox.addItem(gem.version)
333
+ @msgLabel.text = 'Download gem ' + gem.name + ' (' + gem.version.strip + ')'
334
+ Settings.updateWidgets(self)
335
+ return true if @skipVersionCheck.checked
336
+ exec == Qt::Dialog::Accepted
337
+ end
338
+
339
+ def makeDownloadArgs
340
+ Settings.updateSettings(self)
341
+
342
+ args = [ 'fetch' ]
343
+ args.push( @gem.package )
344
+ if @versionComboBox.currentIndex != 0 then
345
+ args.push( '-v' )
346
+ args.push( @versionComboBox.currentText )
347
+ end
348
+ args
349
+ end
350
+ end
data/lib/gemhelpdlg.rb ADDED
@@ -0,0 +1,74 @@
1
+ #
2
+ #
3
+ #
4
+ class GemHelpDlg < KDE::MainWindow
5
+ slots 'listSelected(QListWidgetItem*)'
6
+ GroupName = "GemHelpDlg"
7
+
8
+ def initialize(parent=nil)
9
+ super(parent)
10
+ setCaption("gem (command line version) command help")
11
+ createWidget
12
+ iniHelpList
13
+ setAutoSaveSettings(GroupName)
14
+ readSettings
15
+ end
16
+
17
+ def createWidget
18
+ closeBtn = KDE::PushButton.new(KDE::Icon.new('dialog-close'), i18n('Close'))
19
+ @helpList = Qt::ListWidget.new
20
+ @helpText = Qt::PlainTextEdit.new
21
+ @helpText.readOnly = true
22
+
23
+ connect(@helpList, SIGNAL('itemClicked(QListWidgetItem*)'),
24
+ self, SLOT('listSelected(QListWidgetItem*)'))
25
+ connect(closeBtn, SIGNAL(:clicked), self, SLOT(:hide))
26
+
27
+ # layout
28
+ @splitter = Qt::Splitter.new do |s|
29
+ s.addWidget(@helpList)
30
+ s.addWidget(@helpText)
31
+ end
32
+ @splitter.setStretchFactor(0,0)
33
+ @splitter.setStretchFactor(1,1)
34
+ lo = Qt::VBoxLayout.new do |l|
35
+ l.addWidget(@splitter)
36
+ l.addWidgets(nil, closeBtn)
37
+ end
38
+ w = Qt::Widget.new
39
+ w.setLayout(lo)
40
+ setCentralWidget(w)
41
+ end
42
+
43
+ def iniHelpList
44
+ list = %x{gem help command}.inject([]) do |a, line|
45
+ line =~ /^\s{4}(\w+)/ ? a << $1 : a
46
+ end
47
+ list.unshift('examples')
48
+ @helpList.clear
49
+ @helpList.addItems(list)
50
+ end
51
+
52
+
53
+ def listSelected(item)
54
+ text = %x{gem help #{item.text}}
55
+ @helpText.clear
56
+ @helpText.appendHtml("<pre>" + text + "</pre>")
57
+ end
58
+
59
+ # virtual function slot
60
+ def closeEvent(event)
61
+ writeSettings
62
+ super(event)
63
+ end
64
+
65
+ def readSettings
66
+ config = $config.group(GroupName)
67
+ @splitter.restoreState(config.readEntry('SplitterState', @splitter.saveState))
68
+ end
69
+
70
+ def writeSettings
71
+ config = $config.group(GroupName)
72
+ config.writeEntry('SplitterState', @splitter.saveState)
73
+ end
74
+ end
data/lib/gemitem.rb ADDED
@@ -0,0 +1,162 @@
1
+ require 'ftools'
2
+ require 'fileutils'
3
+ require 'rubygems'
4
+ require 'rubygems/specification'
5
+
6
+ # additional libs
7
+ require 'korundum4'
8
+
9
+
10
+ #--------------------------------------------------------------------
11
+ #
12
+ # gemItem is created from gem command output in command line
13
+ # and used for inserting item to Qt::TableWidget.
14
+ #
15
+ class GemItem
16
+ attr_accessor :package, :version, :author, :rubyforge, :homepage, :platform
17
+ attr_accessor :summary, :status, :spec, :downloads
18
+ alias :name :package
19
+ alias :authors :author
20
+ def initialize(pkg_and_ver, ver=nil)
21
+ if ver.nil?
22
+ pkg, ver = pkg_and_ver.split(/ /, 2)
23
+ ver.tr!('()', '')
24
+ ver.strip!
25
+ else
26
+ pkg = pkg_and_ver
27
+ end
28
+ @package = pkg
29
+ @version = ver
30
+ @author = ''
31
+ @rubyforge = ''
32
+ @homepage = ''
33
+ @platform = ''
34
+ @summary = ''
35
+ @spec = nil
36
+ @downloads = 0
37
+ end
38
+
39
+ attr_reader :filePath
40
+ def addLocalPath(filePath)
41
+ @filePath = filePath
42
+ end
43
+
44
+ def nowVersion
45
+ version.split(/,/, 2).first
46
+ end
47
+
48
+ # available versions at remote server.
49
+ def availableVersions
50
+ return @versions if instance_variable_defined? :@versions
51
+
52
+ res = %x{ gem list #{name} -a -r }
53
+ res =~ /#{Regexp.escape(name)}\s+\(([^\)]+)\)/
54
+ res = $1.split(/,\s+/).map { |v| v.split(/ /).first.strip }
55
+ if res then
56
+ @versions = res
57
+ else
58
+ @versions = nil
59
+ end
60
+ end
61
+
62
+ def installedLocal?
63
+ res = %x{ gem query -l -d -n '^#{@package}$' }
64
+ res =~ /#{@package}/ and res =~ %r? /home/?
65
+ end
66
+
67
+ def self.parseHashGem(hGem)
68
+ gem = self.new(hGem['name'], hGem['version'].to_s)
69
+ gem.author = hGem['authors']
70
+ gem.homepage = hGem['homepage_uri']
71
+ gem.downloads = hGem['downloads']
72
+ gem.summary = hGem['info']
73
+ gem
74
+ end
75
+
76
+ def self.parseGemSpec(spec)
77
+ gem = self.new(spec.name, spec.version.to_s)
78
+ gem.author = spec.authors || ''
79
+ gem.homepage = spec.homepage || ''
80
+ gem.summary = spec.summary || ''
81
+ gem.spec = spec
82
+ gem
83
+ end
84
+
85
+ def self.getGemfromPath(path)
86
+ res = %x{ gem specification #{path} -b --marshal }
87
+ return nil if res.empty?
88
+ spec = Marshal.load(res)
89
+ GemItem::parseGemSpec(spec)
90
+ end
91
+ end
92
+
93
+
94
+
95
+ module InstalledGemList
96
+ extend self
97
+
98
+ def get
99
+ gemList = nil
100
+ cnt = 0
101
+ gemf = open('|gem query -d -l')
102
+ begin
103
+ summary = ''
104
+ gem = nil
105
+ while line = gemf.gets
106
+ case line
107
+ when /^(\w.*)/ then
108
+ if gem then
109
+ gem.summary = summary.strip
110
+ gemList ||= []
111
+ gemList << gem
112
+ cnt += 1
113
+ end
114
+ gem = GemItem.new(line)
115
+ summary = ''
116
+ when /\s+Authors?:\s*(.*)\s*/i
117
+ gem.author = $1
118
+ when /\s+Rubyforge:\s*(.*)\s*/i
119
+ gem.rubyforge = $1
120
+ when /\s+Homepage:\s*(.*)\s*/i
121
+ gem.homepage = $1
122
+ when /\s+Platform:\s*(.*)\s*/i
123
+ gem.platform = $1
124
+ when /\s+Installed\s+at.*?:\s*(.*)\s*/i
125
+ when /\s+\(.*?\):\s*(.*)\s*/i
126
+ else
127
+ summary += line.strip + "\n"
128
+ end
129
+ end
130
+ gem.summary = summary.strip
131
+ gemList << gem
132
+ ensure
133
+ gemf.close
134
+ end
135
+
136
+ oldeGems = gemList.inject([]) do |s, g|
137
+ vers = g.version.split(/,/).map { |v| v.strip }
138
+ if vers.size > 1 then
139
+ g.version = vers.shift
140
+ vers.each do |v|
141
+ dupg = g.dup
142
+ dupg.version = v
143
+ s << dupg
144
+ end
145
+ end
146
+ s
147
+ end
148
+ @gemList = gemList + oldeGems
149
+ end
150
+
151
+ def getCached
152
+ @gemList ||= get
153
+ end
154
+
155
+ def checkVersionGemInstalled(versionedName)
156
+ vname = versionedName.gsub(/\.gem$/, '')
157
+ gem = getCached.find do |gem|
158
+ gem.name + '-' + gem.version == vname
159
+ end
160
+ not gem.nil?
161
+ end
162
+ end