Beispiel #1
0
def compile_and_cache(package, module, namespace):
    srcfile = SRC_FOLDER + package + os.path.sep + module
    cachefile = CACHE_FOLDER + package + os.path.sep + module + ".js"
    if os.path.exists(srcfile + ".py"):
        srcfile += ".py"
        mtime = datetime.utcfromtimestamp(os.path.getmtime(srcfile))
        if not os.path.exists(cachefile) or os.path.getmtime(srcfile) > os.path.getmtime(cachefile):
            if not os.path.exists(CACHE_FOLDER + package):
                os.mkdir(CACHE_FOLDER + package)
            try:
                from pycow import (
                    translate_file,
                    ParseError,
                )  # Import has been placed here, so PyCow is not a dependency
            except ImportError:
                # Symlink/copy shipped version
                shippedfile = SHIPPED_FOLDER + package + os.path.sep + module + ".js"
                if os.name == "posix":
                    target = os.path.relpath(shippedfile, os.path.dirname(cachefile))
                    os.symlink(target, cachefile)
                else:
                    open(cachefile, "w").write(open(shippedfile, "r").read())
                return (cachefile, "changed", mtime)
            else:
                try:
                    translate_file(srcfile, cachefile, namespace=namespace, warnings=False)
                    return (cachefile, "changed", mtime)
                except ParseError, e:
                    os.unlink(cachefile)
                    return ("", "error", PARSE_ERROR_MESSAGE % (srcfile, e.value))
Beispiel #2
0
def compile_and_cache(srcfile, cachefile, package, namespace):
	if os.path.exists(srcfile + ".py"):
		srcfile += ".py"
		mtime = datetime.utcfromtimestamp(os.path.getmtime(srcfile))
		if not os.path.exists(cachefile) or os.path.getmtime(srcfile) > os.path.getmtime(cachefile):
			from pycow import translate_file, ParseError # Import has been placed here, so PyCow is not a dependency
			if not os.path.exists(CACHE_FOLDER + package):
				os.mkdir(CACHE_FOLDER + package)
			try:
				translate_file(srcfile, cachefile, namespace=namespace, warnings=False)
				return ("changed", mtime)
			except ParseError, e:
				os.unlink(cachefile)
				return ("error", PARSE_ERROR_MESSAGE % (srcfile, e.value))
Beispiel #3
0
i = 1
while i < len(sys.argv):
    arg = sys.argv[i]
    if arg == "-o":
        if i + 1 >= len(sys.argv):
            print "Error parsing command line: Missing parameter for option '-o'."
            sys.exit(1)
        out_filename = sys.argv[i + 1]
        i += 1
    elif arg == "-n":
        if i + 1 >= len(sys.argv):
            print "Error parsing command line: Missing parameter for option '-n'."
            sys.exit(1)
        namespace = sys.argv[i + 1]
        i += 1
    elif arg == "-W":
        warnings = False
    else:
        in_filename = arg
    i += 1

if in_filename == "":
    print "Error parsing command line: Missing input file."
    sys.exit(1)

translate_file(in_filename,
               out_filename,
               namespace=namespace,
               warnings=warnings)