|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# rubocop:disable Metrics/AbcSize,Metrics/MethodLength, Lint/MissingCopEnableDirective |
| 4 | + |
| 5 | +module AutoHCK |
| 6 | + class Session |
| 7 | + def self.save(workspace_path, options) |
| 8 | + File.write("#{workspace_path}/session.json", compose_session_json(options)) |
| 9 | + end |
| 10 | + |
| 11 | + def self.load(cli) |
| 12 | + json_data = JSON.parse(File.read("#{session_path(cli)}/session.json")) |
| 13 | + cli.test.platform = json_data['test']['platform'] |
| 14 | + cli.test.drivers = json_data['test']['drivers'] |
| 15 | + cli.test.driver_path = json_data['test']['driver_path'] |
| 16 | + cli.test.commit = json_data['test']['commit'] |
| 17 | + cli.test.diff_file = json_data['test']['diff_file'] |
| 18 | + cli.test.svvp = json_data['test']['svvp'] |
| 19 | + cli.test.dump = json_data['test']['dump'] |
| 20 | + cli.test.gthb_context_prefix = json_data['test']['gthb_context_prefix'] |
| 21 | + cli.test.gthb_context_suffix = json_data['test']['gthb_context_suffix'] |
| 22 | + cli.test.playlist = json_data['test']['playlist'] |
| 23 | + cli.test.select_test_names = json_data['test']['select_test_names'] |
| 24 | + cli.test.reject_test_names = json_data['test']['reject_test_names'] |
| 25 | + cli.test.triggers_file = json_data['test']['triggers_file'] |
| 26 | + cli.test.reject_report_sections = json_data['test']['reject_report_sections'] |
| 27 | + cli.test.boot_device = json_data['test']['boot_device'] |
| 28 | + cli.test.allow_test_duplication = json_data['test']['allow_test_duplication'] |
| 29 | + cli.test.manual = true |
| 30 | + cli.test.package_with_playlist = json_data['test']['package_with_playlist'] |
| 31 | + cli.test.session = session_path(cli) |
| 32 | + cli.test.latest_session = json_data['test']['latest_session'] |
| 33 | + cli.common.verbose = json_data['common']['verbose'] |
| 34 | + cli.common.config = json_data['common']['config'] |
| 35 | + cli.common.client_world_net = json_data['common']['client_world_net'] |
| 36 | + cli.common.id = json_data['common']['id'] |
| 37 | + cli.common.share_on_host_path = json_data['common']['share_on_host_path'] |
| 38 | + end |
| 39 | + |
| 40 | + def self.session_path(cli) |
| 41 | + cli.test.latest_session ? "#{Config.read['workspace_path']}/latest" : cli.test.session |
| 42 | + end |
| 43 | + |
| 44 | + private_class_method def self.compose_session_json(options) |
| 45 | + { |
| 46 | + 'test' => { |
| 47 | + 'platform' => options.test.platform, |
| 48 | + 'drivers' => options.test.drivers, |
| 49 | + 'driver_path' => options.test.driver_path, |
| 50 | + 'commit' => options.test.commit, |
| 51 | + 'diff_file' => options.test.diff_file, |
| 52 | + 'svvp' => options.test.svvp, |
| 53 | + 'dump' => options.test.dump, |
| 54 | + 'gthb_context_prefix' => options.test.gthb_context_prefix, |
| 55 | + 'gthb_context_suffix' => options.test.gthb_context_suffix, |
| 56 | + 'playlist' => options.test.playlist, |
| 57 | + 'select_test_names' => options.test.select_test_names, |
| 58 | + 'reject_test_names' => options.test.reject_test_names, |
| 59 | + 'triggers_file' => options.test.triggers_file, |
| 60 | + 'reject_report_sections' => options.test.reject_report_sections, |
| 61 | + 'boot_device' => options.test.boot_device, |
| 62 | + 'allow_test_duplication' => options.test.allow_test_duplication, |
| 63 | + 'manual' => options.test.manual, |
| 64 | + 'package_with_playlist' => options.test.package_with_playlist |
| 65 | + }, |
| 66 | + 'common' => { |
| 67 | + 'verbose' => options.common.verbose, |
| 68 | + 'config' => options.common.config, |
| 69 | + 'client_world_net' => options.common.client_world_net, |
| 70 | + 'id' => options.common.id, |
| 71 | + 'share_on_host_path' => options.common.share_on_host_path |
| 72 | + } |
| 73 | + }.to_json |
| 74 | + end |
| 75 | + end |
| 76 | +end |
0 commit comments