depot3 0.0.0a1 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +55 -1
  3. data/bin/d3 +323 -0
  4. data/bin/d3admin +1011 -0
  5. data/bin/d3helper +354 -0
  6. data/bin/puppytime +334 -0
  7. data/data/d3/com.pixar.d3.RepoMan.plist +23 -0
  8. data/data/d3/d3.conf.example +507 -0
  9. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftAppKit.dylib +0 -0
  10. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftCore.dylib +0 -0
  11. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftCoreData.dylib +0 -0
  12. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftCoreGraphics.dylib +0 -0
  13. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftCoreImage.dylib +0 -0
  14. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftDarwin.dylib +0 -0
  15. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftDispatch.dylib +0 -0
  16. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftFoundation.dylib +0 -0
  17. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftObjectiveC.dylib +0 -0
  18. data/data/d3/d3RepoMan.app/Contents/Info.plist +56 -0
  19. data/data/d3/d3RepoMan.app/Contents/MacOS/d3RepoMan +0 -0
  20. data/data/d3/d3RepoMan.app/Contents/PkgInfo +1 -0
  21. data/data/d3/d3RepoMan.app/Contents/Resources/Base.lproj/MainMenu.nib +0 -0
  22. data/data/d3/d3RepoMan.app/Contents/Resources/last-foreground-times-template.plist +5 -0
  23. data/data/d3/d3RepoMan.app/Contents/_CodeSignature/CodeResources +214 -0
  24. data/data/d3/puppytime/ImageLicenses.txt +165 -0
  25. data/data/d3/puppytime/notification_image +1 -0
  26. data/data/d3/puppytime/opt_out_image +1 -0
  27. data/data/d3/puppytime/slideshow/2008-07-11_White_German_Shepherd_pup_chilling_at_the_Coker_Arboretum.jpg +0 -0
  28. data/data/d3/puppytime/slideshow/2009-04-21_APBT_pup_on_deck.jpg +0 -0
  29. data/data/d3/puppytime/slideshow/A_puppy_Yorkie.jpg +0 -0
  30. data/data/d3/puppytime/slideshow/Alert_Pug_Puppy.jpg +0 -0
  31. data/data/d3/puppytime/slideshow/Australian_Cattle_Dog_puppies_04.JPG +0 -0
  32. data/data/d3/puppytime/slideshow/Beagle_puppy_Cadet.jpg +0 -0
  33. data/data/d3/puppytime/slideshow/Bernese_Mountain_Dog.jpg +0 -0
  34. data/data/d3/puppytime/slideshow/Bloodhound_Puppy.jpg +0 -0
  35. data/data/d3/puppytime/slideshow/Boston_terrier_with_toy.jpg +0 -0
  36. data/data/d3/puppytime/slideshow/Boxer_puppy_fawn_portrai.jpg +0 -0
  37. data/data/d3/puppytime/slideshow/Caracal_kitten.jpg +0 -0
  38. data/data/d3/puppytime/slideshow/Chihuahua_&_Doberman_Pup.jpg +0 -0
  39. data/data/d3/puppytime/slideshow/Cuccioli_di_Margot_a_35_gg_Basenjis.jpg +0 -0
  40. data/data/d3/puppytime/slideshow/Dalmatian_puppy_03.jpg +0 -0
  41. data/data/d3/puppytime/slideshow/GoldenRetrieverPuppyDaisyParker.JPG +0 -0
  42. data/data/d3/puppytime/slideshow/Green_eyed_beige_Chihuahua.jpg +0 -0
  43. data/data/d3/puppytime/slideshow/Let_Sleeping_Dogs_Lie.jpg +0 -0
  44. data/data/d3/puppytime/slideshow/Meatball_-_French_Bulldog_Puppy.jpg +0 -0
  45. data/data/d3/puppytime/slideshow/Oola_-_9_weeks.jpg +0 -0
  46. data/data/d3/puppytime/slideshow/Pancho0008.JPG +0 -0
  47. data/data/d3/puppytime/slideshow/Pomeranian_orange-sable_Coco.jpg +0 -0
  48. data/data/d3/puppytime/slideshow/Pug_puppy_001.jpg +0 -0
  49. data/data/d3/puppytime/slideshow/Puggle_puppy_6_weeks.JPG +0 -0
  50. data/data/d3/puppytime/slideshow/Puli_kan.jpg +0 -0
  51. data/data/d3/puppytime/slideshow/Puppy_French_Bulldog.jpg +0 -0
  52. data/data/d3/puppytime/slideshow/Rocco_the_Bulldog.jpg +0 -0
  53. data/data/d3/puppytime/slideshow/Rottweiler_Face.jpg +0 -0
  54. data/data/d3/puppytime/slideshow/Saint_Bernard_puppy.jpg +0 -0
  55. data/data/d3/puppytime/slideshow/Scottish_froment.jpg +0 -0
  56. data/data/d3/puppytime/slideshow/Shar_pei_puppy_(age_2_months).jpg +0 -0
  57. data/data/d3/puppytime/slideshow/Shiba-Inu_beim_Spielen_im_Schnee.JPG +0 -0
  58. data/data/d3/puppytime/slideshow/Smooth-coat_Border_Collie_puppy..jpg +0 -0
  59. data/data/d3/puppytime/slideshow/Smooth_Dachshund_puppies.jpg +0 -0
  60. data/data/d3/puppytime/slideshow/Snow_dog.jpg +0 -0
  61. data/data/d3/puppytime/slideshow/Taylor_the_Pembroke_Welsh_Corgi.png +0 -0
  62. data/data/d3/puppytime/slideshow/Weim_Pups_001.jpg +0 -0
  63. data/data/d3/puppytime/slideshow/Westie_pups.jpg +0 -0
  64. data/data/d3/puppytime/slideshow/Yellow_Labrador_puppies_(4165737325).jpg +0 -0
  65. data/lib/d3/admin/add.rb +451 -0
  66. data/lib/d3/admin/auth.rb +470 -0
  67. data/lib/d3/admin/edit.rb +297 -0
  68. data/lib/d3/admin/help.rb +396 -0
  69. data/lib/d3/admin/interactive.rb +972 -0
  70. data/lib/d3/admin/options.rb +454 -0
  71. data/lib/d3/admin/prefs.rb +204 -0
  72. data/lib/d3/admin/report.rb +727 -0
  73. data/lib/d3/admin/state.rb +42 -0
  74. data/lib/d3/admin/validate.rb +413 -0
  75. data/lib/d3/admin.rb +42 -0
  76. data/lib/d3/basename.rb +217 -0
  77. data/lib/d3/client/auth.rb +108 -0
  78. data/lib/d3/client/class_methods.rb +766 -0
  79. data/lib/d3/client/class_variables.rb +47 -0
  80. data/lib/d3/client/cli.rb +187 -0
  81. data/lib/d3/client/environment.rb +134 -0
  82. data/lib/d3/client/help.rb +110 -0
  83. data/lib/d3/client/lists.rb +314 -0
  84. data/lib/d3/client/receipt.rb +1173 -0
  85. data/lib/d3/client.rb +45 -0
  86. data/lib/d3/configuration.rb +319 -0
  87. data/lib/d3/constants.rb +60 -0
  88. data/lib/d3/database.rb +488 -0
  89. data/lib/d3/exceptions.rb +44 -0
  90. data/lib/d3/log.rb +271 -0
  91. data/lib/d3/package/aliases.rb +80 -0
  92. data/lib/d3/package/attributes.rb +97 -0
  93. data/lib/d3/package/class_methods.rb +817 -0
  94. data/lib/d3/package/class_variables.rb +46 -0
  95. data/lib/d3/package/client_actions.rb +293 -0
  96. data/lib/d3/package/constants.rb +58 -0
  97. data/lib/d3/package/constructor.rb +191 -0
  98. data/lib/d3/package/getters.rb +164 -0
  99. data/lib/d3/package/mixins.rb +39 -0
  100. data/lib/d3/package/private_methods.rb +227 -0
  101. data/lib/d3/package/questions.rb +95 -0
  102. data/lib/d3/package/server_actions.rb +683 -0
  103. data/lib/d3/package/setters.rb +326 -0
  104. data/lib/d3/package/validate.rb +448 -0
  105. data/lib/d3/package.rb +51 -0
  106. data/lib/d3/puppytime/pending_puppy.rb +108 -0
  107. data/lib/d3/puppytime/puppy_queue.rb +274 -0
  108. data/lib/d3/puppytime.rb +68 -0
  109. data/lib/d3/state.rb +105 -0
  110. data/lib/d3/utility.rb +325 -0
  111. data/lib/d3/version.rb +1 -1
  112. metadata +162 -9
