'''
    Copyright (C) 2009 Fabio Erculiani
    Released under GPLv2 License
    
    - This is a template for external triggers. Only 4 functions will be called by Entropy:
	@ preinstall(): triggered before injecting data into the database and copying files on the system
	@ preremove(): triggered before removing files from the system and from the database
	@ postinstall(): triggered after injecting data into the database and copying files on the system
	@ postremove(): triggered after removing files from the system and from the database
    
    - You must always specify them.
    - Each function can only print errors and ONLY in case of critical ones, return != 0 that will be grabbed by the trigger (setting ext_status)

    How it works:
	- this file will be stored inside the entropy database
	- trigger code will be extracted and saved into a file with the name trigger inside the package unpack directory
	- will be issued:
	 	stage = 'postinstall' # this can be postinstall, preinstall, postremove, preremove
		execfile(etpConst['entropyunpackdir']+...+"trigger")
	- code will have access to the entropy package dictionary and will be executed inside TriggersInterface (postinstall(),preinstall(),postremove(),preremove())

    Example of pkgdata:
	{
		'config_protect_mask': '/etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/splash /etc/terminfo /etc/texmf/web2c /etc/udev/rules.d',
		'etpapi': 1, 
		'config_protect': '/usr/NX/etc /usr/NX/home /etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/share/config/kdm /usr/kde/3.5/shutdown /usr/share/X11/xkb /usr/share/config',
		'sources': set(['http://www.zlib.net/zlib-1.2.3.tar.bz2', 'http://www.gzip.org/zlib/zlib-1.2.3.tar.bz2']),
		'download': 'packages/amd64/3.5/zlib-1.2.3-r1.tbz2',
		'digest': '35c9749fb6f782d76a746cb6c8ec1d82',
		'description': 'Standard (de)compression library',
		'category': 'sys-libs',
		'versiontag': '',
		'provide': set([]),
		'conflicts': set([]),
		'content': {'/path/to/file': "filetype (can be sym,obj,dir)"},
		'needed': set(['libc.so.6']),
		'version': '1.2.3-r1',
		'cflags': '-Os -march=x86-64 -pipe',
		'size': '154723',
		'homepage': 'http://www.zlib.net/',
		'slot': '0',
		'datecreation': '1194274924.0',
		'branch': '3.5',
		'useflags': set([]),
		'eclasses': set(['toolchain-funcs', 'multilib', 'portability', 'eutils', 'flag-o-matic']),
		'binkeywords': set(['x86', 'amd64']),
		'mirrorlinks': [],
		'cxxflags': '-Os -march=x86-64 -pipe',
		'dependencies': set([]),
		'chost': 'x86_64-pc-linux-gn',
		'systempackage': True,
		'name': 'zlib',
		'license': 'ZLIB',
		'counter': 14629,
		'messages': [],
		'keywords': set(['ppc', 's390', 'amd64', '~x86-fbsd', 'x86', 'ppc64', 'm68k', 'arm', 'sparc', 'sh', 'mips', 'ia64', 'alpha', 'hppa', '~sparc-fbsd']),
		'disksize': 434998
	}

'''

'''
   space for real triggers
'''
def ext_postinstall(pkgdata):
	print my_ext_printhello()+" postinstall"
	return 0

def ext_preinstall(pkgdata):
	print my_ext_printhello()+" preinstall"
	return 0

def ext_postremove(pkgdata):
	print my_ext_printhello()+" postremove"
	return 0

def ext_preremove(pkgdata):
	print my_ext_printhello()+" preremove"
	return 0

'''
   space for private functions
   Important: function must be declared globally and have suffix my_ext_
'''
global my_ext_printhello
def my_ext_printhello():
	return "hello!"

'''
   run the selected function
'''
global my_ext_status
my_ext_status = eval("ext_"+stage)(pkgdata)
