Beispiel #1
0
    def onXbmcExport(self, name=None):
        errMsg = ""
        if name:
            zipFile = zipfile.ZipFile(name, "w")
            copySrcFile = zipFile.write
            genFileFromStr = zipFile.writestr
        else:
            baseDirectory = translatePath("special://home/addons")
            copySrcFile = shutil.copyfile

        addonFiles = self.listAddonFiles(name)
        for elem in addonFiles:
            dstFile, mode, srcFile = elem
            if not name:
                dstFile = translatePath("special://home/addons/" + dstFile)
                dstDirectory = os.path.split(dstFile)[0]
                if not os.path.exists(dstDirectory):
                    os.makedirs(dstDirectory)
            try:
                if mode == "f":
                    copySrcFile(srcFile, dstFile)
                elif mode == "s":
                    srcFile = self.fileGenerator.getSource(srcFile)
                    if name:
                        genFileFromStr(dstFile, srcFile)
                    else:
                        with open(dstFile, "w") as wfile:
                            wfile.write(srcFile)
            except:
                errFile = dstFile.rpartition("\\")[2]
                errMsg += errFile + "\n"
        if name:
            zipFile.close()
        addonId = self.getAddonSettings("addon_id")
        addonName = self.getAddonSettings("addon_name")
        if errMsg:
            errMsg = (
                "During addon creation for "
                + addonName
                + " ("
                + addonId
                + ") , the following source files were not found: \n"
                + errMsg
            )
            tkMessageBox.showerror("Addon creation", errMsg)
        else:
            errMsg = "Addon for " + addonName + " (" + addonId + ") succesfully created"
            tkMessageBox.showinfo("Addon creation", errMsg)
Beispiel #2
0
 def changeDisplay(self, *args, **kwargs):
     if self.sntxIndx.get() == 0:
         return
     elif self.sntxIndx.get() == 1:
         logfile = os.path.join(translatePath('special://logpath'), 'kodi.log')
         with open(logfile, 'r') as f:
             content = f.read()
         contentDesc = (content, 'file', logfile)
         sintaxArray = self.errorSintax()
         self.sintaxEd.setContent(contentDesc,'1.0', sintaxArray, isEditable = False)
     elif self.sntxIndx.get() == 2:
         self.getUrlLog()
    def onXbmcExport(self, name=None):
        errMsg = ''
        if name:
            zipFile = zipfile.ZipFile(name, 'w')
            copySrcFile = zipFile.write
            genFileFromStr = zipFile.writestr
        else:
            baseDirectory = translatePath('special://home/addons')
            copySrcFile = shutil.copyfile

        addonFiles = self.listAddonFiles(name)
        for elem in addonFiles:
            dstFile, mode, srcFile = elem
            if not name:
                dstFile = translatePath('special://home/addons/' + dstFile)
                dstDirectory = os.path.split(dstFile)[0]
                if not os.path.exists(dstDirectory): os.makedirs(dstDirectory)
            try:
                if mode == 'f':
                    copySrcFile(srcFile, dstFile)
                elif mode == 's':
                    srcFile = self.fileGenerator.getSource(srcFile)
                    if name:
                        genFileFromStr(dstFile, srcFile)
                    else:
                        with open(dstFile, 'w') as wfile:
                            wfile.write(srcFile)
            except:
                errFile = dstFile.rpartition('\\')[2]
                errMsg += errFile + '\n'
        if name: zipFile.close()
        addonId = self.getAddonSettings('addon_id')
        addonName = self.getAddonSettings('addon_name')
        if errMsg:
            errMsg = 'During addon creation for ' + addonName + ' (' + addonId + ') , the following source files were not found: \n' + errMsg
            tkMessageBox.showerror('Addon creation', errMsg)
        else:
            errMsg = 'Addon for ' + addonName + ' (' + addonId + ') succesfully created'
            tkMessageBox.showinfo('Addon creation', errMsg)
Beispiel #4
0
 def changeDisplay(self, *args, **kwargs):
     if self.sntxIndx.get() == 0:
         return
     elif self.sntxIndx.get() == 1:
         logfile = os.path.join(translatePath('special://logpath'),
                                'kodi.log')
         with open(logfile, 'r') as f:
             content = f.read()
         contentDesc = (content, 'file', logfile)
         sintaxArray = self.errorSintax()
         self.sintaxEd.setContent(contentDesc,
                                  '1.0',
                                  sintaxArray,
                                  isEditable=False)
     elif self.sntxIndx.get() == 2:
         self.getUrlLog()
