Class: FMPVC::FMPReport
- Inherits:
-
Object
- Object
- FMPVC::FMPReport
- Defined in:
- lib/fmpvc/FMPReport.rb
Instance Attribute Summary collapse
-
#accounts ⇒ Object
readonly
Returns the value of attribute accounts.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#custom_functions ⇒ Object
readonly
Returns the value of attribute custom_functions.
-
#extended_privileges ⇒ Object
readonly
Returns the value of attribute extended_privileges.
-
#external_sources ⇒ Object
readonly
Returns the value of attribute external_sources.
-
#file_access ⇒ Object
readonly
Returns the value of attribute file_access.
-
#file_options ⇒ Object
readonly
Returns the value of attribute file_options.
-
#layouts ⇒ Object
readonly
Returns the value of attribute layouts.
-
#named_objects ⇒ Object
readonly
Returns the value of attribute named_objects.
-
#privileges ⇒ Object
readonly
Returns the value of attribute privileges.
-
#relationships ⇒ Object
readonly
Returns the value of attribute relationships.
-
#report_dirpath ⇒ Object
readonly
Returns the value of attribute report_dirpath.
-
#scripts ⇒ Object
readonly
Returns the value of attribute scripts.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
-
#text_dir ⇒ Object
readonly
Returns the value of attribute text_dir.
-
#text_filename ⇒ Object
readonly
Returns the value of attribute text_filename.
-
#themes ⇒ Object
readonly
Returns the value of attribute themes.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value_lists ⇒ Object
readonly
Returns the value of attribute value_lists.
Instance Method Summary collapse
- #clean_dir ⇒ Object
- #define_content_procs ⇒ Object
-
#disk_path_from_base(object_base, object_xpath, path = '') ⇒ Object
e.g.
- #element2yaml(xml_element) ⇒ Object
- #fs_id(fs_name, id) ⇒ Object
- #fs_sanitize(text_string) ⇒ Object
-
#initialize(report_filename, ddr) ⇒ FMPReport
constructor
A new instance of FMPReport.
- #parse ⇒ Object
- #parse_fmp_obj(object_base, object_nodes, obj_content, one_file = false) ⇒ Object
- #post_notification(object, verb = 'Updating') ⇒ Object
- #suppress_record_info ⇒ Object
- #write_all_objects ⇒ Object
- #write_dir ⇒ Object
- #write_obj_to_disk(objs, full_path) ⇒ Object
Constructor Details
#initialize(report_filename, ddr) ⇒ FMPReport
Returns a new instance of FMPReport.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fmpvc/FMPReport.rb', line 16 def initialize(report_filename, ddr) report_dirpath = "#{ddr.base_dir_ddr}/#{report_filename}" # location of the fmpfilename.xml file raise(RuntimeError, "Error: can't find the report file, #{report_dirpath}") unless File.readable?(report_dirpath) @content = IO.read(report_dirpath) @text_dir = "#{ddr.base_dir_ddr}/../#{FMPVC.configuration.text_dirname}" @text_filename = fs_sanitize(report_filename) @report_dirpath = "#{@text_dir}/#{@text_filename}" self.define_content_procs self.parse self.clean_dir self.write_dir ### hierarchical folder structure @scripts = parse_fmp_obj( "/FMPReport/File/ScriptCatalog", "/*[name()='Group' or name()='Script']", @script_content ) @layouts = parse_fmp_obj( "/FMPReport/File/LayoutCatalog", "/*[name()='Group' or name()='Layout']", @layouts_content ) ### single folder with files @value_lists = parse_fmp_obj( "/FMPReport/File/ValueListCatalog", "/*[name()='ValueList']", @value_list_content ) @tables = parse_fmp_obj( "/FMPReport/File/BaseTableCatalog", "/*[name()='BaseTable']", @table_content ) suppress_record_info if FMPVC.configuration.show_record_info == false @custom_functions = parse_fmp_obj( "/FMPReport/File/CustomFunctionCatalog", "/*[name()='CustomFunction']", @custom_function_content ) @menu_sets = parse_fmp_obj( "/FMPReport/File/CustomMenuSetCatalog", "/*[name()='CustomMenuSet']", @menu_sets_content ) @custom_menus = parse_fmp_obj( "/FMPReport/File/CustomMenuCatalog", "/*[name()='CustomMenu']", @custom_menus_content ) ### single file output @accounts = parse_fmp_obj( "/FMPReport/File/AccountCatalog", "/*[name()='Account']", @accounts_content, true ) @privileges = parse_fmp_obj( "/FMPReport/File/PrivilegesCatalog", "/*[name()='PrivilegeSet']", @privileges_content, true ) @extended_privileges = parse_fmp_obj( "/FMPReport/File/ExtendedPrivilegeCatalog", "/*[name()='ExtendedPrivilege']", @extended_priviledge_content, true ) @relationships = parse_fmp_obj( "/FMPReport/File/RelationshipGraph", "/RelationshipList/*[name()='Relationship']", @relationships_content, true ) @file_access = parse_fmp_obj( "/FMPReport/File/AuthFileCatalog", '', @file_access_content, true ) @external_sources = parse_fmp_obj( "/FMPReport/File/ExternalDataSourcesCatalog", '', @external_sources_content, true ) @file_options = parse_fmp_obj( "/FMPReport/File/Options", '', @file_options_content, true ) @themes = parse_fmp_obj( "/FMPReport/File/ThemeCatalog", "/*[name()='Theme']", @themes_content, true ) @named_objects = [ { :content => @scripts, :disk_path => "/Scripts" }, { :content => @layouts, :disk_path => "/Layouts" }, { :content => @value_lists, :disk_path => "/ValueLists" }, { :content => @tables, :disk_path => "/Tables" }, { :content => @custom_functions, :disk_path => "/CustomFunctions" }, { :content => @menu_sets, :disk_path => "/CustomMenuSets" }, { :content => @custom_menus, :disk_path => "/CustomMenus" }, { :content => @accounts, :disk_path => "/Accounts.txt" }, { :content => @privileges, :disk_path => "/PrivilegeSets.txt" }, { :content => @extended_privileges, :disk_path => "/ExtendedPrivileges.txt" }, { :content => @relationships, :disk_path => "/Relationships.txt" }, { :content => @file_access, :disk_path => "/FileAccess.txt" }, { :content => @external_sources, :disk_path => "/ExternalDataSources.txt" }, { :content => @file_options, :disk_path => "/Options.txt" }, { :content => @themes, :disk_path => "/Themes.txt" } ] end |
Instance Attribute Details
#accounts ⇒ Object (readonly)
Returns the value of attribute accounts.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def accounts @accounts end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def content @content end |
#custom_functions ⇒ Object (readonly)
Returns the value of attribute custom_functions.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def custom_functions @custom_functions end |
#extended_privileges ⇒ Object (readonly)
Returns the value of attribute extended_privileges.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def extended_privileges @extended_privileges end |
#external_sources ⇒ Object (readonly)
Returns the value of attribute external_sources.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def external_sources @external_sources end |
#file_access ⇒ Object (readonly)
Returns the value of attribute file_access.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def file_access @file_access end |
#file_options ⇒ Object (readonly)
Returns the value of attribute file_options.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def @file_options end |
#layouts ⇒ Object (readonly)
Returns the value of attribute layouts.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def layouts @layouts end |
#named_objects ⇒ Object (readonly)
Returns the value of attribute named_objects.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def named_objects @named_objects end |
#privileges ⇒ Object (readonly)
Returns the value of attribute privileges.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def privileges @privileges end |
#relationships ⇒ Object (readonly)
Returns the value of attribute relationships.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def relationships @relationships end |
#report_dirpath ⇒ Object (readonly)
Returns the value of attribute report_dirpath.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def report_dirpath @report_dirpath end |
#scripts ⇒ Object (readonly)
Returns the value of attribute scripts.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def scripts @scripts end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def tables @tables end |
#text_dir ⇒ Object (readonly)
Returns the value of attribute text_dir.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def text_dir @text_dir end |
#text_filename ⇒ Object (readonly)
Returns the value of attribute text_filename.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def text_filename @text_filename end |
#themes ⇒ Object (readonly)
Returns the value of attribute themes.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def themes @themes end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def type @type end |
#value_lists ⇒ Object (readonly)
Returns the value of attribute value_lists.
14 15 16 |
# File 'lib/fmpvc/FMPReport.rb', line 14 def value_lists @value_lists end |
Instance Method Details
#clean_dir ⇒ Object
105 106 107 |
# File 'lib/fmpvc/FMPReport.rb', line 105 def clean_dir FileUtils.rm_rf(@report_dirpath) end |
#define_content_procs ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
# File 'lib/fmpvc/FMPReport.rb', line 193 def define_content_procs @script_content = Proc.new do |a_script| content = '' a_script.xpath("./StepList/Step/StepText").each {|t| content += t.text.gsub(%r{\n},'') + "\n" } # remove \n from middle of steps content end @layouts_content = Proc.new do |a_layout| content = '' layout_name = a_layout['name'] layout_id = a_layout['id'] layout_table = a_layout.xpath('./Table').first['name'] layout_theme = a_layout.xpath('./Theme').empty? ? '' : a_layout.xpath('./Theme').first['name'] layout_format = "%18s %-25s\n" object_format = " %-16s %-35s\n" content += format(layout_format, "Layout name: ", layout_name) content += format(layout_format, "id: ", layout_id) content += format(layout_format, "Table: ", layout_table) content += format(layout_format, "Theme: ", layout_theme) content += NEWLINE content += format(layout_format, "Objects: ", '') layout_objects = a_layout.xpath("./*[name()='Object']") # find all objects layout_objects_types = layout_objects.map { |o| o['type']} # list of 'types' if !layout_objects_types.empty? # [].uniq! => nil - don't do that layout_objects_types.uniq! content += format(object_format, "Type", "'Name'" ) content += format(object_format, "----", "------" ) end layout_objects_types.each do |a_type| selected_objects = layout_objects.select { |o| o['type'] == a_type } # get all the objects of a given type selected_objects.each do |type_obj| # collect all objects of type content += format(object_format, type_obj['type'], type_obj.xpath('./*/Name').text) unless type_obj['type'] == "Text" end end content end @value_list_content = Proc.new do |a_value_list| content = '' source_type = a_value_list.xpath("./Source").first['value'] if source_type == "Custom" a_value_list.xpath("./CustomValues/Text").each {|t| content += t.text} end content end @table_content = Proc.new do |a_table| content = '' table_format = "%6d %-25s %-15s %-15s %-50s\n" table_header_format = table_format.gsub(%r{d}, 's') content += format(table_header_format, "id", "Field Name", "Data Type", "Field Type", "Comment") content += format(table_header_format, "--", "----------", "---------", "----------", "-------") a_table.xpath(%{//BaseTable[@name=$table_name]/FieldCatalog/*[name()='Field']}, nil, :table_name => a_table['name']).each do |t| t_comment = t.xpath("./Comment").text content += format(table_format, t['id'], t['name'], t['dataType'], t['fieldType'], t_comment) end content end @custom_function_content = Proc.new do |a_custom_function| content = '' content += a_custom_function.xpath("./Calculation").map {|t| t.text}.join(NEWLINE) content end @menu_sets_content = Proc.new do || content = '' = "%6d %-35s\n" = .gsub(%r{d}, 's') content += format(, "id", "Menu") content += format(, "--", "----") .xpath("./CustomMenuList/*[name()='CustomMenu']").each do || content += format(, ['id'], ['name']) end content end @custom_menus_content = Proc.new do || content = '' = ['name'] = ['id'] = .xpath('./BaseMenu').empty? ? "" : .xpath('./BaseMenu').first['name'] = .xpath('./Comment').text = "%17s %-35s\n" content += format(, "Menu name:", ) content += format(, "id:", ) content += format(, "Base menu:", ) content += format(, "Comment:", ) content += NEWLINE = .xpath("./MenuItemList/*[name()='MenuItem']") .each do |an_item| an_item.xpath('./Command').each { |c| content += " #{c['name']}\n"} end content end @accounts_content = Proc.new do |accounts| content = '' accounts_format = "%6d %-25s %-10s %-12s %-20s %-12s %-12s %-50s" accounts_header_format = accounts_format.gsub(%r{d}, 's') content += format(accounts_header_format, "id", "Name", "Status", "Management", "Privilege Set", "Empty Pass?", "Change Pass?", "Description") + NEWLINE content += format(accounts_header_format, "--", "----", "------", "----------", "-------------", "-----------", "------------", "-----------") + NEWLINE content += accounts.map do |an_account| account_name = an_account['name'] account_id = an_account['id'] account_privilegeSet = an_account['privilegeSet'] account_emptyPassword = an_account['emptyPassword'] account_changePasswordOnNextLogin = an_account['changePasswordOnNextLogin'] account_managedBy = an_account['managedBy'] account_status = an_account['status'] account_Description = an_account.xpath('./Description').text format( accounts_format \ , account_id \ , account_name \ , account_status \ , account_managedBy \ , account_privilegeSet \ , account_emptyPassword \ , account_changePasswordOnNextLogin \ , account_Description ) end.join(NEWLINE) content end @privileges_content = Proc.new do |privileges| content = '' privileges_format = "%6d %-25s %-8s %-10s %-15s %-12s %-12s %-12s %-8s %-18s %-11s %-10s %-12s %-10s %-16s %-10s %-70s" privileges_header_format = privileges_format.gsub(%r{d}, 's') content += format(privileges_header_format, "id", "Name", "Print?", "Export?", "Manage Ext'd?", "Override?", "Disconnect?", "Password?", "Menus", "Records", "Layouts", "(Creation)", "ValueLists", "(Creation)", "Scripts", "(Creation)", "Description") + NEWLINE content += format(privileges_header_format, "--", "----", "------", "-------", "-------------", "---------", "-----------", "---------", "-----", "-------", "-------", "----------", "----------", "----------", "-------", "----------", "-----------") + NEWLINE privileges.each do |a_privilege_set| privilege_set_id = a_privilege_set['id'] privilege_set_name = a_privilege_set['name'] privilege_set_comment = a_privilege_set['comment'] privilege_set_printing = a_privilege_set['printing'] privilege_set_exporting = a_privilege_set['exporting'] privilege_set_managedExtended = a_privilege_set['managedExtended'] privilege_set_overrideValidationWarning = a_privilege_set['overrideValidationWarning'] privilege_set_idleDisconnect = a_privilege_set['idleDisconnect'] privilege_set_allowModifyPassword = a_privilege_set['allowModifyPassword'] = a_privilege_set['menu'] privilege_set_records_value = a_privilege_set.xpath('./Records').first['value'] privilege_set_layouts_value = a_privilege_set.xpath('./Layouts').first['value'] privilege_set_layouts_creation = a_privilege_set.xpath('./Layouts').first['allowCreation'] privilege_set_valuelists_value = a_privilege_set.xpath('./ValueLists').first['value'] privilege_set_valuelists_creation = a_privilege_set.xpath('./ValueLists').first['allowCreation'] privilege_set_scripts_value = a_privilege_set.xpath('./Scripts').first['value'] privilege_set_scripts_creation = a_privilege_set.xpath('./Scripts').first['allowCreation'] content += format( privileges_format \ , privilege_set_id \ , privilege_set_name \ , privilege_set_printing \ , privilege_set_exporting \ , privilege_set_managedExtended \ , privilege_set_overrideValidationWarning \ , privilege_set_idleDisconnect \ , privilege_set_allowModifyPassword \ , \ , privilege_set_records_value \ , privilege_set_layouts_value \ , privilege_set_layouts_creation \ , privilege_set_valuelists_value \ , privilege_set_valuelists_creation \ , privilege_set_scripts_value \ , privilege_set_scripts_creation \ , privilege_set_comment \ ) + NEWLINE end content end @extended_priviledge_content = Proc.new do |ext_privileges| content = '' ext_privilege_format = "%6d %-20s %-85s %-150s\n" ext_privilege_header_format = ext_privilege_format.gsub(%r{d}, 's') content += format(ext_privilege_header_format, "id", "Name", "Description", "Privilege Sets") content += format(ext_privilege_header_format, "--", "----", "-----------", "--------------") ext_privileges.each do |an_ext_privilege| ext_privilege_id = an_ext_privilege['id'] ext_privilege_name = an_ext_privilege['name'] ext_privilege_comment = an_ext_privilege['comment'] ext_privilege_sets = an_ext_privilege.xpath('./PrivilegeSetList/*[name()="PrivilegeSet"]').map {|s| s['name']}.join(", ") content += format( ext_privilege_format \ , ext_privilege_id \ , ext_privilege_name \ , ext_privilege_comment \ , ext_privilege_sets \ ) end content end @relationships_content = Proc.new do |relationships| content = '' tables = @report.xpath("/FMPReport/File/RelationshipGraph/TableList/*[name()='Table']") table_format = " %-25s %-25s" content +="Tables\n" content += NEWLINE content +=format(table_format, "Base Table (id)", "Table occurrence (id)") + NEWLINE content +=format(table_format, "---------------", "---------------------") + NEWLINE content += NEWLINE tables.each do |a_table| table_id = a_table['id'] table_name = a_table['name'] basetable_id = a_table['baseTableId'] basetable_name = a_table['baseTable'] content +=format(table_format, "#{basetable_name} (#{basetable_id})", "#{table_name} (#{table_id})") + NEWLINE end content += NEWLINE relationship_format = " %-35s %-15s %-35s" content +="Relationships" + NEWLINE relationships.each do |a_relationship| content += NEWLINE content += format(" Relationship: %-4d", a_relationship['id']) + NEWLINE predicates = a_relationship.xpath('./JoinPredicateList/*[name()="JoinPredicate"]') predicates.each do |a_predicate| predicate_type = a_predicate['type'] left_field = a_predicate.xpath('./LeftField/*[name()="Field"]').first left_table = left_field['table'] left_field_name = left_field['name'] right_field = a_predicate.xpath('./RightField/*[name()="Field"]').first right_table = right_field['table'] right_field_name = right_field['name'] content += format(relationship_format, "#{left_table}::#{left_field_name}", "#{predicate_type}", "#{right_table}::#{right_field_name}") + NEWLINE end end content end @file_access_content = Proc.new do |file_access| content = '' inbound_access = file_access.xpath("./Inbound/*[name()='InboundAuthorization']") outbound_access = file_access.xpath("./Outbound/*[name()='OutboundAuthorization']") access_format = " %6d %-25s %-25s %-25s" access_format_header = access_format.gsub(%r{d}, 's') auth_requirement = file_access.first['requireAuthorization'] content += "Authorization required: #{auth_requirement}" + NEWLINE if auth_requirement == "True" content += NEWLINE content += format(access_format_header, "id", "Timestamp", "Account", "Filenames") + NEWLINE content += format(access_format_header, "--", "---------", "-------", "---------") + NEWLINE content += format("%12s", "Inbound:") + NEWLINE inbound_access.each do |i| content += format(access_format, i['id'], i['date'], i['user'], i['filenames']) + NEWLINE end content += format("%12s", "Outbound:") + NEWLINE outbound_access.each do |o| content += format(access_format, o['id'], o['date'], o['user'], o['filenames']) + NEWLINE end end content += NEWLINE content end @external_sources_content = Proc.new do |data_sources| content = '' file_references = data_sources.xpath("./*[name()='FileReference']") odbc_sources = data_sources.xpath("./*[name()='OdbcDataSource']") file_references_format = " %6d %-25s %-25s\n" file_references_header_format = file_references_format.gsub(%r{d},'s') odbc_source_format = " %6d %-25s %-25s %-25s\n" odbc_source_header_format = odbc_source_format.gsub(%r{d},'s') content += format(file_references_header_format, "id", "File Reference", "Path List") content += format(file_references_header_format, "--", "--------------", "---------") file_references.each do |r| content += format(file_references_format, r['id'], r['name'], r['pathList']) end content += NEWLINE content += format(odbc_source_header_format, "id", "ODBC Source", "DSN", "Link") content += format(odbc_source_header_format, "--", "-----------", "---", "----") odbc_sources.each do |s| content += format(odbc_source_format, s['id'], s['name'], s['DSN'], s['link']) end content end @file_options_content = Proc.new do || content = '' = " %-27s %-30s\n" trigger_format = " %-23s %-30s\n" # optional <FMPReport><File><Options>, see DDR_grammar doc, p. 5 open_account_search = .xpath('./OnOpen/Account') open_account = (open_account_search.size > 0 ? open_account_search.first['name']: "") open_layout_search = .xpath('./OnOpen/Layout') open_layout = ( open_layout_search.size > 0 ? open_layout_search.first['name'] : "" ) # puts "encryption: >>#{file_options.xpath('./Encryption').empty?}<<" encryption_type = .xpath('./Encryption').empty? ? '' : .xpath('./Encryption').first['type'] encryption_note = case encryption_type when "" when "0" "no encryption" when "1" "AES256 encrypted" end minimum_allowed_version = .xpath('./OnOpen/MinimumAllowedVersion').empty? ? '' : .xpath('./OnOpen/MinimumAllowedVersion').first['name'] content += "File Options\n" content += "------------\n" content += NEWLINE content += format(, "Encryption:", "#{encryption_type} (#{encryption_note})") content += NEWLINE content += format(, "Minimum Allowed Version:", minimum_allowed_version) content += format(, "Account:", open_account) content += format(, "Layout:", open_layout) content += NEWLINE content += format(, "Default Custom Menu Set:", .xpath('./DefaultCustomMenuSet/CustomMenuSet').first['name']) content += NEWLINE content += " Triggers\n" .xpath('./WindowTriggers/*').each do |t| content += format(trigger_format, t.name, t.xpath('./Script').first['name']) end content end @themes_content = Proc.new do |themes| content = '' theme_format = " %6s %-20s %-20s %-10s %-10s %-20s\n" content += format(theme_format, "id", "Name", "Group", "Version", "Locale", "Internal Name") content += format(theme_format, "--", "----", "-----", "-------", "------", "-------------") themes.each do |a_theme| content += format(theme_format, a_theme['id'], a_theme['name'], a_theme['group'], a_theme['version'], a_theme['locale'], a_theme['internalName']) end content end end |
#disk_path_from_base(object_base, object_xpath, path = '') ⇒ Object
e.g. /FMPReport/File/ScriptCatalog , /FMPReport/File/ScriptCatalog/Group/Group return: “/Actors/Actor Triggers”
93 94 95 96 97 98 99 |
# File 'lib/fmpvc/FMPReport.rb', line 93 def disk_path_from_base(object_base, object_xpath, path = '') return "#{path}" if object_xpath == object_base curent_node_filename = @report.xpath("#{object_xpath}").first['name'] current_node_id = @report.xpath("#{object_xpath}").first['id'] parent_node_xpath = @report.xpath("#{object_xpath}/..").first.path disk_path_from_base(object_base, parent_node_xpath, "/#{fs_id(curent_node_filename, current_node_id)}" + "#{path}" ) end |
#element2yaml(xml_element) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/fmpvc/FMPReport.rb', line 109 def element2yaml(xml_element) return '' unless FMPVC.configuration.yaml element_xml = xml_element.to_xml({:encoding => 'UTF-8'}) # REMEMBER: the encoding element_hash = Hash.from_xml(element_xml) element_yaml = element_hash.to_yaml end |
#fs_id(fs_name, id) ⇒ Object
87 88 89 |
# File 'lib/fmpvc/FMPReport.rb', line 87 def fs_id(fs_name, id) fs_name + " (id #{id})" end |
#fs_sanitize(text_string) ⇒ Object
82 83 84 85 |
# File 'lib/fmpvc/FMPReport.rb', line 82 def fs_sanitize(text_string) safe_name = text_string.gsub(%r{\A [\/\.]+ }mx, '') # remove leading dir symbols: . / safe_name.gsub(%r{[\/]}, '_') # just remove [ / ] for now. end |
#parse ⇒ Object
76 77 78 79 80 |
# File 'lib/fmpvc/FMPReport.rb', line 76 def parse @report = Nokogiri::XML(@content) @type = @report.xpath("//FMPReport").first["type"] raise RuntimeError, "Incorrect file type: not an FMPReport Report file" unless @type == "Report" end |
#parse_fmp_obj(object_base, object_nodes, obj_content, one_file = false) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/fmpvc/FMPReport.rb', line 130 def parse_fmp_obj(object_base, object_nodes, obj_content, one_file = false) post_notification(object_base.gsub(%r{\/FMPReport\/File\/},''), ' Parsing') objects_parsed = Array.new objects = @report.xpath("#{object_base}#{object_nodes}") objects.each do |an_obj| obj_id = an_obj['id'] if one_file sanitized_obj_name_id_ext = nil else obj_name = an_obj['name'] sanitized_obj_name = fs_sanitize(obj_name) sanitized_obj_name_id = fs_id(sanitized_obj_name, obj_id) sanitized_obj_name_id_ext = sanitized_obj_name_id + '.txt' end obj_parsed = { :name => sanitized_obj_name_id_ext \ , :type => :file \ , :xpath => an_obj.path \ } # if it's a Group, then make a directory for it, else make a file if an_obj.name == 'Group' obj_parsed[:type] = :dir obj_parsed[:name] = sanitized_obj_name_id obj_parsed[:children] = parse_fmp_obj(an_obj.path, object_nodes, obj_content) else obj_parsed[:content] = one_file ? obj_content.call(objects) : obj_content.call(an_obj) obj_parsed[:yaml] = one_file ? element2yaml(@report.xpath(object_base)) : element2yaml(an_obj) end objects_parsed.push(obj_parsed) break if one_file == true end objects_parsed end |
#post_notification(object, verb = 'Updating') ⇒ Object
116 117 118 |
# File 'lib/fmpvc/FMPReport.rb', line 116 def post_notification(object, verb = 'Updating') $stdout.puts [verb, object].join(" ") unless FMPVC.configuration.quiet end |
#suppress_record_info ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/fmpvc/FMPReport.rb', line 120 def suppress_record_info() @tables.each do |a_table| current_yaml = a_table[:yaml] yaml_serial_number_fixed = current_yaml.gsub(%r{(nextValue:.*\D)(\d+)(\D*?)(?=\n)}, '\1\3') # e.g. nextValue: 123serial456 or nextValue: 123serial yaml_record_count_fixed = yaml_serial_number_fixed.gsub(%r{(BaseTable: \s+ id:\ '\d+' \s+ records:\ '.*?)(\d+)'}mx, '\1\'') # e.g. records: '234' a_table[:yaml] = yaml_record_count_fixed end end |
#write_all_objects ⇒ Object
71 72 73 74 |
# File 'lib/fmpvc/FMPReport.rb', line 71 def write_all_objects() post_notification('report files', 'Writing') @named_objects.each { |obj| write_obj_to_disk(obj[:content], @report_dirpath + obj[:disk_path])} end |
#write_dir ⇒ Object
101 102 103 |
# File 'lib/fmpvc/FMPReport.rb', line 101 def write_dir FileUtils.mkdir_p(@report_dirpath) end |
#write_obj_to_disk(objs, full_path) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/fmpvc/FMPReport.rb', line 167 def write_obj_to_disk(objs, full_path) post_notification(full_path.gsub(%r{.*#{FMPVC.configuration.text_dirname}/},''), ' Writing') if full_path =~ %r{\.txt} # single file objects File.open(full_path, 'w') do |f| unless objs.empty? f.write(objs.first[:content] + NEWLINE) unless objs.first[:content] == '' f.write(NEWLINE + objs.first[:yaml]) end end else # multi-file objects in directory FileUtils.mkdir_p(full_path) unless File.directory?(full_path) objs.each do |obj| if obj[:type] == :file File.open("#{full_path}/#{obj[:name]}", 'w') do |f| f.write(obj[:content] + NEWLINE) unless obj[:content] == '' f.write(NEWLINE + obj[:yaml]) end elsif obj[:type] == :dir write_obj_to_disk(obj[:children], full_path + "/#{obj[:name]}") end end end end |