Skip to content

Instantly share code, notes, and snippets.

@AlexTalker
Created March 31, 2014 21:16
Show Gist options
  • Save AlexTalker/9902565 to your computer and use it in GitHub Desktop.
Save AlexTalker/9902565 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
class Package
Makepkg = '/usr/bin/makepkg'
Pacman = '/usr/bin/pacman'
LogBuild = 'manager-build.log'
LogInstall = 'manager-install.log'
def initialize(file='PKGBUILD')
raise ArgumentErorr, "Package: argument must respond to to_s" unless file.respond_to? :to_s
@file = file.to_s
end
def build
system(Makepkg, '-s', '-p',@file, '--noconfirm', '-L', LogBuild)
$? == 0
end
def install
system(Makepkg, '-i', '--noconfirm', '--logfile', LogInstall, '--skipchecksums')
$? == 0
end
end
def cd(i)
begin
Dir.chdir(i)
rescue
puts "An error happened in cd().Path don't found: #{i}"
false
end
end
key, *args = ARGV.clone
def eaching(args)
args.each do |package|
if cd(package)
p = Package.new
yield p,package
end
end
end
Help = <<TEXT
build <packages> -- build packages in directories at it with name like name package
install <packages> -- build packages in directories at it with name like name package
help -- get this help
TEXT
case key
when 'help'
puts Help
when 'build'
eaching(args) do |p,name|
puts "Build Error in package #{name}" unless p.build
cd('..')
end
when 'install'
eaching(args) do |p,name|
puts "Install Error in package #{name}" unless p.install
cd('..')
end
else
puts "Unsuppported key, write 'manager help' for get help!"
end
# ARGV.each { |package|
# if cd(package)
# system('pwd')
# cd('..')
# end
# }
@jhass
Copy link

jhass commented Mar 31, 2014

(20:47:58) jhass: I prefer constants to be in SCREAMING_SNAKE_CASE
and not in CamlCase which is for classes and modules, but that's style
(20:49:05) jhass: Kernel#system already returns true/false depending on 
non-zero exit code, so $? == 0 is redundant
(21:47:36) jhass: use more newlines
(21:47:59) jhass: separate methods and class definitions and
code blocks with empty lines 
(21:48:40) jhass: def foo; begin; ...; rescue; ...end; end; -> def foo; ...; rescue; ...; end;,
 methods have an implicit begin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment