lib/helpers.rb in encbs-0.1.3 vs lib/helpers.rb in encbs-0.2.0.alpha
- old
+ new
@@ -1,7 +1,7 @@
def puts_fail(msg)
- STDERR.puts "#{"Error: ".red}#{msg}"
+ STDERR.puts "#{"Error! ".red}#{msg}"
exit msg.length
end
def puts_verbose(msg)
@@ -10,19 +10,10 @@
def print_verbose(msg)
print msg if $PRINT_VERBOSE
end
-def safe_require(&block)
- yield
-rescue Exception => e
- puts_fail %Q{This script use these gems: fog, slop.
- Make sure that you have them all.
- If you don't have, you may install them: $ gem install fog slop ruby-progressbar
- }
-end
-
def try_create_dir(dir)
begin
FileUtils.mkdir_p dir unless Dir.exists? dir
rescue Errno::EACCES
puts_fail "Permission denied for #{dir.dark_green}"
@@ -37,9 +28,23 @@
def check_rights(file, first_uid, first_gid, second_uid, second_gid)
unless first_uid == second_uid and first_gid == second_gid
puts_fail "Group and user wasn't change for #{file.dark_green}"
end
+end
+
+def create_lock
+ open("/tmp/encbs.lock", "w") do |f|
+ f.puts Process.pid
+ end
+end
+
+def remove_lock
+ FileUtils.rm "/tmp/encbs.lock" if File.exists? "/tmp/encbs.lock"
+end
+
+def lock_exists?
+ File.exists? "/tmp/encbs.lock"
end
class String
def red
colorize(self, "\e[1m\e[31m")