yast-rake 0.2.36 → 0.2.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 604fa7a174e99d46c9d37b8ea3fff3d2d94ce7b6344a1d1c80bdec247203a56c
4
- data.tar.gz: a8aa455360687b68e4879732c8e28bc6e430e68dd7a3e9cec14931c10d3c0c05
3
+ metadata.gz: 98b02611f30a453046b09d43d2a9475915d3f62ddaa25e86501a8dac1d7c34ac
4
+ data.tar.gz: 72c1f696a456ea27607324326863ff0ab902e1c02d6852fe91aafa692e267e5a
5
5
  SHA512:
6
- metadata.gz: 176ca7514b8829e75d7f73d63d5279b1ac7eada517595db0a44689a84c21d71a4089136ac5cc062b0b828bade746292acb8f555248e8e24770c1d393690ce9b7
7
- data.tar.gz: 623c0548088ad30f2c7c090444df16ce266ebfa09428b59ae52e4bfd3f4925e78430b3a4a908298dea1b331e08733fa023b0f068b19801754c1a761acaf1287b
6
+ metadata.gz: 8242f408e27684ee7a5888453f9efef2bb2922d4203dba46529391bb22926a65709ad522d52ce5c641fd74b3932a2d9f24b690e5d8b41193d952602593040833
7
+ data.tar.gz: 6780d86f72ed7cd3950238d15428a5c0d83e22284ec50e1601151bd8d5ae97a29e0113e46ab45cb1eb58f33bf879c2733d1427f92289688d803b2f9e358c01e2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.36
1
+ 0.2.37
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <!-- This is a simple main page for the "rake server" task. -->
3
+ <html>
4
+ <head>
5
+ <title>Source Code Tarball Server</title>
6
+ </head>
7
+ <body>
8
+
9
+ <h1>Source Code Tarball Server</h1>
10
+ <p>This server provides dynamically generated source code tarballs.</p>
11
+
12
+ <h2>Supported URL Paths</h2>
13
+ <p>
14
+ <ul>
15
+ <li>
16
+ <b><a href = "/archive/current.tar.gz">/archive/current.tar.gz</a></b>
17
+ - dynamically generated tarball with the current source files
18
+ </li>
19
+ <li>
20
+ <b><a href = "/servers/index.json">/servers/index.json</a></b>
21
+ - index of other running servers on the machine
22
+ </li>
23
+ </ul>
24
+ </p>
25
+
26
+ </body>
27
+ </html>
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Yast rake
5
+ #
6
+ # Copyright (C) 2020, SUSE LLC
7
+ # This library is free software; you can redistribute it and/or modify
8
+ # it only under the terms of version 2.1 of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation.
10
+ #
11
+ # This library is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14
+ # details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+ require_relative "../yast/tarball_server"
22
+
23
+ # Rake task for running a source code web server,
24
+ # designed for the `yupdate` script.
25
+ desc "Start an HTTP server providing dynamically generated source code tarball"
26
+ task :server, [:port] do |_task, args|
27
+ server = Yast::TarballServer.new(args[:port])
28
+
29
+ puts "Starting tarball webserver:"
30
+ server.addresses.each { |a| puts " * #{a}" }
31
+ puts
32
+
33
+ server.start
34
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Yast rake
5
+ #
6
+ # Copyright (C) 2020, SUSE LLC
7
+ # This library is free software; you can redistribute it and/or modify
8
+ # it only under the terms of version 2.1 of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation.
10
+ #
11
+ # This library is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14
+ # details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+ require "webrick"
22
+
23
+ module Yast
24
+ # a webrick servlet which returns a basic HTML info about the server,
25
+ # just to avoid that nasty 404 error page when someone opens the
26
+ # server URL in a web browser
27
+ class IndexServlet < WEBrick::HTTPServlet::AbstractServlet
28
+ INDEX_FILE = File.expand_path("../../data/index.html", __dir__)
29
+
30
+ def do_GET(_request, response)
31
+ response.status = 200
32
+ response.content_type = "text/html"
33
+ response.body = File.read(INDEX_FILE)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Yast rake
5
+ #
6
+ # Copyright (C) 2020, SUSE LLC
7
+ # This library is free software; you can redistribute it and/or modify
8
+ # it only under the terms of version 2.1 of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation.
10
+ #
11
+ # This library is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14
+ # details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+ require "json"
22
+ require "webrick"
23
+
24
+ module Yast
25
+ # a webrick servlet which lists all rake servers running on this machine
26
+ class ServersServlet < WEBrick::HTTPServlet::AbstractServlet
27
+ def do_GET(_request, response)
28
+ response.status = 200
29
+ response.content_type = "application/json"
30
+ response.body = servers.to_json
31
+ end
32
+
33
+ private
34
+
35
+ # find the locally running "rake server" processes
36
+ def servers
37
+ output = `pgrep -a -f "rake server \\([0-9]+,.*\\)"`
38
+ output.lines.map do |l|
39
+ l.match(/rake server \(([0-9]+),(.*)\)/)
40
+ {
41
+ port: Regexp.last_match[1],
42
+ dir: Regexp.last_match[2]
43
+ }
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Yast rake
5
+ #
6
+ # Copyright (C) 2020, SUSE LLC
7
+ # This library is free software; you can redistribute it and/or modify
8
+ # it only under the terms of version 2.1 of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation.
10
+ #
11
+ # This library is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14
+ # details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+ require "webrick"
22
+ require "socket"
23
+
24
+ require_relative "index_servlet"
25
+ require_relative "servers_servlet"
26
+ require_relative "tarball_servlet"
27
+
28
+ module Yast
29
+ # a webrick server which provides the source tarballs
30
+ #
31
+ # the server handles these URL paths:
32
+ # - "/archive/current.tar.gz" - the generated source code tarball
33
+ # - "/servers/index.json" - index of the tarball servers running on this machine
34
+ # - "/" - just a simple index page
35
+ #
36
+ # to stop the server press Ctrl+C
37
+ class TarballServer
38
+ # the default port number
39
+ DEFAULT_HTTP_PORT = 8000
40
+
41
+ attr_reader :port
42
+
43
+ # create all URLs valid for this machine, use all network interfaces
44
+ # (except the loop backs, the server will be used only from outside)
45
+ # @return [Array<String>] list of URLs
46
+ def addresses
47
+ # ignore the loopback addresses
48
+ hosts = Socket.ip_address_list.reject { |a| a.ipv4_loopback? || a.ipv6_loopback? }
49
+ # IPv6 addresses need to be closed in square brackets in URLs
50
+ hosts.map! { |a| a.ipv6? ? "[#{a.ip_address}]" : a.ip_address.to_s }
51
+ # include also the hostname to make it easier to write
52
+ hostname = Socket.gethostname
53
+ hosts << hostname if !hostname&.empty?
54
+ hosts.map! { |h| "http://#{h}:#{port}" }
55
+ end
56
+
57
+ # constructor
58
+ #
59
+ # @param port [Integer,nil] the port number, if nil the port will be found automatically
60
+ #
61
+ def initialize(port = nil)
62
+ @port = port || find_port
63
+ end
64
+
65
+ # start the webserver, it can be closed by pressing Ctrl+C or by sending SIGTERM signal
66
+ def start
67
+ dir = File.basename(Dir.pwd)
68
+ # change the process title so we can find the running
69
+ # servers and their ports just by simple grepping the running processes
70
+ Process.setproctitle("rake server (#{port},#{dir})")
71
+
72
+ # Use "*" to bind also the IPv6 addresses
73
+ server = WEBrick::HTTPServer.new(Port: port, BindAddress: "*")
74
+ server.mount("/archive/current.tar.gz", TarballServlet)
75
+ server.mount("/servers/index.json", ServersServlet)
76
+ server.mount("/", IndexServlet)
77
+
78
+ # stop the server when receiving a signal like Ctrl+C
79
+ # (inspired by the "un.rb" from the Ruby stdlib)
80
+ signals = ["TERM", "QUIT"]
81
+ signals.concat(["HUP", "INT"]) if $stdin.tty?
82
+ signals.each do |s|
83
+ trap(s) { server.shutdown }
84
+ end
85
+
86
+ server.start
87
+ end
88
+
89
+ private
90
+
91
+ # is the local port already taken by some other application?
92
+ # @param port [Integer] the port number
93
+ # @return [Boolean] true if the port is taken, false otherwise
94
+ def port_taken?(port)
95
+ # open the port and close it immediately, if that succeeds
96
+ # some other application is already using it
97
+ TCPSocket.new("localhost", port).close
98
+ true
99
+ rescue Errno::ECONNREFUSED
100
+ false
101
+ end
102
+
103
+ # find a free port starting from the default port number
104
+ # @return [Integer] the free port number
105
+ def find_port
106
+ DEFAULT_HTTP_PORT.step.find { |p| !port_taken?(p) }
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Yast rake
5
+ #
6
+ # Copyright (C) 2020, SUSE LLC
7
+ # This library is free software; you can redistribute it and/or modify
8
+ # it only under the terms of version 2.1 of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation.
10
+ #
11
+ # This library is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14
+ # details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+ require "webrick"
22
+
23
+ module Yast
24
+ # a webrick servlet which dynamically creates a tarball
25
+ # with the content of the current Git checkout
26
+ class TarballServlet < WEBrick::HTTPServlet::AbstractServlet
27
+ def do_GET(_request, response)
28
+ response.status = 200
29
+ response.content_type = "application/gzip"
30
+ response.body = source_archive
31
+ end
32
+
33
+ private
34
+
35
+ # compress the current sources into a tarball,
36
+ # no caching to ensure we always provide the latest content
37
+ def source_archive
38
+ # pack all Git files (including the non-tracked files (-o),
39
+ # use --ignore-failed-read to not fail for removed files)
40
+ # -z and --null: NUL-delimited
41
+ git = "git ls-files --cached --others --exclude-standard -z"
42
+ tar = "tar --create --ignore-failed-read --null --files-from -"
43
+ `#{git} | #{tar} | #{gzip}`
44
+ end
45
+
46
+ # find which gzip is installed, use the faster parallel gzip ("pigz") if it is available
47
+ # @return [String] "pigz or "gzip"
48
+ def gzip
49
+ return @gzip if @gzip
50
+
51
+ # parallel gzip installed?
52
+ @gzip = system("which pigz") ? "pigz" : "gzip"
53
+ end
54
+ end
55
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yast-rake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.36
4
+ version: 0.2.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josef Reidinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-06 00:00:00.000000000 Z
11
+ date: 2020-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: packaging_rake_tasks
@@ -49,17 +49,23 @@ extra_rdoc_files: []
49
49
  files:
