Skip to content

Commit

Permalink
Add prerelease flag to download
Browse files Browse the repository at this point in the history
  • Loading branch information
dpad46 committed Sep 14, 2022
1 parent e3a1594 commit 4c8aa5b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
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

0 comments on commit 4c8aa5b

Please sign in to comment.