Esempio n. 1
0
def main():
    print 'Looking for new IANA tzdata...'

    iana_tar_filenames = []

    ftp = ftplib.FTP('ftp.iana.org')
    ftp.login()
    ftp.cwd('tz/releases')
    for filename in ftp.nlst():
        if "/" in filename:
            print "FTP server returned bogus file name"
            sys.exit(1)

        if filename.startswith('tzdata20') and filename.endswith('.tar.gz'):
            iana_tar_filenames.append(filename)
    iana_tar_filenames.sort(reverse=True)

    if len(iana_tar_filenames) == 0:
        print 'No tzdata files found'
        sys.exit(1)

    latest_iana_tar_filename = iana_tar_filenames[0]

    local_iana_tar_file = tzdatautil.GetIanaTarFile(iana_data_dir, 'data')

    if local_iana_tar_file:
        local_iana_tar_filename = os.path.basename(local_iana_tar_file)
        if latest_iana_tar_filename <= local_iana_tar_filename:
            print 'Available data %s is older or the same as current data %s' % (
                latest_iana_tar_filename, local_iana_tar_filename)
            sys.exit(0)

    print 'Found new tzdata: %s' % latest_iana_tar_filename
    i18nutil.SwitchToNewTemporaryDirectory()

    print 'Downloading data (%s)...' % latest_iana_tar_filename
    FtpRetrieveFile(ftp, latest_iana_tar_filename)

    signature_filename = '%s.asc' % latest_iana_tar_filename
    print 'Downloading signature (%s)...' % signature_filename
    FtpRetrieveFile(ftp, signature_filename)

    CheckSignature(latest_iana_tar_filename, signature_filename)

    new_local_iana_tar_file = '%s/%s' % (iana_data_dir,
                                         latest_iana_tar_filename)
    shutil.copyfile(latest_iana_tar_filename, new_local_iana_tar_file)
    new_local_signature_file = '%s/%s' % (iana_data_dir, signature_filename)
    shutil.copyfile(signature_filename, new_local_signature_file)

    # Delete the existing local IANA tar file, if there is one.
    if local_iana_tar_file:
        os.remove(local_iana_tar_file)

    local_signature_file = '%s.asc' % local_iana_tar_file
    if os.path.exists(local_signature_file):
        os.remove(local_signature_file)

    print 'Look in %s for new IANA data files' % new_local_iana_tar_file
    sys.exit(0)
def main():
    print 'Found bionic in %s ...' % bionic_dir
    print 'Found icu in %s ...' % updateicudata.icuDir()

    print 'Looking for new tzdata...'

    tzdata_filenames = []

    # The FTP server lets you download intermediate releases, and also lets you
    # download the signatures for verification, so it's your best choice.
    use_ftp = True

    if use_ftp:
        ftp = ftplib.FTP('ftp.iana.org')
        ftp.login()
        ftp.cwd('tz/releases')
        for filename in ftp.nlst():
            if filename.startswith('tzdata20') and filename.endswith(
                    '.tar.gz'):
                tzdata_filenames.append(filename)
        tzdata_filenames.sort()
    else:
        http = httplib.HTTPConnection('www.iana.org')
        http.request("GET", "/time-zones")
        index_lines = http.getresponse().read().split('\n')
        for line in index_lines:
            m = re.compile(
                '.*href="/time-zones/repository/releases/(tzdata20\d\d\c\.tar\.gz)".*'
            ).match(line)
            if m:
                tzdata_filenames.append(m.group(1))

    # If you're several releases behind, we'll walk you through the upgrades
    # one by one.
    current_version = GetCurrentTzDataVersion()
    current_filename = '%s.tar.gz' % current_version
    for filename in tzdata_filenames:
        if filename > current_filename:
            print 'Found new tzdata: %s' % filename
            i18nutil.SwitchToNewTemporaryDirectory()
            if use_ftp:
                FtpRetrieveFileAndSignature(ftp, filename)
            else:
                HttpRetrieveFileAndSignature(http, filename)

            CheckSignature(filename)
            BuildIcuToolsAndData(filename)
            BuildBionicToolsAndData(filename)
            print 'Look in %s and %s for new data files' % (
                bionic_dir, updateicudata.icuDir())
            sys.exit(0)

    print 'You already have the latest tzdata in bionic (%s)!' % current_version
    sys.exit(0)
Esempio n. 3
0
def main():
    i18nutil.SwitchToNewTemporaryDirectory()
    icu_build_dir = '%s/icu' % os.getcwd()

    print 'Found icu in %s ...' % icu_dir

    PrepareIcuBuild(icu_build_dir)

    MakeAndCopyIcuDataFiles(icu_build_dir)

    print 'Look in %s for new data files' % icu_dir
    sys.exit(0)
