zeno 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0e9663b92c8a4e45072629e98ef83c2a00998858
4
+ data.tar.gz: e2f951043000b9c55f990867f0c99c091c96c757
5
+ SHA512:
6
+ metadata.gz: e7a5e1fa8a37ddbc6aa40bcc57ff916b01306f4a313c88bfad80c07cd813bdf29151dea256a3f2add7e83194adde7264a2c8ef4d304c4527d0f13440cbdad8bb
7
+ data.tar.gz: c01e0b76e9933be79f4accd1847876bf059892c31716ceaad268fd9f3ec4094cc98d7b9e989b921fc739695455cdfdb9c6049359e3fbc6cadfaccf6ce3c0435b
data/bin/zeno ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDOUT.sync = true
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), *%w(.. lib)))
5
+
6
+ require 'zeno'
7
+
8
+ Zeno.start(ARGV)
9
+
@@ -0,0 +1,33 @@
1
+ #
2
+ # Zeno module
3
+ # Copyright (C) 2016 Michel Megens <dev@bietje.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ module Zeno
20
+ class ApplicationAlreadyExistsError < StandardError
21
+ attr_reader :msg
22
+
23
+ @msg = nil
24
+ def initialize(msg = nil)
25
+ @msg = msg || "The requested application name already exists!"
26
+ end
27
+
28
+ def message
29
+ @msg
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,57 @@
1
+ #
2
+ # Zeno module
3
+ # Copyright (C) 2016 Michel Megens <dev@bietje.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ module Zeno
20
+ class FileGenerator
21
+ attr_reader :path, :vars
22
+
23
+ @path = nil
24
+ @vars = nil
25
+
26
+ def initialize(path)
27
+ @path = path
28
+ @vars = Hash.new
29
+ end
30
+
31
+ def add_var(name, value, assign = '=')
32
+ @vars[name] = value
33
+ end
34
+
35
+ def del_var(name)
36
+ @vars.delete name
37
+ end
38
+
39
+ def generate
40
+ File.open(path, 'w') do |file|
41
+ file.puts self.to_s
42
+ end
43
+
44
+ nil
45
+ end
46
+
47
+ def to_s
48
+ output = ""
49
+ @vars.each do |key, value|
50
+ output += "#{key}=#{value}\n"
51
+ end
52
+
53
+ output
54
+ end
55
+ end
56
+ end
57
+
@@ -0,0 +1,61 @@
1
+ #
2
+ # Zeno module
3
+ # Copyright (C) 2016 Michel Megens <dev@bietje.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'zeno/filegenerator'
20
+
21
+ module Zeno
22
+ class Makefile < Zeno::FileGenerator
23
+ def initialize(path)
24
+ super
25
+ @targets = Hash.new
26
+ end
27
+
28
+ def add_target(target, rules)
29
+ @targets[target] = rules
30
+ end
31
+
32
+ def generate
33
+ File.open(@path, 'w') do |makefile|
34
+ makefile.puts self.to_s
35
+ end
36
+
37
+ nil
38
+ end
39
+
40
+ def to_s
41
+ output = super
42
+
43
+ output += "\n"
44
+ @targets.each do |key, value|
45
+ output += "#{key}:\n"
46
+ if value.is_a? Array
47
+ value.each do |e|
48
+ output += "\t#{e}\n"
49
+ end
50
+ else
51
+ output += "\t#{value}\n"
52
+ end
53
+
54
+ output += "\n"
55
+ end
56
+
57
+ output
58
+ end
59
+ end
60
+ end
61
+
@@ -0,0 +1,72 @@
1
+ #
2
+ # Zeno module
3
+ # Copyright (C) 2016 Michel Megens <dev@bietje.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'fileutils'
20
+
21
+ require 'zeno/makefile'
22
+ require 'zeno/filegenerator'
23
+ require 'zeno/applicationalreadyexistserror'
24
+
25
+ module Zeno
26
+ class Scaffolder
27
+ attr_reader :dirname, :etaos_path, :arch, :libdir
28
+
29
+ def initialize(name, path, libdir, arch)
30
+ @dirname = name
31
+ @etaos_path = path
32
+ @libdir = libdir
33
+ @arch = arch
34
+ end
35
+
36
+ def create
37
+ raise Zeno::ApplicationAlreadyExistsError if File.directory? @dirname
38
+ FileUtils.mkdir_p @dirname
39
+ end
40
+
41
+ def generate
42
+ generate_mkfile
43
+ generate_kbuildfile
44
+ end
45
+
46
+ private
47
+
48
+ def generate_mkfile
49
+ target_rule = "@$(MAKE) -C $(ETAOS) A=#{Dir.pwd}/#{@dirname} ARCH=#{@arch} CROSS_COMPILE=#{@arch}-"
50
+ file = "#{@dirname}/Makefile"
51
+ mkfile = Zeno::Makefile.new file
52
+ mkfile.add_var('ETAOS', @etaos_path)
53
+ mkfile.add_target('all', target_rule + " app")
54
+ mkfile.add_target('clean', target_rule + " clean")
55
+ mkfile.generate
56
+ end
57
+
58
+ def generate_kbuildfile
59
+ file = "#{@dirname}/Kbuild"
60
+ gen = Zeno::FileGenerator.new file
61
+ gen.add_var('obj-y', '# TODO: add source files', '+=')
62
+ gen.add_var('crurom-y', '# TODO: add crurom directory or delete this line', ':=')
63
+ gen.add_var('crurom-obj', '# TODO: add crurom object file or delete this line', ':=')
64
+ gen.add_var('ETAOS_LIBS', '-lc', '+=')
65
+ gen.add_var('ETAOS_LIB_DIR', @libdir, ':=')
66
+ gen.add_var('APP_TARGET', "#{@dirname}.img", ':=')
67
+ gen.add_var('clean-files', "#{@dirname}.img", '+=')
68
+ gen.generate
69
+ end
70
+ end
71
+ end
72
+
@@ -0,0 +1,3 @@
1
+ module Zeno
2
+ VERSION = '0.0.1'
3
+ end
data/lib/zeno.rb ADDED
@@ -0,0 +1,325 @@
1
+ #
2
+ # Zeno module
3
+ # Copyright (C) 2016 Michel Megens <dev@bietje.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'optparse'
20
+ require 'optparse/time'
21
+ require 'ostruct'
22
+ require 'tempfile'
23
+ require 'pp'
24
+ require 'zip'
25
+
26
+ require 'net/http'
27
+
28
+ require 'zeno/version'
29
+ require 'zeno/scaffolder'
30
+ require 'zeno/applicationalreadyexistserror'
31
+
32
+ module Zeno
33
+ class << self
34
+ def start(args)
35
+ case args.shift
36
+ when 'app'
37
+ start_app(args)
38
+ when 'get'
39
+ start_get(args)
40
+ when 'solution'
41
+ start_solution(args)
42
+ when '-v'
43
+ puts "Zeno #{Zeno::VERSION}"
44
+ exit
45
+ when '--version'
46
+ puts "Zeno #{Zeno::VERSION}"
47
+ exit
48
+ else
49
+ puts "Usage: zeno <command> <args>"
50
+ puts ""
51
+ puts "Available commands are:"
52
+ puts " app\tScaffolder to create new ETA/OS applications"
53
+ puts " get\tETA/OS download service"
54
+ end
55
+ end
56
+
57
+ def start_get(args)
58
+ options = OpenStruct.new
59
+ options.output = Dir.pwd
60
+ options.target = 'stable'
61
+
62
+ parser = OptionParser.new do |opts|
63
+ opts.banner = "Usage: zeno get [options]"
64
+ opts.separator ""
65
+ opts.separator "Specific options:"
66
+
67
+ opts.on('-o', '--output PATH',
68
+ 'Place to dump the ETA/OS download') do |path|
69
+ options.output = path
70
+ end
71
+
72
+ opts.on('-t', '--target TARGET',
73
+ 'Download target. Available targets are: stable, old-stable and bleeding.') do |target|
74
+ options.target = target
75
+ end
76
+
77
+ opts.on('-V', '--versions',
78
+ 'List all available ETA/OS versions.') do
79
+ puts "Available ETA/OS versions:"
80
+ puts ""
81
+ puts Zeno.get_versions
82
+ exit
83
+ end
84
+
85
+ opts.separator ""
86
+ opts.separator "Common options:"
87
+
88
+ opts.on_tail("-h", "--help", "Show this message") do
89
+ puts opts
90
+ exit
91
+ end
92
+
93
+ opts.on_tail("-v", "--version", "Print the Zeno version") do
94
+ puts "Zeno #{Zeno::VERSION}"
95
+ exit
96
+ end
97
+ end
98
+
99
+ parser.parse!
100
+ Zeno.download(options.output, options.target)
101
+ end
102
+
103
+ def start_solution(args)
104
+ options = OpenStruct.new
105
+ options.name = nil
106
+ options.path = Dir.pwd
107
+ options.libdir = nil
108
+ options.target = nil
109
+ options.version = nil
110
+
111
+ parser = OptionParser.new do |opts|
112
+ opts.banner = "Usage: zeno solution [options]"
113
+ opts.separator ""
114
+ opts.separator "Specific options:"
115
+
116
+ opts.on("-b", "--base PATH",
117
+ "Solution base path") do |path|
118
+ options.path = path || Dir.pwd
119
+ end
120
+
121
+ # Mandatory
122
+ opts.on("-n", "--name NAME",
123
+ "Solution name") do |name|
124
+ options.name = name
125
+ end
126
+
127
+ # Mandatory
128
+ opts.on("-l", "--libs PATH",
129
+ "Path to the ETA/OS libraries") do |path|
130
+ options.libdir = path
131
+ end
132
+
133
+ # Mandatory
134
+ opts.on("-t", "--target TARGET",
135
+ "ETA/OS target architecture") do |arch|
136
+ options.target = arch
137
+ end
138
+
139
+ opts.on("-V", "-ref VERSION",
140
+ "ETA/OS version (git ref) to download") do |ref|
141
+ options.version = ref
142
+ end
143
+
144
+ opts.separator ""
145
+ opts.separator "Common options:"
146
+
147
+ opts.on_tail("-h", "--help", "Show this message") do
148
+ puts opts
149
+ exit
150
+ end
151
+
152
+ opts.on_tail("-v", "--version", "Print the Zeno version") do
153
+ puts "Zeno #{Zeno::VERSION}"
154
+ exit
155
+ end
156
+ end
157
+
158
+ parser.parse!
159
+
160
+ mandatory = [:name, :libdir, :target]
161
+ missing = mandatory.select do |param|
162
+ if options[param].nil? or options[param] == false
163
+ param
164
+ end
165
+ end
166
+
167
+ unless missing.empty?
168
+ puts "Missing mandatory options!"
169
+ puts ""
170
+ puts parser
171
+ exit
172
+ end
173
+
174
+ ref = Zeno.parse_target(options.version)
175
+ etaos_path = "../etaos-#{ref}"
176
+ Zeno.download(options.path, options.version)
177
+
178
+ begin
179
+ Dir.chdir options.name
180
+ scaffolder = Zeno::Scaffolder.new(options.name, etaos_path,
181
+ options.libdir, options.target)
182
+ scaffolder.create
183
+ scaffolder.generate
184
+ rescue ApplicationAlreadyExistsError => e
185
+ puts "Error: #{e.message}"
186
+ exit
187
+ end
188
+ end
189
+
190
+ def start_app(args)
191
+ options = OpenStruct.new
192
+ options.name = nil
193
+ options.epath = nil
194
+ options.app = false
195
+ options.libdir = nil
196
+ options.target = nil
197
+
198
+ parser = OptionParser.new do |opts|
199
+ opts.banner = "Usage: zeno app [options]"
200
+ opts.separator ""
201
+ opts.separator "Specific options:"
202
+
203
+ # Mandatory
204
+ opts.on("-r", "--root PATH",
205
+ "Absolute path to ETA/OS") do |path|
206
+ options.epath = path
207
+ end
208
+
209
+ # Mandatory
210
+ opts.on("-n", "--name NAME",
211
+ "Name of the application") do |name|
212
+ options.name = name
213
+ end
214
+
215
+ # Mandatory
216
+ opts.on("-l", "--libs PATH",
217
+ "Path to the ETA/OS libraries") do |path|
218
+ options.libdir = path
219
+ end
220
+
221
+ # Mandatory
222
+ opts.on("-t", "--target TARGET",
223
+ "Target architecture") do |target|
224
+ options.target = target
225
+ end
226
+
227
+ opts.separator ""
228
+ opts.separator "Common options:"
229
+
230
+ opts.on_tail("-h", "--help", "Show this message") do
231
+ puts opts
232
+ exit
233
+ end
234
+
235
+ opts.on_tail("-v", "--version", "Print the Zeno version") do
236
+ puts "Zeno #{Zeno::VERSION}"
237
+ exit
238
+ end
239
+ end
240
+
241
+ parser.parse!(args)
242
+ options.app = true
243
+
244
+ mandatory = [:app, :epath, :name, :target, :libdir]
245
+ missing = mandatory.select do |param|
246
+ if options[param].nil? or options[param] == false
247
+ param
248
+ end
249
+ end
250
+
251
+ unless missing.empty?
252
+ puts "Missing mandatory arguments"
253
+ puts ""
254
+ puts parser
255
+ exit
256
+ end
257
+
258
+ begin
259
+ scaffolder = Zeno::Scaffolder.new(options.name, options.epath,
260
+ options.libdir, options.target)
261
+ scaffolder.create
262
+ scaffolder.generate
263
+ rescue ApplicationAlreadyExistsError => e
264
+ puts "Error: #{e.message}"
265
+ exit
266
+ end
267
+ end
268
+
269
+ def parse_target(target)
270
+ ref = target
271
+ odd_versions = ['stable', 'latest', 'old-stable', 'bleeding']
272
+
273
+ if odd_versions.include? target
274
+ uri = URI("http://zeno.bietje.net/#{target}.txt")
275
+ ref = Net::HTTP.get(uri)
276
+ end
277
+
278
+ ref
279
+ end
280
+
281
+ def get_versions
282
+ uri = URI("http://zeno.bietje.net/versions.txt")
283
+ Net::HTTP.get(uri)
284
+ end
285
+
286
+ def download(out, target)
287
+ # The correct git refs for the target can be found using the Zeno
288
+ # web service (zeno.bietje.net).
289
+ first = true
290
+ silly_name = nil
291
+ ref = Zeno.parse_target(target)
292
+ ref.strip!
293
+ uri = URI("https://git.bietje.net/etaos/etaos/repository/archive.zip?ref=#{ref}")
294
+ http = Net::HTTP.new(uri.host, uri.port)
295
+ http.use_ssl = true
296
+
297
+ request = Net::HTTP::Get.new(uri.request_uri)
298
+ response = http.request(request)
299
+ zip = Tempfile.new("etaos-#{ref}.zip", Dir.tmpdir, 'wb+')
300
+ zip.binmode
301
+ zip.write(response.body)
302
+ path = zip.path
303
+ zip.close
304
+
305
+ Zip::File.open(path) do |zip_file|
306
+ zip_file.each do |f|
307
+ if first
308
+ silly_name = f.name
309
+ first = false
310
+ end
311
+
312
+ f_path = File.join(out, f.name)
313
+ FileUtils.mkdir_p(File.dirname(f_path))
314
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
315
+ end
316
+ end
317
+
318
+ # fix the silly top dir name
319
+ f_path = File.join(out, silly_name)
320
+ f_path_new = File.join(out, "etaos-#{ref}")
321
+ FileUtils.mv f_path, f_path_new
322
+ end
323
+ end
324
+ end
325
+
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zeno
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michel Megens
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubyzip
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.0
69
+ description: Zeno generates ETA/OS applications with a single command.
70
+ email:
71
+ - dev@bietje.net
72
+ executables:
73
+ - zeno
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - bin/zeno
78
+ - lib/zeno.rb
79
+ - lib/zeno/applicationalreadyexistserror.rb
80
+ - lib/zeno/filegenerator.rb
81
+ - lib/zeno/makefile.rb
82
+ - lib/zeno/scaffolder.rb
83
+ - lib/zeno/version.rb
84
+ homepage: http://bietje.net/zeno
85
+ licenses: []
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.8
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: ETA/OS scaffolder
107
+ test_files: []