scripts/export_image.py
changeset 50 43df6d7be888
parent 46 0fb942ba3046
equal deleted inserted replaced
49:7b6914018044 50:43df6d7be888
    37 from trunk.scripts import app_image
    37 from trunk.scripts import app_image
    38 from trunk.scripts import settings
    38 from trunk.scripts import settings
    39 from trunk.scripts import svn_helper
    39 from trunk.scripts import svn_helper
    40 
    40 
    41 
    41 
    42 def buildOptionList(defaults):
    42 def buildOptionList(defaults={}):
    43   """Returns a list of command-line settings.Options for this script.
    43   """Returns a list of command-line settings.Options for this script.
    44 
    44 
    45   Args:
    45   Args:
    46     defaults: dict of possible pre-loaded default values (may be empty)
    46     defaults: dict of possible pre-loaded default values; default is empty
       
    47       dict (which is safe because it is not altered)
    47   """
    48   """
    48   def_repo = defaults.get('repo')
    49   def_repo = defaults.get('repo')
    49 
    50 
    50   if def_repo:
    51   if def_repo:
    51     repo_help_msg = 'SVN repository; default is %s' % def_repo
    52     repo_help_msg = 'SVN repository; default is %s' % def_repo
    52   else:
    53   else:
    53     repo_help_msg = 'SVN repository; REQUIRED if default unavailable'
    54     repo_help_msg = 'SVN repository; REQUIRED if a default is missing'
    54 
    55 
    55   return [
    56   return [
    56       settings.Option(
    57       settings.Option(
    57           '-R', '--repo', action='store', dest='repo',
    58           '-R', '--repo', action='store', dest='repo',
    58           default=def_repo, help=repo_help_msg),
    59           default=def_repo, help=repo_help_msg),
    67           default=None, help='optional revision number on which to export'),
    68           default=None, help='optional revision number on which to export'),
    68   ]
    69   ]
    69 
    70 
    70 
    71 
    71 def main(args):
    72 def main(args):
       
    73   # create parser just for usage info before settings file is read successfully
       
    74   usage_parser = settings.OptionParser(option_list=buildOptionList())
       
    75 
    72   # attempt to read the common trunk/scripts settings file
    76   # attempt to read the common trunk/scripts settings file
    73   defaults = settings.readPythonSettingsOrDie(
    77   defaults = settings.readPythonSettingsOrDie(parser=usage_parser)
    74       parser=settings.OptionParser(option_list=buildOptionList({})))
       
    75 
    78 
    76   # create the command-line options parser
    79   # create the command-line options parser
    77   parser = settings.makeOptionParserOrDie(
    80   parser = settings.makeOptionParserOrDie(
    78       option_list=buildOptionList(defaults))
    81       option_list=buildOptionList(defaults))
    79 
    82 
    88   # (which is why no working copy path is needed or supplied)
    91   # (which is why no working copy path is needed or supplied)
    89   image = svn_helper.getExpandedWorkingCopyPath(image)
    92   image = svn_helper.getExpandedWorkingCopyPath(image)
    90 
    93 
    91   setup_errors = []
    94   setup_errors = []
    92 
    95 
    93   # dirname() called twice because image always ends with os.sep
    96   if os.path.exists(image):
    94   parent_dir = os.path.dirname(os.path.dirname(image))
       
    95 
       
    96   if os.path.isdir(image):
       
    97     setup_errors.extend(
    97     setup_errors.extend(
    98         ['--image destination directory must not already exist:',
    98         ['--image destination directory must not already exist:',
    99          '  %s' % image])
    99          '  %s' % image])
       
   100 
       
   101   # dirname() called twice because image always ends with os.sep as a result
       
   102   # of svn_helper.getExpandedWorkingCopyPath()
       
   103   parent_dir = os.path.dirname(os.path.dirname(image))
   100 
   104 
   101   if not os.path.isdir(parent_dir):
   105   if not os.path.isdir(parent_dir):
   102     try:
   106     try:
   103       os.makedirs(parent_dir)
   107       os.makedirs(parent_dir)
   104       print 'Created --image parent directory:\n %s\n' % parent_dir
   108       print 'Created --image parent directory:\n %s\n' % parent_dir