Ejemplo n.º 1
0
def call(fn, args):
    if fn.getIdentifier() == "import":
        filen = args[0].getValue()
        if os.path.exists("{0}.AScript".format(filen)):
            print("\n\n><_> RUNTIME COMPILE - {0} <_><\n\n".format(filen))
            compileFile(filen)
        
        if os.path.exists("{0}.asop".format(filen)):
            fileReaders.append(FileReader("{0}.asop".format(filen)))
        else:
            stack.append(StackObject(StackObjectType.BOOLEAN, False))
    elif fn.getIdentifier() == "print":
        for argz in args:
            print(argz.getValue())
    elif fn.getIdentifier() == "input":
        if len(args) > 0:
            stack.append(StackObject(StackObjectType.STRING, input(args[0].getValue())))
        else:
            stack.append(StackObject(StackObjectType.STRING, input()))
    elif fn.getIdentifier() == "sqrt":
        if len(args) > 0 and args[0].getType() == StackObjectType.INTEGER or args[0].getType() == StackObjectType.FLOAT or args[0].getType() == StackObjectType.VARIABLE:
            stack.append(StackObject(StackObjectType.FLOAT, args[0].getValue() ** 0.5))
        else:
            Error.major("Sqrt Error", "INTEGER", " ")
    elif fn.getIdentifier() == "sleep":
        length = args[0].getValue()
        time.sleep(length)
Ejemplo n.º 2
0
def build_egg(name):
    py_module = 'update_%s.py' % name

    code = open('update_NAME.py').read()
    code = code.replace('@NAME@', name)
    open(py_module, 'w').write(code)
    compileFile(py_module)

    z = zipfile.ZipFile(join('update_%s-1.0.egg' % name),
                        'w', zipfile.ZIP_DEFLATED)
    for ext in ('', 'c'):
        z.write(py_module + ext)

    data = open('appinst.dat').read()
    data = data.replace('@NAME@', name)
    z.writestr('EGG-INFO/inst/appinst.dat', data)

    z.writestr('EGG-INFO/entry_points.txt',
               '[console_scripts]\n'
               'update-%s = update_%s:main\n' % (name, name))
    z.write('update.ico', 'EGG-INFO/inst/update.ico')
    z.write('update.icns', 'EGG-INFO/inst/update.icns')
    z.close()

    for ext in ('', 'c'):
        os.unlink(py_module + ext)
Ejemplo n.º 3
0
def compile_files(dir):
    print "Compiling", dir, "\n\t",
    line_len = 10
    for file in os.listdir(dir):
        base, ext = os.path.splitext(file)
        if ext == '.py':
            source = os.path.join(dir, file)
            line_len = line_len + len(file) + 1
            if line_len > 75:
                print "\n\t",
                line_len = len(source) + 9
            print file,
            try:
                compileFile(source)
            except SyntaxError, err:
                print err
                continue
            # make sure the .pyc file is not over-written
            os.chmod(source + "c", 444)
        else:
            path = os.path.join(dir, file)
            if os.path.isdir(path):
                print
                print
                compile_files(path)
                print "\t",
                line_len = 10
Ejemplo n.º 4
0
	def _compilePYC( directory, pythonLibs ):
		import compiler
		import os

		# Collect .py files
		files = []
		pythonLibsSet = set( pythonLibs )
		for dirpath, dirnames, filenames in os.walk( directory ):
			for dir in dirnames[:]:
				if dir not in pythonLibsSet:
					dirnames.remove(dir)
			for file in filenames:
				if os.path.splitext(file)[1] == '.py':
					files.append( os.path.join(dirpath,file) )
		# Compile .py into .pyc
		for file in files:
			compiler.compileFile( file )
