Skip to content

Commit

Permalink
remove a usage of 'cmp'
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyanxing committed May 20, 2015
1 parent baacdd6 commit 2496d8a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
65 changes: 54 additions & 11 deletions build/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
require 'semantic/core_ext'
require 'fileutils'
require 'zip/zip'
require 'rubygems/package'
require 'zlib'

# configs
@release = false
@cache_dir = 'cache'
@build_dir = 'release'
@url = 'http://dl.nwjs.io/'
#@platforms = ['osx-x64', 'win-ia32', 'win-x64']
# @platforms = ['osx-x64', 'win-ia32', 'linux-x64', 'linux-ia32']
@platforms = []
@menifest = '../package.json'
@app_name = 'judge_fgdsb'
Expand All @@ -34,9 +36,15 @@
elsif ARGV.include? '-win32'
puts 'Build to win32'
@platforms = ['win-ia32']
elsif ARGV.include? '-linux32'
puts 'Build to linux32'
@platforms = ['linux-ia32']
elsif ARGV.include? '-linux64'
puts 'Build to linux64'
@platforms = ['linux-x64']
else
puts 'Build to all platforms'
@platforms = ['osx-x64', 'win-ia32']
@platforms = ['osx-x64', 'win-ia32', 'linux-x64', 'linux-ia32']
end

########################################################################
Expand Down Expand Up @@ -89,19 +97,51 @@ def download_new_ver

# do each platform
@platforms.each do |p|
is_linux = p.start_with?('linux')

# ext name
ext = is_linux ? 'tar.gz' : 'zip'

# download
file = download_file "#{@url}v#{latest.to_s}/nwjs-v#{latest.to_s}-#{p}.zip", "cache/#{latest.to_s}/#{p}"
file = download_file "#{@url}v#{latest.to_s}/nwjs-v#{latest.to_s}-#{p}.#{ext}", "cache/#{latest.to_s}/#{p}"

# extract zip file
puts
$stdout.flush
puts 'Extracting zip files...'

Zip::ZipFile.open(file) do |zip_file|
zip_file.each do |f|
f_path = File.join("cache/#{latest.to_s}", f.name)
FileUtils.mkdir_p(File.dirname(f_path))
zip_file.extract(f, f_path) unless File.exist?(f_path)
puts 'Extracting zip/tar files...'

if is_linux
destination = "cache/#{latest.to_s}"
Gem::Package::TarReader.new( Zlib::GzipReader.open file ) do |tar|
dest = nil
tar.each do |entry|
if entry.full_name == '././@LongLink'
dest = File.join destination, entry.read.strip
next
end
dest ||= File.join destination, entry.full_name
if entry.directory?
File.delete dest if File.file? dest
FileUtils.mkdir_p dest, :mode => entry.header.mode, :verbose => false
elsif entry.file?
FileUtils.rm_rf dest if File.directory? dest
File.open dest, "wb" do |f|
f.print entry.read
end
FileUtils.chmod entry.header.mode, dest, :verbose => false
elsif entry.header.typeflag == '2' #Symlink!
File.symlink entry.header.linkname, dest
end
dest = nil
end
end
else
Zip::ZipFile.open(file) do |zip_file|
zip_file.each do |f|
f_path = File.join("cache/#{latest.to_s}", f.name)
FileUtils.mkdir_p(File.dirname(f_path))
zip_file.extract(f, f_path) unless File.exist?(f_path)
end
end
end

Expand Down Expand Up @@ -198,7 +238,10 @@ def generate_app
elsif p.start_with? 'win'
FileUtils::copy_entry "#{@cache_dir}/#{@latest_version}/#{p}", "#{folder}/#{p}/#{@app_name}"
FileUtils::cp "#{@build_dir}/app.nw", "#{folder}/#{p}/#{@app_name}/package.nw"
end
elsif p.start_with? 'linux'
FileUtils::copy_entry "#{@cache_dir}/#{@latest_version}/#{p}", "#{folder}/#{p}/#{@app_name}"
FileUtils::cp "#{@build_dir}/app.nw", "#{folder}/#{p}/#{@app_name}/package.nw"
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion judge/python/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_anagram(a0, a1):
t0, t1 = copy.deepcopy(a0), copy.deepcopy(a1)
t0.sort()
t1.sort()
return cmp(t0, t1) == 0
return (t0 > t1) - (t0 < t1) == 0

# loaders
def read_tree(f, nums):
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "judge_fgdsb",
"version": "0.0.6",
"version": "0.0.7",
"author": "Yanxing Wang <demiwangya@gmail.com>",
"main": "app/index.html",
"dev": true,
Expand Down

0 comments on commit 2496d8a

Please sign in to comment.