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) ⇒ Object
Collect brand data for display rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
-
.collect_project_data(brand_arg, brand_path, brand_info, project, is_git_repo, detailed: false) ⇒ Object
Collect project data for display rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/ParameterLists.
-
.find_last_modified(brand, projects) ⇒ Object
Find the most recent modification time across all projects.
-
.format_age(time) ⇒ Object
Format age as relative time (e.g., “3 days”, “2 weeks”).
-
.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) ⇒ Object
List all projects for a specific brand (Mode 3) rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
-
.list_brands_with_counts(detailed: false) ⇒ Object
List all brands with summary table rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
-
.list_with_pattern(brand_arg, pattern) ⇒ Object
List with pattern matching (Mode 3b) rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
-
.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 rubocop:disable Metrics/AbcSize.
-
.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
377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 377 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
408 409 410 411 412 413 414 415 416 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 408 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
419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 419 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
392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 392 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
435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 435 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
520 521 522 523 524 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 520 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) ⇒ Object
Collect brand data for display rubocop:disable Metrics/AbcSize, Metrics/MethodLength
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 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 316 def self.collect_brand_data(brand, detailed: 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) s3_sync_status = calculate_s3_sync_status(brand, projects) 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) ⇒ Object
Collect project data for display rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/ParameterLists
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 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 452 def self.collect_project_data(brand_arg, brand_path, brand_info, project, is_git_repo, detailed: 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 s3_sync = calculate_project_s3_sync_status(brand_arg, brand_info, project) result = { name: project, path: project_path, size: size, modified: modified, age: 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) = (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] ) end result end |
.find_last_modified(brand, projects) ⇒ Object
Find the most recent modification time across all projects
527 528 529 530 531 532 533 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 527 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_age(time) ⇒ Object
Format age as relative time (e.g., “3 days”, “2 weeks”)
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 548 def self.format_age(time) return 'N/A' if time.nil? seconds = Time.now - time return 'just now' if seconds < 60 minutes = seconds / 60 return "#{minutes.round}m" if minutes < 60 hours = minutes / 60 return "#{hours.round}h" if hours < 24 days = hours / 24 return "#{days.round}d" if days < 7 weeks = days / 7 return "#{weeks.round}w" if weeks < 4 months = days / 30 return "#{months.round}mo" if months < 12 years = days / 365 "#{years.round}y" end |
.format_date(time) ⇒ Object
Format date/time in readable format
541 542 543 544 545 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 541 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
536 537 538 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 536 def self.format_size(bytes) FileHelper.format_size(bytes) end |
.list_brand_projects(brand_arg, detailed: false) ⇒ Object
List all projects for a specific brand (Mode 3) rubocop:disable Metrics/AbcSize, Metrics/MethodLength
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 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 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 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 96 def self.list_brand_projects(brand_arg, detailed: 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 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) 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 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' ) # rubocop:enable Style/RedundantFormat puts '-' * 280 project_data.each do |data| age_display = data[:stale] ? "#{data[:age]} ⚠️" : data[:age] s3_upload = data[:s3_last_upload] ? format_age(data[:s3_last_upload]) : 'N/A' s3_download = data[:s3_last_download] ? 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 ) end else # Default view - use same format for header and data # rubocop:disable Style/RedundantFormat puts format( '%-45s %12s %15s %-15s %-12s', 'PROJECT', 'SIZE', 'AGE', 'GIT', 'S3' ) # rubocop:enable Style/RedundantFormat puts '-' * 130 project_data.each do |data| age_display = data[:stale] ? "#{data[:age]} ⚠️" : data[:age] puts format( '%-45s %12s %15s %-15s %-12s', data[:name], format_size(data[:size]), age_display, data[:git_status], data[:s3_sync] ) 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) ⇒ Object
List all brands with summary table rubocop:disable Metrics/AbcSize, Metrics/MethodLength
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 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 14 def self.list_brands_with_counts(detailed: false) brands = Config.available_brands if brands.empty? puts "⚠️ No brands found in #{Config.projects_root}" return end # Gather brand data brand_data = brands.map { |brand| collect_brand_data(brand, detailed: detailed) } if detailed # Detailed view with additional columns header = 'BRAND KEY PROJECTS SIZE LAST MODIFIED ' \ 'GIT S3 SYNC PATH SSD BACKUP ' \ 'WORKFLOW ACTIVE' puts header puts '-' * 200 brand_data.each do |data| brand_display = "#{data[:shortcut]} - #{data[:name]}" 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 ) end else # Default view - use same format for header and data # rubocop:disable Style/RedundantFormat puts format( '%-30s %-15s %10s %12s %20s %-15s %-10s', 'BRAND', 'KEY', 'PROJECTS', 'SIZE', 'LAST MODIFIED', 'GIT', 'S3 SYNC' ) # rubocop:enable Style/RedundantFormat puts '-' * 133 brand_data.each do |data| brand_display = "#{data[:shortcut]} - #{data[:name]}" 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] ) 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) rubocop:disable Metrics/AbcSize, Metrics/MethodLength
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 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 210 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: 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 ~
582 583 584 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 582 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 rubocop:disable Metrics/AbcSize
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 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 278 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)
574 575 576 577 578 579 |
# File 'lib/appydave/tools/dam/project_listing.rb', line 574 def self.stale?(time) return false if time.nil? days = (Time.now - time) / 86_400 # seconds in a day days > 90 end |