#!/usr/bin/ruby

require '/usr/share/philesight/philesight'
require 'getoptlong'

##############################################################################
# Config variables
##############################################################################

$path_db = "/var/clearos/disk_usage/ps.db"
$img_size = 500
$img_rings = 4
$img_gradients = true

if (! File.exists?('/var/clearos/disk_usage/ps.db'))
    puts('Disk usage data is not available.')
    exit(1)
end

@ps = Philesight.new($img_rings, $img_size, $img_gradients)
@ps.db_open($path_db)

##############################################################################
# Command line arguments
##############################################################################

# Define actions
opts = GetoptLong.new(
  [ '--action', '-a', GetoptLong::REQUIRED_ARGUMENT ],
  [ '--path', '-p', GetoptLong::REQUIRED_ARGUMENT ],
  [ '--xcoord', '-x', GetoptLong::REQUIRED_ARGUMENT ],
  [ '--ycoord', '-y', GetoptLong::REQUIRED_ARGUMENT ]
)


# Load parameters
action = ''
path = '/';
xcoord = 0;
ycoord = 0;

opts.each do |opt, arg|
	case opt
		when '--path'
			path = arg.to_s
		when '--action'
			action = arg.to_s
		when '--xcoord'
			xcoord = arg.to_i
		when '--ycoord'
			ycoord = arg.to_i
	end
end

# Do actions
if (action == 'image') 
	@ps.draw(path, "-")
elsif (action == 'find') 
	puts @ps.find(path, xcoord, ycoord)
end
