Ejemplo n.º 1
0
    def __init__(self):

        log('main addon starting')

        if not os.path.isfile('/walkthrough_completed'):
            # Tell Kodi that OSMC is running the walkthrough
            try:
                xbmc.setosmcwalkthroughstatus(1)
            except Exception as e:
                log(traceback.format_exc())
        else:
            try:
                # Tell Kodi that OSMC is done
                xbmc.setosmcwalkthroughstatus(2)
            except Exception as e:
                log(traceback.format_exc())

        # queue for communication with the comm and Main
        self.parent_queue = Queue.Queue()

        # create socket, listen for comms
        self.listener = osmc_comms.communicator(
            self.parent_queue, socket_file='/var/tmp/osmc.settings.sockfile')
        self.listener.start()

        # the gui is created and stored in memory for quick access
        # after a few hours, the gui should be removed from memory
        self.create_gui()
        self.gui_last_accessed = datetime.datetime.now()
        self.skip_check = True

        # monitor created to check for xbmc abort requests
        self.monitor = xbmc.Monitor()

        # current skin directory, used to detect when the user has changed skins and prompts a reconstruction of the gui
        self.skindir = xbmc.getSkinDir()

        # run the ubiquifonts script to import the needed fonts into the Font.xml
        response = osmc_ubiquifonts.import_osmc_fonts()

        if response == 'reload_please':

            log('Skin reload requested')

            xbmc.executebuiltin('ReloadSkin()')

        # daemon
        self._daemon()

        log('_daemon exited')
Ejemplo n.º 2
0
	def __init__(self):

		log('main addon starting')

		if not os.path.isfile('/walkthrough_completed'):
			# Tell Kodi that OSMC is running the walkthrough
			try:
				xbmc.setosmcwalkthroughstatus(1)
			except Exception as e:
				log(traceback.format_exc())
		else:
			try:
				# Tell Kodi that OSMC is done
				xbmc.setosmcwalkthroughstatus(2)
			except Exception as e:
				log(traceback.format_exc())

		# queue for communication with the comm and Main
		self.parent_queue = Queue.Queue()

		# create socket, listen for comms
		self.listener = osmc_comms.communicator(self.parent_queue, socket_file='/var/tmp/osmc.settings.sockfile')
		self.listener.start()

		# the gui is created and stored in memory for quick access
		# after a few hours, the gui should be removed from memory
		self.create_gui()
		self.gui_last_accessed = datetime.datetime.now()
		self.skip_check = True

		# monitor created to check for xbmc abort requests
		self.monitor = xbmc.Monitor()

		# current skin directory, used to detect when the user has changed skins and prompts a reconstruction of the gui
		self.skindir = xbmc.getSkinDir()

		# run the ubiquifonts script to import the needed fonts into the Font.xml
		response = osmc_ubiquifonts.import_osmc_fonts()

		if response == 'reload_please':

			log('Skin reload requested')

			xbmc.executebuiltin('ReloadSkin()')
			
		# daemon
		self._daemon()

		log('_daemon exited')