Beispiel #5
0
 def hyperLinkProcessor(self, texto):
     match = re.search('File "(?P<filename>[^"]+)", line (?P<lineno>[0-9]+)', texto)
     if not match:
         tkMessageBox.showinfo("Hyperlink Not Process", texto)
     else:
         fileName = match.group("filename")
         lineNo = match.group("lineno")
         rootId = self.explorerTree.treeview.get_children()[0]
         baseDirectory = translatePath("special://home/addons/")
         if not fileName.startswith(baseDirectory):
             return tkMessageBox.showerror("Hyperlink Not in actual addon", texto)
         nodeId = fileName[len(baseDirectory) :].replace("\\", "/")
         if not fileName.startswith(os.path.join(baseDirectory, rootId)):
             nodeId = rootId + "/Dependencies/" + fileName[len(baseDirectory) :].replace("\\", "/")
             if not self.explorerTree.treeview.exists(nodeId):
                 return tkMessageBox.showerror("Hyperlink Not Found", texto)
         self.explorerTree.treeview.set(nodeId, column="inspos", value=lineNo + ".0")
         self.explorerTree.onTreeSelection(nodeId)
         self.addonFilesViewer.focus_force()
 def hyperLinkProcessor(self, texto):
     match = re.search(
         'File "(?P<filename>[^"]+)", line (?P<lineno>[0-9]+)', texto)
     if not match:
         tkMessageBox.showinfo('Hyperlink Not Process', texto)
     else:
         fileName = match.group('filename')
         lineNo = match.group('lineno')
         rootId = self.explorerTree.treeview.get_children()[0]
         baseDirectory = translatePath('special://home/addons/')
         if not fileName.startswith(baseDirectory):
             return tkMessageBox.showerror('Hyperlink Not in actual addon',
                                           texto)
         nodeId = fileName[len(baseDirectory):].replace('\\', '/')
         if not fileName.startswith(os.path.join(baseDirectory, rootId)):
             nodeId = rootId + '/Dependencies/' + fileName[
                 len(baseDirectory):].replace('\\', '/')
             if not self.explorerTree.treeview.exists(nodeId):
                 return tkMessageBox.showerror('Hyperlink Not Found', texto)
         self.explorerTree.treeview.set(nodeId,
                                        column='inspos',
                                        value=lineNo + '.0')
         self.explorerTree.onTreeSelection(nodeId)
         self.addonFilesViewer.focus_force()
Beispiel #7
0
def exportAddon(xmlAddonStructure, settings, calcFiles, afile = None):
    def verifyDestDir(dstFile,afile):
        if afile == None:
            dstDirectory, dstName = os.path.split(dstFile)
            if not os.path.exists(dstDirectory):
                os.makedirs(dstDirectory)
        
    def calcStringFiles(srcFile, dstFile, calcFiles, afile = None):
        verifyDestDir(dstFile, afile)
        srcString = calcFiles[srcFile]
        if not srcString: return
        if afile == None:
            with open(dstFile,'w') as wfile:
                wfile.write(srcString)
        else:
            afile.writestr(dstFile, srcString)
            
    def copySrcFile(srcFile, dstFile, afile = None):
        verifyDestDir(dstFile, afile)
        if afile == None:
            shutil.copyfile(srcFile, dstFile)
        else:
            afile.write(srcFile, dstFile)
            
    root = ET.parse(xmlAddonStructure).getroot()
    lastDirectory = ''
    for elem in root.iter():
        if elem.tag == 'structure':
            path = elem.get('path')
            path = settings[path]
            if not afile:
                baseDirectory = translatePath('special://home/addons')                
                baseDirectory = os.path.join(baseDirectory, path)
                if os.path.exists(baseDirectory):
                    if tkMessageBox.askokcancel('Export addon', 'El directorio propuesto ya existe, desea sobreescribirlo'):
                        try:
                            shutil.rmtree(baseDirectory, ignore_errors = True)
                        except:
                            tkMessageBox.showerror('Error', 'Directory acces dennied')
                            return
            else:
                afile = zipfile.ZipFile(addonzip, 'w')
                baseDirectory = path 
            lastDirectory = os.path.normpath(baseDirectory)
        elif elem.tag == 'folder':
            nameId = elem.get('id')
            path = elem.get('path')
            if not path: continue
            if elem.get('optional') == 'false' or (settings.has_key(nameId) and not elem.attrib.has_key('name')):
                path = os.path.join(baseDirectory, path)
                lastDirectory = os.path.normpath(path)
            elif settings.has_key(nameId) and elem.attrib.has_key('name'):
                name = elem.get('name')
                if name in settings[nameId]:
                    resourceFiles = [kElem.split(',') for kElem in settings[nameId].split('|')]
                    path = os.path.join(baseDirectory, path)
                    for ka in resourceFiles:
                        if name not in ','.join(ka): continue
                        srcName = ka[0]
                        dstName = os.path.normpath(os.path.join(path, srcName))
                        copySrcFile(srcName, dstName, afile)
            else:
                continue
        elif elem.tag == 'file':
            nameId = elem.get('id')
            if elem.get('optional') == 'false':
                srcName = settings.get(nameId, None) or elem.get('name')
                dstName = os.path.join(lastDirectory, srcName)
                calcStringFiles(srcName, dstName, calcFiles, afile)
            else:
                if settings.has_key(nameId):
                    srcName = settings[nameId]
                    if not os.path.exists(srcName):continue
                    dstName = elem.get('name')
                    dstName = os.path.join(lastDirectory, dstName)
                    copySrcFile(srcName, dstName, afile)
                else:
                    continue
    if afile: afile.close()    
