"""This is a proxy module for common functions used by file plugins"""

from MetadataService import common
from File import File


# FIXME: Document that this is the official plugin utilities interface
is_utf8_encoded = common.is_utf8_encoded
transcode_to_platform_encoding = common.transcode_to_platform_encoding
platform_to_utf8 = common.platform_to_utf8
utf8_to_platform = common.utf8_to_platform
transcode_to_utf8_encoding = common.transcode_to_utf8_encoding
transcode = common.transcode
local_timestamp_to_utc = common.local_timestamp_to_utc
utc_timestamp_to_local = common.utc_timestamp_to_local
shell_quote = common.shell_quote
remove_whitespace = common.remove_whitespace
detect_encoding = common.detect_encoding
File = File
from platform import is_executable
def require_command(command):
	if type(command) is not str or len(command) < 1:
		raise ValueError, "supplied command is invalid"
	if not is_executable(command): raise ImportError, "Plugin requires unavailable %s command" % repr(command)
		
def require_commands(commands):
	if type(commands) is not list: raise TypeError, "require_commands needs a list of commands"
	for command in commands: require_command(command)

import platform
platform = platform

import logging
def log(channel):
	assert type(channel) is str and len(channel) > 0
	return logging.getLogger("Plugins.%s"%channel)

extractors = {}
try: import libextractor; extractors["libextractor"] = libextractor.get_metadata
except: pass

def get_extractor(name):
	assert type(name) is str and len(name) > 0
	try: return extractors[name]
	except KeyError: raise ImportError, "%s is not available on this system"%name
