Class: Catori::App

Inherits:
Object
  • Object
show all
Defined in:
lib/catori.rb

Instance Method Summary collapse

Instance Method Details

#runObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/catori.rb', line 34

def run
iArgs=ARGV.size
parser = GetoptLong.new
parser.set_options(
['--catalog',				'-c', 	GetoptLong::REQUIRED_ARGUMENT],
['--gui',							GetoptLong::NO_ARGUMENT],
['--install',						GetoptLong::NO_ARGUMENT],
['--user',							GetoptLong::REQUIRED_ARGUMENT],
['--database',						GetoptLong::REQUIRED_ARGUMENT],
['--password',						GetoptLong::REQUIRED_ARGUMENT],
['--pretend',				'-p',	GetoptLong::NO_ARGUMENT],
['--mount',					'-m', 	GetoptLong::NO_ARGUMENT],
['--device',           		'-d', 	GetoptLong::REQUIRED_ARGUMENT],
['--help',                        	GetoptLong::NO_ARGUMENT],
['--version',                     	GetoptLong::NO_ARGUMENT],
['--query',					'-u', 	GetoptLong::NO_ARGUMENT],
['--edit',					'-e',	GetoptLong::NO_ARGUMENT],
['--artist',						GetoptLong::REQUIRED_ARGUMENT],
['--album',							GetoptLong::REQUIRED_ARGUMENT],
['--title',							GetoptLong::REQUIRED_ARGUMENT],
['--file',							GetoptLong::REQUIRED_ARGUMENT],
['--delete',						GetoptLong::NO_ARGUMENT],
['--cd',							GetoptLong::REQUIRED_ARGUMENT]
)
parser.each_option do |name, arg|
	eval "$OPT_#{name.sub(/^--/, '').gsub(/-/, '_').upcase} = '#{arg}'"
end
	hQuery=Hash.new
	hQuery['artist']=$OPT_ARTIST if !$OPT_ARTIST.nil? 
	hQuery['album']=$OPT_ALBUM if !$OPT_ALBUM.nil? 
	hQuery['title']=$OPT_TITLE if !$OPT_TITLE.nil?
	hQuery['file']=$OPT_FILE if !$OPT_FILE.nil? 
	hQuery['cd']=$OPT_CD if !$OPT_CD.nil? 
	
if iArgs==0 or !$OPT_HELP.nil?
	puts Catori::usage
elsif !$OPT_GUI.nil?
	require 'catori/Gui'
	require 'catori/Query'
	
	gui=Catori::Gui.new(hQuery)
	gui.start
	exit
elsif !$OPT_INSTALL.nil?
	require 'catori/Installer'
	if $OPT_DATABASE.nil? or $OPT_USER.nil? or $OPT_PASSWORD.nil?
		puts "Use\ncatori --install --database DATABASE --user USER --password PASSWORD"
		exit
	end
	Catori::Installer.install($OPT_DATABASE,$OPT_USER,$OPT_PASSWORD)
elsif !$OPT_QUERY.nil?
	raise "Need info for query" if hQuery.size==0
	require 'catori/Query'
	q=Catori::Query.new(hQuery)
	puts q.plain
elsif !$OPT_EDIT.nil?
	raise "Need info for query" if hQuery.size==0
	require 'catori/Query'
	require 'catori/XML'
	q=Catori::Query.new(hQuery)
	temp=`mktemp /tmp/catori.XXXXXX`.strip
	if temp
		fp=File.open(temp,"w")
		fp.puts(q.xml)
		fp.close
		fecha=File.stat(temp).mtime
		system("$EDITOR #{temp}")
		if(File.stat(temp).mtime!=fecha)
			xml=Catori::XML.new(temp)
			if(xml.rastrea and i=xml.actualizar)
				$stderr.puts "Actualizados "+i.to_s+" archivos"
			else
				$stderr.puts "Se produjo un error!"
			end
		else
			$stderr.puts "No hay modificaciones"
		end
		
	else
	raise "Can't make a temp file"
	end
elsif !$OPT_VERSION.nil?
	puts Catori::version
elsif !$OPT_CATALOG.nil?
	$stderr.puts "Iniciando"
	device=$OPT_DEVICE.nil? ? '/mnt/cdrom' : $OPT_DEVICE;
	`mount #{device} &> /dev/null` if $OPT_MOUNT
	c=Catori::Catalogador.new($OPT_CATALOG,!$OPT_PRETEND.nil?,device)
	c.deletePrevious if !$OPT_DELETE.nil?
	c.rastrea
	`umount #{device} &> /dev/null` if $OPT_MOUNT
	`eject #{device} &> /dev/null`if $OPT_MOUNT
	$stderr.puts "Listo"
end
end