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/applicationalreadyexistserror.rb
Overview
Zeno module
Copyright (C) 2016 Michel Megens <dev@bietje.net>
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, Solution
Constant Summary collapse
- VERSION =
'0.1.3'
Class Method Summary collapse
-
.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
.download(out, target) ⇒ Object
Download a specific version of ETA/OS.
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/zeno.rb', line 310 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}") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) response = http.request(request) zip = Tempfile.new("etaos-#{ref}.zip", Dir.tmpdir, 'wb+') zip.binmode zip.write(response.body) 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.
302 303 304 305 |
# File 'lib/zeno.rb', line 302 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.
288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/zeno.rb', line 288 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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/zeno.rb', line 38 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.
203 204 205 206 207 208 209 210 211 212 213 214 215 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 |
# File 'lib/zeno.rb', line 203 def start_app(args) = OpenStruct.new .name = nil .epath = nil .app = false .libdir = nil .target = nil parser = OptionParser.new do |opts| opts. = "Usage: zeno app [options]" opts.separator "" opts.separator "Specific options:" # Mandatory opts.on("-r", "--root PATH", "Absolute 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", "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.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] missing = mandatory.select do |param| if [param].nil? or [param] == false param end end unless missing.empty? puts "Missing mandatory arguments" puts "" puts parser exit end begin scaffolder = Zeno::Application.new(.name, .epath, .libdir, .target) scaffolder.create scaffolder.generate rescue ApplicationAlreadyExistsError => e puts "Error: #{e.message}" exit end end |
.start_get(args) ⇒ Object
Start the get subcommand.
64 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 |
# File 'lib/zeno.rb', line 64 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.
112 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 |
# File 'lib/zeno.rb', line 112 def start_solution(args) = OpenStruct.new .name = nil .path = Dir.pwd .libdir = nil .target = nil .version = nil .apps = 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", "Path to the ETA/OS libraries") do |path| .libdir = File. path end opts.on("-a", "--apps APPS", "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.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, :libdir, :target] missing = mandatory.select do |param| if [param].nil? or [param] == false param end end unless missing.empty? puts "Missing mandatory options!" puts "" 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 solution = Zeno::Solution.new(opts) solution.create end |