Esempio n. 1
0
def process_infile(indir, infile):
    """Process infile (.in) - substitutes and create reflection file
    (with the same name but without '.in' extension)"""
    f = change_ext(infile, '')
    shutil.copyfile(infile, f)
    buf = core.fread23(f)
    buf = substitute_infile(indir, buf)
    core.fwrite23(f, buf)
Esempio n. 2
0
def process_infile(indir, infile):
    """Process infile (.in) - substitutes and create reflection file
    (with the same name but without '.in' extension)"""
    f = change_ext(infile, '')
    shutil.copyfile(infile, f)
    buf = core.fread23(f)
    buf = substitute_infile(indir, buf)
    core.fwrite23(f, buf)
Esempio n. 3
0
    def runTest(self, *args):
        shfile = change_ext(self.filename, '.sh')
        args = [sys.executable, script_path("nlp.py")]
        if os.path.exists(shfile):
            # XXX no spaces in path!!!!
            args = args + core.fread23(shfile).split()
        else:
            args = args + ["-i", self.filename]
        proc = subprocess.Popen(args, stderr=subprocess.PIPE)
        exitcode = proc.wait()
        stderrbuf = core.bytestostr23(proc.stderr.read()).strip('\n')

        if exitcode != 0 or len(stderrbuf) != 0:
            err = os.path.splitext(self.filename)[0] + '.stderr'
            if os.path.exists(err):
                errbuf = readfile(err)
                self.assertRegexpMatches(stderrbuf, errbuf, msgfmt('unexpected exception'))
            else:
                self.fail('Exit with 1, stderr="%s"'%stderrbuf)
Esempio n. 4
0
    def runTest(self, *args):
        shfile = change_ext(self.filename, '.sh')
        args = [sys.executable, script_path("nlp.py")]
        if os.path.exists(shfile):
            # XXX no spaces in path!!!!
            args = args + core.fread23(shfile).split()
        else:
            args = args + ["-i", self.filename]
        proc = subprocess.Popen(args, stderr=subprocess.PIPE)
        exitcode = proc.wait()
        stderrbuf = core.bytestostr23(proc.stderr.read()).strip('\n')

        if exitcode != 0 or len(stderrbuf) != 0:
            err = os.path.splitext(self.filename)[0] + '.stderr'
            if os.path.exists(err):
                errbuf = readfile(err)
                self.assertRegexpMatches(stderrbuf, errbuf,
                                         msgfmt('unexpected exception'))
            else:
                self.fail('Exit with 1, stderr="%s"' % stderrbuf)
Esempio n. 5
0
def readfile(filename):
    """Return buffer from *.master file"""
    return core.fix_crlf(core.fread23(filename)).rstrip('\r\n')
Esempio n. 6
0
def readfile(filename):
    """Return buffer from *.master file"""
    return core.fix_crlf(core.fread23(filename)).rstrip('\r\n')
Esempio n. 7
0
File: cat.py Progetto: kalkin/nanolp
# Itself testing facilities. Analogue of shell 'cat' command
#
# Author: Balkansoft.BlogSpot.com
# GNU GPL licensed

import sys
from nanolp import core
if len(sys.argv) > 1:
    sys.stdout.write(core.fread23(sys.argv[1]))
Esempio n. 8
0
    def publish(self, filename):
        # modify input HTML...
        tokstream = core.HTMLTokensStream()
        tokstream.feed(core.fread23(filename))
        headpos = 0
        for itok, tok in enumerate(tokstream.tokens):
            if tok.match(
                    tag='script',
                    kind=core.HTMLToken.OPEN,
                    attrs={'src': '/.*?%s.*?/' % re.escape(self.JSFILENAME)}):
                raise RuntimeError('This document is already modified')
            if tok.match(tag='head', kind=core.HTMLToken.CLOSE):
                headpos = itok
                break

        # Script 0
        cmds = collections.OrderedDict()
        for cmd in self.parser.chunkdict.keys():
            infile = cmd.srcinfo.infile
            if infile:
                infile = "" if infile == self.parser.infile else self.__url(
                    infile)
            cmds[cmd.jpath()] = infile
        fmtargs = {
            'SURR': self.parser.surr,
            'CMDS': cmds,
        }
        for k, v in fmtargs.items():
            fmtargs[k] = json.dumps(v).replace('"', "'")  # ' instead of "
        text = self._script0.format(**fmtargs)
        script0 = [
            core.HTMLToken(tag='script',
                           kind=core.HTMLToken.OPEN,
                           attrs={'type': 'text/javascript'},
                           data=text),
            core.HTMLToken(tag='script', kind=core.HTMLToken.CLOSE)
        ]

        # Script 1
        script1 = [
            core.HTMLToken(tag='script',
                           kind=core.HTMLToken.OPEN,
                           attrs='src=%s|type=text/javascript' %
                           self.__url(self.JSFILENAME)),
            core.HTMLToken(tag='script', kind=core.HTMLToken.CLOSE)
        ]

        # Stylesheet
        css = [
            core.HTMLToken(tag='link',
                           kind=core.HTMLToken.SINGLE,
                           attrs='href=%s|rel=stylesheet|type=text/css' %
                           self.__url(self.CSSFILENAME))
        ]

        # Head inserts
        tokstream.tokens[headpos:headpos] = css + script0 + script1

        # Save to file
        xml = ''.join(tokstream.serialize())
        core.prn("modifying '%s' for publish..." % filename,
                 engine=self.parser.engine,
                 file='stdout')
        core.fwrite23(filename, xml)

        # Flush additional files
        indir = os.path.dirname(filename)
        cssfname = os.path.join(indir, self.CSSFILENAME)
        jsfname = os.path.join(indir, self.JSFILENAME)
        if not os.path.exists(cssfname):
            core.prn("writing CSS-styles file '%s'..." % cssfname,
                     engine=self.parser.engine,
                     file='stdout')
            shutil.copyfile(core.extrapath(self.CSSFILENAME), cssfname)
            #core.fwrite23(cssfname, self._css)
        if not os.path.exists(jsfname):
            core.prn("writing JS file '%s'..." % jsfname,
                     engine=self.parser.engine,
                     file='stdout')
            shutil.copyfile(core.extrapath(self.JSFILENAME), jsfname)