depot3 3.0.15 → 3.0.20

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.
@@ -572,7 +572,7 @@ module D3
572
572
  end
573
573
 
574
574
  @apple_pkg_ids = args[:apple_pkg_ids]
575
- @installed_at = args[:installed_at]
575
+ @installed_at = args[:installed_at] ? args[:installed_at].to_time : Time.now
576
576
 
577
577
  @removable = args[:removable]
578
578
  @prohibiting_processes = args[:prohibiting_processes]
@@ -1130,7 +1130,7 @@ Last brought to foreground: #{last_usage_display}
1130
1130
  usage_times = D3.parse_plist plist
1131
1131
  my_usage_keys = usage_times.keys.map{|p| Pathname.new(p)}
1132
1132
  exp_paths_with_usage = @expiration_paths & my_usage_keys
1133
- exp_paths_with_usage.each{|p| all_usages << usage_times[p.to_s] }
1133
+ exp_paths_with_usage.each{|p| all_usages << usage_times[p.to_s].to_time }
1134
1134
  end # do plist
1135
1135
 
1136
1136
  @last_usage = all_usages.compact.max
@@ -22,76 +22,74 @@
22
22
  ###
23
23
  ###
24
24
 
25
-
26
25
  ###
27
26
  module D3
28
27
 
28
+ ###
29
29
  module Database
30
30
 
31
31
  ################# Module Constants #################
32
32
 
33
-
34
33
  ### Booleans are stored as 1's and 0's in the db.
35
34
  TRUE_VAL = 1
36
35
  FALSE_VAL = 0
37
36
 
38
37
  # This table has info about the JSS schema
39
- SCHEMA_TABLE = "db_schema_information"
38
+ SCHEMA_TABLE = 'db_schema_information'.freeze
40
39
 
41
- # the minimum JSS schema version allower
42
- MIN_SCHEMA_VERSION = "9.4"
40
+ # the minimum JSS schema version allowed
41
+ MIN_SCHEMA_VERSION = '9.4'.freeze
43
42
 
44
- # the minimum JSS schema version allower
45
- MAX_SCHEMA_VERSION = "9.97"
43
+ # the max JSS schema version allowed
44
+ MAX_SCHEMA_VERSION = "10.999.0"
46
45
 
47
46
  ### these Proc objects allow us to encapsulate and pass around various
48
47
  ### blocks of code more easily for converting data between their mysql
49
48
  ### representation and the Ruby classses we use internally.
50
49
 
51
50
  ### Ruby Time objects are stored as JSS epochs (unix epoch plus milliseconds)
52
- EPOCH_TO_TIME = Proc.new{|v| (v.nil? or v.to_s.empty?) ? nil : JSS.epoch_to_time(v) }
51
+ EPOCH_TO_TIME = proc { |v| v.nil? || v.to_s.empty? ? nil : JSS.epoch_to_time(v) }
53
52
 
54
53
  ### JSS epochs (unix epoch plus milliseconds) as used as Ruby Time objects
55
- TIME_TO_EPOCH = Proc.new{|v|(v.nil? or v.to_s.empty?) ? nil : v.to_jss_epoch }
54
+ TIME_TO_EPOCH = proc { |v| v.nil? || v.to_s.empty? ? nil : v.to_jss_epoch }
56
55
 
57
56
  ### Integers come from the database as strings, but empty ones should be nil, not zero, as #to_i would do
58
- STRING_TO_INT = Proc.new{|v| (v.nil? or v.to_s.empty?) ? nil : v.to_i}
57
+ STRING_TO_INT = proc { |v| v.nil? || v.to_s.empty? ? nil : v.to_i }
59
58
 
60
59
  ### Some values are stored as comma-separated strings, but used as Arrays
61
- COMMA_STRING_TO_ARRAY = Proc.new{|v| JSS.to_s_and_a(v)[:arrayform] }
60
+ COMMA_STRING_TO_ARRAY = proc { |v| JSS.to_s_and_a(v)[:arrayform] }
62
61
 
63
62
  ### Some values are stored as comma-separated strings, but used as Arrays of Pathnames
