Exemplo n.º 1
0
 def compile(self,file,dp,force_reload=0):
     sourcefile_name = '%spy' % file.name[:-3]
     if not self._use_cache(file):
         # Process all the directives
         dp = _DirectiveProcessor(file,self.WEB_ROOT)
         include_files = dp.get_include_filenames()
         file = dp.process()
         # Convert to psp to py file
         psp_convert = PSPConverter(file)
         psp_convert.convert()
         sourcefile = open(sourcefile_name,'w' )
         # add all the imports to the source file
         self._add_imports(sourcefile,dp.get_imports())
         sourcefile.write(psp_convert.get())
         sourcefile.close()
         targetfile = '%spyc' % file.name[:-3]
         if os.path.isfile(targetfile):
             os.remove(targetfile)
         _sdterr = sys.stderr
         stderr = StringIO.StringIO()
         sys.stderr = stderr
         py_compile.compile(sourcefile_name, targetfile)
         sys.stderr = _sdterr
         stderr.seek(0)
         err = ''
         for l in stderr.readlines():
             err += '%s<br>' % l
         if err != '':
             raise CompileError(err)
         module_name =os.tmpnam()
         psp_module = imp.load_module(module_name,open(targetfile),'',
                                      ('pyc','r',imp.PY_COMPILED))
         self.cache[file.name] = {'module':psp_module,
                          'psp_last_modified':os.stat(file.name)[ST_MTIME],
                          'py_last_modified':os.stat(sourcefile_name)[ST_MTIME],
                          'include_files':{},
                           'dp':dp}
         for f in include_files:
             self.cache[file.name]['include_files'][f] = os.stat(f)[ST_MTIME]
     else:
         if os.stat(sourcefile_name)[ST_MTIME] > self.cache[file.name]['py_last_modified']:
             targetfile = '%spyc' % file.name[:-3]
             if os.path.isfile(targetfile):
                 os.remove(targetfile)
             _sdterr = sys.stderr
             stderr = StringIO.StringIO()
             sys.stderr = stderr
             py_compile.compile(sourcefile_name, targetfile)
             sys.stderr = _sdterr
             stderr.seek(0)
             err = ''
             for l in stderr.readlines():
                 err += '%s<br>' % l
             if err != '':
                 raise CompileError(err)
             module_name =os.tmpnam()
             psp_module = imp.load_module(module_name,open(targetfile),'',
                                              ('pyc','r',imp.PY_COMPILED))
             self.cache[file.name]['py_last_modified'] = os.stat(sourcefile_name)[ST_MTIME]
Exemplo n.º 2
0
 def test_look_for_tags_1(self):
     l = 'Logs: <select id="<%=log%>" name="log" onchange="get_log()">'
     converter = PSPConverter(None)
     t = converter._look_for_tags(l)
   
     if t[0] != '<%=log%>':
         msg = 'Not converted right\n'
         msg += 'Line:%s\n' % l
         msg += 'After:%s' % t
         self.fail(msg)
Exemplo n.º 3
0
 def test_multi_1_replace_tags(self):
     l = '<td width="50%"><%=node.get()%>Test<%=time.get%></td>'
     converter = PSPConverter(None)
     tags = converter._look_for_tags(l)
     nl = converter._replace_quotes(l)
     shouldbe = '"<td width="50%">" + str(node.get()) + "Test" + str(time.get) + "</td>\\n"'
     nl = converter._replace_tags(l,tags)
     if nl != shouldbe:
         msg = 'Did not replace tags right\n'
         msg += 'Original line:%s\n' % l
         msg += 'new Line:%s\n' % nl
         msg += 'should be:%s\n' % shouldbe
         self.fail(msg)