Ejemplo n.º 3
0
    def _daemon(self):

        log('daemon started')

        if not os.path.isfile('/walkthrough_completed'):

            for module in self.stored_gui.live_modules:
                if 'id' in module:
                    if module['id'] == "script.module.osmcsetting.networking":
                        networking_instance = module['SET']

                        vendor = check_vendor()

                        osmc_walkthru.open_gui(networking_instance)

                        log("Vendor is %s" % vendor)

                        with open('/tmp/walkthrough_completed', 'w+') as f:
                            log('/tmp/walkthrough_completed written')
                            pass

                        subprocess.call([
                            'sudo', 'mv', '/tmp/walkthrough_completed',
                            '/walkthrough_completed'
                        ])
                        try:
                            xbmc.setosmcwalkthroughstatus(2)
                        except Exception as e:
                            log(traceback.format_exc())

                        WINDOW.clearProperty('walkthrough_is_running')

                        xbmc.executebuiltin('ReloadSkin()')

                        log('Skin reloaded')

                        # @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

                        # Query user about whether they would like to update now

                        update_check_now = False

                        if vendor == 'noobs':

                            update_check_now = DIALOG.yesno(
                                lang(32026), lang(32027), lang(32028),
                                lang(32029))

                        elif vendor == 'ts':

                            update_check_now = DIALOG.yesno(
                                lang(32026), lang(32030), lang(32031),
                                lang(32029))

                        if update_check_now:

                            log('User elected to update now')

                            try:

                                address = '/var/tmp/osmc.settings.update.sockfile'

                                message = ('settings_command', {
                                    'action': 'update'
                                })

                                message = json.dumps(message)

                                sock = socket.socket(socket.AF_UNIX,
                                                     socket.SOCK_STREAM)
                                sock.connect(address)
                                sock.sendall(message)
                                sock.close()

                            except Exception as e:

                                log(traceback.format_exc())

                        # @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

                        break
            else:
                log('Networking module not found')

        while True:

            # Check the current skin directory, if it is different to the previous one, then
            # recreate the gui. This is required because reference in the gui left in memory
            # do not survive a refresh of the skins textures (???)
            if self.skindir != xbmc.getSkinDir():

                log('Old Skin: %s' % self.skindir)

                self.skindir = xbmc.getSkinDir()

                log('New Skin: %s' % self.skindir)

                try:
                    resp = osmc_ubiquifonts.import_osmc_fonts()

                    log('Ubiquifonts result: %s' % resp)

                    if resp == 'reload_please':

                        while True:

                            xbmc.sleep(1000)

                            xml = xbmc.getInfoLabel('Window.Property(xmlfile)')

                            if xml not in [
                                    'DialogYesNo.xml', 'Dialogyesno.xml',
                                    'DialogYesno.xml', 'DialogyesNo.xml',
                                    'dialogyesno.xml'
                            ]:

                                log('Skin reload requested')

                                xbmc.executebuiltin('ReloadSkin()')

                                break

                except Exception as e:

                    log(traceback.format_exc())

                try:
                    log('skin changed, reloading gui')
                    del self.stored_gui
                except:
                    pass

                self.create_gui()

            # if xbmc is aborting
            if self.monitor.waitForAbort(1):

                self.exit()

                break

            if not self.parent_queue.empty():

                response = self.parent_queue.get()

                log('response : %s' % response)

                self.parent_queue.task_done()

                if response == 'open':
                    try:
                        del self.stored_gui  # TESTING: this will mean that the gui is populated and loaded every time it opens
                    except:
                        pass
                    self.open_gui()

                elif response == 'refresh_gui':
                    ''' This may need to be moved to a separate thread, so that it doesnt hold up the other functions. '''

                    # if the gui calls for its own refresh, then delete the existing one and open a new instance

                    # del self.stored_gui

                    self.open_gui()

                elif response == 'exit':

                    self.exit()
                    break

                elif response == 'walkthru':

                    log('Running manually called walkthru')

                    osmc_walkthru.open_gui(None, testing=True)

                    # for module in self.stored_gui.live_modules:
                    # 	if 'id' in module:
                    # 		log(module['id'])
                    # 		if module['id'] == "script.module.osmcsetting.networking":
                    # 			networking_instance = module['SET']

                    # 			osmc_walkthru.open_gui(networking_instance)

                    # 			break

                    # else:
                    # 	log('Networking module not found')

                elif 'new_device:' in response:

                    # a usb device is attached to the hardware

                    # get the device id
                    device_id = response[len('new_device:'):]

                    # proceed only if the device_id is not null
                    if device_id:

                        # get ignore list
                        ignore_list_raw = __setting__('ignored_devices')
                        ignore_list = ignore_list_raw.split('|')

                        # get sources list
                        media_string = self.get_sources_list()

                        # post dialogs to ask the user if they want to add the source, or ignore the device
                        if device_id not in ignore_list and device_id not in media_string:

                            d1 = DIALOG.yesno(lang(32002), lang(32003),
                                              lang(32004))

                            if d1:

                                xbmc.executebuiltin(
                                    "ActivateWindow(mediasource)")

                            else:

                                d2 = DIALOG.yesno(lang(32002), lang(32005))

                                if d2:
                                    ignore_list.append(str(device_id))
                                    ignore_string = '|'.join(ignore_list)
                                    __addon__.setSetting(
                                        'ignored_devices', ignore_string)

                else:
                    # check whether the response is one of the live_modules, if it is then launch that module

                    for module in self.stored_gui.live_modules:
                        if response == module.get('id', 'id_not_found'):

                            instance = module.get('SET', False)

                            if instance.isAlive():
                                log('Opening %s from widget' % instance)
                                instance.run()

                            else:
                                log('Starting %s from widget' % instance)

                                setting_instance = module[
                                    'OSMCSetting'].OSMCSettingClass()
                                setting_instance.setDaemon(True)

                                module['SET'] = setting_instance

                                setting_instance.start()

            # THIS PART MAY NOT BE NEEDED, BUT IS INCLUDED HERE ANYWAY FOR TESTING PURPOSES
            # if the gui was last accessed more than four hours
            # if not self.skip_check and (datetime.datetime.now() - self.gui_last_accessed).total_seconds() > 14400:

            # 	self.skip_check = True

            # 	del self.stored_gui

        log('_daemon exiting')
