parameters: (argv=sys.argv)
docstring: Entry point when the script is called from the command line, not used
      as a module.
docstring_summary: Entry point when the script is called from the command line, not used
      as a module.
docstring_tokens: Entry point when the script is called from the command line not used as a module .
function: def main(argv=sys.argv):
      """
      Entry point when the script is called from the command line, not used
      as a module.
      """
      import optparse
      usage = """%prog [options] source [destination]
      
  Destination can be either a directory or a zip file"""
      parser = optparse.OptionParser(usage)
      parser.add_option("-c", "--no-concat", dest="concat",
                        default=True, action="store_false",
                        help="Do NOT concatenate script and css")
      parser.add_option("-l", "--no-license", dest="license",
                        default=True, action="store_false",
                        help="Do NOT append license file to js and css. (license is taken from $cwd/include-license.txt")
      parser.add_option("-k", "--keyword", dest="kwlist",
                        default=None, type="string", action="append",
                        help="A key/value pair. All instances of key will be replaced by value in all files. More than one key/value is allowed by adding more -k switches", metavar="key=value")
      parser.add_option("-d", "--delete", default=False,
                        action="store_true", dest="overwrite_dst",
                        help="Delete the destination before copying to it. Makes sure that there are no files left over from previous builds. Is destructive!")
      parser.add_option("-t", "--translate", default=False,
                        action="store_true", dest="translate_build",
                        help="Apply translation changes to the finished build")
      parser.add_option("-s", "--no-string-check", default=True,
                        action="store_false", dest="check_strings",
                        help="Don't check validity of strings before building")
      parser.add_option("-e", "--no-enc-check", default=True,
                        action="store_false", dest="check_encodings",
                        help="Don't check encoding of files before building")
      parser.add_option("-m", "--minify", default=False,
                        action="store_true", dest="minify",
                        help="Minify the sources")
      parser.add_option("-u", "--no-data-uri", default=True,
                        action="store_false", dest="make_data_uris",
                        help="Don't generate data URIs for images in css")
  
      parser.add_option("-b", "--set-base", default=None,
                        type="string", dest="set_base",
                        help="""Set a base url in the document. """
                        """The value of the setting is the realative root in the """
                        """destination path. E.g. a the value "app" with the destination"""
                        """ "<some loca path>/app/core-2-5" will set the base url"""
                        """ to "/app/core-2-5/". The purpose is to ba able to rewrite"""
                        """ urls without breaking other urls of the rewritten document,"""
                        """ e.g. handling all different core version on the "/app/" path"""
                        """ without redirects.""")
  
      parser.add_option("--fixBOM", default=False,
                        action="store_true", dest="fix_BOM",
                        help="Try to convert ANSI to UTF8 with BOM. Use only with source.")
  
      options, args = parser.parse_args()
      globals()['options'] = options
  
      if len(args) == 1 and options.fix_BOM:
          bad = _get_bad_encoding_files(args[0])
          for path in bad:
              _ansi2utf8(path)
          return 0
      
      # Make sure we have a source and destination
      if len(args) != 2:
          parser.error("Source and destination argument is required")
      else:
          src, dst = args
      
      dirvars = {}
      
      if options.concat:
          exdirs = ["scripts", "ui-style", "ecma-debugger", "ui-strings"]
      else:
          exdirs = []
      
      if options.translate_build:
          dirvars["exclude_uistrings"]=True
  
      if options.set_base:
          path_segs = os.path.normpath(dst).split(os.sep)
          pos = path_segs.index(options.set_base)
          dirvars["base_url"] = pos > -1 and "/%s/" % "/".join(path_segs[pos:]) or ""
      
      # Parse the keyword definitons
      keywords = {}
      if options.kwlist:
          try:
              for kw in options.kwlist:
                  key, val = kw.split("=")
                  keywords[key] = val
          except ValueError:
              parser.error("""Could not parse keyword option: "%s" """ % kw)
      
      if options.translate_build and not options.concat:
          parser.error("""Can't translate when not concatenateing. use --no-concat OR --translate""")
      
      if options.check_encodings:
          bad = _get_bad_encoding_files(src)
          if bad:
              print "The following files do not seem to be UTF8 with BOM encoded:"
              for b in bad: print "\t%s" % b
              sys.exit()
  
      if options.check_strings:
          missingstrings = _get_missing_strings_for_dir(os.path.join(src, "ui-strings"), "en")
          if missingstrings==None:
              print "couldn't parse the master string list!"
              sys.exit()
          elif missingstrings:
              for lang, strings in missingstrings.items():
                  print """Language "%s" is missing the following strings:""" % lang
                  for s in strings: print "\t%s" % s
              sys.exit()
      
      if dst.endswith(".zip"): # export to a zip file
          if os.path.isfile(dst):
              if not options.overwrite_dst:
                  parser.error("Destination exists! use -d to force overwrite")
              else:
                  os.unlink(dst)
  
          tempdir = tempfile.mkdtemp(".tmp", "dfbuild.")
          export(src, tempdir, process_directives=options.concat, exclude_dirs=exdirs,
                 keywords=keywords, directive_vars=dirvars)
  
          if options.translate_build:
              _localize_buildout(tempdir, os.path.join(os.path.abspath(src), "ui-strings"))
  
          if options.make_data_uris:
              _convert_imgs_to_data_uris(dst)
  
          if options.minify:
              _minify_buildout(dst)
  
          if options.license:
              _add_license(tempdir)
  
          make_archive(tempdir, dst)
          shutil.rmtree(tempdir)
  
      else: # export to a directory
          if os.path.isdir(dst) and not options.overwrite_dst:
              parser.error("Destination exists! use -d to force overwrite")
  
          export(src, dst, process_directives=options.concat, exclude_dirs=exdirs,
                 keywords=keywords, directive_vars=dirvars)
  
          if options.translate_build:
              _localize_buildout(dst, os.path.join(os.path.abspath(src), "ui-strings"))
  
          if options.make_data_uris:
              _convert_imgs_to_data_uris(dst)
              # any remaining image in ui-images is not used
              img_dir = os.path.join(dst, 'ui-images')
              shutil.rmtree(img_dir)
   
          if options.minify:
              _minify_buildout(dst)
  
          if options.license:
              _add_license(dst)
  
          AUTHORS = os.path.join(src, '..', 'AUTHORS')
          if os.path.isfile(AUTHORS):
              shutil.copy(AUTHORS, os.path.join(dst, 'AUTHORS'))
