Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prerelease flag to download #201

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion lib/cldr/download.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ module Download
DEFAULT_VERSION = 41

class << self
def download(source = DEFAULT_SOURCE, target = DEFAULT_TARGET, version = DEFAULT_VERSION, &block)
def download(source = DEFAULT_SOURCE, target = DEFAULT_TARGET, version = DEFAULT_VERSION, pre_release: false, &block)
if pre_release
download_prerelease(source, target, version, &block)
else
download_release(source, target, version, &block)
end
end

private

def download_release(source, target, version, &block)
source = format(source, version: version)
target ||= File.expand_path(DEFAULT_TARGET)

Expand All @@ -28,6 +38,27 @@ def download(source = DEFAULT_SOURCE, target = DEFAULT_TARGET, version = DEFAULT
end
end
end

def download_prerelease(source, target, version, &block)
source = format(source, version: version)
target ||= File.expand_path(DEFAULT_TARGET)

URI.parse(source).open do |tempfile|
FileUtils.mkdir_p(target)
Zip.on_exists_proc = true
Zip::File.open(tempfile.path) do |file|
root_dir = file.first.name
production_dir = root_dir + "production"
file.each do |entry|
next unless entry.name.start_with?(production_dir)

path = target + "/" + entry.name.gsub(production_dir, "")
FileUtils.mkdir_p(File.dirname(path))
file.extract(entry, path)
end
end
end
end
end
end
end
7 changes: 5 additions & 2 deletions lib/cldr/thor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Cldr
class Thor < ::Thor
namespace "cldr"

desc "download [--version=#{Cldr::Download::DEFAULT_VERSION}] [--target=#{Cldr::Download::DEFAULT_TARGET}] [--source=#{format(Cldr::Download::DEFAULT_SOURCE, version: Cldr::Download::DEFAULT_VERSION)}]", "Download and extract CLDR data"
desc "download [--version=#{Cldr::Download::DEFAULT_VERSION}] [--target=#{Cldr::Download::DEFAULT_TARGET}] [--source=#{format(Cldr::Download::DEFAULT_SOURCE, version: Cldr::Download::DEFAULT_VERSION)}] [--pre-release]", "Download and extract CLDR data"
option :version, aliases: [:v], type: :numeric,
default: Cldr::Download::DEFAULT_VERSION,
banner: Cldr::Download::DEFAULT_VERSION,
Expand All @@ -23,8 +23,11 @@ class Thor < ::Thor
default: Cldr::Download::DEFAULT_SOURCE,
banner: Cldr::Download::DEFAULT_SOURCE,
desc: "Override the location of the CLDR zip to download. Overrides --version"
option :"pre-release", type: :boolean,
default: false,
desc: "Whether the source is a pre-release version"
def download
Cldr::Download.download(options["source"], options["target"], options["version"]) { putc(".") }
Cldr::Download.download(options["source"], options["target"], options["version"], pre_release: options["pre-release"]) { putc(".") }
end

DEFAULT_MINIMUM_DRAFT_STATUS = Cldr::DraftStatus::CONTRIBUTED
Expand Down