# User: Vitalie Lazu # Date: Jan 17, 2007 # Time: 12:08:42 PM require "fileutils" require 'inifile' class ControlTool include FileUtils::Verbose attr_accessor :config, :settings DU_CMD = "/usr/bin/du -s" # -b option does not work on FreeBSD - to show summary in bytes TAR = "/bin/tar" def fix_project_name(name) return name.gsub(/[^a-z0-9_\-]/i, '') end def disk_space(settings) 0 end # Do a self check to look for runtime problems and log them def check end def dir_disk_space(dir) if FileTest.directory?(dir) IO.popen("#{DU_CMD} '#{dir}'") do |f| s = f.read if s =~ /^(\d+)/ return $1.to_i * 1024 end end else $log.info("disk space: dir does not exists: #{dir}") end 0 end def run(cmd) $log.info(cmd) rez = system(cmd) $log.info(rez ? 'success' : 'failed') rez end def update_permissions repository_name, allow_anonymous ini = IniFile.new(breakout_ini_file(dest_dir(repository_name))) ini['breakout']['allow_anonymous'] = allow_anonymous ? 'yes' : 'no' ini.write end def dest_dir dir raise "Not implemented here" end def create_breakout_ini(dest_dir, settings) File.open(breakout_ini_file(dest_dir), "w") { |aFile| aFile << "[breakout]\n" aFile << "secretKey = #{settings['secret_key']}\n" aFile << "space_tool_id = #{settings['space_tool_id']}\n" aFile << "allow_anonymous = yes\n" if settings['allow_anonymous'] } end def breakout_ini_file dir File.join dir, "breakout.ini" end def base_dir $base_dir end def tmp_dir base_dir + "/tmp" end def logger $log end end