function_tokens: def main ( argv = sys . argv ) : import optparse usage = """%prog [options] source [destination]
      
  Destination can be either a directory or a zip file""" parser = optparse . OptionParser ( usage ) parser . add_option ( "-c" , "--no-concat" , dest = "concat" , default = True , action = "store_false" , help = "Do NOT concatenate script and css" ) parser . add_option ( "-l" , "--no-license" , dest = "license" , default = True , action = "store_false" , help = "Do NOT append license file to js and css. (license is taken from $cwd/include-license.txt" ) parser . add_option ( "-k" , "--keyword" , dest = "kwlist" , default = None , type = "string" , action = "append" , help = "A key/value pair. All instances of key will be replaced by value in all files. More than one key/value is allowed by adding more -k switches" , metavar = "key=value" ) parser . add_option ( "-d" , "--delete" , default = False , action = "store_true" , dest = "overwrite_dst" , help = "Delete the destination before copying to it. Makes sure that there are no files left over from previous builds. Is destructive!" ) parser . add_option ( "-t" , "--translate" , default = False , action = "store_true" , dest = "translate_build" , help = "Apply translation changes to the finished build" ) parser . add_option ( "-s" , "--no-string-check" , default = True , action = "store_false" , dest = "check_strings" , help = "Don't check validity of strings before building" ) parser . add_option ( "-e" , "--no-enc-check" , default = True , action = "store_false" , dest = "check_encodings" , help = "Don't check encoding of files before building" ) parser . add_option ( "-m" , "--minify" , default = False , action = "store_true" , dest = "minify" , help = "Minify the sources" ) parser . add_option ( "-u" , "--no-data-uri" , default = True , action = "store_false" , dest = "make_data_uris" , help = "Don't generate data URIs for images in css" ) parser . add_option ( "-b" , "--set-base" , default = None , type = "string" , dest = "set_base" , help = """Set a base url in the document. """ """The value of the setting is the realative root in the """ """destination path. E.g. a the value "app" with the destination""" """ "<some loca path>/app/core-2-5" will set the base url""" """ to "/app/core-2-5/". The purpose is to ba able to rewrite""" """ urls without breaking other urls of the rewritten document,""" """ e.g. handling all different core version on the "/app/" path""" """ without redirects.""" ) parser . add_option ( "--fixBOM" , default = False , action = "store_true" , dest = "fix_BOM" , help = "Try to convert ANSI to UTF8 with BOM. Use only with source." ) options , args = parser . parse_args ( ) globals ( ) [ 'options' ] = options if len ( args ) == 1 and options . fix_BOM : bad = _get_bad_encoding_files ( args [ 0 ] ) for path in bad : _ansi2utf8 ( path ) return 0 # Make sure we have a source and destination if len ( args ) != 2 : parser . error ( "Source and destination argument is required" ) else : src , dst = args dirvars = { } if options . concat : exdirs = [ "scripts" , "ui-style" , "ecma-debugger" , "ui-strings" ] else : exdirs = [ ] if options . translate_build : dirvars [ "exclude_uistrings" ] = True if options . set_base : path_segs = os . path . normpath ( dst ) . split ( os . sep ) pos = path_segs . index ( options . set_base ) dirvars [ "base_url" ] = pos > - 1 and "/%s/" % "/" . join ( path_segs [ pos : ] ) or "" # Parse the keyword definitons keywords = { } if options . kwlist : try : for kw in options . kwlist : key , val = kw . split ( "=" ) keywords [ key ] = val except ValueError : parser . error ( """Could not parse keyword option: "%s" """ % kw ) if options . translate_build and not options . concat : parser . error ( """Can't translate when not concatenateing. use --no-concat OR --translate""" ) if options . check_encodings : bad = _get_bad_encoding_files ( src ) if bad : print "The following files do not seem to be UTF8 with BOM encoded:" for b in bad : print "\t%s" % b sys . exit ( ) if options . check_strings : missingstrings = _get_missing_strings_for_dir ( os . path . join ( src , "ui-strings" ) , "en" ) if missingstrings == None : print "couldn't parse the master string list!" sys . exit ( ) elif missingstrings : for lang , strings in missingstrings . items ( ) : print """Language "%s" is missing the following strings:""" % lang for s in strings : print "\t%s" % s sys . exit ( ) if dst . endswith ( ".zip" ) : # export to a zip file if os . path . isfile ( dst ) : if not options . overwrite_dst : parser . error ( "Destination exists! use -d to force overwrite" ) else : os . unlink ( dst ) tempdir = tempfile . mkdtemp ( ".tmp" , "dfbuild." ) export ( src , tempdir , process_directives = options . concat , exclude_dirs = exdirs , keywords = keywords , directive_vars = dirvars ) if options . translate_build : _localize_buildout ( tempdir , os . path . join ( os . path . abspath ( src ) , "ui-strings" ) ) if options . make_data_uris : _convert_imgs_to_data_uris ( dst ) if options . minify : _minify_buildout ( dst ) if options . license : _add_license ( tempdir ) make_archive ( tempdir , dst ) shutil . rmtree ( tempdir ) else : # export to a directory if os . path . isdir ( dst ) and not options . overwrite_dst : parser . error ( "Destination exists! use -d to force overwrite" ) export ( src , dst , process_directives = options . concat , exclude_dirs = exdirs , keywords = keywords , directive_vars = dirvars ) if options . translate_build : _localize_buildout ( dst , os . path . join ( os . path . abspath ( src ) , "ui-strings" ) ) if options . make_data_uris : _convert_imgs_to_data_uris ( dst ) # any remaining image in ui-images is not used img_dir = os . path . join ( dst , 'ui-images' ) shutil . rmtree ( img_dir ) if options . minify : _minify_buildout ( dst ) if options . license : _add_license ( dst ) AUTHORS = os . path . join ( src , '..' , 'AUTHORS' ) if os . path . isfile ( AUTHORS ) : shutil . copy ( AUTHORS , os . path . join ( dst , 'AUTHORS' ) )