def remove_auth(): # triggered from settings.xml - asks if user wants to delete OAuth token information shouldDelete = xbmcgui.Dialog().yesno(utils.getString(30093), utils.getString(30094), utils.getString(30095), autoclose=7000) if(shouldDelete): # delete any of the known token file types xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "tokens.txt")) # dropbox xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "google_drive.dat")) # google drive
def _getToken(self): #get token, if it exists if(xbmcvfs.exists(xbmc.translatePath(utils.data_dir() + "tokens.txt"))): token_file = open(xbmc.translatePath(utils.data_dir() + "tokens.txt")) token = token_file.read() token_file.close() return token else: return ""
def _resumeCheck(self): shouldContinue = False if(xbmcvfs.exists(xbmc.translatePath(utils.data_dir() + "resume.txt"))): rFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "resume.txt"),'r') self.restore_point = rFile.read() rFile.close() xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "resume.txt")) shouldContinue = xbmcgui.Dialog().yesno(utils.getString(30042),utils.getString(30043),utils.getString(30044)) return shouldContinue
def _resumeCheck(self): shouldContinue = False if (xbmcvfs.exists(xbmc.translatePath(utils.data_dir() + "resume.txt"))): rFile = xbmcvfs.File( xbmc.translatePath(utils.data_dir() + "resume.txt"), 'r') self.restore_point = rFile.read() rFile.close() xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "resume.txt")) shouldContinue = xbmcgui.Dialog().yesno(utils.getString(30042), utils.getString(30043), utils.getString(30044)) return shouldContinue
def writeLastRun(self): runFile = xbmcvfs.File( xbmcvfs.translatePath(utils.data_dir() + "last_run.txt"), 'w') runFile.write(str(self.last_run)) runFile.close() self.showNotify(True)
def readLastRun(self): if(self.last_run == 0): #read it in from the settings if(xbmcvfs.exists(xbmc.translatePath(utils.data_dir() + "last_run.txt"))): runFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "last_run.txt")) try: #there may be an issue with this file, we'll get it the next time through self.last_run = float(runFile.read()) except ValueError: self.last_run = 0 runFile.close() else: self.last_run = 0
def __init__(self): self.monitor = UpdateMonitor(update_method = self.settingsChanged) self.enabled = utils.getSetting("enable_scheduler") self.next_run_path = xbmc.translatePath(utils.data_dir()) + 'next_run.txt' if(self.enabled == "true"): nr = 0 if(xbmcvfs.exists(self.next_run_path)): fh = xbmcvfs.File(self.next_run_path) try: #check if we saved a run time from the last run nr = float(fh.read()) except ValueError: nr = 0 fh.close() #if we missed and the user wants to play catch-up if(0 < nr <= time.time() and utils.getSetting('schedule_miss') == 'true'): utils.log("scheduled backup was missed, doing it now...") progress_mode = int(utils.getSetting('progress_mode')) if(progress_mode == 0): progress_mode = 1 # Kodi just started, don't block it with a foreground progress bar self.doScheduledBackup(progress_mode) self.setup()
def __init__(self): self.monitor = UpdateMonitor(update_method=self.settingsChanged) self.enabled = utils.getSetting("enable_scheduler") self.next_run_path = xbmc.translatePath( utils.data_dir()) + 'next_run.txt' if (self.enabled == "true"): nr = 0 if (xbmcvfs.exists(self.next_run_path)): fh = xbmcvfs.File(self.next_run_path) try: #check if we saved a run time from the last run nr = float(fh.read()) except ValueError: nr = 0 fh.close() #if we missed and the user wants to play catch-up if (0 < nr <= time.time() and utils.getSetting('schedule_miss') == 'true'): utils.log("scheduled backup was missed, doing it now...") progress_mode = int(utils.getSetting('progress_mode')) if (progress_mode == 0): progress_mode = 1 # Kodi just started, don't block it with a foreground progress bar self.doScheduledBackup(progress_mode) self.setup()
def authorize(self): result = True if (not self.setup()): return False #create authorization helper and load default settings gauth = GoogleAuth( xbmc.validatePath( xbmc.translatePath(utils.addon_dir() + '/resources/lib/pydrive/settings.yaml'))) gauth.LoadClientConfigSettings() settings = { "client_id": self.CLIENT_ID, 'client_secret': self.CLIENT_SECRET } drive_url = gauth.GetAuthUrl(settings) utils.log("Google Drive Authorize URL: " + drive_url) xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30056), utils.getString(30102), tinyurl.shorten(drive_url)) code = xbmcgui.Dialog().input( utils.getString(30098) + ' ' + utils.getString(30103)) gauth.Auth(code) gauth.SaveCredentialsFile( xbmc.validatePath( xbmc.translatePath(utils.data_dir() + 'google_drive.dat'))) return result
def getClient(self): #create authorization helper and load default settings gauth = GoogleAuth(xbmc.validatePath(xbmc.translatePath(utils.addon_dir() + '/resources/lib/pydrive/settings.yaml'))) gauth.LoadClientConfigSettings() gauth.LoadCredentialsFile(xbmc.validatePath(xbmc.translatePath(utils.data_dir() + 'google_drive.dat'))) result = GoogleDrive(gauth) return result
def findNextRun(self,now,forceUpdate = False): mod_time = self.settings_update_time #check if the schedule has been modified try: #get the last modified time of the file mod_time = os.path.getmtime(xbmc.translatePath(utils.data_dir()) + "settings.xml") except: #don't do anything here mod_time = self.settings_update_time if(mod_time > self.settings_update_time or forceUpdate): self.settings_update_time = mod_time #find the cron expression and get the next run time cron_exp = self.parseSchedule() cron_ob = croniter(cron_exp,datetime.datetime.fromtimestamp(now)) new_run_time = cron_ob.get_next(float) if(new_run_time != self.next_run): self.next_run = new_run_time utils.log("scheduler will run again on " + datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M'))
def authorize(self): result = True if(not self.setup()): return False #create authorization helper and load default settings gauth = GoogleAuth(xbmc.validatePath(xbmc.translatePath(utils.addon_dir() + '/resources/lib/pydrive/settings.yaml'))) gauth.LoadClientConfigSettings() settings = {"client_id":self.CLIENT_ID,'client_secret':self.CLIENT_SECRET} drive_url = gauth.GetAuthUrl(settings) utils.log("Google Drive Authorize URL: " + drive_url) xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30056),utils.getString(30102),tinyurl.shorten(drive_url)) code = xbmcgui.Dialog().input(utils.getString(30098) + ' ' + utils.getString(30103)) gauth.Auth(code) gauth.SaveCredentialsFile(xbmc.validatePath(xbmc.translatePath(utils.data_dir() + 'google_drive.dat'))) return result
import xbmc import xbmcgui import xbmcvfs import resources.lib.utils as utils #triggered from settings.xml - asks if user wants to delete OAuth token information shouldDelete = xbmcgui.Dialog().yesno(utils.getString(30093), utils.getString(30094), utils.getString(30095), autoclose=7000) if (shouldDelete): #delete any of the known token file types xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "tokens.txt")) #dropbox xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "google_drive.dat")) #google drive
def _settingsBackup(self): #make a backup of the settings file (in case pin is incorrect) settings_file = xbmc.translatePath(utils.data_dir() + "settings.xml") if(xbmcvfs.exists(settings_file)): xbmcvfs.copy(settings_file,settings_file + ".bak")
def writeLastRun(self): runFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "last_run.txt"),'w') runFile.write(str(self.last_run)) runFile.close() self.showNotify(True)
import xbmc import xbmcgui import xbmcvfs import resources.lib.utils as utils #triggered from settings.xml - asks if user wants to delete OAuth token information shouldDelete = xbmcgui.Dialog().yesno(utils.getString(30093),utils.getString(30094),utils.getString(30095),autoclose=7000) if(shouldDelete): #delete any of the known token file types xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "tokens.txt")) #dropbox
def _deleteToken(self): if(xbmcvfs.exists(xbmc.translatePath(utils.data_dir() + "tokens.txt"))): xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "tokens.txt"))
def isAuthorized(self): return xbmcvfs.exists(xbmc.translatePath(utils.data_dir() + "google_drive.dat"))
import xbmc import xbmcgui import xbmcvfs import resources.lib.utils as utils #triggered from settings.xml - asks if user wants to delete OAuth token information shouldDelete = xbmcgui.Dialog().yesno(utils.getString(30093),utils.getString(30094),utils.getString(30095),autoclose=7000) if(shouldDelete): #delete any of the known token file types xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "tokens.txt")) #dropbox xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "google_drive.dat")) #google drive
def _settingsRestore(self): #restore the settings file (in case pin is incorrect) settings_file = xbmc.translatePath(utils.data_dir() + "settings.xml") if(xbmcvfs.exists(settings_file)): xbmcvfs.copy(settings_file + ".bak",settings_file)
def _setToken(self,token): #write the token files token_file = open(xbmc.translatePath(utils.data_dir() + "tokens.txt"),'w') token_file.write(token) token_file.close()