parameters: (topsrcdir, args)
docstring: Update the time zone cpp file.
docstring_summary: Update the time zone cpp file.
docstring_tokens: Update the time zone cpp file .
function: def updateTzdata(topsrcdir, args):
      """ Update the time zone cpp file. """
  
      icuDir = os.path.join(topsrcdir, "intl/icu/source")
      if not os.path.isdir(icuDir):
          raise RuntimeError("not a directory: %s" % icuDir)
  
      icuTzDir = os.path.join(topsrcdir, "intl/tzdata/source")
      if not os.path.isdir(icuTzDir):
          raise RuntimeError("not a directory: %s" % icuTzDir)
  
      dateTimeFormatTestDir = os.path.join(topsrcdir, "js/src/tests/non262/Intl/DateTimeFormat")
      if not os.path.isdir(dateTimeFormatTestDir):
          raise RuntimeError("not a directory: %s" % dateTimeFormatTestDir)
  
      tzDir = args.tz
      if tzDir is not None and not (os.path.isdir(tzDir) or os.path.isfile(tzDir)):
          raise RuntimeError("not a directory or file: %s" % tzDir)
      ignoreBackzone = args.ignore_backzone
      # TODO: Accept or ignore the placeholder time zone "Factory"?
      ignoreFactory = False
      out = args.out
  
      version = icuTzDataVersion(icuTzDir)
      url = "https://www.iana.org/time-zones/repository/releases/tzdata%s.tar.gz" % version
  
      print("Arguments:")
      print("\ttzdata version: %s" % version)
      print("\ttzdata URL: %s" % url)
      print("\ttzdata directory|file: %s" % tzDir)
      print("\tICU directory: %s" % icuDir)
      print("\tICU timezone directory: %s" % icuTzDir)
      print("\tIgnore backzone file: %s" % ignoreBackzone)
      print("\tOutput file: %s" % out)
      print("")
  
      def updateFrom(f):
          if os.path.isfile(f) and tarfile.is_tarfile(f):
              with tarfile.open(f, "r:*") as tar:
                  processTimeZones(TzDataFile(tar), icuDir, icuTzDir, version,
                                   ignoreBackzone, ignoreFactory, out)
                  generateTzDataTests(TzDataFile(tar), version,
                                      ignoreBackzone, dateTimeFormatTestDir)
          elif os.path.isdir(f):
              processTimeZones(TzDataDir(f), icuDir, icuTzDir, version,
                               ignoreBackzone, ignoreFactory, out)
              generateTzDataTests(TzDataDir(f), version, ignoreBackzone, dateTimeFormatTestDir)
          else:
              raise RuntimeError("unknown format")
  
      if tzDir is None:
          print("Downloading tzdata file...")
          with closing(urlopen(url)) as tzfile:
              fname = urlsplit(tzfile.geturl()).path.split("/")[-1]
              with tempfile.NamedTemporaryFile(suffix=fname) as tztmpfile:
                  print("File stored in %s" % tztmpfile.name)
                  tztmpfile.write(tzfile.read())
                  tztmpfile.flush()
                  updateFrom(tztmpfile.name)
      else:
          updateFrom(tzDir)
function_tokens: def updateTzdata ( topsrcdir , args ) : icuDir = os . path . join ( topsrcdir , "intl/icu/source" ) if not os . path . isdir ( icuDir ) : raise RuntimeError ( "not a directory: %s" % icuDir ) icuTzDir = os . path . join ( topsrcdir , "intl/tzdata/source" ) if not os . path . isdir ( icuTzDir ) : raise RuntimeError ( "not a directory: %s" % icuTzDir ) dateTimeFormatTestDir = os . path . join ( topsrcdir , "js/src/tests/non262/Intl/DateTimeFormat" ) if not os . path . isdir ( dateTimeFormatTestDir ) : raise RuntimeError ( "not a directory: %s" % dateTimeFormatTestDir ) tzDir = args . tz if tzDir is not None and not ( os . path . isdir ( tzDir ) or os . path . isfile ( tzDir ) ) : raise RuntimeError ( "not a directory or file: %s" % tzDir ) ignoreBackzone = args . ignore_backzone # TODO: Accept or ignore the placeholder time zone "Factory"? ignoreFactory = False out = args . out version = icuTzDataVersion ( icuTzDir ) url = "https://www.iana.org/time-zones/repository/releases/tzdata%s.tar.gz" % version print ( "Arguments:" ) print ( "\ttzdata version: %s" % version ) print ( "\ttzdata URL: %s" % url ) print ( "\ttzdata directory|file: %s" % tzDir ) print ( "\tICU directory: %s" % icuDir ) print ( "\tICU timezone directory: %s" % icuTzDir ) print ( "\tIgnore backzone file: %s" % ignoreBackzone ) print ( "\tOutput file: %s" % out ) print ( "" ) def updateFrom ( f ) : if os . path . isfile ( f ) and tarfile . is_tarfile ( f ) : with tarfile . open ( f , "r:*" ) as tar : processTimeZones ( TzDataFile ( tar ) , icuDir , icuTzDir , version , ignoreBackzone , ignoreFactory , out ) generateTzDataTests ( TzDataFile ( tar ) , version , ignoreBackzone , dateTimeFormatTestDir ) elif os . path . isdir ( f ) : processTimeZones ( TzDataDir ( f ) , icuDir , icuTzDir , version , ignoreBackzone , ignoreFactory , out ) generateTzDataTests ( TzDataDir ( f ) , version , ignoreBackzone , dateTimeFormatTestDir ) else : raise RuntimeError ( "unknown format" ) if tzDir is None : print ( "Downloading tzdata file..." ) with closing ( urlopen ( url ) ) as tzfile : fname = urlsplit ( tzfile . geturl ( ) ) . path . split ( "/" ) [ - 1 ] with tempfile . NamedTemporaryFile ( suffix = fname ) as tztmpfile : print ( "File stored in %s" % tztmpfile . name ) tztmpfile . write ( tzfile . read ( ) ) tztmpfile . flush ( ) updateFrom ( tztmpfile . name ) else : updateFrom ( tzDir )