from Plugins.Plugin import PluginDescriptor
from Screens.PluginBrowser import *
from Screens.ServiceInfo import ServiceInfoList, ServiceInfoListEntry
from Components.SelectionList import SelectionList
from Tools.Directories import resolveFilename, fileExists, pathExists, createDir, SCOPE_MEDIA
from enigma import *
from Screens.MessageBox import MessageBox
from Screens.ChoiceBox import ChoiceBox
from Screens.Screen import Screen
from Components.ActionMap import ActionMap, NumberActionMap
from Components.MenuList import MenuList
from Components.Label import Label
from Components.ScrollLabel import ScrollLabel
from Components.Pixmap import Pixmap
from Components.config import ConfigSubsection, ConfigText, getConfigListEntry, ConfigSelection,  ConfigIP, ConfigYesNo, ConfigSequence, ConfigNumber
from Components.ConfigList import ConfigListScreen

from Components.FileList import FileList
from Components.Sources.StaticText import StaticText
from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest

#import ServiceReference
import os
import sys
import subprocess
from subprocess import Popen,PIPE
import ServiceReference
import time
import urllib

# import py_compile
# py_compile.compile("/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/plugin.py")

from Plugins.Extensions.AddonManager.downloader import *
#from Plugins.Extensions.AddonManager.FileListBB import FileListBB

config.AddonManager = ConfigSubsection()
config.AddonManager.which_server = ConfigInteger(1, limits=(1, 2))
config.AddonManager.preview_timeout = ConfigInteger(default=600,limits=(50, 2000))
config.AddonManager.preview_on = ConfigInteger(1, limits=(0, 1))
config.AddonManager.marker_on = ConfigInteger(1, limits=(0, 1))
config.AddonManager.marker_off = ConfigInteger(1, limits=(0, 1))
config.AddonManager.mark_color = ConfigInteger(1, limits=(0, 2))
config.AddonManager.ungenau = ConfigInteger(0, limits=(0, 1))
config.AddonManager.Schriftart = ConfigInteger(14, limits=(10, 22))
config.AddonManager.ba_settings_on = ConfigInteger(1, limits=(0, 1))
config.AddonManager.ba_plugins_on = ConfigInteger(0, limits=(0, 1))
config.AddonManager.ba_skins_on = ConfigInteger(0, limits=(0, 1))
config.AddonManager.ba_remove_on = ConfigInteger(0, limits=(0, 1))
config.AddonManager.ba_usersettings_on = ConfigInteger(0, limits=(0, 1))


global version
global menu

AAF_Panel_Version = 'Addon Manager ' + version

def main(session, **kwargs):
		file = open("/proc/stb/info/model", "r")
		box = file.readline().strip()
		file.close()
		if box <> "dm8000":
			evfd.getInstance().vfd_write_string(AAF_Panel_Version)
		session.open(Addonpanel)

def Apanel(menuid, **kwargs):
	if menuid == "mainmenu":
		return [("Addon-Manager", main, "Addonpanel", None)]
	else:
		return []

def Plugins(**kwargs):
	return [ PluginDescriptor(name="Addon-Manager", description="Addonpanel AAF-Enigma2 07/11/2010", where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = main) ]

font = "Regular;18"

def applySkinVars(skin,dict):
    for key in dict.keys():
        try:
            skin = skin.replace('{'+key+'}',dict[key])
        except Exception,e:
            print e,"@key=",key
    return skin


# -------------------------------------------------------------------
class CenterList(MenuList):
	def __init__(self):
			MenuList.__init__(self, [], True, eListboxPythonMultiContent)
			self.l.setItemHeight(25)
			self.l.setFont(0, gFont('Regular', 20))


class PanelList(MenuList):
	def __init__(self, list, font0 = 24, font1 = 16, itemHeight = 50, enableWrapAround = True):
		MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
		self.l.setFont(0, gFont("Regular", font0))
		self.l.setFont(1, gFont("Regular", font1))
		self.l.setItemHeight(itemHeight)

def MenuEntryItem(entry):
	res = [entry]
	res.append(MultiContentEntryPixmapAlphaTest(pos=(2, 5), size=(100, 40), png=entry[0]))  # png vorn
	res.append(MultiContentEntryText(pos=(110, 10), size=(440, 40), font=0, text=entry[1]))  # menupunkt
#	res.append(MultiContentEntryText(pos=(10, 29), size=(340, 14), font=1, text=entry[2])) # menubeschreibung
	return res


def AafEntryComponent(file):
	png = LoadPixmap("/usr/lib/enigma2/python/Plugins/Extensions/Aafpanel/pics/" + file + ".png")
	if png == None:
		png = LoadPixmap("/usr/lib/enigma2/python/Plugins/Extensions/Aafpanel/pics/default.png")
	res = (png)
	return res

# -------------------------------------------------------------------
class Addonpanel(Screen):
	skin = """
	<screen name="Addonpanel" position="center,center" size="550, 370" title="Addonpanel">
		<widget name="Mlist" position="10,10" size="530, 350" scrollbarMode="showOnDemand" enableWrapAround="1" transparent="1" />
		<widget name="key_red" position="120,5" zPosition="1" size="75,33" font="Regular;12" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
		<widget name="key_green" position="195,5" zPosition="1" size="75,33" font="Regular;12" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
		<widget name="key_yellow" position="270,5" zPosition="1" size="75,33" font="Regular;12" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
		<widget name="key_blue" position="345,5" zPosition="1" size="75,33" font="Regular;12" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
		<widget name="label1" position="121,287" size="200,20" font="Regular;20" transparent="1" foregroundColor="#f2e000" halign="center" />
	</screen>"""

#-- Start HD skin detection BB
	def __init__(self, session, services = None):
		if os.path.exists("/var/baroot/.multipart") is True:
			self.BAtyp = "new"
		if os.path.exists("/UFS_Images") is True:
			self.BAtyp = "old"

		#switch automatic to current skin
		current_w = getDesktop(0).size().width()
		current_h = getDesktop(0).size().height()
		print "DESKTOPsize is",current_w,current_h

		# define the start koordinates and size
		if current_w == 1280:
				pos_w = 421
				pos_h = 200
		else:
				pos_w = 141
				pos_h = 128

		# set Skinvariables
		self.dict = {
				'font': font,
				'screen.pos': "%i,%i"%(pos_w,pos_h),
				}
		self.skin = applySkinVars(Addonpanel.skin,self.dict)
#-- Ende HD skin detection BB

		self.service = None
		global skin
		global servicelist
		if services is not None:
			servicelist = services
		else:
			servicelist = None

		self.list = []

		Screen.__init__(self, session)
		self.Mlist = []