64
- COMMA_STRING_TO_ARRAY_OF_PATHNAMES = Proc.new{|v| JSS.to_s_and_a(v)[:arrayform].map{|p| Pathname.new(p)} }
65
- ARRAY_OF_PATHNAMES_TO_COMMA_STRING = Proc.new{|v| v.is_a?(Array) ? v.join(", ") : "" }
63
+ COMMA_STRING_TO_ARRAY_OF_PATHNAMES = proc { |v| JSS.to_s_and_a(v)[:arrayform].map { |p| Pathname.new(p) } }
64
+ ARRAY_OF_PATHNAMES_TO_COMMA_STRING = proc { |v| v.is_a?(Array) ? v.join(', ') : '' }
66
65
 
67
66
  ### Some values are used as Arrays but stored as comma-separated strings
68
- ARRAY_TO_COMMA_STRING = Proc.new{|v| JSS.to_s_and_a(v)[:stringform] }
67
+ ARRAY_TO_COMMA_STRING = proc { |v| JSS.to_s_and_a(v)[:stringform] }
69
68
 
70
69
  ### Some values are stored in the DB as YAML dumps
71
- RUBY_TO_YAML = Proc.new{|v| YAML.dump v }
70
+ RUBY_TO_YAML = proc { |v| YAML.dump v }
72
71
 
73
- YAML_TO_RUBY = Proc.new{|v| YAML.load v.to_s }
72
+ YAML_TO_RUBY = proc { |v| YAML.load v.to_s }
74
73
 
75
74
  ### Booleans are stored as zero and one
76
- BOOL_TO_INT = Proc.new{|v| v == true ? TRUE_VAL : FALSE_VAL}
75
+ BOOL_TO_INT = proc { |v| v == true ? TRUE_VAL : FALSE_VAL }
77
76
 
78
77
  ### Booleans are stored as zero and one
79
- INT_TO_BOOL = Proc.new{|v| v.to_i == FALSE_VAL ? false : true}
78
+ INT_TO_BOOL = proc { |v| v.to_i == FALSE_VAL ? false : true }
80
79
 
81
80
  ### Regexps are stored as strings
82
- STRING_TO_REGEXP = Proc.new{|v| v.to_s.empty? ? nil : Regexp.new(v.to_s) }
81
+ STRING_TO_REGEXP = proc { |v| v.to_s.empty? ? nil : Regexp.new(v.to_s) }
83
82
 
84
83
  ### Regexps are stored as strings
85
- REGEXP_TO_STRING = Proc.new{|v| v.to_s }
84
+ REGEXP_TO_STRING = proc { |v| v.to_s }
86
85
 
87
86
  ### Status values are stored as strings, but used as symbols
88
- STATUS_TO_STRING = Proc.new{|v| v.to_s }
89
- STRING_TO_STATUS = Proc.new{|v| v.to_sym }
87
+ STATUS_TO_STRING = proc { |v| v.to_s }
88
+ STRING_TO_STATUS = proc { |v| v.to_sym }
90
89
 
91
90
  ### Expiration paths are stored as strings, but used as Pathnames
92
- STRING_TO_PATHNAME = Proc.new{|v| Pathname.new v.to_s}
93
- PATHNAME_TO_STRING = Proc.new{|v| v.to_s}
94
-
91
+ STRING_TO_PATHNAME = proc { |v| Pathname.new v.to_s }
92
+ PATHNAME_TO_STRING = proc { |v| v.to_s }
95
93
 
96
94
  ### The MySQL table that defines which JSS Packages are a part of d3
97
95
  ###
@@ -173,177 +171,176 @@ module D3
173
171
  ###
174
172
  ### See also the attributes of {D3::Package}, which mostly mirror the
175
173
  ###
