Class: Appydave::Tools::Dam::ProjectListing
- Inherits:
-
Object
- Object
- Appydave::Tools::Dam::ProjectListing
- Defined in:
- lib/appydave/tools/dam/project_listing.rb
Overview
Project listing functionality for VAT
Class Method Summary collapse
-
.calculate_git_status(brand_path) ⇒ Object
Calculate git status for a brand.
-
.calculate_project_git_status(brand_path, project) ⇒ Object
Calculate git status for a specific project.
-
.calculate_project_s3_sync_status(brand_arg, brand_info, project) ⇒ Object
Calculate 3-state S3 sync status for a project.
-
.calculate_s3_sync_status(brand, projects) ⇒ Object
Calculate S3 sync status for a brand.
-
.calculate_s3_timestamps(brand_arg, brand_info, project) ⇒ Object
Calculate S3 sync timestamps for a project.
-
.calculate_total_size(brand, projects) ⇒ Object
Calculate total size of all projects in a brand.
-
.collect_brand_data(brand, detailed: false, s3: false) ⇒ Object
Collect brand data for display.
-
.collect_project_data(brand_arg, brand_path, brand_info, project, is_git_repo, detailed: false, s3: false) ⇒ Object
Collect project data for display rubocop:disable Metrics/ParameterLists.
-
.find_last_modified(brand, projects) ⇒ Object
Find the most recent modification time across all projects.
-
.format_date(time) ⇒ Object
Format date/time in readable format.
-
.format_size(bytes) ⇒ Object
Format size in human-readable format.
-
.list_brand_projects(brand_arg, detailed: false, s3: false) ⇒ Object
List all projects for a specific brand (Mode 3).
-
.list_brands_with_counts(detailed: false, s3: false) ⇒ Object
List all brands with summary table.
-
.list_with_pattern(brand_arg, pattern) ⇒ Object
List with pattern matching (Mode 3b).
-
.shorten_path(path) ⇒ Object
Shorten path by replacing home directory with ~.
-
.show_brand_header(brand_arg, brand) ⇒ Object
Show brand context header with git, S3, and SSD info.
-
.stale?(time) ⇒ Boolean
Check if project is stale (>90 days old).
Class Method Details
.calculate_git_status(brand_path) ⇒ Object
Calculate git status for a brand
468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 468 def self.calculate_git_status(brand_path) if Dir.exist?(File.join(brand_path, '.git')) modified = GitHelper.modified_files_count(brand_path) untracked = GitHelper.untracked_files_count(brand_path) if modified.positive? || untracked.positive? '⚠️ changes' else '✓ clean' end else 'N/A' end end |
.calculate_project_git_status(brand_path, project) ⇒ Object
Calculate git status for a specific project
499 500 501 502 503 504 505 506 507 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 499 def self.calculate_project_git_status(brand_path, project) # Use git status --short to check for changes in project folder result = `cd "#{brand_path}" && git status --short "#{project}" 2>/dev/null` if result.empty? '✓ clean' else '⚠️ changes' end end |
.calculate_project_s3_sync_status(brand_arg, brand_info, project) ⇒ Object
Calculate 3-state S3 sync status for a project
510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 510 def self.calculate_project_s3_sync_status(brand_arg, brand_info, project) # Check if S3 is configured s3_bucket = brand_info.aws.s3_bucket return 'N/A' if s3_bucket.nil? || s3_bucket.empty? || s3_bucket == 'NOT-SET' # Use S3Operations to calculate sync status begin s3_ops = S3Operations.new(brand_arg, project, brand_info: brand_info) s3_ops.calculate_sync_status rescue StandardError # S3 not accessible or other error 'N/A' end end |
.calculate_s3_sync_status(brand, projects) ⇒ Object
Calculate S3 sync status for a brand
483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 483 def self.calculate_s3_sync_status(brand, projects) return 'N/A' if projects.empty? s3_count = projects.count do |project| project_path = Config.project_path(brand, project) Dir.exist?(File.join(project_path, 's3-staging')) end if s3_count.zero? 'none' else "#{s3_count}/#{projects.size}" end end |
.calculate_s3_timestamps(brand_arg, brand_info, project) ⇒ Object
Calculate S3 sync timestamps for a project
526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 526 def self.(brand_arg, brand_info, project) # Check if S3 is configured s3_bucket = brand_info.aws.s3_bucket return { last_upload: nil, last_download: nil } if s3_bucket.nil? || s3_bucket.empty? || s3_bucket == 'NOT-SET' # Use S3Operations to get timestamps begin s3_ops = S3Operations.new(brand_arg, project, brand_info: brand_info) s3_ops. rescue StandardError # S3 not accessible or other error { last_upload: nil, last_download: nil } end end |
.calculate_total_size(brand, projects) ⇒ Object
Calculate total size of all projects in a brand
618 619 620 621 622 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 618 def self.calculate_total_size(brand, projects) projects.sum do |project| FileHelper.calculate_directory_size(Config.project_path(brand, project)) end end |
.collect_brand_data(brand, detailed: false, s3: false) ⇒ Object
Collect brand data for display
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 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 408 def self.collect_brand_data(brand, detailed: false, s3: false) Appydave::Tools::Configuration::Config.configure brand_info = Appydave::Tools::Configuration::Config.brands.get_brand(brand) brand_path = Config.brand_path(brand) projects = ProjectResolver.list_projects(brand) total_size = calculate_total_size(brand, projects) last_modified = find_last_modified(brand, projects) # Get shortcut, key, and name with fallbacks shortcut = brand_info.shortcut&.strip shortcut = nil if shortcut&.empty? key = brand_info.key name = brand_info.name&.strip name = nil if name&.empty? # Get git status git_status = calculate_git_status(brand_path) # Get S3 sync status (count of projects with s3-staging) - only if requested s3_sync_status = s3 ? calculate_s3_sync_status(brand, projects) : 'N/A' result = { shortcut: shortcut || key, key: key, name: name || key.capitalize, path: brand_path, count: projects.size, size: total_size, modified: last_modified, git_status: git_status, s3_sync: s3_sync_status } # Add detailed fields if requested if detailed # SSD backup path ssd_backup = brand_info.locations.ssd_backup ssd_backup = nil if ssd_backup.nil? || ssd_backup.empty? || ssd_backup == 'NOT-SET' # Workflow type (inferred from projects_subfolder setting) workflow = brand_info.settings.projects_subfolder == 'projects' ? 'storyline' : 'flivideo' # Active project count (projects with flat structure, not archived) active_count = projects.count do |project| project_path = Config.project_path(brand, project) # Check if not in archived/ subfolder !project_path.include?('/archived/') end result.merge!( ssd_backup: ssd_backup ? shorten_path(ssd_backup) : nil, workflow: workflow, active_count: active_count ) end result end |
.collect_project_data(brand_arg, brand_path, brand_info, project, is_git_repo, detailed: false, s3: false) ⇒ Object
Collect project data for display rubocop:disable Metrics/ParameterLists
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 543 def self.collect_project_data(brand_arg, brand_path, brand_info, project, is_git_repo, detailed: false, s3: false) project_path = Config.project_path(brand_arg, project) size = FileHelper.calculate_directory_size(project_path) modified = File.mtime(project_path) # Check if project has uncommitted changes (if brand is git repo) git_status = if is_git_repo calculate_project_git_status(brand_path, project) else 'N/A' end # Calculate 3-state S3 sync status - only if requested (performance optimization) s3_sync = s3 ? calculate_project_s3_sync_status(brand_arg, brand_info, project) : 'N/A' result = { name: project, path: project_path, size: size, modified: modified, age: FileHelper.format_age(modified), stale: stale?(modified), git_status: git_status, s3_sync: s3_sync } # Add detailed fields if requested if detailed # Heavy files (video files in root) heavy_count = 0 heavy_size = 0 Dir.glob(File.join(project_path, '*.{mp4,mov,avi,mkv,webm}')).each do |file| heavy_count += 1 heavy_size += File.size(file) end # Light files (subtitles, images, metadata) light_count = 0 light_size = 0 Dir.glob(File.join(project_path, '**/*.{srt,vtt,jpg,png,md,txt,json,yml}')).each do |file| light_count += 1 light_size += File.size(file) end # SSD backup path (if exists) ssd_backup = brand_info.locations.ssd_backup ssd_path = if ssd_backup && !ssd_backup.empty? && ssd_backup != 'NOT-SET' ssd_project_path = File.join(ssd_backup, project) File.exist?(ssd_project_path) ? shorten_path(ssd_project_path) : nil end # S3 timestamps (last upload/download) - only if requested (performance optimization) if s3 = (brand_arg, brand_info, project) result.merge!( heavy_files: "#{heavy_count} (#{format_size(heavy_size)})", light_files: "#{light_count} (#{format_size(light_size)})", ssd_backup: ssd_path, s3_last_upload: [:last_upload], s3_last_download: [:last_download] ) else result.merge!( heavy_files: "#{heavy_count} (#{format_size(heavy_size)})", light_files: "#{light_count} (#{format_size(light_size)})", ssd_backup: ssd_path ) end end result end |
.find_last_modified(brand, projects) ⇒ Object
Find the most recent modification time across all projects
625 626 627 628 629 630 631 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 625 def self.find_last_modified(brand, projects) return nil if projects.empty? projects.map do |project| File.mtime(Config.project_path(brand, project)) end.max end |
.format_date(time) ⇒ Object
Format date/time in readable format
639 640 641 642 643 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 639 def self.format_date(time) return 'N/A' if time.nil? time.strftime('%Y-%m-%d %H:%M') end |
.format_size(bytes) ⇒ Object
Format size in human-readable format
634 635 636 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 634 def self.format_size(bytes) FileHelper.format_size(bytes) end |
.list_brand_projects(brand_arg, detailed: false, s3: false) ⇒ Object
List all projects for a specific brand (Mode 3)
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 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 192 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 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 142 def self.list_brand_projects(brand_arg, detailed: false, s3: false) # ProjectResolver expects the original brand key/shortcut, not the expanded v-* version projects = ProjectResolver.list_projects(brand_arg) # Only expand brand for display purposes brand = Config.(brand_arg) # Show brand context header show_brand_header(brand_arg, brand) if projects.empty? puts "⚠️ No projects found for brand: #{brand}" puts '' puts ' This could mean:' puts ' - The brand exists but has no project directories' puts ' - The manifest needs updating' puts '' puts " Try: dam manifest #{brand_arg}" return end # Gather project data (skip S3 if not requested) brand_path = Config.brand_path(brand_arg) brand_info = Appydave::Tools::Configuration::Config.brands.get_brand(brand_arg) is_git_repo = Dir.exist?(File.join(brand_path, '.git')) project_data = projects.map do |project| collect_project_data(brand_arg, brand_path, brand_info, project, is_git_repo, detailed: detailed, s3: s3) end # Print common header puts "Projects in #{brand}:" puts '' puts 'ℹ️ Note: Lists only projects with files, not empty directories' puts '' if detailed # Detailed view with additional columns - use same format for header and data # rubocop:disable Style/RedundantFormat if s3 puts format( '%-45s %12s %15s %-15s %-12s %-65s %-18s %-18s %-30s %-15s %-15s', 'PROJECT', 'SIZE', 'AGE', 'GIT', 'S3', 'PATH', 'HEAVY FILES', 'LIGHT FILES', 'SSD BACKUP', 'S3 ↑ UPLOAD', 'S3 ↓ DOWNLOAD' ) puts '-' * 280 else puts format( '%-45s %12s %15s %-15s %-65s %-18s %-18s %-30s', 'PROJECT', 'SIZE', 'AGE', 'GIT', 'PATH', 'HEAVY FILES', 'LIGHT FILES', 'SSD BACKUP' ) puts '-' * 239 end # rubocop:enable Style/RedundantFormat project_data.each do |data| age_display = data[:stale] ? "#{data[:age]} ⚠️" : data[:age] if s3 s3_upload = data[:s3_last_upload] ? FileHelper.format_age(data[:s3_last_upload]) : 'N/A' s3_download = data[:s3_last_download] ? FileHelper.format_age(data[:s3_last_download]) : 'N/A' puts format( '%-45s %12s %15s %-15s %-12s %-65s %-18s %-18s %-30s %-15s %-15s', data[:name], format_size(data[:size]), age_display, data[:git_status], data[:s3_sync], shorten_path(data[:path]), data[:heavy_files] || 'N/A', data[:light_files] || 'N/A', data[:ssd_backup] || 'N/A', s3_upload, s3_download ) else puts format( '%-45s %12s %15s %-15s %-65s %-18s %-18s %-30s', data[:name], format_size(data[:size]), age_display, data[:git_status], shorten_path(data[:path]), data[:heavy_files] || 'N/A', data[:light_files] || 'N/A', data[:ssd_backup] || 'N/A' ) end end else # Default view - use same format for header and data # rubocop:disable Style/RedundantFormat if s3 puts format( '%-45s %12s %15s %-15s %-12s', 'PROJECT', 'SIZE', 'AGE', 'GIT', 'S3' ) puts '-' * 130 else puts format( '%-45s %12s %15s %-15s', 'PROJECT', 'SIZE', 'AGE', 'GIT' ) puts '-' * 117 end # rubocop:enable Style/RedundantFormat project_data.each do |data| age_display = data[:stale] ? "#{data[:age]} ⚠️" : data[:age] if s3 puts format( '%-45s %12s %15s %-15s %-12s', data[:name], format_size(data[:size]), age_display, data[:git_status], data[:s3_sync] ) else puts format( '%-45s %12s %15s %-15s', data[:name], format_size(data[:size]), age_display, data[:git_status] ) end end end # Print footer summary total_size = project_data.sum { |d| d[:size] } project_count = project_data.size puts '' puts "Total: #{project_count} project#{'s' if project_count != 1}, #{format_size(total_size)}" end |
.list_brands_with_counts(detailed: false, s3: false) ⇒ Object
List all brands with summary table
13 14 15 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 13 def self.list_brands_with_counts(detailed: false, s3: false) brands = Config.available_brands if brands.empty? puts "⚠️ No brands found in #{Config.projects_root}" return end # Gather brand data (skip S3 if not requested) brand_data = brands.map { |brand| collect_brand_data(brand, detailed: detailed, s3: s3) } if detailed # Detailed view with additional columns if s3 header = 'BRAND KEY PROJECTS SIZE LAST MODIFIED ' \ 'GIT S3 SYNC PATH SSD BACKUP ' \ 'WORKFLOW ACTIVE' puts header puts '-' * 200 else header = 'BRAND KEY PROJECTS SIZE LAST MODIFIED ' \ 'GIT PATH SSD BACKUP ' \ 'WORKFLOW ACTIVE' puts header puts '-' * 189 end brand_data.each do |data| brand_display = "#{data[:shortcut]} - #{data[:name]}" if s3 puts format( '%-30s %-12s %10d %12s %20s %-15s %-10s %-35s %-30s %-10s %6d', brand_display, data[:key], data[:count], format_size(data[:size]), format_date(data[:modified]), data[:git_status], data[:s3_sync], shorten_path(data[:path]), data[:ssd_backup] || 'N/A', data[:workflow] || 'N/A', data[:active_count] || 0 ) else puts format( '%-30s %-12s %10d %12s %20s %-15s %-35s %-30s %-10s %6d', brand_display, data[:key], data[:count], format_size(data[:size]), format_date(data[:modified]), data[:git_status], shorten_path(data[:path]), data[:ssd_backup] || 'N/A', data[:workflow] || 'N/A', data[:active_count] || 0 ) end end else # Default view - use same format for header and data # rubocop:disable Style/RedundantFormat if s3 puts format( '%-30s %-15s %10s %12s %20s %-15s %-10s', 'BRAND', 'KEY', 'PROJECTS', 'SIZE', 'LAST MODIFIED', 'GIT', 'S3 SYNC' ) puts '-' * 133 else puts format( '%-30s %-15s %10s %12s %20s %-15s', 'BRAND', 'KEY', 'PROJECTS', 'SIZE', 'LAST MODIFIED', 'GIT' ) puts '-' * 122 end # rubocop:enable Style/RedundantFormat brand_data.each do |data| brand_display = "#{data[:shortcut]} - #{data[:name]}" if s3 puts format( '%-30s %-15s %10d %12s %20s %-15s %-10s', brand_display, data[:key], data[:count], format_size(data[:size]), format_date(data[:modified]), data[:git_status], data[:s3_sync] ) else puts format( '%-30s %-15s %10d %12s %20s %-15s', brand_display, data[:key], data[:count], format_size(data[:size]), format_date(data[:modified]), data[:git_status] ) end end end # Print footer summary total_projects = brand_data.sum { |d| d[:count] } total_size = brand_data.sum { |d| d[:size] } puts '' puts "Total: #{brand_data.size} brand#{'s' if brand_data.size != 1}, " \ "#{total_projects} project#{'s' if total_projects != 1}, " \ "#{format_size(total_size)}" end |
.list_with_pattern(brand_arg, pattern) ⇒ Object
List with pattern matching (Mode 3b)
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 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 306 def self.list_with_pattern(brand_arg, pattern) # ProjectResolver expects the original brand key/shortcut, not the expanded v-* version matches = ProjectResolver.resolve_pattern(brand_arg, pattern) # Only expand brand for display purposes brand = Config.(brand_arg) if matches.empty? puts "⚠️ No projects found matching pattern: #{pattern}" puts '' puts ' Pattern tips:' puts ' - Use * for wildcards: b6* matches b60-b69' puts ' - Use ? for single character: b6? matches b60-b69' puts ' - Patterns are case-insensitive' puts '' puts " Try: dam list #{brand_arg} # See all projects" return end # Gather project data project_data = matches.map do |project| project_path = Config.project_path(brand_arg, project) size = FileHelper.calculate_directory_size(project_path) modified = File.mtime(project_path) { name: project, path: project_path, size: size, modified: modified, age: FileHelper.format_age(modified), stale: stale?(modified) } end # Print table header match_count = matches.size puts "#{match_count} project#{'s' if match_count != 1} matching '#{pattern}' in #{brand}:" puts 'PROJECT SIZE AGE' puts '-' * 100 # Print table rows project_data.each do |data| age_display = data[:stale] ? "#{data[:age]} ⚠️" : data[:age] puts format( '%-45s %12s %15s', data[:name], format_size(data[:size]), age_display ) end # Print footer summary total_size = project_data.sum { |d| d[:size] } all_projects = ProjectResolver.list_projects(brand_arg) brand_total_size = calculate_total_size(brand_arg, all_projects) percentage = brand_total_size.positive? ? (total_size.to_f / brand_total_size * 100).round(1) : 0 puts '' puts "Total: #{match_count} project#{'s' if match_count != 1}, #{format_size(total_size)} " \ "(#{percentage}% of #{brand})" end |
.shorten_path(path) ⇒ Object
Shorten path by replacing home directory with ~
654 655 656 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 654 def self.shorten_path(path) path.sub(Dir.home, '~') end |
.show_brand_header(brand_arg, brand) ⇒ Object
Show brand context header with git, S3, and SSD info
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 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 372 def self.show_brand_header(brand_arg, brand) Appydave::Tools::Configuration::Config.configure brand_info = Appydave::Tools::Configuration::Config.brands.get_brand(brand_arg) brand_path = Config.brand_path(brand_arg) puts "📂 Brand: #{brand}" puts '' # Git status if Dir.exist?(File.join(brand_path, '.git')) branch = GitHelper.current_branch(brand_path) puts " Git: #{branch} branch" else puts ' Git: Not a git repository' end # S3 configuration s3_bucket = brand_info.aws.s3_bucket if s3_bucket && !s3_bucket.empty? && s3_bucket != 'NOT-SET' puts " S3: Configured (#{s3_bucket})" else puts ' S3: Not configured' end # SSD backup path ssd_backup = brand_info.locations.ssd_backup if ssd_backup && !ssd_backup.empty? && ssd_backup != 'NOT-SET' puts " SSD: #{shorten_path(ssd_backup)}" else puts ' SSD: Not configured' end puts '' end |
.stale?(time) ⇒ Boolean
Check if project is stale (>90 days old)
646 647 648 649 650 651 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 646 def self.stale?(time) return false if time.nil? days = (Time.now - time) / 86_400 # seconds in a day days > 90 end |