Ejemplo n.º 4
0
 http://www.gnu.org/copyleft/gpl.html
'''

# OS module
import os
import traceback

# XBMC modules
import xbmc
import xbmcaddon
import xbmcgui
WINDOW = xbmcgui.Window(10000)
if not os.path.isfile('/walkthrough_completed'):
    WINDOW.setProperty("walkthrough_is_running", 'any_value')
    try:
        xbmc.setosmcwalkthroughstatus(1)
    except Exception as e:
        print traceback.format_exc()

# Standard modules
import datetime
import json
import Queue
import re
import shutil
import socket
import subprocess
import sys
import threading
import time
Ejemplo n.º 5
0
	def _daemon(self):

		log('daemon started')

		if not os.path.isfile('/walkthrough_completed'):

			for module in self.stored_gui.live_modules:
				if 'id' in module:
					if module['id'] == "script.module.osmcsetting.networking":
						networking_instance = module['SET']

						vendor = check_vendor()

						walkthru.open_gui(networking_instance)

						log("Vendor is %s" % vendor)

						with open('/tmp/walkthrough_completed', 'w+') as f:
							log('/tmp/walkthrough_completed written')
							pass
							
						subprocess.call(['sudo', 'mv', '/tmp/walkthrough_completed', '/walkthrough_completed'])

						xbmc.setosmcwalkthroughstatus(2)

						WINDOW.clearProperty('walkthrough_is_running')
						
						xbmc.executebuiltin('ReloadSkin()')

						log('Skin reloaded')

						# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
						
						# Query user about whether they would like to update now

						update_check_now = False

						if vendor == 'noobs':

							update_check_now = DIALOG.yesno(lang(32026), lang(32027), lang(32028), lang(32029))

						elif vendor == 'ts':

							update_check_now = DIALOG.yesno(lang(32026), lang(32030), lang(32031), lang(32029))

						if update_check_now:

							log('User elected to update now')

							try:

								address = '/var/tmp/osmc.settings.update.sockfile'

								message = ('settings_command', {'action': 'update'})

								message = json.dumps(message)

								sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
								sock.connect(address)
								sock.sendall(message) 
								sock.close()

							except Exception as e:

								log(traceback.format_exc())

						# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
						
						break
			else:
				log('Networking module not found')

		while True:

			# Check the current skin directory, if it is different to the previous one, then 
			# recreate the gui. This is required because reference in the gui left in memory
			# do not survive a refresh of the skins textures (???)
			if self.skindir != xbmc.getSkinDir():

				log('Old Skin: %s' % self.skindir)

				self.skindir = xbmc.getSkinDir()

				log('New Skin: %s' % self.skindir)

				try:
					resp = ubiquifonts.import_osmc_fonts()

					log('Ubiquifonts result: %s' % resp)

					if resp == 'reload_please':

						while True:

							xbmc.sleep(1000)

							xml = xbmc.getInfoLabel('Window.Property(xmlfile)')

							if xml not in ['DialogYesNo.xml', 'Dialogyesno.xml', 'DialogYesno.xml', 'DialogyesNo.xml', 'dialogyesno.xml']: 

								log('Skin reload requested')
								
								xbmc.executebuiltin('ReloadSkin()')
								
								break
				
				except Exception as e:

					log(traceback.format_exc())

				try:
					log('skin changed, reloading gui')
					del self.stored_gui
				except:
					pass

				self.create_gui()
			
			# if xbmc is aborting
			if self.monitor.waitForAbort(1):
				
				self.exit()

				break

			if not self.parent_queue.empty():

				response = self.parent_queue.get()

				log('response : %s' % response)

				self.parent_queue.task_done()
		
				if response == 'open':
					try:
						del self.stored_gui  	# TESTING: this will mean that the gui is populated and loaded every time it opens
					except:
						pass
					self.open_gui()

				elif response == 'refresh_gui':

					''' This may need to be moved to a separate thread, so that it doesnt hold up the other functions. '''

					# if the gui calls for its own refresh, then delete the existing one and open a new instance

					# del self.stored_gui

					self.open_gui()

				elif response == 'exit':

					self.exit()
					break

				elif response == 'walkthru':

					for module in self.stored_gui.live_modules:
						if 'id' in module:
							log(module['id'])
							if module['id'] == "script.module.osmcsetting.networking":
								networking_instance = module['SET']

								walkthru.open_gui(networking_instance)

								break
			
					else:
						log('Networking module not found')

				elif 'new_device:' in response:

					# a usb device is attached to the hardware
					
					# get the device id					
					device_id = response[len('new_device:'):]

					# proceed only if the device_id is not null
					if device_id:

						# get ignore list
						ignore_list_raw = __setting__('ignored_devices')
						ignore_list = ignore_list_raw.split('|')

						# get sources list
						media_string = self.get_sources_list()

						# post dialogs to ask the user if they want to add the source, or ignore the device
						if device_id not in ignore_list and device_id not in media_string:

							d1 = DIALOG.yesno(lang(32002), lang(32003),lang(32004))

							if d1:

								xbmc.executebuiltin("ActivateWindow(mediasource)")

							else:

								d2 = DIALOG.yesno(lang(32002), lang(32005))

								if d2:
									ignore_list.append(str(device_id))
									ignore_string = '|'.join(ignore_list)
									__addon__.setSetting('ignored_devices', ignore_string)

				else:
					# check whether the response is one of the live_modules, if it is then launch that module

					for module in self.stored_gui.live_modules:
						if response == module.get('id', 'id_not_found'):

							instance = module.get('SET', False)

							if instance.isAlive():
								log('Opening %s from widget' % instance)
								instance.run()

							else:
								log('Starting %s from widget' % instance)

								setting_instance = module['OSMCSetting'].OSMCSettingClass()
								setting_instance.setDaemon(True)

								module['SET'] = setting_instance

								setting_instance.start()
							

			# THIS PART MAY NOT BE NEEDED, BUT IS INCLUDED HERE ANYWAY FOR TESTING PURPOSES
			# if the gui was last accessed more than four hours
			if not self.skip_check and (datetime.datetime.now() - self.gui_last_accessed).total_seconds() > 14400:

				self.skip_check = True

				del self.stored_gui

		log('_daemon exiting')
Ejemplo n.º 6
0
 def set_walkthrough_status(value):
     try:
         # Tell Kodi that OSMC is done
         xbmc.setosmcwalkthroughstatus(int(value))
     except Exception:
         log(traceback.format_exc())
Ejemplo n.º 7
0
 http://www.gnu.org/copyleft/gpl.html
'''

# OS module
import os
import traceback

# XBMC modules
import xbmc
import xbmcaddon
import xbmcgui
WINDOW = xbmcgui.Window(10000)
if not os.path.isfile('/walkthrough_completed'):
	WINDOW.setProperty("walkthrough_is_running", 'any_value')
	try:
		xbmc.setosmcwalkthroughstatus(1)
	except Exception as e:
		print traceback.format_exc()

# Standard modules
import datetime
import json
import Queue
import re
import shutil
import socket
import subprocess
import sys
import threading
import time