Example #1
0
    def removeModule(manager, moduleName):
        """Physically deletes a module from the hard disk

		Returns True if module couldn't be found, False otherwise"""
        mod_name = Sword.SWBuf(moduleName)
        s = manager.config.getSections()
        module = s.find(mod_name)
        # we use to have != s.end, but that crashes...
        if mod_name in s:
            manager.deleteModule(moduleName)

            file_buf = Sword.SWBuf("File")
            mod_second = module.value()[1]
            fileBegin = mod_second.lower_bound(file_buf)
            fileEnd = mod_second.upper_bound(file_buf)

            entry = mod_second.find(Sword.SWBuf("AbsoluteDataPath"))
            modDir = entry.value()[1].c_str()
            modDir = removeTrailingSlash(modDir)
            if fileBegin != fileEnd:
                # remove each file
                while fileBegin != fileEnd:
                    modFile = modDir
                    modFile += "/"
                    modFile += fileBegin.value()[1].c_str()

                    # remove file
                    FileMgr.removeFile(modFile.c_str())
                    fileBegin += 1

            else:
                #remove all files in DataPath directory
                FileMgr.removeDir(modDir)

                # BM: this could be a bit ticklish...
                # I hope I have copied the correct behaviour

                # find and remove .conf file
                try:
                    items = os.listdir(manager.configPath)
                except OSError:
                    pass
                else:
                    baseModFile = manager.configPath
                    baseModFile = removeTrailingSlash(baseModFile)

                    for item in items:
                        modFile = baseModFile + "/"
                        modFile += item
                        config = Sword.SWConfig(modFile)
                        if mod_name in config.getSections():
                            del config
                            FileMgr.removeFile(modFile)

            return False

        return True
Example #2
0
    def __init__(self, privatePath="./", sr=None):
        self.statusReporter = sr
        self.privatePath = privatePath
        self.transport = None
        self.passive = False
        self.term = False
        if self.privatePath:
            self.privatePath = removeTrailingSlash(self.privatePath)

        confPath = privatePath + "/InstallMgr.conf"
        FileMgr.createParent(confPath)

        installConf = Sword.SWConfig(confPath)

        #SectionMap::iterator sourcesSection;
        #ConfigEntMap::iterator sourceBegin;
        #ConfigEntMap::iterator sourceEnd;

        self.sources = {}

        self.setFTPPassive(installConf.get("General", "PassiveFTP") == "false")

        sourcesSection = installConf.getSections().find(Sword.SWBuf("Sources"))
        if sourcesSection != installConf.getSections().end():
            ftp_source = Sword.SWBuf("FTPSource")
            ss = sourcesSection.value()[1]

            sourceBegin = ss.lower_bound(ftp_source)
            sourceEnd = ss.upper_bound(ftp_source)

            while sourceBegin != sourceEnd:
                install_source = InstallSource("FTP",
                                               sourceBegin.value()[1].c_str())

                self.sources[install_source.caption] = install_source
                parent = privatePath + "/" + install_source.source + "/file"
                FileMgr.createParent(parent)
                install_source.localShadow = privatePath + "/" + install_source.source
                sourceBegin += 1

        self.defaultMods = set()
        sourcesSection = installConf.getSections().find(Sword.SWBuf("General"))
        general = sourcesSection.value()[1]

        if sourcesSection != installConf.getSections().end():
            default_mod = Sword.SWBuf("DefaultMod")
            sourceBegin = general.lower_bound(default_mod)
            sourceEnd = general.upper_bound(default_mod)

            while sourceBegin != sourceEnd:
                self.defaultMods.add(sourceBegin.value()[1].c_str())
                sourceBegin += 1
Example #3
0
def createBook(moduleName, bookAbbr, mgr):
    bookName = getInfoBasedOnAbbr(bookAbbr)["name"]
    book = {}

    if (moduleLang == "fr"):
        config = Sword.SWConfig("/usr/share/sword/locales.d/fr-utf8.conf")
        book["name"] = config.get("Text", bookName)
    else:
        book["name"] = bookName
    book["chapters"] = []

    prefix = bookPrefix(bookAbbr) + tocOffset
    bookTemplate = env.get_template("book.html")
    bookOutput = bookTemplate.render(book=book)
    """ fileOutput="html/%s-%s.html"%(bookAbbr,chapter) """
    fileOutput = "html/%02d-%s.html" % (int(prefix), bookAbbr)
    with open(fileOutput, "w") as f:
        f.write(bookOutput)

    for chapterInd in range(getNbrChapter(moduleName, bookAbbr, mgr)):
        chapter = chapterInd + 1
        book["chapters"].append(
            createChapter(moduleName, bookAbbr, mgr, chapter))
    return (book)