Ejemplo n.º 5
0
def main():
    VERBOSE = 0
    DISPLAY = 0
    PROFILE = 0
    CONTINUE = 0
    opts, args = getopt.getopt(sys.argv[1:], 'vqdcp')
    for k, v in opts:
        if k == '-v':
            VERBOSE = 1
            visitor.ASTVisitor.VERBOSE = visitor.ASTVisitor.VERBOSE + 1
        if k == '-q':
            if sys.platform[:3]=="win":
                f = open('nul', 'wb') # /dev/null fails on Windows...
            else:
                f = open('/dev/null', 'wb')
            sys.stdout = f
        if k == '-d':
            DISPLAY = 1
        if k == '-c':
            CONTINUE = 1
        if k == '-p':
            PROFILE = 1
    if not args:
        print "no files to compile"
    else:
        for filename in args:
            if VERBOSE:
                print filename
            try:
                if PROFILE:
                    profile.run('compileFile(%s, %s)' % (`filename`,
                                                         `DISPLAY`),
                                filename + ".prof")
                else:
                    compileFile(filename, DISPLAY)
                    
            except SyntaxError, err:
                print err
                if err.lineno is not None:
                    print err.lineno
                if not CONTINUE:
                    sys.exit(-1)
Ejemplo n.º 6
0
def compile_files(dir):
    shout "Compiling", dir, "\n\t",
    line_len = 10
    for file in os.listdir(dir):
        base, ext = os.path.splitext(file)
        if ext == '.py':
            source = os.path.join(dir, file)
            line_len = line_len + len(file) + 1
            if line_len > 75:
                shout "\n\t",
                line_len = len(source) + 9
            shout file,
            try:
                compileFile(source)
            except SyntaxError, err:
                shout err
                continue
            # make sure the .pyc file is not over-written
            os.chmod(source + "c", 444)
        elif file == 'CVS':
            pass
Ejemplo n.º 7
0
def compileTemplate(tpl, cplFileName, moduleName):
	"""Compile one user template to python bytecode
		Input: (string) template file name;
			(string) compiled (target) file name
		Output: none
	"""
	if not hasTemplating:
		return
	
	debug ("Compiling template %s to file: %s" % (moduleName, cplFileName))
	try:
		debug ('  Generating code')
		cpl = Compiler(source = tpl, moduleName = moduleName)
		cpl.compile()
	except:
		printException()
		error('Error compiling template: %s' % moduleName)
		return
	# write compiled template to file
	try:
		debug ('  Writing to file')
		fh = open(cplFileName, 'w')
		fh.write(str(cpl))
		fh.close()
	except:
		printException()
		error('Can not write compiled template to file: %s' % cplFileName)
		return
	# compile generated template to python bytecode
	try:
		debug ('  Compiling to Python bytecode')
		compiler.compileFile(cplFileName)
	except:
		printException()
		error('Can not compile generated template to python bytecode. File: %s' % cplFileName)
		return
Ejemplo n.º 8
0
import compiler
compiler.compileFile('sendrecv.py')
Ejemplo n.º 9
0
 def process_one_file(self, fullname, opts):
     print "Byte-compiling %s ..." % fullname
     compiler.compileFile(fullname)
Ejemplo n.º 10
0
#!/usr/bin/env python
# -*- coding: latin-1 -*-

