def _init():
 parser = OptionParser()
 parser.add_option('--platform', dest='platform', help="Platform ('os' grain)")
 parser.add_option('--log-level', dest='log_level', default='warning', help='Control verbosity of logging. Default: %default')
 path_group = OptionGroup(parser, 'File/Directory Options')
 path_group.add_option('--source-dir', default='/testing', help='Source directory. Must be a git checkout. (default: %default)')
 path_group.add_option('--build-dir', default='/tmp/salt-buildpackage', help='Build root, will be removed if it exists prior to running script. (default: %default)')
 path_group.add_option('--artifact-dir', default='/tmp/salt-packages', help='Location where build artifacts should be placed for Jenkins to retrieve them (default: %default)')
 parser.add_option_group(path_group)
 rpm_group = OptionGroup(parser, 'RPM-specific File/Directory Options')
 rpm_group.add_option('--spec', dest='spec_file', default='/tmp/salt.spec', help='Spec file to use as a template to build RPM. (default: %default)')
 parser.add_option_group(rpm_group)
 opts = parser.parse_args()[0]
 for group in (path_group, rpm_group):
  for path_opt in [opt.dest for opt in group.option_list]:
   path = getattr(opts, path_opt)
   if (not os.path.isabs(path)):
    path = os.path.expanduser(path)
    if (not os.path.isabs(path)):
     path = os.path.realpath(path)
    setattr(opts, path_opt, path)
 problems = []
 if (not opts.platform):
  problems.append("Platform ('os' grain) required")
 if (not os.path.isdir(opts.source_dir)):
  problems.append('Source directory {0} not found'.format(opts.source_dir))
 try:
  shutil.rmtree(opts.build_dir)
 except OSError as exc:
  if (exc.errno not in (errno.ENOENT, errno.ENOTDIR)):
   problems.append('Unable to remove pre-existing destination directory {0}: {1}'.format(opts.build_dir, exc))
 finally:
  try:
   os.makedirs(opts.build_dir)
  except OSError as exc:
   problems.append('Unable to create destination directory {0}: {1}'.format(opts.build_dir, exc))
 try:
  shutil.rmtree(opts.artifact_dir)
 except OSError as exc:
  if (exc.errno not in (errno.ENOENT, errno.ENOTDIR)):
   problems.append('Unable to remove pre-existing artifact directory {0}: {1}'.format(opts.artifact_dir, exc))
 finally:
  try:
   os.makedirs(opts.artifact_dir)
  except OSError as exc:
   problems.append('Unable to create artifact directory {0}: {1}'.format(opts.artifact_dir, exc))
 opts.log_file = os.path.join(opts.artifact_dir, 'salt-buildpackage.log')
 if problems:
  _abort(problems)
 return opts

def _init ( ) : parser = OptionParser ( ) parser . add_option ( '--platform' , dest = 'platform' , help = "Platform ('os' grain)" ) parser . add_option ( '--log-level' , dest = 'log_level' , default = 'warning' , help = 'Control verbosity of logging. Default: %default' ) path_group = OptionGroup ( parser , 'File/Directory Options' ) path_group . add_option ( '--source-dir' , default = '/testing' , help = 'Source directory. Must be a git checkout. (default: %default)' ) path_group . add_option ( '--build-dir' , default = '/tmp/salt-buildpackage' , help = 'Build root, will be removed if it exists prior to running script. (default: %default)' ) path_group . add_option ( '--artifact-dir' , default = '/tmp/salt-packages' , help = 'Location where build artifacts should be placed for Jenkins to retrieve them (default: %default)' ) parser . add_option_group ( path_group ) rpm_group = OptionGroup ( parser , 'RPM-specific File/Directory Options' ) rpm_group . add_option ( '--spec' , dest = 'spec_file' , default = '/tmp/salt.spec' , help = 'Spec file to use as a template to build RPM. (default: %default)' ) parser . add_option_group ( rpm_group ) opts = parser . parse_args ( ) [ 0 ] for group in ( path_group , rpm_group ) : for path_opt in [ opt . dest for opt in group . option_list ] : path = getattr ( opts , path_opt ) if ( not os . path . isabs ( path ) ) : path = os . path . expanduser ( path ) if ( not os . path . isabs ( path ) ) : path = os . path . realpath ( path ) setattr ( opts , path_opt , path ) problems = [ ] if ( not opts . platform ) : problems . append ( "Platform ('os' grain) required" ) if ( not os . path . isdir ( opts . source_dir ) ) : problems . append ( 'Source directory {0} not found' . format ( opts . source_dir ) ) try : shutil . rmtree ( opts . build_dir ) except OSError as exc : if ( exc . errno not in ( errno . ENOENT , errno . ENOTDIR ) ) : problems . append ( 'Unable to remove pre-existing destination directory {0}: {1}' . format ( opts . build_dir , exc ) ) finally : try : os . makedirs ( opts . build_dir ) except OSError as exc : problems . append ( 'Unable to create destination directory {0}: {1}' . format ( opts . build_dir , exc ) ) try : shutil . rmtree ( opts . artifact_dir ) except OSError as exc : if ( exc . errno not in ( errno . ENOENT , errno . ENOTDIR ) ) : problems . append ( 'Unable to remove pre-existing artifact directory {0}: {1}' . format ( opts . artifact_dir , exc ) ) finally : try : os . makedirs ( opts . artifact_dir ) except OSError as exc : problems . append ( 'Unable to create artifact directory {0}: {1}' . format ( opts . artifact_dir , exc ) ) opts . log_file = os . path . join ( opts . artifact_dir , 'salt-buildpackage.log' ) if problems : _abort ( problems ) return opts
internal function to install the module finder .