Example #4
0
    def installModule(self,
                      destMgr,
                      fromLocation,
                      modName,
                      install_source=None):
        """Install a module from destMgr to a location

		Returns -1 on aborted, 0 on success and 1 on error
		"""

        aborted = False
        cipher = False

        print destMgr, fromLocation, modName, install_source
        #printf("***** InstallMgr::installModule\n")

        #if fromLocation:
        #	printf("***** fromLocation: %s \n", fromLocation)

        #printf("***** modName: %s \n", modName)

        if install_source:
            sourceDir = self.privatePath + "/" + install_source.source
        else:
            sourceDir = fromLocation

        sourceDir = removeTrailingSlash(sourceDir)
        sourceDir += '/'

        # do this with False at the end to stop the augmenting
        mgr = Sword.SWMgr(sourceDir, True, None, False, False)

        module = mgr.config.getSections().find(Sword.SWBuf(modName))

        if module != mgr.config.getSections().end():
            mod_second = module.value()[1]

            entry = mod_second.find(Sword.SWBuf("CipherKey"))
            if entry != mod_second.end():
                cipher = True

            # This first check is a method to allow a module to specify each
            # file that needs to be copied
            file_buf = Sword.SWBuf("File")
            file_value = mod_second
            fileEnd = file_value.upper_bound(file_buf)
            fileBegin = file_value.lower_bound(file_buf)
            print fileEnd == fileBegin

            if (fileBegin != fileEnd):
                # copy each file
                if (install_source):
                    while (fileBegin != fileEnd):
                        swbuf = fileBegin.value()[1]
                        src = swbuf.c_str()
                        # ftp each file first
                        buffer = sourceDir + src
                        if self.ftpCopy(install_source, src, buffer):

                            aborted = True
                            break  # user aborted

                        fileBegin += 1

                    fileBegin = mod_second.lower_bound(file_buf)

                if not aborted:
                    # DO THE INSTALL
                    while fileBegin != fileEnd:
                        sourcePath = sourceDir
                        sourcePath += fileBegin.value()[1].c_str()
                        dest = destMgr.prefixPath
                        dest = removeTrailingSlash(dest)
                        dest += '/'
                        dest += fileBegin.value()[1].c_str()
                        FileMgr.copyFile(sourcePath, dest)

                        fileBegin += 1

                # ---------------

                if install_source:
                    fileBegin = mod_second.lower_bound(file_buf)
                    while (fileBegin != fileEnd):
                        # delete each tmp ftp file
                        buffer = sourceDir + fileBegin.value()[1].c_str()
                        FileMgr.removeFile(buffer.c_str())
                        fileBegin += 1

            # This is the REAL install code, the above code I don't think has
            # ever been used
            #
            # Copy all files in DataPath directory
            #
            else:

                entry = mod_second.find(Sword.SWBuf("AbsoluteDataPath"))
                if (entry != mod_second.end()):
                    absolutePath = entry.value()[1].c_str()
                    relativePath = absolutePath

                    entry = mod_second.find(Sword.SWBuf("PrefixPath"))
                    if (entry != mod_second.end()):
                        relativePath = relativePath[entry.value()[1].size():]
                    else:
                        relativePath = relativePath[len(mgr.prefixPath):]

                    printf("***** mgr.prefixPath: %s", mgr.prefixPath)
                    printf("***** destMgr.prefixPath: %s", destMgr.prefixPath)
                    printf("***** absolutePath: %s", absolutePath)
                    printf("***** relativePath: %s", relativePath)

                    if install_source:
                        if self.ftpCopy(install_source, relativePath,
                                        absolutePath, True):
                            aborted = True
                            # user aborted

                    if not aborted:
                        destPath = (destMgr.prefixPath or "") + relativePath
                        FileMgr.copyDir(absolutePath, destPath)

                    if install_source:
                        # delete tmp ftp files
                        mgr.deleteModule(modName)
                        FileMgr.removeDir(absolutePath)

            if not aborted:
                confDir = sourceDir + "mods.d/"
                try:
                    items = os.listdir(confDir)
                except OSError:
                    pass
                else:
                    for item in items:
                        modFile = confDir
                        modFile += item
                        config = Sword.SWConfig(modFile)
                        if config.getSections().find(Sword.SWBuf(modName)) != \
                         config.getSections().end():
                            targetFile = destMgr.configPath or ""  #; //"./mods.d/";
                            targetFile = removeTrailingSlash(targetFile)
                            targetFile += "/"
                            targetFile += item
                            FileMgr.copyFile(modFile, targetFile)
                            if (cipher):
                                if self.getCipherCode(modName, config):
                                    # An error has occurred with getting
                                    # cipher code
                                    # This removes the module
                                    # Is this wise?
                                    newDest = Sword.SWMgr(destMgr.prefixPath)
                                    self.removeModule(newDest, modName)
                                    aborted = True
                                else:
                                    config.Save()
                                    FileMgr.copyFile(modFile, targetFile)

                        del config

            if aborted:
                return -1

            return 0
        return 1
Example #5
0
    for i in range(1, 3):
        vk.setTestament(i)
        for j in range(1, vk.bookCount(i) + 1):
            vk.setBook(j)
            tmp = {}
            tmp['name'] = vk.bookName(i, j)
            tmp['abbr'] = vk.getBookAbbrev()
            tmp['testament'] = i
            tmp['bookCount'] = j
            out.append(tmp)
    return out


locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')
moduleName = "FreCrampon"
outputType = Sword.FMT_PLAIN
markup = Sword.MarkupFilterMgr(outputType)
markup.thisown = False
mgr = Sword.SWMgr(markup)
mod = mgr.getModule(moduleName)
versification = mod.getConfigEntry("Versification")

config = Sword.SWConfig("/usr/share/sword/locales.d/abbr.conf")
config.get("Text", "Genesis")
getAllBooks(versification)

for book in getAllBooks(versification):
    name = book["name"]
    config = Sword.SWConfig("/usr/share/sword/locales.d/fr-utf8.conf")
    print("%s##%s" % (name, config.get("Text", name)))