# --  changeg by bb for the new png-menu ----------------------------------------------------------
		self.Mlist.append(MenuEntryItem((AafEntryComponent('Download Manager'), _("Download Manager"), 'Download Manager')))
		self.Mlist.append(MenuEntryItem((AafEntryComponent('Install from tmp'), _("Install from tmp"), 'Install from tmp')))
		self.Mlist.append(MenuEntryItem((AafEntryComponent('Uninstall Plugins'), _("Uninstall Plugins"), 'Uninstall Plugins')))
		self.Mlist.append(MenuEntryItem((AafEntryComponent('Update Addon-Manager'), _("Update Addon-Manager"), 'Update Addon-Manager')))
		#self.Mlist.append(MenuEntryItem((AafEntryComponent('BA-Image Manager'), _("BA-Image Manager"), 'BA-Image Manager')))
		if (getDesktop(0).size().width() == 1280):
				self["Mlist"] = PanelList([], font0 = 24, font1 = 15, itemHeight = 50)
		else:
				self["Mlist"] = PanelList([])
				self["Mlist"] = PanelList([], font0 = 24, font1 = 15, itemHeight = 50)

		self["Mlist"].l.setList(self.Mlist)
		menu = 0

		file = open("/proc/stb/info/model", "r")
		box = file.readline().strip()
		file.close()
		if box <> "dm8000":
				evfd.getInstance().vfd_write_string( self['Mlist'].l.getCurrentSelection()[0][1] )

		self["key_green"] = Label(" ")
		self["key_red"] = Label(" ")
		self["key_yellow"] = Label(" ")
		self["key_blue"] = Label(" ")
		self["label1"] = Label(" ")

		global menu
		menu = 0

		#// get the remote buttons
		self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ColorActions"],
		{
			"cancel": self.Exit,
			"left": self.left,
			"right": self.right,
			"up": self.up,
			"down": self.down,
			"ok": self.ok,
			#"blue": self.blue,
			"blue": self.check_update,
			"red": self.Red,
			"green": self.Green,
			"yellow": self.yellow,
		}, 1)

	def up(self):
		self["Mlist"].up()
		file = open("/proc/stb/info/model", "r")
		box = file.readline().strip()
		file.close()
		if box <> "dm8000":
				evfd.getInstance().vfd_write_string( self['Mlist'].l.getCurrentSelection()[0][1] )


	def down(self):
		self["Mlist"].down()
		file = open("/proc/stb/info/model", "r")
		box = file.readline().strip()
		file.close()
		if box <> "dm8000":
				evfd.getInstance().vfd_write_string( self['Mlist'].l.getCurrentSelection()[0][1] )

	def left(self):
		pass

	def right(self):
		pass
		
	def Red(self):
		pass

	def Green(self):
		#// Not used
		pass
		
	def yellow(self):
		pass

	def blue(self):
		#// Not used
		pass

	def check_update(self):
		versurl = activesource + "/version_e2.txt"
		h = urllib.urlretrieve(versurl, "/tmp/version_e2.txt")
		dummy = open("/tmp/version_e2.txt").read()
		version_server = dummy[0:len(dummy) -2]
		if version_server == version:
			print "gleich"
			message = "%s %s\n%s %s\n\n%s" % (_("Version am Server:"), version_server, _("Version in der Box:"), version, _("Ein Update ist nicht erforderlich!"))
			self.session.open( MessageBox, message, MessageBox.TYPE_INFO)
		else:
			if version_server > version:
				message = "%s %s\n%s %s\n\n%s" % (_("Version am Server:"), version_server, _("Version in der Box:"), version, _("Ein Update ist empfehlenswert!"))
				self.session.openWithCallback(self.update_now2, MessageBox, message, MessageBox.TYPE_YESNO)
			else:
				message = "%s %s\n%s %s\n\n%s" % (_("\nKlingt wie ein Scherz, aber die Version am Server ist aelter als die auf ihrer Box!\n\nVersion am Server:"), version_server, _("Version in der Box:"), version, _("NICHT UPDATEN, sie besitzen vermutlich eine fortgeschrittene Betaversion!"))
				self.session.openWithCallback(self.update_now2, MessageBox, message, MessageBox.TYPE_YESNO)

	def update_now2(self, answer):
		if answer == True:
			versurl = activesource + "/addon-man_e2.tar.gz"
			h = urllib.urlretrieve(versurl, "/tmp/aaf/addon-man_e2.tar.gz")
			os.system("cd /tmp/aaf; tar -xzf addon-man_e2.tar.gz")
			if os.path.exists("/tmp/aaf/addon-man_e2.tar.gz") is True:
				os.system("cp -RP /tmp/aaf/* / ; sync")
				os.system("rm -r /tmp/aaf")
				os.system("cd / ; rm *tar.gz")
				os.system("mkdir /tmp/aaf")
				message = "%s" % (_("Der Addon-Manager hat einen Neustart angefordert!\nDie Box wird nun neu gestartet!"))
				self.session.open( MessageBox, message, MessageBox.TYPE_INFO)
				TryQuitMainloop(self.session,2)


	def Exit(self):
		#// Exit Aafpanel when pressing the EXIT button or go back to the MainMenu
		self.service = self.session.nav.getCurrentlyPlayingServiceReference()
		service = self.service.toCompareString()
		servicename = ServiceReference.ServiceReference(service).getServiceName().replace('\xc2\x87', '').replace('\xc2\x86', '').ljust(16)
		file = open("/proc/stb/info/model", "r")
		box = file.readline().strip()
		file.close()
		if box <> "dm8000":
			evfd.getInstance().vfd_write_string( servicename )
		self.close()

	def ok(self):
		#// Menu Selection
#		menu = self["Mlist"].getCurrent()
#		global AAFCONF
		menu = self['Mlist'].l.getCurrentSelection()[0][2]
		if menu == "Download Manager":
			self.session.open(PLUGINDownload,"/tmp/usb")
		elif menu == "Uninstall Plugins":
			self.session.open(FileBrowse)
		elif menu == "Install from tmp":
			self.session.open(TmpBrowse)	
		elif menu == "Update Addon-Manager":
			self.check_update()
		elif menu == "BA-Image Manager":
			self.session.open(DelImage)
		else:
			pass

#------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------
class FileBrowse(Screen):
	LIST_FILE = 1
	LIST_IPK = 2
	rebootflag = False

	skin = """
		<screen position="{screen.pos}" size="{screen.size}" title="Uninstall AAF Plugins" >
			<ePixmap position="{logo.pos}" size="70,53" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/picon_default.png" transparent="1" alphatest="on" />
			<ePixmap position="{red_led.pos}" size="36,20" pixmap="skin_default/buttons/key_red.png" transparent="1" alphatest="on" />
			<ePixmap position="{green_led.pos}" size="36,20" pixmap="skin_default/buttons/key_green.png" transparent="1" alphatest="on" />
			<eLabel text="UNINSTALL" position="{label.pos}" size="240,35" font="Regular;30" foregroundColor="#ffa323" transparent="1" />
			<eLabel text="Tar-Files" position="{red.pos}" size="240,25" font="Regular;20" transparent="1" />
			<eLabel text="IPK-Files" position="{green.pos}" size="240,25" font="Regular;20" transparent="1" />
			<widget name="filelist" position="{list.pos}" size="{list.size}" scrollbarMode="showOnDemand" />
			<widget name="ipklist" position="{list.pos}" size="{list.size}" scrollbarMode="showOnDemand" />
			<widget source="global.CurrentTime" render="Label" position="{date.pos}" size="90,23" font="Regular;18" halign="left" valign="top" foregroundColor="#3366ff" transparent="1">
				<convert type="ClockToText">Format:%d.%m.%Y</convert>
			</widget>
			<widget source="global.CurrentTime" render="Label" position="{time.pos}" size="90,23" font="Regular;18" halign="left" valign="top" foregroundColor="#3366ff" transparent="1">
				<convert type="ClockToText">Format:%H:%M:%S</convert>
			</widget>
		</screen>"""

	def __init__(self, session):
		#switch automatic to current skin
		current_w = getDesktop(0).size().width()
		current_h = getDesktop(0).size().height()
		print "DESKTOPsize is",current_w,current_h

		# define the start koordinates and size
		if current_w == 1280:
				size_w = 720
				size_h = 376
		else:
				size_w = 520
				size_h = 376

		# calculate Skin koordinates
		font = "Regular;18"
		pos_w = (current_w - size_w)/2
		pos_h = (current_h - size_h)/2
		list_w = size_w - 20
		list_pos = (size_w - list_w)/2
		red_pos = size_w/2 - 130
		green_pos = size_w/2 + 50
		red_led_pos = red_pos - 40
		green_led_pos = green_pos - 40
		label_pos = size_w/2 -90
		logo_pos = size_w -75
		date_pos = red_led_pos
		time_pos = green_pos

		# set Skinvariables
		self.dict = {
				'font': font,
				'list.size': "%i,232"%(list_w),
				'list.pos': "%i,110"%(list_pos),
				'screen.size': "%i,%i"%(size_w,size_h),
				'screen.pos': "%i,%i"%(pos_w,pos_h),
				'red.pos': "%i,57"%(red_pos),
				'green.pos': "%i,57"%(green_pos),
				'red_led.pos': "%i,57"%(red_led_pos),
				'green_led.pos': "%i,57"%(green_led_pos),
				'label.pos': "%i,12"%(label_pos),
				'logo.pos': "%i,0"%(logo_pos),
				'date.pos': "%i,360"%(date_pos),
				'time.pos': "%i,360"%(time_pos),
				}

		self.skin = applySkinVars(FileBrowse.skin,self.dict)
		Screen.__init__(self, session)

		self.focus = None
		
		self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ColorActions", "MovieSelectionActions"],
		{
			"ok": self.KeyOk,
			"cancel": self.Exit,
			"right": self.rightDown,
			"left": self.leftUp,
			"up": self.up,
			"down": self.down,
			"red": self.plugin_remove,
			"green": self.ipk_remove
		}, -1)

		self.SearchPattern = "(?i)^.*\.(sh|postrm)"
		self.currDir = "/usr/lib/ipkg/info/"
		if not pathExists(self.currDir):
			self.currDir = "/"

		self.ipklist = []
		self.filelist = []
		
		self.ipklist = FileList(self.currDir, showDirectories = False, isTop = True, matchingPattern = self.SearchPattern)
		self["ipklist"] = self.ipklist

		self.currDir = "/var/etc/uninst/"
		if not pathExists(self.currDir):
			self.currDir = "/"

		self.filelist = FileList(self.currDir, showDirectories = False, isTop = True, matchingPattern = self.SearchPattern)
		self["filelist"] = self.filelist

		self["ipklist"].hide()
		self["filelist"].show()
		
		#set the focus to the primary filelist
		self.focus = self.LIST_FILE

	def up(self):
		if self.focus is self.LIST_FILE:
			self["filelist"].up()
		if self.focus is self.LIST_IPK:
			self["ipklist"].up()

	def down(self):
		if self.focus is self.LIST_FILE:
			self["filelist"].down()
		if self.focus is self.LIST_IPK:
			self["ipklist"].down()

	def leftUp(self):
		if self.focus is self.LIST_FILE:
			self["filelist"].pageUp()
		if self.focus is self.LIST_IPK:
			self["ipklist"].pageUp()
		
	def rightDown(self):
		if self.focus is self.LIST_FILE:
			self["filelist"].pageDown()
		if self.focus is self.LIST_IPK:
			self["ipklist"].pageDown()

	def plugin_remove(self):
		self["ipklist"].hide()
		self["filelist"].show()
		self.focus = self.LIST_FILE

	def ipk_remove(self):
		self["filelist"].hide()
		self["ipklist"].show()
		self.focus = self.LIST_IPK

	def KeyOk(self):
		# call the uninstall-Script with subprocess or with os.system
		message = "%s" % (_("Sind sie sicher das Plugin zu loeschen?"))
		self.session.openWithCallback(self.list_remove, MessageBox, message, MessageBox.TYPE_YESNO)

	def list_remove(self, answer):
		if answer == True:
			if self.focus is self.LIST_IPK:
				self.currDir = "/usr/lib/ipkg/info/"
				self.filename = self.ipklist.getFilename()
				self.fullfile = self.currDir + self.filename
				ipkpack = self.filename.split(".")

				#Check for reboot
				if fileExists(self.fullfile):
					rebootcontent = open(self.fullfile, "r").read()
					pos = rebootcontent.find("reboot")
					if pos > 0:
							self.rebootflag = True
							inhalt = rebootcontent[pos:pos+9]
							rebootcontent = rebootcontent.replace(u"reboot","#reboot")
							g = open(self.fullfile, "w")
							g.write(rebootcontent)
							g.close()

			 	argument="remove " + ipkpack[0] + "*"
			 	os.system("ipkg %s" % argument)
			 
			if self.focus is self.LIST_FILE:
			 self.currDir = "/var/etc/uninst/"
			 self.filename = self.filelist.getFilename()
			 self.fullfile = self.currDir + self.filename
			 cmd=[self.fullfile]
			 #subprocess.call(cmd)
			 os.system("%s" % self.fullfile)

		self["filelist"].refresh()
		self["ipklist"].refresh()

	def Exit(self):
		if self.rebootflag:
			#self["statusbar"].text = _("rebooting...")
			message = "%s" % (_("Ein Plugin hat einen Neustart angefordert!\nDie Box wird nun rebootet!"))
			self.session.open( MessageBox, message, MessageBox.TYPE_INFO)
			TryQuitMainloop(self.session,2)
		self.close()
