# Path: dna_project_setup.py
# BACKUP_MAIN_FOLDER = 'setup_backup'


import errno
import os
import sys
from shutil import copyfile
from dna_project_settings import GCS_PROJECT_ROOT
from dna_project_setup import BACKUP_MAIN_FOLDER
  copyfile(
      SERVICE_TEMPLATE_FOLDER + SERVICE_TEMPLATE_PREFIX + SUFFIX_SETTINGS_FILE,
      settings_file)
  replace_service_name(settings_file, service_name)
  print '- %s' % settings_file
  test_file = service_folder + '/' + service_name + SUFFIX_TEST_FILE
  copyfile(SERVICE_TEMPLATE_FOLDER + SERVICE_TEMPLATE_PREFIX + SUFFIX_TEST_FILE,
           test_file)
  replace_service_name(test_file, service_name)
  print '- %s' % test_file
  print '\nDone!!!'

  print ('\nThis script can also update the following files to include the '
         "references to your new service '%s'") % service_name
  print '- %s' % APPENGINE_MAIN_FILE
  print '- %s' % CRON_FILE
  print '- %s' % DEPLOY_FILE
  update_scripts = (raw_input('Do you want to update these scripts too [y/n]?')
                    .upper())
  if update_scripts != 'Y':
    print 'Ok, goodbye!'
    exit(0)

  try:
    os.makedirs(BACKUP_MAIN_FOLDER)
  except OSError as exception:
    if exception.errno != errno.EEXIST:
      raise
  for filepath in FILES_TO_BACKUP:
    copyfile(filepath, BACKUP_MAIN_FOLDER + '/' + filepath)

# Path: dna_project_setup.py
# BACKUP_MAIN_FOLDER = 'setup_backup'


# Path: dna_service_setup.py
import errno
import os
import sys
from shutil import copyfile
from dna_project_settings import GCS_PROJECT_ROOT
from dna_project_setup import BACKUP_MAIN_FOLDER

  copyfile(
      SERVICE_TEMPLATE_FOLDER + SERVICE_TEMPLATE_PREFIX + SUFFIX_SETTINGS_FILE,
      settings_file)
  replace_service_name(settings_file, service_name)
  print '- %s' % settings_file
  test_file = service_folder + '/' + service_name + SUFFIX_TEST_FILE
  copyfile(SERVICE_TEMPLATE_FOLDER + SERVICE_TEMPLATE_PREFIX + SUFFIX_TEST_FILE,
           test_file)
  replace_service_name(test_file, service_name)
  print '- %s' % test_file
  print '\nDone!!!'

  print ('\nThis script can also update the following files to include the '
         "references to your new service '%s'") % service_name
  print '- %s' % APPENGINE_MAIN_FILE
  print '- %s' % CRON_FILE
  print '- %s' % DEPLOY_FILE
  update_scripts = (raw_input('Do you want to update these scripts too [y/n]?')
                    .upper())
  if update_scripts != 'Y':
    print 'Ok, goodbye!'
    exit(0)

  try:
    os.makedirs(BACKUP_MAIN_FOLDER)
  except OSError as exception:
    if exception.errno != errno.EEXIST:
      raise
  for filepath in FILES_TO_BACKUP:
    copyfile(filepath, BACKUP_MAIN_FOLDER + '/' + filepath)

  print 'Original files backed up in the %s folder' % BACKUP_MAIN_FOLDER