fedux_org-stdlib 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31db18c4ed616bb7c477b7669fb4a884a5951ad9
4
- data.tar.gz: a6e28c08271d0c328e5465dccc9035fc779e5ad6
3
+ metadata.gz: 1c2e096b92bc1d2125c38615514cd90d45e16326
4
+ data.tar.gz: 079ff1edb1d88d57f32abc49f374e9b8bdd4e913
5
5
  SHA512:
6
- metadata.gz: 0776e830115fd6e002abd29ebe3f4a545481a50d9bb938459062c040d9359c640ac6e2c5bc63c872b6d5d1fec5834c88b2ef0845e1553e946889214c302a88c6
7
- data.tar.gz: 1317c081ebb2d9efccfa74d4ac2bb4a9a458ed46f50e9189eaeb6d043d786ef04fbbd20885fdd319f9dc30539dc98aee667edf62b0858721e1467930e76863fa
6
+ metadata.gz: af0bc7a4cc94d94bb1e2566c7111dfddcf27f8089a12f387063f4ac87f8a175f7592b295f48550666a9b0913186d1101ed14ae49303dbdc09f80c70017820130
7
+ data.tar.gz: f2e87f3f819133f2da4d19f5e72138a26fbdf04210bc486c2373e3ea765352d656187e79fd94b1ebff06ee90e3c20ff1a95a2174fe4b672f4d11145ecd25b190
data/Gemfile CHANGED
@@ -41,6 +41,7 @@ group :development, :test do
41
41
  gem 'travis-lint'
42
42
  gem 'facter'
43
43
  gem 'hirb'
44
+ gem 'excon'
44
45
  # gem 'tty'
45
46
  #
46
47
  gem 'rugged'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fedux_org-stdlib (0.10.9)
4
+ fedux_org-stdlib (0.11.0)
5
5
  activesupport
6
6
 
7
7
  PATH
@@ -58,6 +58,7 @@ GEM
58
58
  diff-lcs (1.2.5)
59
59
  docile (1.1.5)
60
60
  erubis (2.7.0)
61
+ excon (0.41.0)
61
62
  facter (2.3.0)
62
63
  CFPropertyList (~> 2.2.6)
63
64
  ffi (1.9.6)
@@ -166,6 +167,7 @@ DEPENDENCIES
166
167
  coveralls
167
168
  cucumber
168
169
  erubis
170
+ excon
169
171
  facter
170
172
  fedux_org-stdlib!
171
173
  fedux_org_stdlib-fixtures-plugin_manager-load!
data/Rakefile CHANGED
@@ -3,6 +3,7 @@
3
3
  $LOAD_PATH << File.expand_path('../lib', __FILE__)
4
4
 
5
5
  require 'fedux_org_stdlib/rake_tasks'
6
+ require 'fedux_org_stdlib/rake_tasks/webserver'
6
7
 
7
8
  desc 'Show help for rake'
8
9
  task :default do
@@ -5,7 +5,7 @@ require 'fedux_org_stdlib/process_environment'
5
5
  require 'fedux_org_stdlib/core_ext/array/list'
6
6
  require 'fedux_org_stdlib/core_ext/hash/list'
7
7
  require 'fedux_org_stdlib/logging/logger'
8
- require_library %w(json psych active_support/core_ext/hash/keys active_support/core_ext/string/inflections set active_support/core_ext/hash/slice active_support/core_ext/object/blank active_support/core_ext/hash/keys)
8
+ require_library %w(json psych active_support/core_ext/hash/reverse_merge active_support/core_ext/hash/keys active_support/core_ext/string/inflections set active_support/core_ext/hash/slice active_support/core_ext/object/blank active_support/core_ext/hash/keys)
9
9
 
10
10
  module FeduxOrgStdlib
11
11
  # This class makes a config file available as an object. The config file
@@ -1,11 +1,10 @@
1
1
  # encoding: utf-8
2
2
  require 'fedux_org_stdlib/require_files'
3
3
  require 'fedux_org_stdlib/rake/task'
4
- require_library %w(i18n)
5
- require 'tmpdir'
6
- require 'fileutils'
7
4
  require 'digest/sha2'
8
5
 
6
+ require_library %w(active_support/core_ext/string/strip excon addressable/uri)
7
+
9
8
  module FeduxOrgStdlib
10
9
  module Rake
11
10
  # Webserver Task
@@ -14,67 +13,102 @@ module FeduxOrgStdlib
14
13
  class WebserverTask < Task
15
14
  # @!attribute [r] report
16
15
  # The report to be generated
17
- attr_reader :repository, :build_directory, :directory
16
+ attr_reader :site, :directory, :index_file_content, :files, :checksums_file, :checksums
18
17
 
19
18
  # Create a new webserver task
20
19
  #
21
20
  # @param [String] directory
22
21
  # The directory where the generated server should be stored
23
- # @param [String] repository_url
22
+ # @param [String] url
24
23
  # The url which should be used to fetch the remote repository
25
- # @param [Array] build_directory (/tmp/webserver.xxx)
26
- # The directory where the executables should be build
27
- # @param [Array] build_script (build.sh)
28
- # The script which should be used to build the executables
29
- #
30
24
  # @example Create new task
31
25
  # FeduxOrgStdlib::Rake::WebserverTask.new