Exemplo n.º 4
0
 def process(self,file,line):
     fn = self._get_filename(line)
     il = self._get_indent_level(line)
     if fn[0:1] == '/':
         self.filename = os.path.join(self.web_root,fn[1:])
     else:
         self.filename = os.path.join(os.path.dirname(file.name),fn)
     fp = open(self.filename,'r')
     dp = _DirectiveProcessor(fp,self.web_root)
     fp = dp.process()
     self._include_filenames = dp.get_include_filenames()
     self._imports = dp.get_imports()
     # check to see if this is a psp file
     if self.regx_psp.search(fp.name):
         converter = PSPConverter(fp,standalone=0,indent_level=il)
         converter.convert()
         file.writelines('<%\n' + str(converter.get()) +  '%>\n')
     # if this is a regular file
     else:
         fp.seek(0)
         file.writelines(fp.readlines())
     return file
Exemplo n.º 5
0
 def process(self, file, line):
     fn = self._get_filename(line)
     il = self._get_indent_level(line)
     if fn[0:1] == '/':
         self.filename = os.path.join(self.web_root, fn[1:])
     else:
         self.filename = os.path.join(os.path.dirname(file.name), fn)
     fp = open(self.filename, 'r')
     dp = _DirectiveProcessor(fp, self.web_root)
     fp = dp.process()
     self._include_filenames = dp.get_include_filenames()
     self._imports = dp.get_imports()
     # check to see if this is a psp file
     if self.regx_psp.search(fp.name):
         converter = PSPConverter(fp, standalone=0, indent_level=il)
         converter.convert()
         file.writelines('<%\n' + str(converter.get()) + '%>\n')
     # if this is a regular file
     else:
         fp.seek(0)
         file.writelines(fp.readlines())
     return file
Exemplo n.º 6
0
 def compile(self, file, dp, force_reload=0):
     sourcefile_name = '%spy' % file.name[:-3]
     if not self._use_cache(file):
         # Process all the directives
         dp = _DirectiveProcessor(file, self.WEB_ROOT)
         include_files = dp.get_include_filenames()
         file = dp.process()
         # Convert to psp to py file
         psp_convert = PSPConverter(file)
         psp_convert.convert()
         sourcefile = open(sourcefile_name, 'w')
         # add all the imports to the source file
         self._add_imports(sourcefile, dp.get_imports())
         sourcefile.write(psp_convert.get())
         sourcefile.close()
         targetfile = '%spyc' % file.name[:-3]
         if os.path.isfile(targetfile):
             os.remove(targetfile)
         _sdterr = sys.stderr
         stderr = StringIO.StringIO()
         sys.stderr = stderr
         py_compile.compile(sourcefile_name, targetfile)
         sys.stderr = _sdterr
         stderr.seek(0)
         err = ''
         for l in stderr.readlines():
             err += '%s<br>' % l
         if err != '':
             raise CompileError(err)
         module_name = os.tmpnam()
         psp_module = imp.load_module(module_name, open(targetfile), '',
                                      ('pyc', 'r', imp.PY_COMPILED))
         self.cache[file.name] = {
             'module': psp_module,
             'psp_last_modified': os.stat(file.name)[ST_MTIME],
             'py_last_modified': os.stat(sourcefile_name)[ST_MTIME],
             'include_files': {},
             'dp': dp
         }
         for f in include_files:
             self.cache[file.name]['include_files'][f] = os.stat(
                 f)[ST_MTIME]
     else:
         if os.stat(sourcefile_name)[ST_MTIME] > self.cache[
                 file.name]['py_last_modified']:
             targetfile = '%spyc' % file.name[:-3]
             if os.path.isfile(targetfile):
                 os.remove(targetfile)
             _sdterr = sys.stderr
             stderr = StringIO.StringIO()
             sys.stderr = stderr
             py_compile.compile(sourcefile_name, targetfile)
             sys.stderr = _sdterr
             stderr.seek(0)
             err = ''
             for l in stderr.readlines():
                 err += '%s<br>' % l
             if err != '':
                 raise CompileError(err)
             module_name = os.tmpnam()
             psp_module = imp.load_module(module_name, open(targetfile), '',
                                          ('pyc', 'r', imp.PY_COMPILED))
             self.cache[file.name]['py_last_modified'] = os.stat(
                 sourcefile_name)[ST_MTIME]