import compiler
compiler.compileFile('pingping.py')
Ejemplo n.º 11
0
"""Run the Python regression test using the compiler
Ejemplo n.º 12
0
import sys
Ejemplo n.º 13
0
    # parse step
    logger.info('Update steps')
    resid = {}
    for node in step:
        step_vals = {}
        for key, item in node.items():
            if item == 'False':
                item = False
            step_vals[key] = item
        # get scenario id
        step_vals['scenario_id'] = scenario_id
        # get python src
        filename = '%s/%s.py' % (directory, step_vals['reference_res_id'])
        try:
            compiler.compileFile(filename)
        except Exception, e:
            print 'Compile error in file %s :' % filename
            print ''.join(
                traceback.format_exception(sys.exc_type, sys.exc_value,
                                           sys.exc_traceback))
        python_code = open(filename, 'r')
        step_vals['python_code'] = python_code.read()
        python_code.close()
        # create or update
        step_ids = step_obj.search(
            [('reference_res_id', '=', step_vals['reference_res_id'])], 0,
            None, None, {'active_test': False})
        if step_ids:
            resid[step_vals['reference_res_id']] = step_ids[0]
            all_step_ids -= set(step_ids)
Ejemplo n.º 14
0
#interface

import compiler

compiler.compileFile("H:\\github\\gen_black\\blackwood.py")
compiler.compileFile("H:\\github\\gen_black\\gen_black.py")

base_dir = "H:\\github\\gen_black\\Input\\splr\\"

file_command = "cmd6.txt"

file_input = "H:\\github\\gen_black\\Base\\R\\XR.vob"

import os
import gen_black

os.chdir(base_dir)
gen_black.process(file_command, file_input)

print "DONE"
Ejemplo n.º 15
0
#       
#       * Redistributions of source code must retain the above copyright
#         notice, this list of conditions and the following disclaimer.
#       * Redistributions in binary form must reproduce the above
#         copyright notice, this list of conditions and the following disclaimer
#         in the documentation and/or other materials provided with the
#         distribution.
#       * Neither the name of the  nor the names of its
#         contributors may be used to endorse or promote products derived from
#         this software without specific prior written permission.
#       
#       THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
#       "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
#       LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
#       A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
#       OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#       SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#       LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
#       DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
#       THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#       (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#       OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

if __name__ == "__main__":

    import compiler, sys
    fileNames=sys.argv[1].split(",")
    print fileNames
    for fn in fileNames:
        compiler.compileFile(fn)
Ejemplo n.º 16
0
#interface

import compiler
import config
compiler.compileFile(config.blackwood)
compiler.compileFile(config.gen_black)

import os
import gen_black

os.chdir(config.base_dir)
gen_black.process(config.file_command + "mesh21.txt",
                  config.file_input + "mesh_off.vob")

print "DONE"
Ejemplo n.º 17
0
import compiler
compiler.compileFile('threadring.py')
Ejemplo n.º 18
0
elif scriptType is _SERPENT:

	pyc = _serpent_sword_alphabet_to_hex(_lex_hex(sys.argv[0]))
	pycout = ".".join(sys.argv[0].split(".")[0:-1])+".pyc"

	with open(pycout, "wb") as f:
		for val in pyc:
			f.write(chr(val))

	cmd = "python %s %s" % (pycout, " ".join(sys.argv[1:]))
	subprocess.call(cmd, shell=True)
	os.remove(pycout)

elif scriptType is _PYTHON:

	compiler.compileFile(sys.argv[0])
	tmp, sss = [], []

	with open(sys.argv[0]+'c', 'r') as pyc:
		for line in pyc:
			for char in line:
				tmp.append(int(char.encode('hex'), 16))
	os.remove(sys.argv[0]+'c') # Delete temporary pyc file

	sss = _hex_to_serpent_sword_alphabet(tmp)
	rev = _serpent_sword_alphabet_to_hex(sss)
	
	try:
		assert rev == tmp
	except AssertionError:
		sys.stderr.write("Error in hex/serpent_sword conversion")
Ejemplo n.º 19
0
#!/usr/bin/env python
import compiler
import sys
compiler.compileFile(sys.argv[1])
Ejemplo n.º 20
0
    def __init__(self, fname):
        self.Line = 0
        self.FName = fname
        self.File = open(fname)
            
    def getLine(self):
        self.Line += 1
        return self.File.readline()
    
    def getLineNo(self):
        return self.Line

    def getFName(self):
        return self.FName

compileFile("{0}".format(sys.argv[1]))
fileReaders = [FileReader("{0}.asop".format(sys.argv[1]))]

class StackObjectType(Enum):
    VARIABLE        = 1
    INTEGER         = 2
    FLOAT           = 3
    STRING          = 4
    PARENTHESIS     = 5
    BOOLEAN         = 6
    CONTROL         = 7
    
variables   = {}
labels      = {} # Stores the line no. of labels

class StackObject():
Ejemplo n.º 21
0
#!/usr/bin/python
import compiler

compiler.compileFile('shnatd.py')
compiler.compileFile('shnatld.py')