@@ -0,0 +1,488 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+
26
+ module D3
27
+
28
+ module Database
29
+
30
+ ################# Module Constants #################
31
+
32
+
33
+ ### Booleans are stored as 1's and 0's in the db.
34
+ TRUE_VAL = 1
35
+ FALSE_VAL = 0
36
+
37
+ # This table has info about the JSS schema
38
+ SCHEMA_TABLE = "db_schema_information"
39
+
40
+ # the minimum JSS schema version allower
41
+ MIN_SCHEMA_VERSION = "9.4"
42
+
43
+ # the minimum JSS schema version allower
44
+ MAX_SCHEMA_VERSION = "9.82"
45
+
46
+ ### these Proc objects allow us to encapsulate and pass around various
47
+ ### blocks of code more easily for converting data between their mysql
48
+ ### representation and the Ruby classses we use internally.
49
+
50
+ ### Ruby Time objects are stored as JSS epochs (unix epoch plus milliseconds)
51
+ EPOCH_TO_TIME = Proc.new{|v| (v.nil? or v.to_s.empty?) ? nil : JSS.epoch_to_time(v) }
52
+
53
+ ### JSS epochs (unix epoch plus milliseconds) as used as Ruby Time objects
54
+ TIME_TO_EPOCH = Proc.new{|v|(v.nil? or v.to_s.empty?) ? nil : v.to_jss_epoch }
55
+
56
+ ### Integers come from the database as strings, but empty ones should be nil, not zero, as #to_i would do
57
+ STRING_TO_INT = Proc.new{|v| (v.nil? or v.to_s.empty?) ? nil : v.to_i}
58
+
59
+ ### Some values are stored as comma-separated strings, but used as Arrays
60
+ COMMA_STRING_TO_ARRAY = Proc.new{|v| JSS.to_s_and_a(v)[:arrayform] }
61
+
62
+ ### Some values are used as Arrays but stored as comma-separated strings
63
+ ARRAY_TO_COMMA_STRING = Proc.new{|v| JSS.to_s_and_a(v)[:stringform] }
64
+
65
+ ### Some values are stored in the DB as YAML dumps
66
+ RUBY_TO_YAML = Proc.new{|v| YAML.dump v }
67
+
68
+ YAML_TO_RUBY = Proc.new{|v| YAML.load v.to_s }
69
+
70
+ ### Booleans are stored as zero and one
71
+ BOOL_TO_INT = Proc.new{|v| v == true ? TRUE_VAL : FALSE_VAL}
72
+
73
+ ### Booleans are stored as zero and one
74
+ INT_TO_BOOL = Proc.new{|v| v.to_i == FALSE_VAL ? false : true}
75
+
76
+ ### Regexps are stored as strings
77
+ STRING_TO_REGEXP = Proc.new{|v| v.to_s.empty? ? nil : Regexp.new(v.to_s) }
78
+
79
+ ### Regexps are stored as strings
80
+ REGEXP_TO_STRING = Proc.new{|v| v.to_s }
81
+
82
+ ### Status values are stored as strings, but used as symbols
83
+ STATUS_TO_STRING = Proc.new{|v| v.to_s }
84
+ STRING_TO_STATUS = Proc.new{|v| v.to_sym }
85
+
86
+ ### Expiration paths are stored as strings, but used as Pathnames
87
+ STRING_TO_PATHNAME = Proc.new{|v| Pathname.new v.to_s}
88
+ PATHNAME_TO_STRING = Proc.new{|v| v.to_s}
89
+
90
+
91
+ ### The MySQL table that defines which JSS Packages are a part of d3
92
+ ###
93
+ ### This complex Hash contains all the data needed to create and work with the
94
+ ### d3 Packages table.
95
+ ###
96
+ ### The Hash contains these keys & values:
97
+ ###
98
+ ### - :table_name [String] the name of the table in the database
99
+ ###
100
+ ### - :other_indexes [Array<String>] SQL clauses for defining multi-field indexes
101
+ ### in the CREATE TABLE statement. Single-field indexes are defined in the field definitions.
102
+ ###
103
+ ### - :field_definitions [Hash<Hash>] The definitions of the fields in the table, used throughout the D3 module to
104
+ ### refer to the data from the database. The keys are also used as the attribute names of {DD3::Package} objects
105
+ ### Each field definition is a subHash with these keys:
106
+ ### - - :field_name [String] the name of the field in the table
107
+ ### - - :sql_type [String] The SQL data type clause and options for creating the field in the table
108
+ ### - - :index [Boolean,Symbol] How should the field be indexed in the table? One of: true, :primary, :unique or nil/false
109
+ ### - - :to_sql [Proc] the Proc to call with a Ruby object, to convert it to the storable format for the field.
110
+ ### Integers and Strings don't need conversion. Mysql.encode will be called on all values automatically.
111
+ ### - - :to_ruby [Proc] The Proc to call with a MySQL return value, to convert it to the Ruby class
112
+ ### used by this module. nil if the value should be a String in Ruby.
113
+ ###
114
+ ### The fields in the table, their Ruby classes, and their meanings are:
115
+ ###
116
+ ### - :id [Integer] the JSS::Package id of this package
117
+ ###
118
+ ### - :basename [String] the basename to which this pkg belongs
119
+ ###
120
+ ### - :version [String] the version number for this basename, installed by this package
121
+ ###
122
+ ### - :revision [Integer] the d3 pkg-revision number of this version. I.e. how many times has this basename-version
123
+ ### been added to d3?
124
+ ###
125
+ ### - :apple_receipt_data [Array<Hash>] the apple package data for this pkg and all it's sub-pkgs
126
+ ### Each Hash contains these keys for each pkg installed
127
+ ### - :apple_pkg_id The identifier for the item, e.g. com.avid.edlmanager.pkg
128
+ ### - :version The version installed, which might not match the version of the metapkg
129
+ ### - :installed_kb The disk spaced used by this pkg when installed
130
+ ### When .[m]pkgs are installed, the identifiers and metadata for each are recorded in the OS's receipts database
131
+ ### and are accessible via the pkgutil command. (e.g. pkgutil --pkg-info com.company.application). Storing the apple rcpt
132
+ ### data in the DB allows us to do uninstalls and other client tasks without needing to index the pkg in casper. This is
133
+ ### stored in the DB as a YAML string
134
+ ###
135
+ ### - :added_date [Time] when was this package was added to d3
136
+ ###
137
+ ### - :added_by [String,nil] the login name of the admin who added this packge to d3
138
+ ###
139
+ ### - :status [Integer] the status of this pkg, one of {D3::Basename::STATUSES}
140
+ ###
141
+ ### - :release_date [Time,nil] when was this package made live in d3
142
+ ###
143
+ ### - :released_by [String,nil] the login name of the admin who made it live
144
+ ###
145
+ ### - :auto_groups [Array] a list of JSS::ComputerGroup names whose members get this
146
+ ### package installed automatically. The special value :standard means all computers
147
+ ### get this package automatically, except those in excluded groups.
148
+ ###
149
+ ### - :excluded_groups [Array] a list of JSS::ComputerGroup names for whose members this
150
+ ### package is not available without force
151
+ ###
152
+ ### - :triggers_swu [Boolean] when installed, will this package trigger a GUI software update check,
153
+ ### either immediately if there's a console user, or at the next console login?
154
+ ###
155
+ ### - :prohibiting_process [String] a string for matching to the output lines
156
+ ### of '/bin/ps -A -c -o comm'. If there's a matching line, this pkg won't be installed
157
+ ###
158
+ ### - :remove_first [Boolean] should any currently installed versions of this basename
159
+ ### be uninstalled (if possible) before installing this package?
160
+ ###
161
+ ### - :pre_install_id [Integer,nil] the JSS::Script id of the pre-install script, if any
162
+ ###
163
+ ### - :post_install_id [Integer,nil] the JSS::Script id of the post-install script, if any
164
+ ###
165
+ ### - :pre_remove_id [Integer,nil] the JSS::Script id of the pre-remove script, if any
166
+ ###
167
+ ### - :post_remove_id [Integer,nil] the JSS::Script id of the post-remove script, if any
168
+ ###
169
+ ### See also the attributes of {D3::Package}, which mostly mirror the
170
+ ###
171
+ PACKAGE_TABLE = { :table_name => 'd3_packages',
172
+
173
+ :field_definitions => {
174
+
175
+ :id => {
176
+ :field_name => "package_id",
177
+ :sql_type => 'int(11) NOT NULL',
178
+ :index => :unique,
179
+ :to_sql => nil,
180
+ :to_ruby => STRING_TO_INT
181
+ },
182
+
183
+ :basename => {
184
+ :field_name => "basename",
185
+ :sql_type => 'varchar(60) NOT NULL',
186
+ :index => true,
187
+ :to_sql => nil,
188
+ :to_ruby => nil
189
+ },
190
+
191
+ :version => {
192
+ :field_name => "version",
193
+ :sql_type => 'varchar(30) NOT NULL',
194
+ :index => nil,
195
+ :to_sql => nil,
196
+ :to_ruby => nil
197
+ },
198
+
199
+ :revision => {
200
+ :field_name => "revision",
201
+ :sql_type => 'int(4) NOT NULL',
202
+ :index => nil,
203
+ :to_sql => nil,
204
+ :to_ruby => STRING_TO_INT
205
+ },
206
+
207
+ :apple_receipt_data => {
208
+ :field_name => "apple_receipt_data",
209
+ :sql_type => "text",
210
+ :index => nil,
211
+ :to_sql => RUBY_TO_YAML,
212
+ :to_ruby => YAML_TO_RUBY
213
+ },
214
+
215
+ :added_date => {
216
+ :field_name => "added_date_epoch",
217
+ :sql_type => "bigint(32) DEFAULT NULL",
218
+ :index => nil,
219
+ :to_sql => TIME_TO_EPOCH,
220
+ :to_ruby => EPOCH_TO_TIME
221
+ },
222
+
223
+ :added_by => {
224
+ :field_name => "added_by",
225
+ :sql_type => 'varchar(30)',
226
+ :index => nil,
227
+ :to_sql => nil,
228
+ :to_ruby => nil
229
+ },
230
+
231
+ :status => {
232
+ :field_name => "status",
233
+ :sql_type => "varchar(30) DEFAULT 'pilot'",
234
+ :index => nil,
235
+ :to_sql => STATUS_TO_STRING,
236
+ :to_ruby => STRING_TO_STATUS
237
+ },
238
+
239
+ :release_date => {
240
+ :field_name => "release_date_epoch",
241
+ :sql_type => "bigint(32) DEFAULT NULL",
242
+ :index => nil,
243
+ :to_sql => TIME_TO_EPOCH,
244
+ :to_ruby => EPOCH_TO_TIME
245
+ },
246
+
247
+ :released_by => {
248
+ :field_name => "released_by",
249
+ :sql_type => 'varchar(30)',
250
+ :index => nil,
251
+ :to_sql => nil,
252
+ :to_ruby => nil
253
+ },
254
+
255
+ :auto_groups => {
256
+ :field_name => 'auto_install_groups',
257
+ :sql_type => 'text',
258
+ :index => nil,
259
+ :to_sql => ARRAY_TO_COMMA_STRING,
260
+ :to_ruby => COMMA_STRING_TO_ARRAY
261
+ },
262
+
263
+ :excluded_groups => {
264
+ :field_name => 'excluded_groups',
265
+ :sql_type => 'text',
266
+ :index => nil,
267
+ :to_sql => ARRAY_TO_COMMA_STRING,
268
+ :to_ruby => COMMA_STRING_TO_ARRAY
269
+ },
270
+
271
+ :prohibiting_process => {
272
+ :field_name => "prohibiting_process",
273
+ :sql_type => 'varchar(100)',
274
+ :index => nil,
275
+ :to_sql => nil,
276
+ :to_ruby => nil
277
+ },
278
+
279
+ :remove_first => {
280
+ :field_name => "remove_first",
281
+ :sql_type => "tinyint(1) DEFAULT '0'",
282
+ :index => nil,
283
+ :to_sql => BOOL_TO_INT,
284
+ :to_ruby => INT_TO_BOOL
285
+ },
286
+
287
+ :pre_install_script_id => {
288
+ :field_name => "pre_install_id",
289
+ :sql_type => 'int(11)',
290
+ :index => nil,
291
+ :to_sql => nil,
292
+ :to_ruby => STRING_TO_INT
293
+ },
294
+
295
+ :post_install_script_id => {
296
+ :field_name => "post_install_id",
297
+ :sql_type => 'int(11)',
298
+ :index => nil,
299
+ :to_sql => nil,
300
+ :to_ruby => STRING_TO_INT
301
+ },
302
+
303
+ :pre_remove_script_id => {
304
+ :field_name => "pre_remove_id",
305
+ :sql_type => 'int(11)',
306
+ :index => nil,
307
+ :to_sql => nil,
308
+ :to_ruby => STRING_TO_INT
309
+ },
310
+
311
+ :post_remove_script_id => {
312
+ :field_name => "post_remove_id",
313
+ :sql_type => 'int(11)',
314
+ :index => nil,
315
+ :to_sql => nil,
316
+ :to_ruby => STRING_TO_INT
317
+ },
318
+
319
+ :expiration => {
320
+ :field_name => "expiration",
321
+ :sql_type => 'int(11)',
322
+ :index => nil,
323
+ :to_sql => nil,
324
+ :to_ruby => STRING_TO_INT
325
+ },
326
+
327
+ :expiration_path => {
328
+ :field_name => "expiration_app_path",
329
+ :sql_type => 'varchar(300)',
330
+ :index => nil,
331
+ :to_sql => PATHNAME_TO_STRING,
332
+ :to_ruby => STRING_TO_PATHNAME
333
+ }
334
+ },
335
+
336
+ :other_indexes => [
337
+ "UNIQUE KEY `edition` (`basename`,`version`,`revision`)"
338
+ ]
339
+ } # end PACKAGE_TABLE
340
+
341
+
342
+
343
+ ################# Module Methods #################
344
+
345
+ ### Retrieve all records for one of the tables defined in D3::Database
346
+ ###
347
+ ### This is generally used by the method {D3::Package.package_data},
348
+ ###
349
+ ### Returns an Array of Hashes, one for each record in the desired table.
350
+ ### The keys of each hash are the keys of the :field_definitions hash from
351
+ ### the table definition.
352
+ ###
353
+ ### @param table_def[Hash] one of the d3 mysql table definitions, currently only
354
+ ### {D3::Database::PACKAGE_TABLE}
355
+ ###
356
+ ### @return [Array<Hash>] the records from the desired table, with all values converted to
357
+ ### appropriate Ruby classes as defined in the table_def
358
+ ###
359
+ ###
360
+ def self.table_records(table_def)
361
+
362
+ recs = []
363
+
364
+ result = JSS.db.query "SELECT * FROM #{table_def[:table_name]}"
365
+
366
+ # parse each record into a hash
367
+ result.each_hash do |record|
368
+
369
+ rec = {}
370
+
371
+ # go through each field in the record, adding it to the hash
372
+ # converting it to its ruby data type if defined in field conversions
373
+ table_def[:field_definitions].each_pair do |key,field_def|
374
+
375
+ # do we convert the value from the DB to something else in ruby?
376
+ if field_def[:to_ruby]
377
+ rec[key] = field_def[:to_ruby].call record[field_def[:field_name]]
378
+
379
+ # or do we use the value as it comes from the DB?
380
+ else
381
+ rec[key] = record[field_def[:field_name]]
382
+ end # if
383
+
384
+ end # do key, field_def
385
+
386
+ recs << rec
387
+
388
+ end # do record
389
+
390
+ return recs
391
+ end # self.table_records(table_def)
392
+
393
+ ### Print the sql for creating the d3_packages table
394
+ ### as defined in the PACKAGE_TABLE constant
395
+ ###
396
+ ### @return [void]
397
+ ###
398
+ def self.table_creation_sql
399
+ puts self.create_table(:display)
400
+ end
401
+
402
+
403
+ ### Raise an exception if JSS schema is to old or too new
404
+ def self.check_schema_version
405
+ raw = JSS::DB_CNX.db.query("SELECT version FROM #{SCHEMA_TABLE}").fetch[0]
406
+ current = JSS.parse_jss_version(raw)[:version]
407
+ min = JSS.parse_jss_version(MIN_SCHEMA_VERSION)[:version]
408
+ max = JSS.parse_jss_version(MAX_SCHEMA_VERSION)[:version]
409
+ raise JSS::InvalidConnectionError, "Invalid JSS database schema version: #{raw}, min: #{MIN_SCHEMA_VERSION}, max: #{MAX_SCHEMA_VERSION}" if current < min or current > max
410
+ return true
411
+ end
412
+
413
+ private
414
+
415
+
416
+ ### Given a table constant defining a d3 table (PACKAGES_TABLE, at this point),
417
+ ### create the table in the database.
418
+ ###
419
+ ### @param table_constant[Hash] one of the d3 table definition constants, currently only
420
+ ### {D3::Database::PACKAGE_TABLE}
421
+ ###
422
+ ### @param print[Boolean] just print to stdout the SQL statement for creating the table, don't execute it.
423
+ ###
424
+ ### @return [void]
425
+ ###
426
+ def self.create_table(display=false)
427
+
428
+ # as of now, only one table.
429
+ table_constant = PACKAGE_TABLE
430
+
431
+ sql = "CREATE TABLE `#{table_constant[:table_name]}` ("
432
+ indexes = ''
433
+
434
+ table_constant[:field_definitions].keys.sort.each do |key|
435
+
436
+ field = table_constant[:field_definitions][key]
437
+
438
+ sql += "\n `#{field[:field_name]}` #{field[:sql_type]},"
439
+
440
+ indexes += case field[:index]
441
+ when :primary
442
+ "\n PRIMARY KEY (`#{field[:field_name]}`),"
443
+ when :unique
444
+ "\n UNIQUE KEY (`#{field[:field_name]}`),"
445
+ when true
446
+ "\n KEY (`#{field[:field_name]}`),"
447
+ else
448
+ ''
449
+ end # indexes += case
450
+ end #each do key
451
+
452
+ sql += indexes
453
+
454
+ table_constant[:other_indexes].each do |idx|
455
+ sql += "\n #{idx},"
456
+ end
457
+
458
+ sql.chomp! ","
459
+ sql += "\n) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"
460
+
461
+ if display
462
+ puts sql
463
+ return
464
+ end
465
+
466
+ stmt = JSS::DB_CNX.db.prepare sql
467
+ stmt.execute
468
+
469
+ end # create d3 table
470
+
471
+
472
+
473
+ ### @return [Array<String>] A list of all d3-related tables in the database
474
+ ###
475
+ def self.tables
476
+ res = JSS::DB_CNX.db.query "show tables"
477
+ d3_tables = []
478
+ res.each do |t|
479
+ d3_tables << t[0] if t[0].start_with? 'd3_'
480
+ end # res.each do |t|
481
+ res.free
482
+ d3_tables
483
+ end
484
+
485
+ end # module Database
486
+ end # module D3
487
+
488
+
@@ -0,0 +1,44 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+
26
+ module D3
27
+
28
+ class InstallError < RuntimeError ; end
29
+
30
+ class ScriptError < RuntimeError ; end
31
+
32
+ class PreInstallError < ScriptError ; end
33
+
34
+ class PostInstallError < ScriptError ; end
35
+
36
+ class PreRemoveError < ScriptError ; end
37
+
38
+ class PostRemoveError < ScriptError ; end
39
+
40
+ class UninstallError < RuntimeError ; end
41
+
42
+ class PermissionError < RuntimeError ; end
43
+
44
+ end # module PixD3