50
50
  - COPYING
51
51
  - VERSION
52
+ - data/index.html
52
53
  - data/targets.yml
53
54
  - lib/tasks/install.rake
54
55
  - lib/tasks/pot.rake
55
56
  - lib/tasks/rubocop.rake
56
57
  - lib/tasks/run.rake
58
+ - lib/tasks/server.rake
57
59
  - lib/tasks/spell.yml
58
60
  - lib/tasks/spellcheck.rake
59
61
  - lib/tasks/spellcheck_task.rb
60
62
  - lib/tasks/test_unit.rake
61
63
  - lib/tasks/version.rake
64
+ - lib/yast/index_servlet.rb
62
65
  - lib/yast/rake.rb
66
+ - lib/yast/servers_servlet.rb
67
+ - lib/yast/tarball_server.rb
68
+ - lib/yast/tarball_servlet.rb
63
69
  - lib/yast/tasks.rb
64
70
  homepage: https://github.com/yast/yast-rake
65
71
  licenses:
@@ -80,7 +86,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
86
  - !ruby/object:Gem::Version
81
87
  version: '0'
82
88
  requirements: []
83
- rubygems_version: 3.0.3
89
+ rubyforge_project:
90
+ rubygems_version: 2.7.6.2
84
91
  signing_key:
85
92
  specification_version: 4
86
93
  summary: Rake tasks providing basic work-flow for Yast development