Module: Zeno
- Defined in:
- lib/zeno.rb,
lib/zeno/version.rb,
lib/zeno/makefile.rb,
lib/zeno/solution.rb,
lib/zeno/application.rb,
lib/zeno/filegenerator.rb,
lib/zeno/missingargumentexception.rb,
lib/zeno/applicationalreadyexistserror.rb
Overview
Zeno module
Copyright (C) 2016 Michel Megens <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Defined Under Namespace
Classes: Application, ApplicationAlreadyExistsError, FileGenerator, Makefile, MissingArgumentException, Solution
Constant Summary collapse
- VERSION =
'0.2.0'
Class Method Summary collapse
-
.check_missing_args!(options, mandatory = {}) ⇒ Object
Check if any arguments are missing.
-
.download(out, target) ⇒ Object
Download a specific version of ETA/OS.
-
.get_versions ⇒ String
Get all available ETA/OS versions.
-
.parse_target(target) ⇒ String
Parse a target string (git reference).
-
.start(args) ⇒ Object
Start the Zeno application.
-
.start_app(args) ⇒ Object
Start the app subcommand.
-
.start_get(args) ⇒ Object
Start the get subcommand.
-
.start_solution(args) ⇒ Object
Start the solution subcommand.
Class Method Details
.check_missing_args!(options, mandatory = {}) ⇒ Object
Check if any arguments are missing.
377 378 379 380 381 382 383 384 385 386 |
# File 'lib/zeno.rb', line 377 def check_missing_args!(, mandatory = {}) return nil if mandatory.empty? missing = mandatory.select do |param, value| [param].nil? or [param] == false end raise Zeno::MissingArgumentException.new(missing) unless missing.empty? nil end |
.download(out, target) ⇒ Object
Download a specific version of ETA/OS.
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/zeno.rb', line 338 def download(out, target) # The correct git refs for the target can be found using the Zeno # web service (zeno.bietje.net). first = true silly_name = nil ref = Zeno.parse_target(target) ref.strip! uri = URI("https://git.bietje.net/etaos/etaos/repository/archive.zip?ref=#{ref}") response = Net::HTTP.get(uri) zip = Tempfile.new("etaos-#{ref}.zip", Dir.tmpdir, 'wb+') zip.binmode zip.write(response) path = zip.path zip.close Zip::File.open(path) do |zip_file| zip_file.each do |f| if first silly_name = f.name first = false end f_path = File.join(out, f.name) FileUtils.mkdir_p(File.dirname(f_path)) zip_file.extract(f, f_path) unless File.exist?(f_path) end end # fix the silly top dir name f_path = File.join(out, silly_name) f_path_new = File.join(out, "etaos-#{ref}") FileUtils.mv f_path, f_path_new end |
.get_versions ⇒ String
Get all available ETA/OS versions.
330 331 332 333 |
# File 'lib/zeno.rb', line 330 def get_versions uri = URI("http://zeno.bietje.net/versions.txt") Net::HTTP.get(uri) end |
.parse_target(target) ⇒ String
Parse a target string (git reference). Targets such as ‘stable’, ‘old-stable’ and ‘bleeding’ are turned into actual git refs using this method.
316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/zeno.rb', line 316 def parse_target(target) ref = target odd_versions = ['stable', 'latest', 'old-stable', 'bleeding'] if odd_versions.include? target uri = URI("http://zeno.bietje.net/#{target}.txt") ref = Net::HTTP.get(uri) end ref end |
.start(args) ⇒ Object
Start the Zeno application
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/zeno.rb', line 39 def start(args) case args.shift when 'app' start_app(args) when 'get' start_get(args) when 'solution' start_solution(args) when '-v' puts "Zeno #{Zeno::VERSION}" exit when '--version' puts "Zeno #{Zeno::VERSION}" exit else puts "Usage: zeno <command> <args>" puts "" puts "Available commands are:" puts " app\t\tApplication to create new ETA/OS applications" puts " get\t\tETA/OS download service" puts " solution\tCreate an ETA/OS solution" end end |
.start_app(args) ⇒ Object
Start the app subcommand.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/zeno.rb', line 216 def start_app(args) = OpenStruct.new .name = nil .epath = nil .app = false .libdir = nil .target = nil .uploader = nil parser = OptionParser.new do |opts| opts. = "Usage: zeno app [options]" opts.separator "" opts.separator "Specific options:" # Mandatory opts.on("-r", "--root PATH", "Path to ETA/OS") do |path| .epath = path end # Mandatory opts.on("-n", "--name NAME", "Name of the application") do |name| .name = name end # Mandatory opts.on("-l", "--libs PATH", "Relative path to the ETA/OS libraries") do |path| .libdir = path end # Mandatory opts.on("-t", "--target TARGET", "Target architecture") do |target| .target = target end opts.on("-A", "--avrupload", "Configure the application Makefiles to use avrupload") do |u| .uploader = :avrupload end opts.on("-d", "--avrdude", "Configure the application Makefiles to use avrdude") do |a| .uploader = :avrdude end opts.separator "" opts.separator "Common options:" opts.on_tail("-h", "--help", "Show this message") do puts opts exit end opts.on_tail("-v", "--version", "Print the Zeno version") do puts "Zeno #{Zeno::VERSION}" exit end end parser.parse!(args) .app = true mandatory = [:app, :epath, :name, :target, :libdir] mandatory = { :app => 'Critical failure', :epath => '-r', :name => '-n', :target => '-t', :libdir => '-l' } begin Zeno.check_missing_args!(, mandatory) rescue MissingArgumentException => e puts "#{e.msg}: #{e.missing_arguments.values.join(', ')}" puts parser exit end begin scaffolder = Zeno::Application.new(.name, .epath, .libdir, .target, .uploader) scaffolder.create scaffolder.generate rescue ApplicationAlreadyExistsError => e puts "Error: #{e.}" exit end end |
.start_get(args) ⇒ Object
Start the get subcommand.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/zeno.rb', line 65 def start_get(args) = OpenStruct.new .output = Dir.pwd .target = 'stable' parser = OptionParser.new do |opts| opts. = "Usage: zeno get [options]" opts.separator "" opts.separator "Specific options:" opts.on('-o', '--output PATH', 'Place to dump the ETA/OS download') do |path| .output = path end opts.on('-t', '--target TARGET', 'Download target. Available targets are: stable, old-stable and bleeding.') do |target| .target = target end opts.on('-V', '--versions', 'List all available ETA/OS versions.') do puts "Available ETA/OS versions:" puts "" puts Zeno.get_versions exit end opts.separator "" opts.separator "Common options:" opts.on_tail("-h", "--help", "Show this message") do puts opts exit end opts.on_tail("-v", "--version", "Print the Zeno version") do puts "Zeno #{Zeno::VERSION}" exit end end parser.parse! Zeno.download(.output, .target) end |
.start_solution(args) ⇒ Object
Start the solution subcommand.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/zeno.rb', line 113 def start_solution(args) = OpenStruct.new .name = nil .path = Dir.pwd .libdir = nil .target = nil .version = 'stable' .apps = nil .uploader = nil parser = OptionParser.new do |opts| opts. = "Usage: zeno solution [options]" opts.separator "" opts.separator "Specific options:" opts.on("-b", "--base PATH", "Solution base path") do |path| .path = path || Dir.pwd end # Mandatory opts.on("-n", "--name NAME", "Solution name") do |name| .name = name end # Mandatory opts.on("-l", "--libs PATH", "Relative path to the ETA/OS libraries") do |path| .libdir = path end opts.on("-a", "--apps APP1[,APP2,APPn]", "List of applications to generate (comma separated") do |apps| .apps = apps.split(',') end # Mandatory opts.on("-t", "--target TARGET", "ETA/OS target architecture") do |arch| .target = arch end opts.on("-V", "-ref VERSION", "ETA/OS version (git ref) to download") do |ref| .version = ref end opts.on("-A", "--avrupload", "Configure the application Makefiles to use avrupload") do |u| .uploader = :avrupload end opts.on("-d", "--avrdude", "Configure the application Makefiles to use avrdude") do |a| .uploader = :avrdude end opts.separator "" opts.separator "Common options:" opts.on_tail("-h", "--help", "Show this message") do puts opts exit end opts.on_tail("-v", "--version", "Print the Zeno version") do puts "Zeno #{Zeno::VERSION}" exit end end parser.parse! mandatory = { :name => '-n', :libdir => '-l', :target => '-t' } begin Zeno.check_missing_args!(, mandatory) rescue MissingArgumentException => e puts "#{e.msg}: #{e.missing_arguments.values.join(', ')}" puts parser exit end opts = Hash.new opts['apps'] = .apps opts['name'] = .name opts['ref'] = .version opts['libs'] = .libdir opts['path'] = .path opts['target'] = .target opts['uploader'] = .uploader solution = Zeno::Solution.new(opts) solution.create end |