def DownloadAndReplaceLocalFiles(file_prefixes, ftp, local_dir):
    output_files = []

    for file_prefix in file_prefixes:
        latest_iana_tar_filename = FindLatestRemoteTar(ftp, file_prefix)
        local_iana_tar_file = tzdatautil.GetIanaTarFile(local_dir, file_prefix)
        if local_iana_tar_file:
            local_iana_tar_filename = os.path.basename(local_iana_tar_file)
            if latest_iana_tar_filename <= local_iana_tar_filename:
                print(
                    'Latest remote file for %s is called %s and is older or the same as'
                    ' current local file %s' %
                    (local_dir, latest_iana_tar_filename,
                     local_iana_tar_filename))
                continue

        print 'Found new %s* file for %s: %s' % (file_prefix, local_dir,
                                                 latest_iana_tar_filename)
        i18nutil.SwitchToNewTemporaryDirectory()

        print 'Downloading file %s...' % latest_iana_tar_filename
        FtpRetrieveFile(ftp, latest_iana_tar_filename)

        signature_filename = '%s.asc' % latest_iana_tar_filename
        print 'Downloading signature %s...' % signature_filename
        FtpRetrieveFile(ftp, signature_filename)

        CheckSignature(latest_iana_tar_filename, signature_filename)

        new_local_iana_tar_file = '%s/%s' % (local_dir,
                                             latest_iana_tar_filename)
        shutil.copyfile(latest_iana_tar_filename, new_local_iana_tar_file)
        new_local_signature_file = '%s/%s' % (local_dir, signature_filename)
        shutil.copyfile(signature_filename, new_local_signature_file)

        output_files.append(new_local_iana_tar_file)
        output_files.append(new_local_signature_file)

        # Delete the existing local IANA tar file, if there is one.
        if local_iana_tar_file:
            os.remove(local_iana_tar_file)

        local_signature_file = '%s.asc' % local_iana_tar_file
        if os.path.exists(local_signature_file):
            os.remove(local_signature_file)

    return output_files
Esempio n. 5
0
def CreateTimeZoneDistro(iana_version, revision, tzdata_file, icu_file,
                         tzlookup_file, output_dir):
    original_cwd = os.getcwd()

    i18nutil.SwitchToNewTemporaryDirectory()
    working_dir = os.getcwd()

    # Generate the properties file.
    properties_file = '%s/distro.properties' % working_dir
    with open(properties_file, "w") as properties:
        properties.write('rules.version=%s\n' % iana_version)
        properties.write('revision=%s\n' % revision)
        properties.write('tzdata.file=%s\n' % tzdata_file)
        properties.write('icu.file=%s\n' % icu_file)
        properties.write('tzlookup.file=%s\n' % tzlookup_file)

    RunCreateTimeZoneDistro(properties_file, output_dir)

    os.chdir(original_cwd)
Esempio n. 6
0
def main():
    cldr_dir = icuutil.cldrDir()
    print('Found cldr in %s ...' % cldr_dir)
    icu_dir = icuutil.icuDir()
    print('Found icu in %s ...' % icu_dir)

    # Ant doesn't have any mechanism for using a build directory separate from the
    # source directory so this build script creates a temporary directory and then
    # copies all necessary ICU4J and CLDR source code to here before building it:
    i18nutil.SwitchToNewTemporaryDirectory()

    print('Copying ICU4J source code ...')
    shutil.copytree(os.path.join(icu_dir, 'icu4j'), 'icu4j', True)
    print('Building ICU4J ...')
    subprocess.check_call([
        'ant',
        '-f',
        'icu4j/build.xml',
        'jar',
        'cldrUtil',
    ])

    # Append the newly built JAR files to the Java CLASSPATH to use these instead
    # of the pre-built JAR files in the CLDR source tree, to ensure that the same
    # version of ICU is being used to build the data as will use the data:
    cp = []
    try:
        cp.append(os.environ['CLASSPATH'])
    except KeyError:
        pass
    cp.append('icu4j/icu4j.jar')
    cp.append('icu4j/out/cldr_util/lib/utilities.jar')
    os.environ['CLASSPATH'] = ':'.join(cp)

    # This is the location of the original CLDR source tree (not the temporary
    # copy of the tools source code) from where the data files are to be read:
    os.environ['CLDR_DIR'] = os.path.join(os.getcwd(), 'cldr')

    print('Copying CLDR source code ...')
    shutil.copytree(cldr_dir, 'cldr', True)
    print('Building CLDR tools ...')
    subprocess.check_call([
        'ant',
        '-f',
        os.path.join('cldr', 'tools', 'java', 'build.xml'),
        'jar',
        'AddPseudolocales',
    ])

    # This is the temporary directory in which the CLDR tools have been built:
    os.environ['CLDR_CLASSES'] = os.path.join(os.getcwd(), 'cldr', 'tools',
                                              'java', 'classes')

    # It's essential to set CLDR_DTD_CACHE for otherwise the repeated requests for
    # the same file will cause the unicode.org web server to block this machine:
    os.makedirs('cldr-dtd-cache')
    os.environ['ANT_OPTS'] = '-DCLDR_DTD_CACHE=%s' % pipes.quote(
        os.path.join(os.getcwd(), 'cldr-dtd-cache'))

    print('Building ICU data source files ...')
    subprocess.check_call([
        'ant',
        '-f',
        os.path.join(icu_dir, 'icu4c/source/data/build.xml'),
        'clean',
        'all',
    ])

    print('Look in %s/icu4c/source/data for new data source files' % icu_dir)
    sys.exit(0)