def __init__(self, params): self._content_type = params.get('content_type', 'executable') #check if the accounts directory is present, create otherwise # keep dataPath "utf-8" encoded dataPath = xbmc.translatePath( ADDON.getAddonInfo('profile')).decode("utf-8") self._accounts_dir = dataPath + u'/accounts/' if not xbmcvfs.exists(self._accounts_dir.encode("utf-8")): xbmcvfs.mkdirs(self._accounts_dir.encode("utf-8")) #Check if we need to get previous account settings from old addon settings if ADDON.getSetting('access_token').decode("utf-8") != u'': #Old access_token present so convert old settings! log('Converting old account settings and saving it') account_name = u'Account1' access_token = ADDON.getSetting('access_token').decode("utf-8") client = XBMCDropBoxClient(access_token=access_token) account_info = client.getAccountInfo() if 'display_name' in account_info: account_name = path_from(account_info['display_name']) new_account = AccountSettings(account_name) new_account.access_token = ADDON.getSetting('access_token').decode( "utf-8") new_account.passcode = ADDON.getSetting('passcode') passcodetimeout = ADDON.getSetting('passcodetimeout') if passcodetimeout != '': new_account.passcodetimeout = int(passcodetimeout) #new_account.session_id = tmp_dict.session_id new_account.synchronisation = ( 'true' == ADDON.getSetting('synchronisation').lower()) syncfreq = ADDON.getSetting('syncfreq') if syncfreq != '': new_account.syncfreq = int(syncfreq) new_account.syncpath = ADDON.getSetting('syncpath').decode("utf-8") new_account.remotepath = ADDON.getSetting('remotepath').decode( "utf-8") new_account.save() #Now clear all old settings ADDON.setSetting('access_token', '') ADDON.setSetting('passcode', '') ADDON.setSetting('passcodetimeout', '') ADDON.setSetting('synchronisation', 'false') ADDON.setSetting('syncpath', '') ADDON.setSetting('remotepath', '') #cleanup old cache and shadow dirs #keep cache_path "utf-8" encoded cache_path = ADDON.getSetting('cachepath') #Use user defined location? if cache_path == '' or os.path.normpath(cache_path) == '': #get the default path cache_path = xbmc.translatePath(ADDON.getAddonInfo('profile')) shadowPath = os.path.normpath(cache_path + '/shadow/') thumbPath = os.path.normpath(cache_path + '/thumb/') if xbmcvfs.exists(shadowPath.encode("utf-8")): shutil.rmtree(shadowPath) if xbmcvfs.exists(thumbPath.encode("utf-8")): shutil.rmtree(thumbPath) #Notify the DropboxSynchronizer of the new account NotifySyncClient().account_added_removed()
def __init__( self, params ): self._content_type = params.get('content_type', 'executable') #check if the accounts directory is present, create otherwise # keep dataPath "utf-8" encoded dataPath = xbmc.translatePath( ADDON.getAddonInfo('profile') ).decode("utf-8") self._accounts_dir = dataPath + u'/accounts/' if not xbmcvfs.exists( self._accounts_dir.encode("utf-8") ): xbmcvfs.mkdirs( self._accounts_dir.encode("utf-8") ) #Check if we need to get previous account settings from old addon settings if ADDON.getSetting('access_token').decode("utf-8") != u'': #Old access_token present so convert old settings! log('Converting old account settings and saving it') account_name = u'Account1' access_token = ADDON.getSetting('access_token').decode("utf-8") client = XBMCDropBoxClient(access_token=access_token) account_info = client.getAccountInfo() if 'display_name' in account_info: account_name = path_from(account_info['display_name']) new_account = AccountSettings(account_name) new_account.access_token = ADDON.getSetting('access_token').decode("utf-8") new_account.passcode = ADDON.getSetting('passcode') passcodetimeout = ADDON.getSetting('passcodetimeout') if passcodetimeout != '': new_account.passcodetimeout = int( passcodetimeout ) #new_account.session_id = tmp_dict.session_id new_account.synchronisation = ('true' == ADDON.getSetting('synchronisation').lower()) syncfreq = ADDON.getSetting('syncfreq') if syncfreq != '': new_account.syncfreq = int( syncfreq ) new_account.syncpath = ADDON.getSetting('syncpath').decode("utf-8") new_account.remotepath = ADDON.getSetting('remotepath').decode("utf-8") new_account.save() #Now clear all old settings ADDON.setSetting('access_token', '') ADDON.setSetting('passcode', '') ADDON.setSetting('passcodetimeout', '') ADDON.setSetting('synchronisation', 'false') ADDON.setSetting('syncpath', '') ADDON.setSetting('remotepath', '') #cleanup old cache and shadow dirs #keep cache_path "utf-8" encoded cache_path = ADDON.getSetting('cachepath') #Use user defined location? if cache_path == '' or os.path.normpath(cache_path) == '': #get the default path cache_path = xbmc.translatePath( ADDON.getAddonInfo('profile') ) shadowPath = os.path.normpath(cache_path + '/shadow/') thumbPath = os.path.normpath(cache_path + '/thumb/') if xbmcvfs.exists(shadowPath.encode("utf-8")): shutil.rmtree(shadowPath) if xbmcvfs.exists(thumbPath.encode("utf-8")): shutil.rmtree(thumbPath) #Notify the DropboxSynchronizer of the new account NotifySyncClient().account_added_removed()
def run(params): # This is the entrypoint action = params.get('action', '') if action == 'add': #add an account access_token = login.getAccessToken() if access_token: #save the new account account_name = 'Account1' client = XBMCDropBoxClient(access_token=access_token) account_info = client.getAccountInfo() if 'display_name' in account_info: account_name = path_from(account_info['display_name']) new_account = AccountSettings(account_name) new_account.access_token = access_token new_account.save() #Notify the DropboxSynchronizer NotifySyncClient().account_added_removed() #notify the user the account is added dialog = xbmcgui.Dialog() dialog.ok(ADDON_NAME, LANGUAGE_STRING(30004), account_name) #return to where we were and refresh xbmc.executebuiltin('container.Refresh()') elif action == 'remove': #remove the selected account account_name = urllib.unquote(params.get('account', '')) account_settings = login.get_account(account_name) if account_settings: dialog = xbmcgui.Dialog() #'are you sure' dialog if dialog.yesno(ADDON_NAME, LANGUAGE_STRING(30045), account_name) == True: try: account_settings.remove() except Exception as exc: log_error("Failed to remove the account: %s" % (str(exc))) else: #Notify the DropboxSynchronizer NotifySyncClient().account_added_removed() else: log_error("Failed to remove the account!") dialog = xbmcgui.Dialog() dialog.ok(ADDON_NAME, LANGUAGE_STRING(30203)) #return to where we were and refresh xbmc.executebuiltin('container.Refresh()') elif action == 'change_passcode': account_name = urllib.unquote(params.get('account', '')) account_settings = login.get_account(account_name) if account_settings: change_passcode(account_settings) #return to where we were xbmcplugin.endOfDirectory(int(sys.argv[1]), succeeded=False) elif action == 'change_synchronization': account_name = urllib.unquote(params.get('account', '')) account_settings = login.get_account(account_name) if account_settings: change_synchronization(account_settings) #return to where we were xbmcplugin.endOfDirectory(int(sys.argv[1]), succeeded=False) else: browser = AccountBrowser(params) browser.buildList() browser.show()
def run(params): # This is the entrypoint action = params.get('action', '') if action == 'add': #add an account access_token = login.getAccessToken() if access_token: #save the new account account_name = 'Account1' client = XBMCDropBoxClient(access_token=access_token) account_info = client.getAccountInfo() if 'display_name' in account_info: account_name = path_from(account_info['display_name']) new_account = AccountSettings(account_name) new_account.access_token = access_token new_account.save() #Notify the DropboxSynchronizer NotifySyncClient().account_added_removed() #notify the user the account is added dialog = xbmcgui.Dialog() dialog.ok(ADDON_NAME, LANGUAGE_STRING(30004), account_name) #return to where we were and refresh xbmc.executebuiltin('container.Refresh()') elif action == 'remove': #remove the selected account account_name = urllib.unquote( params.get('account', '') ) account_settings = login.get_account(account_name) if account_settings: dialog = xbmcgui.Dialog() #'are you sure' dialog if dialog.yesno(ADDON_NAME, LANGUAGE_STRING(30045), account_name ) == True: try: account_settings.remove() except Exception as exc: log_error("Failed to remove the account: %s" % (str(exc)) ) else: #Notify the DropboxSynchronizer NotifySyncClient().account_added_removed() else: log_error("Failed to remove the account!") dialog = xbmcgui.Dialog() dialog.ok(ADDON_NAME, LANGUAGE_STRING(30203)) #return to where we were and refresh xbmc.executebuiltin('container.Refresh()') elif action == 'change_passcode': account_name = urllib.unquote( params.get('account', '') ) account_settings = login.get_account(account_name) if account_settings: change_passcode(account_settings) #return to where we were xbmcplugin.endOfDirectory(int(sys.argv[1]), succeeded=False) elif action == 'change_synchronization': account_name = urllib.unquote( params.get('account', '') ) account_settings = login.get_account(account_name) if account_settings: change_synchronization(account_settings) #return to where we were xbmcplugin.endOfDirectory(int(sys.argv[1]), succeeded=False) else: browser = AccountBrowser(params) browser.buildList() browser.show()
def _get_settings( self ): account = AccountSettings(self.account_name) self._storageFile = os.path.normpath(account.account_dir + u'/sync_data.pik') gotSemaphore = True enable = account.synchronisation tempPath = account.syncpath tempRemotePath = account.remotepath tempFreq = float(account.syncfreq) #The following settings can't be changed while syncing! if not self.syncSemaphore.acquire(False): gotSemaphore = False settingsChanged = False if (enable != self._enabled) or (tempPath != self._syncPath) or (tempRemotePath != self._remoteSyncPath): log('Can\'t change settings while synchronizing for %s!' % (self.account_name) ) dialog = xbmcgui.Dialog() stopSync = dialog.yesno(ADDON_NAME, LANGUAGE_STRING(30110), LANGUAGE_STRING(30113)) if stopSync: self.stop_sync() # stop the Synchronization log('Synchronizing stopped for %s!' % (self.account_name) ) #wait for the semaphore to be released self.syncSemaphore.acquire() gotSemaphore = True else: #revert the changes account.synchronisation = self._enabled account.syncpath = self._syncPath account.remotepath = self._remoteSyncPath account.save() return #Enable? if enable and (tempPath == '' or tempRemotePath == ''): enable = False account.synchronisation = False account.save() log_error('Can\'t enable synchronization: syncpath or remotepath not set!') dialog = xbmcgui.Dialog() dialog.ok(ADDON_NAME, LANGUAGE_STRING(30111)) self._enabled = enable if self._syncPath == u'': #get initial location self._syncPath = tempPath #Sync path changed? if self._syncPath != tempPath: if len(os.listdir(tempPath)) == 0: if xbmcvfs.exists(self._syncPath.encode("utf-8")): #move the old sync path to the new one log('Moving sync location for %s from %s to %s'%(self.account_name, self._syncPath, tempPath)) names = os.listdir(self._syncPath) for name in names: srcname = os.path.join(self._syncPath, name) shutil.move(srcname, tempPath) self._syncPath = tempPath if self.root: self.root.updateLocalRootPath(self._syncPath) log('SyncPath updated for %s' % (self.account_name) ) xbmc.executebuiltin('Notification(%s,%s,%d,%s)' % (LANGUAGE_STRING(30103), tempPath, 7000, ICON)) else: log_error('New sync location is not empty: %s'%(tempPath)) dialog = xbmcgui.Dialog() dialog.ok(ADDON_NAME, LANGUAGE_STRING(30104), tempPath) #restore the old location account.syncpath = self._syncPath account.save() if self._remoteSyncPath == '': #get initial location self._remoteSyncPath = tempRemotePath #remote path changed? if tempRemotePath != self._remoteSyncPath: self._remoteSyncPath = tempRemotePath log('Changed remote path for %s to %s'%(self.account_name, self._remoteSyncPath)) if self.root: #restart the synchronization #remove all the files in current syncPath if xbmcvfs.exists(self._syncPath.encode("utf-8")) and len(os.listdir(self._syncPath)) > 0: shutil.rmtree(self._syncPath) #reset the complete data on client side self.clearSyncData() del self.root self.root = None #Start sync immediately self._newSyncTime = time.time() #Time interval changed? self._updateSyncTime(tempFreq) #reconnect to Dropbox (in case the token has changed) self._access_token = account.access_token self._getClient(reconnect=True) if self._enabled and not self.root: log('Enabled synchronization for %s' % (self.account_name) ) self._setupSyncRoot() elif not self._enabled and self.root: log('Disabled synchronization for %s' % (self.account_name) ) self._syncFreq = 0 # trigger a sync next time it is enabled again self.stop_sync() del self.root self.root = None if gotSemaphore: self.syncSemaphore.release()
def _get_settings(self): account = AccountSettings(self.account_name) self._storageFile = os.path.normpath(account.account_dir + u'/sync_data.pik') gotSemaphore = True enable = account.synchronisation tempPath = account.syncpath tempRemotePath = account.remotepath tempFreq = float(account.syncfreq) #The following settings can't be changed while syncing! if not self.syncSemaphore.acquire(False): gotSemaphore = False settingsChanged = False if (enable != self._enabled) or (tempPath != self._syncPath) or ( tempRemotePath != self._remoteSyncPath): log('Can\'t change settings while synchronizing for %s!' % (self.account_name)) dialog = xbmcgui.Dialog() stopSync = dialog.yesno(ADDON_NAME, LANGUAGE_STRING(30110), LANGUAGE_STRING(30113)) if stopSync: self.stop_sync() # stop the Synchronization log('Synchronizing stopped for %s!' % (self.account_name)) #wait for the semaphore to be released self.syncSemaphore.acquire() gotSemaphore = True else: #revert the changes account.synchronisation = self._enabled account.syncpath = self._syncPath account.remotepath = self._remoteSyncPath account.save() return #Enable? if enable and (tempPath == '' or tempRemotePath == ''): enable = False account.synchronisation = False account.save() log_error( 'Can\'t enable synchronization: syncpath or remotepath not set!' ) dialog = xbmcgui.Dialog() dialog.ok(ADDON_NAME, LANGUAGE_STRING(30111)) self._enabled = enable if self._syncPath == u'': #get initial location self._syncPath = tempPath #Sync path changed? if self._syncPath != tempPath: if len(os.listdir(tempPath)) == 0: if xbmcvfs.exists(self._syncPath.encode("utf-8")): #move the old sync path to the new one log('Moving sync location for %s from %s to %s' % (self.account_name, self._syncPath, tempPath)) names = os.listdir(self._syncPath) for name in names: srcname = os.path.join(self._syncPath, name) shutil.move(srcname, tempPath) self._syncPath = tempPath if self.root: self.root.updateLocalRootPath(self._syncPath) log('SyncPath updated for %s' % (self.account_name)) xbmc.executebuiltin( 'Notification(%s,%s,%d,%s)' % (LANGUAGE_STRING(30103), tempPath, 7000, ICON)) else: log_error('New sync location is not empty: %s' % (tempPath)) dialog = xbmcgui.Dialog() dialog.ok(ADDON_NAME, LANGUAGE_STRING(30104), tempPath) #restore the old location account.syncpath = self._syncPath account.save() if self._remoteSyncPath == '': #get initial location self._remoteSyncPath = tempRemotePath #remote path changed? if tempRemotePath != self._remoteSyncPath: self._remoteSyncPath = tempRemotePath log('Changed remote path for %s to %s' % (self.account_name, self._remoteSyncPath)) if self.root: #restart the synchronization #remove all the files in current syncPath if xbmcvfs.exists(self._syncPath.encode("utf-8")) and len( os.listdir(self._syncPath)) > 0: shutil.rmtree(self._syncPath) #reset the complete data on client side self.clearSyncData() del self.root self.root = None #Start sync immediately self._newSyncTime = time.time() #Time interval changed? self._updateSyncTime(tempFreq) #reconnect to Dropbox (in case the token has changed) self._access_token = account.access_token self._getClient(reconnect=True) if self._enabled and not self.root: log('Enabled synchronization for %s' % (self.account_name)) self._setupSyncRoot() elif not self._enabled and self.root: log('Disabled synchronization for %s' % (self.account_name)) self._syncFreq = 0 # trigger a sync next time it is enabled again self.stop_sync() del self.root self.root = None if gotSemaphore: self.syncSemaphore.release()