Exemple #1
0
def main():
    print 'Found source data file structure in %s ...' % timezone_input_data_dir

    iana_data_dir = '%s/iana' % timezone_input_data_dir
    iana_tar_file = tzdatautil.GetIanaTarFile(iana_data_dir)
    iana_version = ExtractIanaVersion(iana_tar_file)
    print 'Found IANA time zone data release %s in %s ...' % (iana_version,
                                                              iana_tar_file)

    print 'Found android output dir in %s ...' % timezone_output_data_dir

    icu_dir = icuutil.icuDir()
    print 'Found icu in %s ...' % icu_dir

    BuildIcuData(iana_tar_file)
    BuildTzdata(iana_tar_file)
    BuildTzlookup()

    # Create a distro file from the output from prior stages.
    distro_output_dir = '%s/distro' % timezone_output_data_dir
    CreateDistroFiles(iana_version, distro_output_dir)

    print 'Look in %s and %s for new files' % (timezone_output_data_dir,
                                               icu_dir)
    sys.exit(0)
Exemple #2
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 'Source data file structure: %s' % timezone_input_data_dir
    print 'Source tools file structure: %s' % timezone_input_tools_dir
    print 'Output data file structure: %s' % timezone_output_data_dir

    iana_input_data_dir = '%s/iana' % timezone_input_data_dir
    iana_data_tar_file = tzdatautil.GetIanaTarFile(iana_input_data_dir, 'data')
    iana_data_version = GetIanaVersion(iana_data_tar_file)
    print 'IANA time zone data release %s in %s ...' % (iana_data_version,
                                                        iana_data_tar_file)

    icu_dir = icuutil.icuDir()
    print 'Found icu in %s ...' % icu_dir

    BuildIcuData(iana_data_tar_file)

    iana_tools_dir = '%s/iana' % timezone_input_tools_dir
    zic_binary_file = BuildZic(iana_tools_dir)

    iana_data_dir = '%s/iana_data' % tmp_dir
    ExtractTarFile(iana_data_tar_file, iana_data_dir)
    BuildTzdata(zic_binary_file, iana_data_dir, iana_data_version)
    BuildTzlookup(iana_data_dir)

    # Create a distro file from the output from prior stages.
    distro_output_dir = '%s/distro' % timezone_output_data_dir
    CreateDistroFiles(iana_data_version, distro_output_dir)

    # Update test versions of distro files too.
    UpdateTestFiles()

    print 'Look in %s and %s for new files' % (timezone_output_data_dir,
                                               icu_dir)
    sys.exit(0)
def BuildZic(iana_tools_dir):
    iana_zic_code_tar_file = tzdatautil.GetIanaTarFile(iana_tools_dir, 'code')
    iana_zic_code_version = GetIanaVersion(iana_zic_code_tar_file)
    iana_zic_data_tar_file = tzdatautil.GetIanaTarFile(iana_tools_dir, 'data')
    iana_zic_data_version = GetIanaVersion(iana_zic_data_tar_file)

    print 'Found IANA zic release %s/%s in %s/%s ...' \
        % (iana_zic_code_version, iana_zic_data_version, iana_zic_code_tar_file, iana_zic_data_tar_file)

    zic_build_dir = '%s/zic' % tmp_dir
    ExtractTarFile(iana_zic_code_tar_file, zic_build_dir)
    ExtractTarFile(iana_zic_data_tar_file, zic_build_dir)

    # zic
    print 'Building zic...'
    # VERSION_DEPS= is to stop the build process looking for files that might not
    # be present across different versions.
    subprocess.check_call(['make', '-C', zic_build_dir, 'zic'])

    zic_binary_file = '%s/zic' % zic_build_dir
    if not os.path.exists(zic_binary_file):
        print 'Could not find %s' % s
        system.exit(1)
    return zic_binary_file
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