#------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------
class TmpBrowse(Screen):
	LIST_FILE = 1
	LIST_IPK = 2

	skin = """
		<screen position="{screen.pos}" size="{screen.size}" title="Install AAF Plugins aus tmp" >
			<ePixmap position="{logo.pos}" size="70,53" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/picon_default.png" transparent="1" alphatest="on" />
			<ePixmap position="{red_led.pos}" size="36,20" pixmap="skin_default/buttons/key_red.png" transparent="1" alphatest="on" />
			<ePixmap position="{green_led.pos}" size="36,20" pixmap="skin_default/buttons/key_green.png" transparent="1" alphatest="on" />
			<eLabel text="INSTALL-TMP" position="{label.pos}" size="240,35" font="Regular;30" foregroundColor="#ffa323" transparent="1" />
			<eLabel text="Tar-Files" position="{red.pos}" size="240,25" font="Regular;20" transparent="1" />
			<eLabel text="IPK-Files" position="{green.pos}" size="240,25" font="Regular;20" transparent="1" />
			<widget name="filelist" position="{list.pos}" size="{list.size}" scrollbarMode="showOnDemand" />
			<widget name="ipklist" position="{list.pos}" size="{list.size}" scrollbarMode="showOnDemand" />
			<widget source="global.CurrentTime" render="Label" position="{date.pos}" size="90,23" font="Regular;18" halign="left" valign="top" foregroundColor="#3366ff" transparent="1">
				<convert type="ClockToText">Format:%d.%m.%Y</convert>
			</widget>
			<widget source="global.CurrentTime" render="Label" position="{time.pos}" size="90,23" font="Regular;18" halign="left" valign="top" foregroundColor="#3366ff" transparent="1">
				<convert type="ClockToText">Format:%H:%M:%S</convert>
			</widget>
		</screen>"""

	def __init__(self, session):
		#switch automatic to current skin
		current_w = getDesktop(0).size().width()
		current_h = getDesktop(0).size().height()
		print "DESKTOPsize is",current_w,current_h

		# define the start koordinates and size
		if current_w == 1280:
				size_w = 720
				size_h = 376
		else:
				size_w = 520
				size_h = 376

		# calculate Skin koordinates
		font = "Regular;18"
		pos_w = (current_w - size_w)/2
		pos_h = (current_h - size_h)/2
		list_w = size_w - 20
		list_pos = (size_w - list_w)/2
		red_pos = size_w/2 - 130
		green_pos = size_w/2 + 50
		red_led_pos = red_pos - 40
		green_led_pos = green_pos - 40
		label_pos = size_w/2 -90
		logo_pos = size_w -75
		date_pos = red_led_pos
		time_pos = green_pos

		# set Skinvariables
		self.dict = {
				'font': font,
				'list.size': "%i,232"%(list_w),
				'list.pos': "%i,110"%(list_pos),
				'screen.size': "%i,%i"%(size_w,size_h),
				'screen.pos': "%i,%i"%(pos_w,pos_h),
				'red.pos': "%i,57"%(red_pos),
				'green.pos': "%i,57"%(green_pos),
				'red_led.pos': "%i,57"%(red_led_pos),
				'green_led.pos': "%i,57"%(green_led_pos),
				'label.pos': "%i,12"%(label_pos),
				'logo.pos': "%i,0"%(logo_pos),
				'date.pos': "%i,360"%(date_pos),
				'time.pos': "%i,360"%(time_pos),
				}

		self.skin = applySkinVars(TmpBrowse.skin,self.dict)
		Screen.__init__(self, session)

		self.focus = None
		
		self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ColorActions", "MovieSelectionActions"],
		{
			"ok": self.KeyOk,
			"cancel": self.Exit,
			"right": self.rightDown,
			"left": self.leftUp,
			"up": self.up,
			"down": self.down,
			"red": self.plugin_remove,
			"green": self.ipk_remove,
			"yellow": self.ipk_remove
		}, -1)

		self.SearchPattern = "(?i)^.*\.(ipk)"
		self.currDir = "/tmp/"
		if not pathExists(self.currDir):
			self.currDir = "/"

		self.ipklist = FileList(self.currDir, showDirectories = False, isTop = True, matchingPattern = self.SearchPattern)
		self["ipklist"] = self.ipklist


		self.SearchPattern = "(?i)^.*\.(gz|tgz)"
		self.currDir = "/tmp/"
		if not pathExists(self.currDir):
			self.currDir = "/"

		self.filelist = FileList(self.currDir, showDirectories = False, isTop = True, matchingPattern = self.SearchPattern)
		self["filelist"] = self.filelist
		
		self["aktion"] = StaticText()
#		self["ausschrift"] = Pixmap()
		self["ipklist"].hide()
		self["filelist"].show()
#		self["ausschrift"].hide()
		self["aktion"].text = "Install TAR"
#		self["ausschrift"].text = "Install is running"
		
		#set the focus to the primary filelist
		self.focus = self.LIST_FILE

	def up(self):
		if self.focus is self.LIST_FILE:
			self["filelist"].up()
		if self.focus is self.LIST_IPK:
			self["ipklist"].up()

	def down(self):
		if self.focus is self.LIST_FILE:
			self["filelist"].down()
		if self.focus is self.LIST_IPK:
			self["ipklist"].down()

	def leftUp(self):
		if self.focus is self.LIST_FILE:
			self["filelist"].pageUp()
		if self.focus is self.LIST_IPK:
			self["ipklist"].pageUp()
		
	def rightDown(self):
		if self.focus is self.LIST_FILE:
			self["filelist"].pageDown()
		if self.focus is self.LIST_IPK:
			self["ipklist"].pageDown()

	def plugin_remove(self):
		self["ipklist"].hide()
		self["aktion"].text = "Install TAR"
		self["filelist"].show()
		self.focus = self.LIST_FILE

	def ipk_remove(self):
		self["filelist"].hide()
		self["aktion"].text = "Install IPK"
		self["ipklist"].show()
		self.focus = self.LIST_IPK

	def KeyOk(self):
		# call the uninstall-Script with subprocess or with os.system
		self.filename = None
		if self.focus is self.LIST_FILE:
			self.filename = self.filelist.getFilename()
			if self.filename is not None:
				self["filelist"].hide()
#				self["ausschrift"].show()
				self.fullfile = self.currDir + self.filename
				os.system("mkdir /tmp/AAFInst")
				os.system("cd /tmp/AAFInst; tar -xzf  %s" % self.fullfile)
				if os.path.exists("/tmp/AAFInst/inst.sh") is True:
					os.system("cd /tmp/AAFInst; ./inst.sh" )
				else:
					os.system("cp -RP /tmp/AAFInst/* / ; sync")
					os.system("rm -r /tmp/AAFInst")
				self["filelist"].show()
#				self["ausschrift"].hide()	
		
		if self.focus is self.LIST_IPK:
			self.filename = self.ipklist.getFilename()
			if self.filename is not None:
				self["ipklist"].hide()
#				self["ausschrift"].show()
				self.fullfile = self.currDir + self.filename
				cmd=["ipkg", "install", self.fullfile] 
				subprocess.call(cmd)
				self["ipklist"].show()
#				self["ausschrift"].hide()	
					
		if self.filename is not None:
			cmd=["rm", self.fullfile]
			subprocess.call(cmd)
			cmd=["sync"]
			subprocess.call(cmd)
			self["filelist"].refresh()
			self["ipklist"].refresh()
			#self.close()

	def Exit(self):
		self.close()

#------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------
# import py_compile
# py_compile.compile("/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/plugin.py")