176
- PACKAGE_TABLE = { :table_name => 'd3_packages',
174
+ PACKAGE_TABLE = {
175
+ table_name: 'd3_packages',
177
176
 
178
- :field_definitions => {
177
+ field_definitions: {
179
178
 
180
- :id => {
181
- :field_name => "package_id",
182
- :sql_type => 'int(11) NOT NULL',
183
- :index => :unique,
184
- :to_sql => nil,
185
- :to_ruby => STRING_TO_INT
179
+ id: {
180
+ field_name: 'package_id',
181
+ sql_type: 'int(11) NOT NULL',
182
+ index: :unique,
183
+ to_sql: nil,
184
+ to_ruby: STRING_TO_INT
186
185
  },
187
186
 
188
- :basename => {
189
- :field_name => "basename",
190
- :sql_type => 'varchar(60) NOT NULL',
191
- :index => true,
192
- :to_sql => nil,
193
- :to_ruby => nil
187
+ basename: {
188
+ field_name: 'basename',
189
+ sql_type: 'varchar(60) NOT NULL',
190
+ index: true,
191
+ to_sql: nil,
192
+ to_ruby: nil
194
193
  },
195
194
 
196
- :version => {
197
- :field_name => "version",
198
- :sql_type => 'varchar(30) NOT NULL',
199
- :index => nil,
200
- :to_sql => nil,
201
- :to_ruby => nil
195
+ version: {
196
+ field_name: 'version',
197
+ sql_type: 'varchar(30) NOT NULL',
198
+ index: nil,
199
+ to_sql: nil,
200
+ to_ruby: nil
202
201
  },
203
202
 
204
- :revision => {
205
- :field_name => "revision",
206
- :sql_type => 'int(4) NOT NULL',
207
- :index => nil,
208
- :to_sql => nil,
209
- :to_ruby => STRING_TO_INT
203
+ revision: {
204
+ field_name: 'revision',
205
+ sql_type: 'int(4) NOT NULL',
206
+ index: nil,
207
+ to_sql: nil,
208
+ to_ruby: STRING_TO_INT
210
209
  },
211
210
 
212
- :apple_receipt_data => {
213
- :field_name => "apple_receipt_data",
214
- :sql_type => "text",
215
- :index => nil,
216
- :to_sql => RUBY_TO_YAML,
217
- :to_ruby => YAML_TO_RUBY
211
+ apple_receipt_data: {
212
+ field_name: 'apple_receipt_data',
213
+ sql_type: 'text',
214
+ index: nil,
215
+ to_sql: RUBY_TO_YAML,
216
+ to_ruby: YAML_TO_RUBY
218
217
  },
219
218
 
220
- :added_date => {
221
- :field_name => "added_date_epoch",
222
- :sql_type => "bigint(32) DEFAULT NULL",
223
- :index => nil,
224
- :to_sql => TIME_TO_EPOCH,
225
- :to_ruby => EPOCH_TO_TIME
219
+ added_date: {
220
+ field_name: 'added_date_epoch',
221
+ sql_type: 'bigint(32) DEFAULT NULL',
222
+ index: nil,
223
+ to_sql: TIME_TO_EPOCH,
224
+ to_ruby: EPOCH_TO_TIME
226
225
  },
227
226
 
228
- :added_by => {
229
- :field_name => "added_by",
230
- :sql_type => 'varchar(30)',
231
- :index => nil,
232
- :to_sql => nil,
233
- :to_ruby => nil
227
+ added_by: {
228
+ field_name: 'added_by',
229
+ sql_type: 'varchar(30)',
230
+ index: nil,
231
+ to_sql: nil,
232
+ to_ruby: nil
234
233
  },
235
234
 
236
- :status => {
237
- :field_name => "status",
238
- :sql_type => "varchar(30) DEFAULT 'pilot'",
239
- :index => nil,
240
- :to_sql => STATUS_TO_STRING,
241
- :to_ruby => STRING_TO_STATUS
235
+ status: {
236
+ field_name: 'status',
237
+ sql_type: "varchar(30) DEFAULT 'pilot'",
238
+ index: nil,
239
+ to_sql: STATUS_TO_STRING,
240
+ to_ruby: STRING_TO_STATUS
242
241
  },
243
242
 
244
- :release_date => {
245
- :field_name => "release_date_epoch",
246
- :sql_type => "bigint(32) DEFAULT NULL",
247
- :index => nil,
248
- :to_sql => TIME_TO_EPOCH,
249
- :to_ruby => EPOCH_TO_TIME
243
+ release_date: {
244
+ field_name: 'release_date_epoch',
245
+ sql_type: 'bigint(32) DEFAULT NULL',
246
+ index: nil,
247
+ to_sql: TIME_TO_EPOCH,
248
+ to_ruby: EPOCH_TO_TIME
250
249
  },
251
250
 
252
- :released_by => {
253
- :field_name => "released_by",
254
- :sql_type => 'varchar(30)',
255
- :index => nil,
256
- :to_sql => nil,
257
- :to_ruby => nil
251
+ released_by: {
252
+ field_name: 'released_by',
253
+ sql_type: 'varchar(30)',
254
+ index: nil,
255
+ to_sql: nil,
256
+ to_ruby: nil
258
257
  },
259
258
 
260
- :auto_groups => {
261
- :field_name => 'auto_install_groups',
262
- :sql_type => 'text',
263
- :index => nil,
264
- :to_sql => ARRAY_TO_COMMA_STRING,
265
- :to_ruby => COMMA_STRING_TO_ARRAY
259
+ auto_groups: {
260
+ field_name: 'auto_install_groups',
261
+ sql_type: 'text',
262
+ index: nil,
263
+ to_sql: ARRAY_TO_COMMA_STRING,
264
+ to_ruby: COMMA_STRING_TO_ARRAY
266
265
  },
267
266
 
268
- :excluded_groups => {
269
- :field_name => 'excluded_groups',
270
- :sql_type => 'text',
271
- :index => nil,
272
- :to_sql => ARRAY_TO_COMMA_STRING,
273
- :to_ruby => COMMA_STRING_TO_ARRAY
267
+ excluded_groups: {
268
+ field_name: 'excluded_groups',
269
+ sql_type: 'text',
270
+ index: nil,
271
+ to_sql: ARRAY_TO_COMMA_STRING,
272
+ to_ruby: COMMA_STRING_TO_ARRAY
274
273
  },
275
274
 
276
- :prohibiting_processes => {
277
- :field_name => "prohibiting_process",
278
- :sql_type => 'varchar(100)',
279
- :index => nil,
280
- :to_sql => ARRAY_TO_COMMA_STRING,
281
- :to_ruby => COMMA_STRING_TO_ARRAY
275
+ prohibiting_processes: {
276
+ field_name: 'prohibiting_process',
277
+ sql_type: 'varchar(100)',
278
+ index: nil,
279
+ to_sql: ARRAY_TO_COMMA_STRING,
280
+ to_ruby: COMMA_STRING_TO_ARRAY
282
281
  },
283
282
 
284
- :remove_first => {
285
- :field_name => "remove_first",
286
- :sql_type => "tinyint(1) DEFAULT '0'",
287
- :index => nil,
288
- :to_sql => BOOL_TO_INT,
289
- :to_ruby => INT_TO_BOOL
283
+ remove_first: {
284
+ field_name: 'remove_first',
285
+ sql_type: "tinyint(1) DEFAULT '0'",
286
+ index: nil,
287
+ to_sql: BOOL_TO_INT,
288
+ to_ruby: INT_TO_BOOL
290
289
  },
291
290
 
292
- :pre_install_script_id => {
293
- :field_name => "pre_install_id",
294
- :sql_type => 'int(11)',
295
- :index => nil,
296
- :to_sql => nil,
297
- :to_ruby => STRING_TO_INT
291
+ pre_install_script_id: {
292
+ field_name: 'pre_install_id',
293
+ sql_type: 'int(11)',
294
+ index: nil,
295
+ to_sql: nil,
296
+ to_ruby: STRING_TO_INT
298
297
  },
299
298
 
300
- :post_install_script_id => {
301
- :field_name => "post_install_id",
302
- :sql_type => 'int(11)',
303
- :index => nil,
304
- :to_sql => nil,
305
- :to_ruby => STRING_TO_INT
299
+ post_install_script_id: {
300
+ field_name: 'post_install_id',
301
+ sql_type: 'int(11)',
302
+ index: nil,
303
+ to_sql: nil,
304
+ to_ruby: STRING_TO_INT
306
305
  },
307
306
 
308
- :pre_remove_script_id => {
309
- :field_name => "pre_remove_id",
310
- :sql_type => 'int(11)',
311
- :index => nil,
312
- :to_sql => nil,
313
- :to_ruby => STRING_TO_INT
307
+ pre_remove_script_id: {
308
+ field_name: 'pre_remove_id',
309
+ sql_type: 'int(11)',
310
+ index: nil,
311
+ to_sql: nil,
312
+ to_ruby: STRING_TO_INT
314
313
  },
315
314
 
316
- :post_remove_script_id => {
317
- :field_name => "post_remove_id",
318
- :sql_type => 'int(11)',
319
- :index => nil,
320
- :to_sql => nil,
321
- :to_ruby => STRING_TO_INT
315
+ post_remove_script_id: {
316
+ field_name: 'post_remove_id',
317
+ sql_type: 'int(11)',
318
+ index: nil,
319
+ to_sql: nil,
320
+ to_ruby: STRING_TO_INT
322
321
  },
323
322
 
324
- :expiration => {
325
- :field_name => "expiration",
326
- :sql_type => 'int(11)',
327
- :index => nil,
328
- :to_sql => nil,
329
- :to_ruby => STRING_TO_INT
323
+ expiration: {
324
+ field_name: 'expiration',
325
+ sql_type: 'int(11)',
326
+ index: nil,
327
+ to_sql: nil,
328
+ to_ruby: STRING_TO_INT
330
329
  },
331
330
 
332
- :expiration_paths => {
333
- :field_name => "expiration_app_path",
334
- :sql_type => 'varchar(300)',
335
- :index => nil,
336
- :to_sql => ARRAY_OF_PATHNAMES_TO_COMMA_STRING,
337
- :to_ruby => COMMA_STRING_TO_ARRAY_OF_PATHNAMES
331
+ expiration_paths: {
332
+ field_name: 'expiration_app_path',
333
+ sql_type: 'varchar(300)',
334
+ index: nil,
335
+ to_sql: ARRAY_OF_PATHNAMES_TO_COMMA_STRING,
336
+ to_ruby: COMMA_STRING_TO_ARRAY_OF_PATHNAMES
338
337
  }
339
338
  },
340
339
 
341
- :other_indexes => [
342
- "UNIQUE KEY `edition` (`basename`,`version`,`revision`)"
340
+ other_indexes: [
341
+ 'UNIQUE KEY `edition` (`basename`,`version`,`revision`)'
343
342
  ]
344
- } # end PACKAGE_TABLE
345
-
346
-
343
+ }.freeze # end PACKAGE_TABLE
347
344
 
348
345
  ################# Module Methods #################
349
346
 
@@ -363,20 +360,17 @@ module D3
363
360
  ###
364
361
  ###
365
362
  def self.table_records(table_def)
366
-
367
363
  recs = []
368
364
 
369
365
  result = JSS.db.query "SELECT * FROM #{table_def[:table_name]}"
370
366
 
371
367
  # parse each record into a hash
372
368
  result.each_hash do |record|
373
-
374
369
  rec = {}
375
370
 
376
371
  # go through each field in the record, adding it to the hash
377
372
  # converting it to its ruby data type if defined in field conversions
378
- table_def[:field_definitions].each_pair do |key,field_def|
379
-
373
+ table_def[:field_definitions].each_pair do |key, field_def|
380
374
  # do we convert the value from the DB to something else in ruby?
381
375
  if field_def[:to_ruby]
382
376
  rec[key] = field_def[:to_ruby].call record[field_def[:field_name]]
@@ -385,14 +379,12 @@ module D3
385
379
  else
386
380
  rec[key] = record[field_def[:field_name]]
387
381
  end # if
388
-
389
382
  end # do key, field_def
390
383
 
391
384
  recs << rec
392
-
393
385
  end # do record
394
386
 
395
- return recs
387
+ recs
396
388
  end # self.table_records(table_def)
397
389
 
398
390
  ### Print the sql for creating the d3_packages table
@@ -404,7 +396,6 @@ module D3
404
396
  puts self.create_table(:display)
405
397
  end
406
398
 
407
-
408
399
  ### Raise an exception if JSS schema is to old or too new
409
400
  def self.check_schema_version
410
401
  raw = JSS::DB_CNX.db.query("SELECT version FROM #{SCHEMA_TABLE}").fetch[0]
@@ -412,8 +403,8 @@ module D3
412
403
  current = JSS.parse_jss_version(simmered)[:version]
413
404
  min = JSS.parse_jss_version(MIN_SCHEMA_VERSION)[:version]
414
405
  max = JSS.parse_jss_version(MAX_SCHEMA_VERSION)[:version]
415
- raise JSS::InvalidConnectionError, "Invalid JSS database schema version: #{raw}, min: #{MIN_SCHEMA_VERSION}, max: #{MAX_SCHEMA_VERSION}" if current < min or current > max
416
- return true
406
+ raise JSS::InvalidConnectionError, "Invalid JSS database schema version: #{raw}, min: #{MIN_SCHEMA_VERSION}, max: #{MAX_SCHEMA_VERSION}" if (current < min) || (current > max)
407
+ true
417
408
  end
418
409
 
419
410
  private
@@ -429,8 +420,7 @@ module D3
429
420
  ###
430
421
  ### @return [void]
431
422
  ###
432
- def self.create_table(display=false)
433
-
423
+ def self.create_table(display = false)
434
424
  # as of now, only one table.
435
425
  table_constant = PACKAGE_TABLE
436
426
 
@@ -438,22 +428,21 @@ module D3
438
428
  indexes = ''
439
429
 
440
430
  table_constant[:field_definitions].keys.sort.each do |key|
441
-
442
431
  field = table_constant[:field_definitions][key]
443
432
 
444
433
  sql += "\n `#{field[:field_name]}` #{field[:sql_type]},"
445
434
 
446
435
  indexes += case field[:index]
447
- when :primary
448
- "\n PRIMARY KEY (`#{field[:field_name]}`),"
449
- when :unique
450
- "\n UNIQUE KEY (`#{field[:field_name]}`),"
451
- when true
452
- "\n KEY (`#{field[:field_name]}`),"
453
- else
454
- ''
455
- end # indexes += case
456
- end #each do key
436
+ when :primary
437
+ "\n PRIMARY KEY (`#{field[:field_name]}`),"
438
+ when :unique
439
+ "\n UNIQUE KEY (`#{field[:field_name]}`),"
440
+ when true
441
+ "\n KEY (`#{field[:field_name]}`),"
442
+ else
443
+ ''
444
+ end # indexes += case
445
+ end # each do key
457
446
 
458
447
  sql += indexes
459
448
 
@@ -461,7 +450,7 @@ module D3
461
450
  sql += "\n #{idx},"
462
451
  end
463
452
 
464
- sql.chomp! ","
453
+ sql.chomp! ','
465
454
  sql += "\n) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"
466
455
 
467
456
  if display
@@ -471,15 +460,12 @@ module D3
471
460
 
472
461
  stmt = JSS::DB_CNX.db.prepare sql
473
462
  stmt.execute
474
-
475
463
  end # create d3 table
476
464
 
477
-
478
-
479
465
  ### @return [Array<String>] A list of all d3-related tables in the database
480
466
  ###
481
467
  def self.tables
482
- res = JSS::DB_CNX.db.query "show tables"
468
+ res = JSS::DB_CNX.db.query 'show tables'
483
469
  d3_tables = []
484
470
  res.each do |t|
485
471
  d3_tables << t[0] if t[0].start_with? 'd3_'
@@ -489,4 +475,5 @@ module D3
489
475
  end
490
476
 
491
477
  end # module Database
478
+
492
479
  end # module D3