32
26
  def initialize(
33
27
  directory: File.expand_path('utils/server'),
34
- repository_url: 'https://github.com/dg-ratiodata/local_webserver',
35
- build_directory: Dir.mktmpdir('webserver'),
36
- build_script: 'build.sh',
28
+ site: 'http://fedux.org/downloads/local_webserver',
29
+ checksums_file: 'CHECKSUMS',
30
+ index_file_content: nil,
31
+ files: %w(
32
+ private_server.darwin.amd64
33
+ private_server.linux.amd64
34
+ private_server.windows.amd64.exe
35
+ public_server.darwin.amd64
36
+ public_server.linux.amd64
37
+ public_server.windows.amd64.exe
38
+ ),
39
+ redirect_to: nil,
37
40
  **args
38
41
  )
39
42
  super(**args)
40
43
 
41
- @repository = FeduxOrgStdlib::RemoteRepository.new(repository_url)
42
- @directory = File.expand_path(directory)
43
- @build_directory = File.expand_path(build_directory)
44
- @build_script = build_script
44
+ @site = Addressable::URI.heuristic_parse(site)
45
+ @files = Array(files)
46
+ @checksums_file = checksums_file
47
+ @directory = File.expand_path(directory)
48
+ @index_file_content = if index_file_content
49
+ index_file_content
50
+ elsif redirect_to
51
+ redirect_to_destination(redirect_to)
52
+ else
53
+ nil
54
+ end
45
55
  end
46
56
 
47
57
  # @private
48
58
  def run_task(_verbose)
49
- create_build_directory
50
- fetch_repository
51
- build_server
52
- copy_files_to_destination_directory
59
+ fetch_checksums
60
+ fetch_files
61
+ create_index_file unless index_file_content.blank?
53
62
  end
54
63
 
55
64
  private
56
65
 
57
- def create_build_directory
58
- FileUtils.mkdir_p build_directory
66
+ def create_index_file
67
+ File.write(File.join(directory, 'index.html'), index_file_content)
59
68
  end
60
69
 
61
- def fetch_repository
62
- repository.clone_to build_directory
70
+ def redirect_to_destination(destination)
71
+ <<-EOS.strip_heredoc
72
+ <head>
73
+ <meta http-equiv="refresh" content="0; URL=#{destination}">
74
+ </head>
75
+ EOS
63
76
  end
64
77
 
65
- def build_server
66
- Dir.chdir build_directory do
67
- system File.join('.', build_script)
78
+ def fetch_checksums
79
+ url = site.to_s + '/' + checksums_file
80
+ response = Excon.get(url)
81
+
82
+ puts "[INFO] Fetching #{url}."
83
+ fail "[ERROR] Error while downloading #{url}." unless response.status == 200
84
+
85
+ @checksums = response.body.split("\n").each_with_object({}) do |e,a|
86
+ sum, file = e.split(/\s+/)
87
+
88
+ a[file] = sum
68
89
  end
69
90
  end
70
91
 
71
- def copy_files_to_destination_directory
72
- FileUtils.mkdir_p directory
73
- FileUtils.cp new_executable_files, directory
92
+ def fetch_files
93
+ files.each do |f|
94
+ url = site.to_s + '/' + f
95
+
96
+ puts "[INFO] Fetching #{url}"
97
+ response = Excon.get(url)
98
+
99
+ fail "[ERROR] Error while downloading \"#{url}\"." unless response.status == 200
100
+ puts "[INFO] Checking downloaded content against checksum \"#{checksums[f]}\"."
101
+ fail "[ERROR] Checksum error for file \"#{url}\"." unless has_checksum?(response.body, checksums[f])
102
+
103
+ path = File.join(directory, f)
104
+ puts "[INFO] Save content to #{path}."
105
+ FileUtils.mkdir_p File.dirname(path)
106
+ File.write(path, response.body)
107
+ end
74
108
  end
75
109
 
76
- def new_executable_files
77
- Dir.glob(File.join(build_directory, '**', '*')).select { |f| File.executable? f }
110
+ def has_checksum?(file, sum)
111
+ Digest::SHA256.hexdigest(file) == sum
78
112
  end
79
113
  end
80
114
  end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ require 'fedux_org_stdlib/rake/webserver_task'
3
+
4
+ FeduxOrgStdlib::Rake::WebserverTask.new(
5
+ name: 'webserver:fetch',
6
+ description: 'Fetch and build standalone webserver'
7
+ )
@@ -15,7 +15,7 @@ module FeduxOrgStdlib
15
15
  end
16
16
 
17
17
  def clone_to(directory)
18
- Rugged::Repository.clone_at(url.to_s, directory)
18
+ system("git clone #{url.to_s} #{directory} >/dev/null 2>&1")
19
19
  end
20
20
  end
21
21
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # FeduxOrgStdlib
3
3
  module FeduxOrgStdlib
4
- VERSION = '0.11.0'
4
+ VERSION = '0.11.1'
5
5
  end
@@ -3,6 +3,7 @@
3
3
  $LOAD_PATH << File.expand_path('../lib', __FILE__)
4
4
 
5
5
  require 'fedux_org_stdlib/rake_tasks'
6
+ require 'fedux_org_stdlib/rake_tasks/webserver'
6
7
 
7
8
  desc 'Show help for rake'
8
9
  task :default do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedux_org-stdlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Meyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-28 00:00:00.000000000 Z
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -151,6 +151,7 @@ files:
151
151
  - lib/fedux_org_stdlib/rake_tasks/tests/cucumber.rb
152
152
  - lib/fedux_org_stdlib/rake_tasks/tests/rspec.rb
153
153
  - lib/fedux_org_stdlib/rake_tasks/tests/travis.rb
154
+ - lib/fedux_org_stdlib/rake_tasks/webserver.rb
154
155
  - lib/fedux_org_stdlib/recursive_file_finder.rb
155
156
  - lib/fedux_org_stdlib/remote_repository.rb
156
157
  - lib/fedux_org_stdlib/require_files.rb