Example #1
0
        if handler.type is not None:
            t = convert_node(handler.type, scope)
            top = 'if (__pjs_err.__class__ && $b.isinstance(__pjs_err, %s)) ' % t
        else:
            top = ''

        subs.append(single % (top, eb))
    text = TEMPLATES['try'] % (body, ' else '.join(subs))
    return text

# @end

#WONTFIX: with

html_out = open(localfile('template.html')).read()
js_out = open(localfile('template.js')).read()
rhino_out = open(localfile('template.ss.js')).read()

def do_compile(filename, fmt, options):
    modules = convert_modules(filename, options)
    text = '\n'.join(modules[filen] for filen in sorted(modules.keys()))
    lib = os.path.join(options.get('lib_dir', '.'), 'pjslib.js')
    data = {'file':os.path.abspath(filename), 'text':text, 'lib':lib}
    data['path'] = sys.path
    if options.get('rhino', False):
        template = rhino_out
    elif options.get('html', False):
        template = html_out
    else:
        template = js_out
Example #2
0
import time
import utils
import json

__author__ = 'Tom'

HISTORY_FILE = utils.localfile("history.log")


def _tail(path, window=20):
    """
    Returns the last `window` lines of file `f` as a list.
    """
    with open(path, "r") as f:
        if window == 0:
            return []
        BUFSIZ = 4096
        f.seek(0, 2)
        bytes = f.tell()
        size = window + 1
        block = -1
        data = []
        while size > 0 and bytes > 0:
            if bytes - BUFSIZ > 0:
                # Seek back one whole BUFSIZ
                f.seek(block * BUFSIZ, 2)
                # read BUFFER
                data.insert(0, f.read(BUFSIZ))
            else:
                # file too small, start from begining
                f.seek(0, 0)
Example #3
0
import utils
import os
import json

__author__ = "Tom"

CONFIG_FILE = utils.localfile("config.json")


def load():
    with open(CONFIG_FILE) as outfile:
        return json.load(outfile)


def save(config):
    with open(CONFIG_FILE, "w") as outfile:
        json.dump(config, outfile, indent=4, sort_keys=True)
Example #4
0
import time
import utils
import json

__author__ = 'Tom'

HISTORY_FILE = utils.localfile("history.log")


def _tail(path, window=20):
    """
    Returns the last `window` lines of file `f` as a list.
    """
    with open(path, "r") as f:
        if window == 0:
            return []
        BUFSIZ = 4096
        f.seek(0, 2)
        bytes = f.tell()
        size = window + 1
        block = -1
        data = []
        while size > 0 and bytes > 0:
            if bytes - BUFSIZ > 0:
                # Seek back one whole BUFSIZ
                f.seek(block * BUFSIZ, 2)
                # read BUFFER
                data.insert(0, f.read(BUFSIZ))
            else:
                # file too small, start from begining
                f.seek(0, 0)
Example #5
0
import utils
import os
import json

__author__ = 'Tom'

CONFIG_FILE = utils.localfile("config.json")


def load():
    with open(CONFIG_FILE) as outfile:
        return json.load(outfile)


def save(config):
    with open(CONFIG_FILE, "w") as outfile:
        json.dump(config, outfile, indent=4, sort_keys=True)