module Neutron
Main module
Constants
- VERSION
Public Class Methods
cat(*files, out, **opts)
click to toggle source
# File lib/neutron.rb, line 42 def self.cat(*files, out, **opts) out = File.expand_path(out) File.delete(out) if File.exist?(out) f = File.open(out, 'w') puts "] Open: #{out}" if opts[:prepend] f.write(opts[:prepend]) puts "] Prepended content to #{out}" end files.each do |s| s = File.expand_path(s) f.write(File.read(s)) puts "] Write #{s} to #{out}" end f.close puts "] Close: #{out}" end
clean(*files)
click to toggle source
# File lib/neutron/clean.rb, line 4 def self.clean(*files) files << Neutron::PkgStatus::FNAME files.map! do |file| File.expand_path(file) end files.each do |file| if File.exist?(file) Neutron.execute( "rm -r #{file}", must_success: true ) end end end
execute(string, **opts)
click to toggle source
Executes given command @param [String] string Command to execute @param [Hash] opts @option opts [Boolean] :must_success If exit code is not 0 - raises an exception @return [Array] Output and exit code
# File lib/neutron.rb, line 112 def self.execute(string, **opts) puts "> #{string}" stdin, stdout, waiter = *Open3.popen2e(string) out = '' while s = stdout.getc print s out << s end stdin.close stdout.close if opts[:must_success] and waiter.value.exitstatus != 0 raise Neutron::ExecutionError, "Exitcode #{waiter.value.exitstatus} returned!" end return [out, waiter.value.exitstatus] end
file_to_ext(f, ext)
click to toggle source
# File lib/neutron.rb, line 33 def self.file_to_ext(f, ext) m = /(.+)\..+/.match(f) if m m[1] + ext else f + ext end end
files(sources, t_ext)
click to toggle source
Returns list of files which need to be processed @param [Array<String>] sources @param [String] t_ext Target extension @return [Neutron::FilePairList<FilePair>]
# File lib/neutron.rb, line 85 def self.files(sources, t_ext) targets = sources.ext(t_ext) pairs = sources.zip(targets) pairs = pairs.keep_if do |item| source = item[0] target = item[1] if File.exist? target st = File.stat(File.expand_path(source)).mtime tt = File.stat(File.expand_path(target)).mtime if st > tt true else false end else true end end pairs.map!{|item| Neutron::FilePair.new(item[0], item[1])} Neutron::FilePairList.new(pairs) end
install(*files, dir)
click to toggle source
# File lib/neutron/install.rb, line 4 def self.install(*files, dir) prefix = if ENV['PREFIX'] then ENV['PREFIX'] else '/usr' end dir = File.expand_path(File.join(prefix, dir)) sudo = if ENV['USE_SUDO'] then 'sudo ' else '' end unless File.exist? dir Neutron.execute( "#{sudo}mkdir --parents --mode=755 #{dir}", must_success: true ) end files.each do |file| p file dn = File.join(dir, File.dirname(file)) p dn #file = File.expand_path(file) unless File.exist?(dn) Neutron.execute("#{sudo}mkdir --parents --mode=755 #{dn}") end Neutron.execute( "#{sudo}rsync -a --relative --chmod=755 #{file} #{dir}/", must_success: true ) end end