Ejemplo n.º 1
0
    def run(self,mode=-1,runSilent=False):
	#check if we should use the progress bar
        if(utils.getSetting('run_silent') == 'false' and not runSilent):
            self.progressBar = xbmcgui.DialogProgress()
            self.progressBar.create(utils.getString(30010),utils.getString(30049) + "......")

        #determine backup mode
        if(mode == -1):
            mode = int(utils.getSetting('addon_mode'))

        #append backup folder name
        if(mode == self.Backup and self.remote_path != ''):
            self.remote_path = self.remote_path + time.strftime("%Y%m%d") + "/"
	elif(mode == self.Restore and utils.getSetting("backup_name") != '' and self.remote_path != ''):
	    self.remote_path = self.remote_path + utils.getSetting("backup_name") + "/"
	else:
	    self.remote_path = ""

        utils.log(utils.getString(30047) + ": " + self.local_path)
        utils.log(utils.getString(30048) + ": " + self.remote_path)

        #run the correct mode
        if(mode == self.Backup):
            utils.log(utils.getString(30023) + " - " + utils.getString(30016))
            self.fileManager = FileManager(self.local_path)

            #for backups check if remote path exists
            if(vfs.exists(self.remote_path)):
                #this will fail - need a disclaimer here
                utils.log(utils.getString(30050))

            self.syncFiles()
        else:
            utils.log(utils.getString(30023) + " - " + utils.getString(30017))
            self.fileManager = FileManager(self.remote_path)

            #for restores remote path must exist
            if(vfs.exists(self.remote_path)):
                self.restoreFiles()
            else:
                xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30045),self.remote_path)

        if(utils.getSetting('run_silent') == 'false' and not runSilent):
            self.progressBar.close()
Ejemplo n.º 2
0
    def format(self, tb, code = None, lineno = -1, filename = "",
               deep_trace = False):

        # tracebacks are dangerous objects; to avoid circular references,
        # we have to drop references to a traceback ASAP

        # get recent traceback
        exc_type = tb[0]
        exc_value = tb[1]
        exc_tb = tb[2]

        # get filename and lineno
        if (not filename and lineno == -1):
            if (hasattr(exc_value, "filename") and
                  hasattr(exc_value, "lineno")):
                filename = exc_value.filename
                lineno = exc_value.lineno
            else:
                tbs = traceback.extract_tb(exc_tb)
                filename = tbs[-1][0]
                lineno = tbs[-1][1]
                del tbs

        # print error message
        out = "\n"
        out += "[EXC]%s\n" % str(exc_value)

        # dig into the traceback for additional information
        if (deep_trace):
            for trace in traceback.extract_tb(exc_tb):
                cntxt = trace[0]
                lno = trace[1]
                funcname = trace[2]
                out += "in %s: line %d %s\n" % (cntxt, lno, funcname)

        # load code from file if no code was specified
        if (not code):
            # get last traceback (otherwise we would load the wrong file for
            # hilighting)
            this_tb = exc_tb
            while (this_tb.tb_next):
                tmp = this_tb
                del this_tb
                this_tb = tmp.tb_next
                del tmp

            # get the .py file; we don't want .pyc or .pyo!
            path = this_tb.tb_frame.f_globals.get("__file__")
            del this_tb
            if (path and path[-4:-1] == ".py"): path = path[:-1]

            if (path and vfs.exists(path)):
                code = vfs.read_entire_file(path)
                filename = path
        #end if

        del exc_tb

        # find and hilight the bad line of code, while adding handy line numbers
        if (code):
            lines = code.splitlines()
            lno = 1
            for i in range(len(lines)):
                if (lno == lineno):
                    lines[i] = "[ERR]>%4d " % lno + lines[i]
                else:
                    lines[i] = "[---] %4d " % lno + lines[i]
                lno += 1
            #end for

            # take a small chop out of the code
            begin = max(0, lineno - 6)
            part = lines[begin:begin + 12]

            out += "[EXC]%s\n\n" % filename
            out += "\n".join(part)

        else:
            out += "[EXC]%s\n\n" % filename
            out += "[EXC]>> could not load source code for hilighting <<"

        #end if

        return out