#!/usr/bin/env python

############################################################################
#    Copyright (C) 2005 by Manuel Amador (Rudd-O)                          #
#    rudd-o@amautacorp.com                                                 #
#                                                                          #
#    This program is free software; you can redistribute it and#or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation; either version 2 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program; if not, write to the                         #
#    Free Software Foundation, Inc.,                                       #
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
############################################################################

from MetadataService.InfospaceAgents.Filesystem.FilePluginManager import FilePluginManager
from MetadataService.InfospaceAgents.Filesystem.InfospaceObjects import Volume
from MetadataService.InfospaceAgents.Filesystem.VolumeExpert import VolumeExpert
import os


# NOT HERE FIXME: the only path that needs to be investigate at runtime is the base module dir (that won't even be necessary if we find a way to portably install into the python lib directory).  The other paths should use defaults taken from (in that order): a cmd-line parameter, a config-file specified in the cmdline, the /etc/metadata-service/ config file (which could very well be a /etc/sysconfig/metadata-service shell script, and the program could use the envvars directly), a path relative to the uninstalled executable's directory, and finally a path relative to the installed executable's directory (such as ../lib/metadata-service)
def setup_logging():
	import logging
	dummylog = logging.getLogger()
	dummylog.setLevel(logging.DEBUG)
	format = "%(levelname)s:%(name)s: %(message)s"
	formatter = logging.Formatter(format)
	handler = logging.StreamHandler()
	handler.setFormatter(formatter)
	dummylog.addHandler(handler)


setup_logging()
indexer_plugin_manager = FilePluginManager()
dummy_expert = VolumeExpert([]) # empty stoplist
# FIXME this is broken! =(

dummy_volume = Volume(dummy_expert.get_guid_for_mountpoint("/"),"/","reiserfs","Dummy label")
import sys
del(sys.argv[0])

for a in sys.argv:
	filerepr = indexer_plugin_manager.get_information_object(os.path.abspath(a),dummy_volume)
	print filerepr
	for key,value in filerepr.__dict__.iteritems():
		keylen = min(len(key),20)
		stub = "  "
		if keylen <= 20: stub = " " * (20-keylen)
		print " ", key, stub, value,"(%s)"%(type(value))
	print ""
