# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from core import perf_benchmark

from telemetry import benchmark
from telemetry.core import discover
from telemetry.page import page_set

from measurements import skpicture_printer


def _MatchPageSetName(page_set_name, page_set_base_dir):
  page_sets = []
  page_sets += discover.DiscoverClasses(page_set_base_dir, page_set_base_dir,
                                        page_set.PageSet,
                                        index_by_class_name=True).values()
  for p in page_sets:
    if page_set_name == p.Name():
      return p
  return None


@benchmark.Disabled
class SkpicturePrinter(perf_benchmark.PerfBenchmark):
  @classmethod
  def AddBenchmarkCommandLineArgs(cls, parser):
    parser.add_option('--page-set-name',  action='store', type='string')
    parser.add_option('--page-set-base-dir', action='store', type='string')
    parser.add_option('-s', '--skp-outdir',
                      help='Output directory for the SKP files')
  @classmethod
  def ProcessCommandLineArgs(cls, parser, args):
    if not args.page_set_name:
      parser.error('Please specify --page-set-name')
    if not args.page_set_base_dir:
      parser.error('Please specify --page-set-base-dir')
    if not args.skp_outdir:
      parser.error('Please specify --skp-outdir')

  @classmethod
  def Name(cls):
    return 'skpicture_printer'

  def CreatePageTest(self, options):
    return skpicture_printer.SkpicturePrinter(options.skp_outdir)

  def CreateStorySet(self, options):
    page_set_class = _MatchPageSetName(options.page_set_name,
                                       options.page_set_base_dir)
    return page_set_class()

@@ -211,25 +211,21 @@
  import 
-benchmark
+story
 %0Afrom te
@@ -235,21 +235,16 @@
 etry
-.core
  import 
 disc
@@ -239,24 +239,25 @@
  import 
-discover
+benchmark
 %0Afrom te
@@ -264,19 +264,19 @@
 lemetry.
-pag
+cor
 e import
@@ -276,24 +276,24 @@
  import 
-page_set
+discover
 %0A%0Afrom m
@@ -353,20 +353,21 @@
 SetName(
-page
+story
 _set_nam
@@ -369,20 +369,21 @@
 t_name, 
-page
+story
 _set_bas
@@ -396,36 +396,19 @@
 :%0A  
-page_sets = %5B%5D%0A  page
+story
 _sets 
-+
 = di
@@ -430,20 +430,21 @@
 Classes(
-page
+story
 _set_bas
@@ -450,20 +450,21 @@
 se_dir, 
-page
+story
 _set_bas
@@ -514,90 +514,22 @@
     
-page_set.PageSet,%0A                                        index_by_class_name=True
+story.StorySet
 ).va
@@ -545,17 +545,18 @@
 for 
-p
+s
  in 
-page
+story
 _set
@@ -565,20 +565,21 @@
 %0A    if 
-page
+story
 _set_nam
@@ -583,17 +583,17 @@
 name == 
-p
+s
 .Name():
@@ -606,17 +606,17 @@
  return 
-p
+s
 %0A  retur
@@ -1547,20 +1547,21 @@
 s):%0A    
-page
+story
 _set_cla
@@ -1645,16 +1645,17 @@
         
+ 
 options.
@@ -1684,20 +1684,21 @@
  return 
-page
+story
 _set_cla

Update skpicture_printer code so it can match user_story classes.