class DelImage(Screen):
	LIST_FILE = 1
	LIST_IPK = 2
	LIST_DEVICE = 3
	rebootflag = False

	skin = """
		<screen position="{screen.pos}" size="{screen.size}" title="BA-Images" >
			<ePixmap position="{logo.pos}" size="70,53" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/picon_default.png" transparent="1" alphatest="on" />
			<ePixmap position="{red_led.pos}" size="36,23" pixmap="skin_default/buttons/key_red.png" transparent="1" alphatest="on" />
			<ePixmap position="{green_led.pos}" size="36,23" pixmap="skin_default/buttons/key_green.png" transparent="1" alphatest="on" />
			<ePixmap position="{yellow_led.pos}" size="36,23" pixmap="skin_default/buttons/key_yellow.png" transparent="1" alphatest="on" />
			<ePixmap position="{blue_led.pos}" size="36,23" pixmap="skin_default/buttons/key_blue.png" transparent="1" alphatest="on" />

			<ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/satlogo.png" position="20,95" size="100,300" alphatest="on" />

			<eLabel text="Select" position="{red.pos}" size="240,25" font="Regular;20" transparent="1" />
			<eLabel text="Install" position="{green.pos}" size="240,25" font="Regular;20" transparent="1" />
			<eLabel text="Settings-copy" position="{yellow.pos}" size="240,25" font="Regular;20" transparent="1" />
			<eLabel text="Delete" position="{blue.pos}" size="240,25" font="Regular;20" transparent="1" />
			<widget name="filelist" position="{list.pos}" size="{list.size}" scrollbarMode="showOnDemand" />
			<widget name="ipklist" position="{list.pos}" size="{list.size}" scrollbarMode="showOnDemand" />
			<widget name="devicelist" position="{list.pos}" size="{list.size}" scrollbarMode="showOnDemand" />
			<widget source="statusbar" render="Label" position="10,310" size="490,25" font="Regular;22" foregroundColor="#ffa323" />
			<widget source="textbar" render="Label" position="{label.pos}" size="240,35" font="Regular;30" foregroundColor="#ffa323" transparent="1" />

			<widget source="global.CurrentTime" render="Label" position="{date.pos}" size="90,23" font="Regular;18" halign="left" valign="top" foregroundColor="#3366ff" transparent="1">
				<convert type="ClockToText">Format:%d.%m.%Y</convert>
			</widget>
			<widget source="global.CurrentTime" render="Label" position="{time.pos}" size="90,23" font="Regular;18" halign="left" valign="top" foregroundColor="#3366ff" transparent="1">
				<convert type="ClockToText">Format:%H:%M:%S</convert>
			</widget>
		</screen>"""

	#<eLabel text="BA - Images" position="{label.pos}" size="240,35" font="Regular;30" foregroundColor="#ffa323" transparent="1" />
	def __init__(self, session):
		#switch automatic to current skin
		current_w = getDesktop(0).size().width()
		current_h = getDesktop(0).size().height()
		print "DESKTOPsize is",current_w,current_h

		# define the start koordinates and size
		if current_w == 1280:
				size_w = 720
				size_h = 376
		else:
				size_w = 520
				size_h = 376

		# calculate Skin koordinates
		font = "Regular;18"
		pos_w = (current_w - size_w)/2
		pos_h = (current_h - size_h)/2
		list_w = size_w - 200
		list_pos = 150
		red_pos = size_w/4 - 80
		green_pos = size_w/4 + 35
		yellow_pos = size_w/4 + 145
		blue_pos = size_w/4 + 320

		red_led_pos = red_pos - 35
		green_led_pos = green_pos - 35
		yellow_led_pos = yellow_pos - 35
		blue_led_pos = blue_pos - 35
		label_pos = size_w/2 -90
		logo_pos = size_w -92
		date_pos = size_w/2 - 100
		time_pos = size_w/2 + 50

		# set Skinvariables
		self.dict = {
				'font': font,
				'list.size': "%i,232"%(list_w),
				'list.pos': "%i,90"%(list_pos),
				'screen.size': "%i,%i"%(size_w,size_h),
				'screen.pos': "%i,%i"%(pos_w,pos_h),
				'red.pos': "%i,53"%(red_pos),
				'green.pos': "%i,53"%(green_pos),
				'blue.pos': "%i,53"%(blue_pos),
				'yellow.pos': "%i,53"%(yellow_pos),
				'red_led.pos': "%i,53"%(red_led_pos),
				'green_led.pos': "%i,53"%(green_led_pos),
				'yellow_led.pos': "%i,53"%(yellow_led_pos),
				'blue_led.pos': "%i,53"%(blue_led_pos),
				'label.pos': "%i,12"%(label_pos),
				'logo.pos': "%i,295"%(logo_pos),
				'date.pos': "%i,355"%(date_pos),
				'time.pos': "%i,355"%(time_pos),
				}

		self.skin = applySkinVars(DelImage.skin,self.dict)
		Screen.__init__(self, session)

		self["statusbar"] = StaticText()
		self["textbar"] = StaticText()
		self.focus = None
		self["textbar"].text = _("Image-Select")
		self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ColorActions", "MenuActions", "MovieSelectionActions"],
		{
			"ok": self.KeyOk,
			"menu": self.settings_menu,
			"cancel": self.Exit,
			"right": self.rightDown,
			"left": self.leftUp,
			"up": self.up,
			"down": self.down,
			"red": self.plugin_select,
			"yellow": self.settings_para,
			"blue": self.plugin_remove,
			"green": self.ipk_remove
		}, -1)

		self.ipklist = []
		self.filelist = []
		self.devicelist = []
		self.select = "1"
		self.BAtyp = "new"

		self.BAtyp = ""
		self.currDir = "/mnt/usb"
		self.devicelist = FileList(self.currDir, showDirectories = True, isTop = True)
		self["devicelist"] = self.devicelist

		if os.path.exists("/var/baroot/activImage") is True:
			self.BAtyp = "new"
		else:
			if os.path.exists("/var/baroot") is False:
				os.system("mkdir /var/baroot")
			os.system("/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/mountbaroot.sh")
			if os.path.exists("/var/baroot/UFS_images") is True:
				self.BAtyp = "old"


		if self.BAtyp == "new":
			self.currDir = "/var/baroot/UFS_Images/"
			if not pathExists(self.currDir):
				self.currDir = "/"
			self.ipklist = FileList(self.currDir, showDirectories = True, isTop = True)
			self.BAtyp = "new"

		else:
			# it is an old BA < 5.4.3
			self.SearchPattern = "(?i)^.*\.(tar.gz)"
			self.currDir = "/var/baroot/UFS_Images/"
			self.ipklist = FileList(self.currDir, showDirectories = True, isTop = True, matchingPattern = self.SearchPattern)
			if not pathExists(self.currDir):
				self.currDir = "/"


			self.currDir = "/mnt/usb"
			self.devicelist = FileList(self.currDir, showDirectories = True, isTop = True)
			self["devicelist"] = self.devicelist

		self["ipklist"] = self.ipklist


		if self.BAtyp == "new":
			self.currDir = "/var/baroot/ba/ba/"
			#if os.path.exists("/var/baroot/ba/ba/Flash") is False:
			#	os.system("mkdir -p /var/baroot/ba/ba/Flash")
			if not pathExists(self.currDir):
				self.currDir = "/"
			self.BAtyp = "new"
		else:
			# it is an old BA < 5.4.3
			self.currDir = "/mnt/usb"
			self.devicelist = FileList(self.currDir, showDirectories = True, isTop = True)
			self["devicelist"] = self.devicelist

			self.currDir = "/var/baroot/ba/ba/"
			if not pathExists(self.currDir):
				self.currDir = "/"
			self.BAtyp = "old"

		self.filelist = FileList(self.currDir, showDirectories = True, isTop = True)
		self["filelist"] = self.filelist

		self["ipklist"].hide()
		self["devicelist"].hide()
		self["filelist"].show()

		#set the focus to the primary filelist
		self.focus = self.LIST_FILE

	def up(self):
		if self.focus is self.LIST_FILE:
			self["filelist"].up()
		if self.focus is self.LIST_IPK:
			self["ipklist"].up()
		if self.focus is self.LIST_DEVICE:
			self["devicelist"].up()

	def down(self):
		if self.focus is self.LIST_FILE:
			self["filelist"].down()
		if self.focus is self.LIST_IPK:
			self["ipklist"].down()
		if self.focus is self.LIST_DEVICE:
			self["devicelist"].down()


	def leftUp(self):
		if self.focus is self.LIST_FILE:
			self["filelist"].pageUp()
		if self.focus is self.LIST_IPK:
			self["ipklist"].pageUp()
		if self.focus is self.LIST_DEVICE:
			self["devicelist"].pageUp()


	def rightDown(self):
		if self.focus is self.LIST_FILE:
			self["filelist"].pageDown()
		if self.focus is self.LIST_IPK:
			self["ipklist"].pageDown()
		if self.focus is self.LIST_DEVICE:
			self["devicelist"].pageDown()


	def settings_para(self):
		if self.BAtyp == "new":
			self["ipklist"].hide()
			self["filelist"].show()
			self["devicelist"].hide()
			self.focus = self.LIST_FILE
			self.select = "2"
			self["textbar"].text = _("Settings-Copy")
			#if os.path.exists("/var/baroot/ba/ba/Flash") is True:
			#	os.system("rm -r /var/baroot/ba/ba/Flash")
			self["filelist"].refresh()

	def plugin_remove(self):
		self["ipklist"].hide()
		self["filelist"].show()
		self.focus = self.LIST_FILE
		self.select = "0"
		self["textbar"].text = _("Image-Delete")
		#if os.path.exists("/var/baroot/ba/ba/Flash") is True:
		#	os.system("rm -r /var/baroot/ba/ba/Flash")
		self["filelist"].refresh()

	def plugin_select(self):
		self["ipklist"].hide()
		self["filelist"].show()
		self.focus = self.LIST_FILE
		self.select = "1"
		self["textbar"].text = _("Image-Select")
		#if self.BAtyp == "new":
		#		if os.path.exists("/var/baroot/ba/ba/Flash") is False:
		#			os.system("mkdir -p /var/baroot/ba/ba/Flash")
		#		self["filelist"].refresh()

	def ipk_remove(self):
			self["filelist"].hide()
			self["devicelist"].hide()
			self["ipklist"].show()
			self.focus = self.LIST_IPK
			self["textbar"].text = _("Image-Install")

	def KeyOk(self):
		# call the uninstall-Script with os.system
		if self.focus is self.LIST_DEVICE:
			self.currDir = "/var/baroot/ba/ba/"
			message = "%s %s" % (_("Wollen sie in diesem Device installieren?"),self.devicelist.getFilename())
			self.session.openWithCallback(self.oldimage_install, MessageBox, message, MessageBox.TYPE_YESNO)


		if self.focus is self.LIST_IPK:
			if self.BAtyp == "old":
			 	 self.focus = self.LIST_DEVICE
			 	 self["filelist"].hide()
			 	 self["devicelist"].show()
			 	 self["ipklist"].hide()
			 	 self["textbar"].text = _("Zieldevice")
			 	 self["filelist"].refresh()
			 	 self["ipklist"].refresh()
			 	 self["devicelist"].refresh()
			else:
			 	 self.currDir = "/var/baroot/ba/ba/"
			 	 message = "%s %s" % (_("Wollen sie dieses Image wirklich installieren?"),self.ipklist.getFilename())
			 	 self.session.openWithCallback(self.image_install, MessageBox, message, MessageBox.TYPE_YESNO)

		if self.focus is self.LIST_FILE:
			self.urlname = self.filelist.getFilename()
			if self.BAtyp == "new":
			 	 self.urlname2 = self.urlname.replace("/var/baroot/ba/ba/","")
			else:
			 	 self.urlname2 = self.urlname.replace("/var/baroot/ba/ba/","")
			self.urlname2 = self.urlname2.replace("/","")

			if self.select == "0":
			 	 self.currDir = "/var/baroot/UFS_Images/"
			 	 message = "%s %s" % (_("Sind sie sicher dieses Image zu loeschen?"),self.urlname2)
			 	 self.session.openWithCallback(self.image_install, MessageBox, message, MessageBox.TYPE_YESNO)

			if self.select == "1":
			 	 if self.BAtyp == "new":
			 	 		self.currDir = "/var/baroot/UFS_Images/"
			 	 else:
			 	 		self.currDir = "/var/baroot/UFS_Images/"
			 	 message = "%s %s" % (_("Dieses Image auswaehlen?"),self.urlname2)
			 	 self.session.openWithCallback(self.image_install, MessageBox, message, MessageBox.TYPE_YESNO)

			if self.select == "2":
			 	 if self.BAtyp == "new":
			 	 		self.currDir = "/var/baroot/UFS_Images/"
			 	 		message = "%s %s" % (_("Settings in dieses Image kopieren?"),self.urlname2)
			 	 		self.session.openWithCallback(self.settings_copy, MessageBox, message, MessageBox.TYPE_YESNO)


	def image_install(self, answer):
		if answer == True:
      # install Image
			if self.focus is self.LIST_IPK:
				self["filelist"].refresh()
				self["ipklist"].refresh()
				self.currDir = "/var/baroot/UFS_Images/"
				self.urlname = self.ipklist.getFilename()
				self.error_counter = "0"

				if os.path.exists("/bootp.conf") is False:
						message = "%s" % (_("Das ist kein Multiboot BA!\nbootp.conf fehlt"))
						self.session.open(MessageBox, message, MessageBox.TYPE_ERROR)
						self.error_counter = "1"

				if os.path.exists("/var/baroot/activImage") is False:
						message = "%s" % (_("Das ist kein Multiboot BA!\nactivImage fehlt!"))
						self.session.open(MessageBox, message, MessageBox.TYPE_ERROR)
						self.error_counter = "1"

				if os.path.exists("/var/baroot/activImage") is True:
					# is enough freespace on stick?
					os.system("df /var/baroot |grep rootfs|cut -c41-50 >/tmp/free.txt")
					if os.path.exists("/tmp/free.txt") is True:
						f = open("/tmp/free.txt", "r" )
						for line in f:
							freesize = line.lstrip()
						f.close
						freesize = freesize.replace("\n","")
						freesize = int(freesize)

					if 42000 > freesize:
						print "nicht OK"
						message = "%s" % (_("Zu wenig Speicher im Stick frei!\n  Speicher = " + str(freesize)))
						self.session.open(MessageBox, message, MessageBox.TYPE_ERROR)
						self.error_counter = "1"
					else:
						print "OK" + str(freesize)
						if os.path.exists("/var/baroot/ba/ba.sh") is False:
							if os.path.exists("/var/baroot") is False:
								os.system("mkdir /var/baroot")

				# is it an multiboot environment?
				if self.error_counter == "0":
				#if os.path.exists("/var/baroot/activImage") is True:
					file = open("/proc/stb/info/model", "r")
					box = file.readline().strip()
					file.close()
					if box <> "dm8000":
							evfd.getInstance().vfd_write_string("Install Image")
					self["statusbar"].text = _("Decompressing Image in progress...")
					#message = "%s" % (_("Das Image wird nun entpackt und installiert!"))
					#self.session.open(MessageBox, message, MessageBox.TYPE_INFO,10)

					# this is the Imagename in /var/baroot/UFS_Images
					self.urlnameorg = self.urlname
					self.urlname = self.urlname.replace(".tar.gz","")
					self.urlname_org = self.urlname
					# chek if exist Image, then make a newer
					TargetDir = "/var/baroot/ba/ba/" + self.urlname
					if os.path.exists(TargetDir) is True:
						self.urlname = self.urlname_org + "_2"
					TargetDir = "/var/baroot/ba/ba/" + self.urlname
					if os.path.exists(TargetDir) is True:
						self.urlname = self.urlname_org + "_3"
					TargetDir = "/var/baroot/ba/ba/" + self.urlname
					if os.path.exists(TargetDir) is True:
						self.urlname = self.urlname_org + "_4"
					TargetDir = "/var/baroot/ba/ba/" + self.urlname
					if os.path.exists(TargetDir) is True:
						self.urlname = self.urlname_org + "_5"
					if os.path.exists(TargetDir) is True:
						self.urlname = self.urlname_org + "_6"
					TargetDir = "/var/baroot/ba/ba/" + self.urlname
					if os.path.exists(TargetDir) is True:
						self.urlname = self.urlname_org + "_7"
					if os.path.exists(TargetDir) is True:
						self.urlname = self.urlname_org + "_8"
					if os.path.exists(TargetDir) is True:
						self.urlname = self.urlname_org + "_9"
					TargetDir = "/var/baroot/ba/ba/" + self.urlname
					if os.path.exists(TargetDir) is True:
						self.urlname = self.urlname_org + "_10"


					TargetDir = "mkdir -p /var/baroot/ba/ba/" + self.urlname
					os.system(TargetDir)

					# write name to userfile
					TargetDir = "NewDir=" + self.urlname
					ffile = open("/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/ba_url", "w")
					ffile.write(TargetDir)
					ffile.close()

					TarString = "cd /var/baroot/UFS_Images; tar -xzf " + self.urlnameorg + " -C /var/baroot/ba/ba/" + self.urlname
					os.system(TarString)
					#self.session.open(Console, title = "decompressing is running", cmdlist = [TarString])

					CpString = "cp /bootp.conf /var/baroot/ba/ba/" + self.urlname
					os.system(CpString)
					if os.path.exists("/bootp2.conf") is True:
						CpString = "cp /bootp2.conf /var/baroot/ba/ba/" + self.urlname
						os.system(CpString)

					#CpString = "cp /etc/init.d/rcS /var/baroot/ba/ba/" + self.urlname + "/etc/init.d/rcS"
					#os.system(CpString)

					RCS = "/var/baroot/ba/ba/" + self.urlname + "/etc/init.d/rcS"
					#CpString = "cat /usr/lib/enigma2/python/Plugins/Extensions/AddonManager/rcs_header > /tmp/rcs.txt"
					#os.system(CpString)

					CpString = "sed -e 's*#!/bin/sh*#*g' -i " + RCS
					os.system(CpString)

					ffile = open("/tmp/rcs.txt", "w")
					CpString = "#!/bin/sh"
					ffile.write(CpString)
					ffile.write("\n")
					CpString = ""
					ffile.write(CpString)
					ffile.write("\n")
					CpString = "if [ -e /activImage ]; then"
					ffile.write(CpString)
					ffile.write("\n")
					CpString = "  echo \"Starte chroot\""
					ffile.write(CpString)
					ffile.write("\n")
					CpString = "  mount -o bind /baroot /activImage/var/baroot"
					ffile.write(CpString)
					ffile.write("\n")
					CpString = "  exec chroot /activImage /etc/init.d/rcS"
					ffile.write(CpString)
					ffile.write("\n")
					CpString = "fi"
					ffile.write(CpString)
					ffile.write("\n")
					CpString = ""
					ffile.write(CpString)
					ffile.write("\n")
					ffile.close()

					CpString = "cat " + RCS + " >> /tmp/rcs.txt"
					os.system(CpString)
					CpString = "cp /tmp/rcs.txt " + RCS
					os.system(CpString)
					CpString = "chmode 755 " + RCS
					os.system(CpString)
					CpString = "sed -e 's/fsck /#fsck /g' -i /var/baroot/ba/ba/" + self.urlname + "/etc/init.d/mountvirtfs"
					os.system(CpString)
					CpString = "mkdir -p /var/baroot/ba/ba/" + self.urlname + "/var/baroot"
					os.system(CpString)
					os.system("sync")

          # set automount in rcs
					os.system("/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/makercs.sh")


          # and now we copy the settings
					if config.AddonManager.ba_settings_on.value == 1:
						file = open("/proc/stb/info/model", "r")
						box = file.readline().strip()
						file.close()
						if box <> "dm8000":
							evfd.getInstance().vfd_write_string("install Settings")
						self["statusbar"].text = _("Settings werden uebernommen....")

						CpString = "rm /var/baroot/ba/ba/" + self.urlname + "/var/etc/.firstboot"
						os.system(CpString)
						CpString = "cp -RP /var/emu /var/baroot/ba/ba/" + self.urlname + "/var/"
						os.system(CpString)
						CpString = "cp -RP /var/keys /var/baroot/ba/ba/" + self.urlname + "/var/"
						os.system(CpString)
						CpString = "cp /var/etc/active_cam /var/baroot/ba/ba/" + self.urlname + "/var/etc/active_cam"
						os.system(CpString)
						CpString = "cp /var/etc/*emu /var/baroot/ba/ba/" + self.urlname + "/var/etc/"
						os.system(CpString)
						CpString = "cp /var/etc/smbfs /var/baroot/ba/ba/" + self.urlname + "/var/etc/"
						os.system(CpString)
						CpString = "cp /var/etc/upnpfs /var/baroot/ba/ba/" + self.urlname + "/var/etc/"
						os.system(CpString)


						CpString = "cp /var/*emu /var/baroot/ba/ba/" + self.urlname + "/var/"
						os.system(CpString)
						CpString = "cp /usr/local/share/enigma2/lamedb /var/baroot/ba/ba/" + self.urlname + "/usr/local/share/enigma2/"
						os.system(CpString)
						CpString = "cp /usr/local/share/enigma2/bouquets* /var/baroot/ba/ba/" + self.urlname + "/usr/local/share/enigma2/"
						os.system(CpString)
						CpString = "cp /usr/local/share/enigma2/userbouquet* /var/baroot/ba/ba/" + self.urlname + "/usr/local/share/enigma2/"
						os.system(CpString)
						CpString = "cp /etc/tuxbox/satellites.xml /var/baroot/ba/ba/" + self.urlname + "/etc/tuxbox/satellites.xml"
						os.system(CpString)
						#CpString = "cp /usr/local/share/enigma2/settings /var/baroot/ba/ba/" + self.urlname + "/usr/local/share/enigma2/"
						#os.system(CpString)
						CpString = "cp /usr/automount/amount.ini /var/baroot/ba/ba/" + self.urlname + "/usr/automount/amount.ini"
						os.system(CpString)

						#// Check for default skin
						defaultSkin = 0
						PathString = "/var/baroot/ba/ba/" + self.urlname + "/var/usr/local/share/enigma2/settings"
						if os.path.exists(PathString) is True:
							em = open(PathString)
							e = em.readlines()
							em.close()
							for line in e:
								if line.find("config.skin.primary_skin") > -1:
										defaultSkin = 1
										PrimarySkin = line

						CpString = "cp /usr/local/share/enigma2/settings /var/baroot/ba/ba/" + self.urlname + "/usr/local/share/enigma2/"
						os.system(CpString)

						if defaultSkin == 1:
								em = open(PathString, "a")
								em.write(PrimarySkin)
								em.close()


					if config.AddonManager.ba_skins_on.value == 1:
							CpString = "cp -RP /usr/local/share/enigma2/ /var/baroot/ba/ba/" + self.urlname + "/usr/local/share/"
							os.system(CpString)

							CpString = "cp -RP /usr/lib/enigma2/python/Plugins/Extensions/InfoBarConfig/ /var/baroot/ba/ba/" + self.urlname + "/usr/lib/enigma2/python/Plugins/Extensions/"
							os.system(CpString)

							CpString = "cp /usr/lib/enigma2/python/Components/Converter/MaxCryptoInfo.pyc /var/baroot/ba/ba/" + self.urlname + "/usr/lib/enigma2/python/Components/Converter/"
							os.system(CpString)

							CpString = "cp /usr/lib/enigma2/python/Components/Converter/MaxServiceInfo.pyc /var/baroot/ba/ba/" + self.urlname + "/usr/lib/enigma2/python/Components/Converter/"
							os.system(CpString)

							if os.path.exists("/usr/share/enigma2/picon/") is True:
								CpString = "cp -RP /usr/share/enigma2/picon/ /var/baroot/ba/ba/" + self.urlname + "/usr/share/enigma2/"
								os.system(CpString)

					if config.AddonManager.ba_plugins_on.value == 1:
							# save AddonManager + Aafpanel, because in new image is newer
							os.system("cp -RP /usr/lib/enigma2/python/Plugins/Extensions/AddonManager /tmp/")
							os.system("cp -RP /usr/lib/enigma2/python/Plugins/Extensions/Aafpanel /tmp/")
							CpString = "cp -RP /usr/lib/enigma2/python/Plugins/Extensions /var/baroot/ba/ba/" + self.urlname + "/usr/lib/enigma2/python/Plugins/"
							os.system(CpString)
							# restore AddonManager + Aafpanel
							CpString = "cp -RP /tmp/AddonManager /var/baroot/ba/ba/" + self.urlname + "/usr/lib/enigma2/python/Plugins/"
							os.system(CpString)
							CpString = "cp -RP /tmp/Aafpanel /var/baroot/ba/ba/" + self.urlname + "/usr/lib/enigma2/python/Plugins/"
							os.system(CpString)

					if config.AddonManager.ba_remove_on.value == 1:
							CpString = "rm -r /var/baroot/UFS_Images/" + self.urlnameorg
							os.system(CpString)

					if config.AddonManager.ba_usersettings_on.value == 1:
						if os.path.exists("/var/baroot/default_settings") is True:
							CpString = "cp /var/baroot/default_settings /var/baroot/ba/ba/" + self.urlname + "/usr/local/share/enigma2/settings"
							os.system(CpString)

					if os.path.exists("/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/ba_script.sh") is True:
						os.system("/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/ba_script.sh")

					file = open("/proc/stb/info/model", "r")
					box = file.readline().strip()
					file.close()
					if box <> "dm8000":
						evfd.getInstance().vfd_write_string("Image Ready!")
					restartbox = self.session.openWithCallback(self.restart,MessageBox,_("Das Image ist nun fertig installiert!\nSoll ein Neustart durchgefuehrt werden?"), MessageBox.TYPE_YESNO)
					restartbox.setTitle(_("UFS-Box starten?"))


      # delete Image
			if self.focus is self.LIST_FILE:
				self.imagename = self.filelist.getFilename()
				if self.imagename == "/var/baroot/ba/":
					print "/var/baroot/ba/"
				else:
					#if self.BAtyp == "new":
					fd=open("/var/baroot/ba/.baboot")
					imgname=fd.read()
					fd.close()
					imgname = imgname.replace("\n","")
					imgname = "/var/baroot/ba/ba/" + imgname + "/"

					# delete Image
					if self.select == "0":
						if self.imagename == imgname:
							message = "%s" % (_("WARNUNG\nDas aktive Image kann NICHT geloescht werden!"))
							self.session.open(MessageBox, message, MessageBox.TYPE_INFO,5)
						else:
							message = "%s" % (_("Das Image wird jetzt geloescht!"))
							self.session.open(MessageBox, message, MessageBox.TYPE_INFO,3)
							if self.BAtyp == "new":
								os.system("rm -r %s" % self.imagename)
							else:
								# and now we read the devicename
								fileread = open(self.imagename + "bootp.conf", "r" )
								for line in fileread:
									if line.split('=')[0] == "BADEVICE":
											self.device = line.split('=')[1]
											self.device = self.device.replace("\n","")
								fileread.close()

								# read mountpoint
								procfile = open("/proc/mounts")
								for n in procfile.readlines():
										if n.split(' ')[0] == self.device:
											self.device = n.split(' ')[1]
								procfile.close()
								os.system("rm -r %s" % self.device)
								os.system("rm -r %s" % self.imagename)

					# select Image
					if self.select == "1":
						if self.imagename == imgname:
							message = "%s" % (_("Dieses Image ist bereits AKTIV!"))
							self.session.open(MessageBox, message, MessageBox.TYPE_INFO,5)
						else:
							self.urlname = self.imagename.replace("/var/baroot/ba/ba/","")
							self.urlname = self.urlname.replace("/","")

							restartbox = self.session.openWithCallback(self.restart,MessageBox,_("Soll nun ein Neustart durchgefuehrt werden?"), MessageBox.TYPE_YESNO)
							restartbox.setTitle(_("UFS-Box starten?"))

		self["filelist"].refresh()
		self["ipklist"].refresh()
		self["devicelist"].refresh()

	def restart(self, answer):
		if answer is True:
			# make bootimage active for restart
			if self.BAtyp == "new":
				ffile = open("/var/baroot/ba/.baboot", "w")
				ffile.write(self.urlname)
				ffile.write("\n")
				ffile.close()
				#if os.path.exists("/var/baroot/ba/ba/Flash") is True:
				#	os.system("rm -r /var/baroot/ba/ba/Flash")
			else:

				ffile = open("/var/baroot/ba/.baboot", "w")
				ffile.write(self.urlname_org)
				ffile.write("\n")
				ffile.close()
				# and now we write the devicename
				fileread = open("/var/baroot/ba/ba/" + self.urlname_org + "/bootp.conf", "r" )
				for line in fileread:
					if line.split('=')[0] == "BADEVICE":
							self.device = line.split('=')[1]
							ffile = open("/var/baroot/ba/.badevice", "w")
							ffile.write(self.device)
							#ffile.write("\n")
							ffile.close()
				fileread.close()

			os.system("sync")
			os.system("reboot -f")


	def Exit(self):
		if self.rebootflag:
			#self["statusbar"].text = _("rebooting...")
			message = "%s" % (_("Ein Plugin hat einen Neustart angefordert!\nDie Box wird nun rebootet!"))
			self.session.open( MessageBox, message, MessageBox.TYPE_INFO)
			TryQuitMainloop(self.session,2)
		self.close()

	def settings_menu(self):
		self.session.open(AddonConfigScreen)



	def settings_copy(self, answer):
		if answer == True:
      # install Image
			if self.focus is self.LIST_FILE:
				self["filelist"].refresh()
				self["ipklist"].refresh()
				self.currDir = "/var/baroot/UFS_Images/"
				self.urlname = self.urlname2
				self.error_counter = "0"

				if os.path.exists("/bootp.conf") is False:
						message = "%s" % (_("Das ist kein Multiboot BA!\nbootp.conf fehlt"))
						self.session.open(MessageBox, message, MessageBox.TYPE_ERROR)
						self.error_counter = "1"

				if os.path.exists("/var/baroot/activImage") is False:
						message = "%s" % (_("Das ist kein Multiboot BA!\nactivImage fehlt!"))
						self.session.open(MessageBox, message, MessageBox.TYPE_ERROR)
						self.error_counter = "1"

				# is it an multiboot environment?
				if self.error_counter == "0":
					file = open("/proc/stb/info/model", "r")
					box = file.readline().strip()
					file.close()
					if box <> "dm8000":
						evfd.getInstance().vfd_write_string("Settings copy")

					# write name to userfile
					TargetDir = "NewDir=" + self.urlname
					ffile = open("/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/ba_url", "w")
					ffile.write(TargetDir)
					ffile.close()

					CpString = "cp /bootp.conf /var/baroot/ba/ba/" + self.urlname
					os.system(CpString)
					if os.path.exists("/bootp2.conf") is True:
						CpString = "cp /bootp2.conf /var/baroot/ba/ba/" + self.urlname
						os.system(CpString)

          # and now we copy the settings
					if config.AddonManager.ba_settings_on.value == 1:
						file = open("/proc/stb/info/model", "r")
						box = file.readline().strip()
						file.close()
						if box <> "dm8000":
							evfd.getInstance().vfd_write_string("install Settings")
						self["statusbar"].text = _("Settings werden uebernommen....")

						CpString = "rm /var/baroot/ba/ba/" + self.urlname + "/var/etc/.firstboot"
						os.system(CpString)
						CpString = "cp -RP /var/emu /var/baroot/ba/ba/" + self.urlname + "/var/"
						os.system(CpString)
						CpString = "cp -RP /var/keys /var/baroot/ba/ba/" + self.urlname + "/var/"
						os.system(CpString)
						CpString = "cp /var/etc/active_cam /var/baroot/ba/ba/" + self.urlname + "/var/etc/active_cam"
						os.system(CpString)
						CpString = "cp /var/etc/*emu /var/baroot/ba/ba/" + self.urlname + "/var/etc/"
						os.system(CpString)
						CpString = "cp /var/etc/smbfs /var/baroot/ba/ba/" + self.urlname + "/var/etc/"
						os.system(CpString)
						CpString = "cp /var/etc/upnpfs /var/baroot/ba/ba/" + self.urlname + "/var/etc/"
						os.system(CpString)


						CpString = "cp /var/*emu /var/baroot/ba/ba/" + self.urlname + "/var/"
						os.system(CpString)
						CpString = "cp /usr/local/share/enigma2/lamedb /var/baroot/ba/ba/" + self.urlname + "/usr/local/share/enigma2/"
						os.system(CpString)
						CpString = "cp /usr/local/share/enigma2/bouquets* /var/baroot/ba/ba/" + self.urlname + "/usr/local/share/enigma2/"
						os.system(CpString)
						CpString = "cp /usr/local/share/enigma2/userbouquet* /var/baroot/ba/ba/" + self.urlname + "/usr/local/share/enigma2/"
						os.system(CpString)
						CpString = "cp /etc/tuxbox/satellites.xml /var/baroot/ba/ba/" + self.urlname + "/etc/tuxbox/satellites.xml"
						os.system(CpString)
						#CpString = "cp /usr/local/share/enigma2/settings /var/baroot/ba/ba/" + self.urlname + "/usr/local/share/enigma2/"
						#os.system(CpString)
						CpString = "cp /usr/automount/amount.ini /var/baroot/ba/ba/" + self.urlname + "/usr/automount/amount.ini"
						os.system(CpString)

						#// Check for default skin
						defaultSkin = 0
						PathString = "/var/baroot/ba/ba/" + self.urlname + "/var/usr/local/share/enigma2/settings"
						if os.path.exists(PathString) is True:
							em = open(PathString)
							e = em.readlines()
							em.close()
							for line in e:
								if line.find("config.skin.primary_skin") > -1:
										defaultSkin = 1
										PrimarySkin = line

						CpString = "cp /usr/local/share/enigma2/settings /var/baroot/ba/ba/" + self.urlname + "/usr/local/share/enigma2/"
						os.system(CpString)

						if defaultSkin == 1:
								em = open(PathString, "a")
								em.write(PrimarySkin)
								em.close()


					if config.AddonManager.ba_skins_on.value == 1:
							CpString = "cp -RP /usr/local/share/enigma2/ /var/baroot/ba/ba/" + self.urlname + "/usr/local/share/"
							os.system(CpString)

							CpString = "cp -RP /usr/lib/enigma2/python/Plugins/Extensions/InfoBarConfig/ /var/baroot/ba/ba/" + self.urlname + "/usr/lib/enigma2/python/Plugins/Extensions/"
							os.system(CpString)

							CpString = "cp /usr/lib/enigma2/python/Components/Converter/MaxCryptoInfo.pyc /var/baroot/ba/ba/" + self.urlname + "/usr/lib/enigma2/python/Components/Converter/"
							os.system(CpString)

							CpString = "cp /usr/lib/enigma2/python/Components/Converter/MaxServiceInfo.pyc /var/baroot/ba/ba/" + self.urlname + "/usr/lib/enigma2/python/Components/Converter/"
							os.system(CpString)

							if os.path.exists("/usr/share/enigma2/picon/") is True:
								CpString = "cp -RP /usr/share/enigma2/picon/ /var/baroot/ba/ba/" + self.urlname + "/usr/share/enigma2/"
								os.system(CpString)

					if config.AddonManager.ba_plugins_on.value == 1:
							# save AddonManager + Aafpanel, because in new image is newer
							os.system("cp -RP /usr/lib/enigma2/python/Plugins/Extensions/AddonManager /tmp/")
							os.system("cp -RP /usr/lib/enigma2/python/Plugins/Extensions/Aafpanel /tmp/")
							CpString = "cp -RP /usr/lib/enigma2/python/Plugins/Extensions /var/baroot/ba/ba/" + self.urlname + "/usr/lib/enigma2/python/Plugins/"
							os.system(CpString)
							# restore AddonManager + Aafpanel
							CpString = "cp -RP /tmp/AddonManager /var/baroot/ba/ba/" + self.urlname + "/usr/lib/enigma2/python/Plugins/"
							os.system(CpString)
							CpString = "cp -RP /tmp/Aafpanel /var/baroot/ba/ba/" + self.urlname + "/usr/lib/enigma2/python/Plugins/"
							os.system(CpString)

					if config.AddonManager.ba_remove_on.value == 1:
							CpString = "rm -r /var/baroot/UFS_Images/" + self.urlnameorg
							os.system(CpString)

					if config.AddonManager.ba_usersettings_on.value == 1:
						if os.path.exists("/var/baroot/default_settings") is True:
							CpString = "cp /var/baroot/default_settings /var/baroot/ba/ba/" + self.urlname + "/usr/local/share/enigma2/settings"
							os.system(CpString)

					if os.path.exists("/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/ba_script.sh") is True:
						os.system("/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/ba_script.sh")

					file = open("/proc/stb/info/model", "r")
					box = file.readline().strip()
					file.close()
					if box <> "dm8000":
						evfd.getInstance().vfd_write_string("Image Ready!")
					restartbox = self.session.openWithCallback(self.restart,MessageBox,_("Die Settings wurden kopiert!\nSoll ein Neustart durchgefuehrt werden?"), MessageBox.TYPE_YESNO)
					restartbox.setTitle(_("UFS-Box starten?"))

	def oldimage_install(self, answer):
		if answer == True:
      # install Old-Image
			if self.focus is self.LIST_DEVICE:
				self.focus = self.LIST_IPK
				self["filelist"].hide()
				self["devicelist"].hide()
				self["ipklist"].show()
				self["textbar"].text = _("Install-Image")
				self["filelist"].refresh()
				self["ipklist"].refresh()
				self["devicelist"].refresh()

				self.target = self.devicelist.getFilename()
				self.currDir = "/UFS_Images/"
				self.urlname = self.ipklist.getFilename()
				self.error_counter = "0"


      # install Old-Image
				if self.BAtyp == "old":
					file = open("/proc/stb/info/model", "r")
					box = file.readline().strip()
					file.close()
					if box <> "dm8000":
						evfd.getInstance().vfd_write_string("Install Image")
					self["statusbar"].text = _("Decompressing Image in progress...")

					# this is the Imagename in /var/baroot/UFS_Images
					self.urlnameorg = self.urlname
					self.urlname = self.urlname.replace(".img.tar.gz","")
					self.urlname = self.urlname.replace(".tar.gz","")
					self.urlname_org = self.urlname

					# write name to userfile
					TargetDir = "NewDir=" + self.urlname_org
					ffile = open("/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/ba_url", "w")
					ffile.write(TargetDir)
					ffile.close()

 					self.fulltarget = "/mnt/usb/" + self.target
					TarString = "cd /UFS_Images; tar -xzf " + self.urlnameorg + " -C " + self.fulltarget
					os.system(TarString)

					os.system("sync")
 					self.device = "/dev/sda2"
 					# read mountpoint
					procfile = open("/proc/mounts")
					for n in procfile.readlines():
						if n.split(' ')[1] == self.fulltarget:
							self.device = n.split(' ')[0]
					procfile.close()

					# read current imagename
					if os.path.exists("/ba/.baboot") is True:
						f = open("/ba/.baboot", "r" )
						for line in f:
							self.sourceimg = line.lstrip()
						f.close
						self.sourceimg = self.sourceimg.replace("\n","")

					TarString = "mkdir -p /ba/ba/" + self.urlname
					os.system(TarString)

					self.devid = "0:" + self.device[8:9]
					fileread = open("/ba/ba/" + self.sourceimg + "/bootp.conf", "r" )
					filewrite = open("/ba/ba/" + self.urlname + "/bootp.conf", "w" )

					self.urlname = self.fulltarget

					for line in fileread:
								if line.split('=')[0] == "BADEVICE":
											line = "BADEVICE=" + self.device + "\n"
								if line.split('=')[0] == "BADEVID":
											line = "BADEVID=" + self.devid + "\n"
								filewrite.write(line)
					fileread.close()
					filewrite.close()

          # and now we copy the settings
					if config.AddonManager.ba_settings_on.value == 1:
						file = open("/proc/stb/info/model", "r")
						box = file.readline().strip()
						file.close()
						if box <> "dm8000":
							evfd.getInstance().vfd_write_string("install Settings")
						self["statusbar"].text = _("Settings werden uebernommen....")

						CpString = "rm  " + self.urlname + "/var/etc/.firstboot"
						os.system(CpString)
						CpString = "cp -RP /var/emu " + self.urlname + "/var/"
						os.system(CpString)
						CpString = "cp -RP /var/keys " + self.urlname + "/var/"
						os.system(CpString)
						CpString = "cp /var/etc/active_cam " + self.urlname + "/var/etc/active_cam"
						os.system(CpString)
						CpString = "cp /var/etc/*emu " + self.urlname + "/var/etc/"
						os.system(CpString)
						CpString = "cp /var/etc/smbfs " + self.urlname + "/var/etc/"
						os.system(CpString)
						CpString = "cp /var/etc/upnpfs " + self.urlname + "/var/etc/"
						os.system(CpString)


						CpString = "cp /var/*emu " + self.urlname + "/var/"
						os.system(CpString)
						CpString = "cp /usr/local/share/enigma2/lamedb " + self.urlname + "/usr/local/share/enigma2/"
						os.system(CpString)
						CpString = "cp /usr/local/share/enigma2/bouquets* " + self.urlname + "/usr/local/share/enigma2/"
						os.system(CpString)
						CpString = "cp /usr/local/share/enigma2/userbouquet* " + self.urlname + "/usr/local/share/enigma2/"
						os.system(CpString)
						CpString = "cp /etc/tuxbox/satellites.xml " + self.urlname + "/etc/tuxbox/satellites.xml"
						os.system(CpString)
						#CpString = "cp /usr/local/share/enigma2/settings " + self.urlname + "/usr/local/share/enigma2/"
						#os.system(CpString)
						CpString = "cp /usr/automount/amount.ini " + self.urlname + "/usr/automount/amount.ini"
						os.system(CpString)

						#// Check for default skin
						defaultSkin = 0
						PathString = self.urlname + "/var/usr/local/share/enigma2/settings"
						if os.path.exists(PathString) is True:
							em = open(PathString)
							e = em.readlines()
							em.close()
							for line in e:
								if line.find("config.skin.primary_skin") > -1:
										defaultSkin = 1
										PrimarySkin = line

						CpString = "cp /usr/local/share/enigma2/settings " + self.urlname + "/usr/local/share/enigma2/"
						os.system(CpString)

						if defaultSkin == 1:
								em = open(PathString, "a")
								em.write(PrimarySkin)
								em.close()


					if config.AddonManager.ba_skins_on.value == 1:
							CpString = "cp -RP /usr/local/share/enigma2/ " + self.urlname + "/usr/local/share/"
							os.system(CpString)

							CpString = "cp -RP /usr/lib/enigma2/python/Plugins/Extensions/InfoBarConfig/ " + self.urlname + "/usr/lib/enigma2/python/Plugins/Extensions/"
							os.system(CpString)

							CpString = "cp /usr/lib/enigma2/python/Components/Converter/MaxCryptoInfo.pyc " + self.urlname + "/usr/lib/enigma2/python/Components/Converter/"
							os.system(CpString)

							CpString = "cp /usr/lib/enigma2/python/Components/Converter/MaxServiceInfo.pyc " + self.urlname + "/usr/lib/enigma2/python/Components/Converter/"
							os.system(CpString)

							if os.path.exists("/usr/share/enigma2/picon/") is True:
								CpString = "cp -RP /usr/share/enigma2/picon/ " + self.urlname + "/usr/share/enigma2/"
								os.system(CpString)

					if config.AddonManager.ba_plugins_on.value == 1:
							# save AddonManager + Aafpanel, because in new image is newer
							os.system("cp -RP /usr/lib/enigma2/python/Plugins/Extensions/AddonManager /tmp/")
							os.system("cp -RP /usr/lib/enigma2/python/Plugins/Extensions/Aafpanel /tmp/")
							CpString = "cp -RP /usr/lib/enigma2/python/Plugins/Extensions " + self.urlname + "/usr/lib/enigma2/python/Plugins/"
							os.system(CpString)
							# restore AddonManager + Aafpanel
							CpString = "cp -RP /tmp/AddonManager " + self.urlname + "/usr/lib/enigma2/python/Plugins/"
							os.system(CpString)
							CpString = "cp -RP /tmp/Aafpanel " + self.urlname + "/usr/lib/enigma2/python/Plugins/"
							os.system(CpString)

					if config.AddonManager.ba_remove_on.value == 1:
							CpString = "rm -r /var/baroot/ba/UFS_Images/" + self.urlname
							os.system(CpString)

					if config.AddonManager.ba_usersettings_on.value == 1:
						if os.path.exists("/default_settings") is True:
							CpString = "cp /default_settings " + self.urlname + "/usr/local/share/enigma2/settings"
							os.system(CpString)

					if os.path.exists("/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/ba_script.sh") is True:
						os.system("/usr/lib/enigma2/python/Plugins/Extensions/AddonManager/ba_script.sh")

					file = open("/proc/stb/info/model", "r")
					box = file.readline().strip()
					file.close()
					if box <> "dm8000":
						evfd.getInstance().vfd_write_string("Image Ready!")
					#restartbox = self.session.openWithCallback(self.restart,MessageBox,_("Das Image ist nun fertig installiert!\nSoll ein Neustart durchgefuehrt werden?"), MessageBox.TYPE_YESNO)
					#restartbox.setTitle(_("UFS-Box starten?"))
		 	 		message = "%s" % (_("Das Image ist nun fertig installiert!\nSoll ein Neustart durchgefuehrt werden?"))
		 	 		self.session.openWithCallback(self.restart, MessageBox, message, MessageBox.TYPE_YESNO)
