Beispiel #1
0
    def _get_and_update_article_content(self, afile, istxt=False):
        html, meta, txt, medias = self._get_article_content(afile)
        if not html:
            return None, None, None, None
        attach = 0
        if not meta.attachments:
            attach = 1
        elif meta.attachments[0] == '$ATTACHMENTS':
            attach = 2
        elif len(meta.attachments) > 0:
            attach = 3

        if medias and attach > 0:
            txt, attachids = self._update_medias(medias, txt)
            idstxt = ','.join(attachids)
            if attach == 1:
                # Add attachments to the TOF.
                txt = 'Attachments: %s\n%s' % (idstxt, txt)
                slog.info('Fill attachments: %s.' % idstxt)
            elif attach == 2:
                txt = Template(txt).safe_substitute(ATTACHMENTS=idstxt)
                slog.info('Fill attachments: %s.' % idstxt)
            elif attach == 3:
                slog.info('Add new attachments: %s.' % idstxt)
                meta.attachments += attachids
                txt = re.sub(r'^Attachments: .*$',
                             'Attachments: ' + ','.join(meta.attachments), txt,
                             0, re.M)

            write_file(afile, txt)
            html, meta, txt, medias = self._get_article_content(txt, True)
            if medias:
                slog.error('Medias in the article is maybe wrong!')
                return None, None, None, None
        return html, meta, txt, medias
Beispiel #2
0
    def _get_and_update_article_content(self, afile, istxt=False):
        html, meta, txt, medias = self._get_article_content(afile)
        if not html:
            return  None, None, None, None
        attach = 0
        if not meta.attachments:
            attach = 1
        elif meta.attachments[0] == '$ATTACHMENTS':
            attach = 2
        elif len(meta.attachments)>0:
            attach = 3

        if medias and attach>0:
            txt,attachids = self._update_medias(medias, txt)
            idstxt = ','.join(attachids)
            if attach == 1:
                # Add attachments to the TOF.
                txt = 'Attachments: %s\n%s'%(idstxt, txt)
                slog.info('Fill attachments: %s.'%idstxt)
            elif attach == 2:
                txt = Template(txt).safe_substitute(ATTACHMENTS=idstxt)
                slog.info('Fill attachments: %s.'%idstxt)
            elif attach == 3:
                slog.info('Add new attachments: %s.'%idstxt)
                meta.attachments += attachids
                txt = re.sub(r'^Attachments: .*$', 
                        'Attachments: '+ ','.join(meta.attachments),
                        txt, 0, re.M)

            write_file(afile, txt)
            html, meta, txt, medias = self._get_article_content(txt, True)
            if medias:
                slog.error('Medias in the article is maybe wrong!')
                return None, None, None, None
        return html, meta, txt, medias
Beispiel #3
0
    def saveFile(self, data, fileName):
        # save path
        filePath = os.path.join(self.export, fileName + '.lua')

        # check path
        self.chkDirPath(filePath)

        write_file(filePath, 'local data={\n' + data + '\n}\nreturn data')
Beispiel #4
0
Datei: etc.py Projekt: HScarb/xlc
    def saveFile(self, data, fileName):
        # save path
        filePath = os.path.join(
            self.export, fileName + '.lua')

        # check path
        self.chkDirPath(filePath)

        write_file(filePath, 'local data={\n' + data + '\n}\nreturn data')
Beispiel #5
0
def convertProtocol(mddir, protfile):
    _dirfolder(mddir)
    buff = []
    buff.append("local _p = {")
    buff.append('["client"] = %s,' % dictToLuaString(pclient,"    ")[:-2])
    buff.append('["server"] = %s,' % dictToLuaString(pserver,"    ")[:-2])
    buff.append('["update"] = %s,' % dictToLuaString(pupdate,"    ")[:-2])
    buff.append("}")
    buff.append("return _p")

    slog.info('protocolNum:%d'%protocolNum)
    slog.info('protocolNum:%d'%verNum)

    slog.info('Write protocol to "%s".'%protfile)
    write_file(protfile, '\n'.join(buff))
Beispiel #6
0
def write_by_jinja(templ, target, content):
    templ_txt = read_file(templ)
    templ = Template(templ_txt)
    write_file(target, templ.render(content))
Beispiel #7
0
def convertVersion(mddir, verfile):
    _dirfolder(mddir)
    slog.info('Write version "%d" to "%s".'%(verNum, verfile))
    slog.info('protocolNum:%d'%protocolNum)
    write_file(path, str(verNum))
Beispiel #8
0
def test_write_file():
    fileName = "__TEST_WRITE_FILE__.txt"
    filePath = os.path.join(workDir, fileName)
    base.write_file(filePath, filePath)
    os.remove(filePath)
Beispiel #9
0
def test_write_file():
    fileName = "__TEST_WRITE_FILE__.txt"
    filePath =  os.path.join(workDir, fileName)
    base.write_file(filePath, filePath)
    os.remove(filePath)