import os
import shutil
import html_helper
from Cheetah.Template import Template


def prep_out_dir(out_dir='out_report'):
    src_dir = os.path.dirname(__file__)
    report_files_dir = os.path.join(src_dir, 'report_files')
    if os.path.exists(out_dir):
        print 'WARNING: output directory "%s" already exists' % out_dir
    else:
        shutil.copytree(report_files_dir, out_dir)


def create_report(name_space={}):
    filename = os.path.join(os.path.dirname(__file__), 'report.html')
    report_text = open(filename).read()
    name_space['helper'] = html_helper
    t = Template(report_text, searchList=[name_space])

    out_dir = 'out_report'
    prep_out_dir(out_dir)

    out_file = open(os.path.join(out_dir, 'index.html'), "w")
    out_file.write(str(t))
    out_file.close()

import os
import html_helper
from Cheetah.Template import Template
from distutils.dir_util import copy_tree


def prep_out_dir(out_dir='out_report'):
    src_dir = os.path.dirname(__file__)
    report_files_dir = os.path.join(src_dir, 'report_files')
    copy_tree(report_files_dir, out_dir)


def create_report(name_space={}):
    filename = os.path.join(os.path.dirname(__file__), 'report.html')
    report_text = open(filename).read()
    name_space['helper'] = html_helper
    t = Template(report_text, searchList=[name_space])

    out_dir = 'out_report'
    prep_out_dir(out_dir)

    out_file = open(os.path.join(out_dir, 'index.html'), "w")
    out_file.write(str(t))
    out_file.close()

Remove warning for existing output directory.
Remove warning for existing output directory.

In our configuration puppet will manage the output directory, so it
is expected behavior for it to exist, removing warning. Also
switching to distutils.dir_util copy_tree since that allows for
copying of required supporting files into an existing output
directory.

Change-Id: I38b2c6ec47fd61814554a4b5007a83553b05aeb2
Reviewed-on: https://review.openstack.org/20647
Approved: Dan Prince <62cccc0004df0a8e3c343b26b69e434f6aa9711c@redhat.com>
Reviewed-by: Dan Prince <62cccc0004df0a8e3c343b26b69e434f6aa9711c@redhat.com>
Tested-by: Jenkins

  import os
- import shutil
  import html_helper
  from Cheetah.Template import Template
+ from distutils.dir_util import copy_tree
  
  
  def prep_out_dir(out_dir='out_report'):
      src_dir = os.path.dirname(__file__)
      report_files_dir = os.path.join(src_dir, 'report_files')
-     if os.path.exists(out_dir):
-         print 'WARNING: output directory "%s" already exists' % out_dir
-     else:
-         shutil.copytree(report_files_dir, out_dir)
+     copy_tree(report_files_dir, out_dir)
  
  
  def create_report(name_space={}):
      filename = os.path.join(os.path.dirname(__file__), 'report.html')
      report_text = open(filename).read()
      name_space['helper'] = html_helper
      t = Template(report_text, searchList=[name_space])
  
      out_dir = 'out_report'
      prep_out_dir(out_dir)
  
      out_file = open(os.path.join(out_dir, 'index.html'), "w")
      out_file.write(str(t))
      out_file.close()
  
Remove warning for existing output directory.
## Code Before:
import os
import shutil
import html_helper
from Cheetah.Template import Template


def prep_out_dir(out_dir='out_report'):
    src_dir = os.path.dirname(__file__)
    report_files_dir = os.path.join(src_dir, 'report_files')
    if os.path.exists(out_dir):
        print 'WARNING: output directory "%s" already exists' % out_dir
    else:
        shutil.copytree(report_files_dir, out_dir)


def create_report(name_space={}):
    filename = os.path.join(os.path.dirname(__file__), 'report.html')
    report_text = open(filename).read()
    name_space['helper'] = html_helper
    t = Template(report_text, searchList=[name_space])

    out_dir = 'out_report'
    prep_out_dir(out_dir)

    out_file = open(os.path.join(out_dir, 'index.html'), "w")
    out_file.write(str(t))
    out_file.close()

## Instruction:
Remove warning for existing output directory.
## Code After:
import os
import html_helper
from Cheetah.Template import Template
from distutils.dir_util import copy_tree


def prep_out_dir(out_dir='out_report'):
    src_dir = os.path.dirname(__file__)
    report_files_dir = os.path.join(src_dir, 'report_files')
    copy_tree(report_files_dir, out_dir)


def create_report(name_space={}):
    filename = os.path.join(os.path.dirname(__file__), 'report.html')
    report_text = open(filename).read()
    name_space['helper'] = html_helper
    t = Template(report_text, searchList=[name_space])

    out_dir = 'out_report'
    prep_out_dir(out_dir)

    out_file = open(os.path.join(out_dir, 'index.html'), "w")
    out_file.write(str(t))
    out_file.close()