Beispiel #8
0
def exportAddon(xmlAddonStructure, settings, calcFiles, afile=None):
    def verifyDestDir(dstFile, afile):
        if afile == None:
            dstDirectory, dstName = os.path.split(dstFile)
            if not os.path.exists(dstDirectory):
                os.makedirs(dstDirectory)

    def calcStringFiles(srcFile, dstFile, calcFiles, afile=None):
        verifyDestDir(dstFile, afile)
        srcString = calcFiles[srcFile]
        if not srcString: return
        if afile == None:
            with open(dstFile, 'w') as wfile:
                wfile.write(srcString)
        else:
            afile.writestr(dstFile, srcString)

    def copySrcFile(srcFile, dstFile, afile=None):
        verifyDestDir(dstFile, afile)
        if afile == None:
            shutil.copyfile(srcFile, dstFile)
        else:
            afile.write(srcFile, dstFile)

    root = ET.parse(xmlAddonStructure).getroot()
    lastDirectory = ''
    for elem in root.iter():
        if elem.tag == 'structure':
            path = elem.get('path')
            path = settings[path]
            if not afile:
                baseDirectory = translatePath('special://home/addons')
                baseDirectory = os.path.join(baseDirectory, path)
                if os.path.exists(baseDirectory):
                    if tkMessageBox.askokcancel(
                            'Export addon',
                            'El directorio propuesto ya existe, desea sobreescribirlo'
                    ):
                        try:
                            shutil.rmtree(baseDirectory, ignore_errors=True)
                        except:
                            tkMessageBox.showerror('Error',
                                                   'Directory acces dennied')
                            return
            else:
                afile = zipfile.ZipFile(addonzip, 'w')
                baseDirectory = path
            lastDirectory = os.path.normpath(baseDirectory)
        elif elem.tag == 'folder':
            nameId = elem.get('id')
            path = elem.get('path')
            if not path: continue
            if elem.get('optional') == 'false' or (
                    settings.has_key(nameId)
                    and not elem.attrib.has_key('name')):
                path = os.path.join(baseDirectory, path)
                lastDirectory = os.path.normpath(path)
            elif settings.has_key(nameId) and elem.attrib.has_key('name'):
                name = elem.get('name')
                if name in settings[nameId]:
                    resourceFiles = [
                        kElem.split(',')
                        for kElem in settings[nameId].split('|')
                    ]
                    path = os.path.join(baseDirectory, path)
                    for ka in resourceFiles:
                        if name not in ','.join(ka): continue
                        srcName = ka[0]
                        dstName = os.path.normpath(os.path.join(path, srcName))
                        copySrcFile(srcName, dstName, afile)
            else:
                continue
        elif elem.tag == 'file':
            nameId = elem.get('id')
            if elem.get('optional') == 'false':
                srcName = settings.get(nameId, None) or elem.get('name')
                dstName = os.path.join(lastDirectory, srcName)
                calcStringFiles(srcName, dstName, calcFiles, afile)
            else:
                if settings.has_key(nameId):
                    srcName = settings[nameId]
                    if not os.path.exists(srcName): continue
                    dstName = elem.get('name')
                    dstName = os.path.join(lastDirectory, dstName)
                    copySrcFile(srcName, dstName, afile)
                else:
                    continue
    if afile: afile.close()