Example #1
0
def println(line):
	# blank line
	if re.match(r'\s*$', line):
		return puts(line)

	# logfile header
	mobj = re.match(r'==> (.*) <==$', line)
	if mobj:
		return puts(style.bright(fore.black('==> ') + fore.white(mobj.group(1)) + fore.black(' <==')))
	
	# exception line
	if re.match(EXCEPTION_PREFIX, line):
		return puts(fore.red(line))

	# standard log line
	basic = r'(.*?\s+)'

	date = basic*3
	time = basic
	type = basic
	file = '(\[.*?\s+)\])'

	mobj = re.match(basic*6 + r'(.*)', line)
	if not mobj:
		# non-conventional line
		return puts(line)
	else:
		groups = list(mobj.groups())

		groups.insert(0, str(fore.cyan))
		groups.insert(4, str(fore.blue))
		groups.insert(6, str(style.bright))
		groups.insert(8, str(style.reset_all))
		groups.insert(9, str(fore.cyan))
		groups.insert(11, str(style.reset_all))

		for idx, string in enumerate(groups):
			string = re.sub(r'(STATUS)', fore.white(r'\1'), string)
			string = re.sub(r'(DEBUG)', fore.white(r'\1'), string)
			string = re.sub(r'(INFO)', fore.green(r'\1'), string)
			string = re.sub(r'(WARNING)', fore.yellow(r'\1'), string)
			string = re.sub(r'(ERROR)', fore.red(r'\1'), string)
			string = re.sub(r'(EXCEPT)', fore.red(r'\1'), string)

			groups[idx] = string


		groups[-1] = re.sub(r'\[', fore.cyan(r'['), groups[-1])
		groups[-1] = re.sub(r'\]', fore.cyan(r']'), groups[-1])

		groups[-1] = re.sub(r'~>', fore.blue(r'~>'), groups[-1])
		groups[-1] = re.sub(r'<~', fore.yellow(r'<~'), groups[-1])

		groups[-1] = re.sub(r'\(', fore.cyan(r'('), groups[-1])
		groups[-1] = re.sub(r'\)', fore.cyan(r')'), groups[-1])

		groups[-1] = re.sub(r"'", fore.cyan(r"'"), groups[-1])
		groups[-1] = re.sub(r'"', fore.cyan(r'"'), groups[-1])

		return puts(''.join(groups))
Example #2
0
	def __init__(self):
		# Find Project Root
		path.current = os.getcwd()
		path.root    = recurse_up(path.current, 'Cakefile')

		if path.root:
			os.chdir(path.root)
			sys.path.insert(0, '')

			# Print project path
			puts(fore.yellow('(in %s)' % path.root))
		else:
			raise CakeError('Cakefile not found')

		# Prepare environment
		self.env   = {}
		self.tasks = {}
	
		# Read Cakefile
		with open('Cakefile') as f:
			exec(f.read(), self.env)

		# Load all tasks
		for name, task in self.env.items():
			if getattr(task, '_task', False):
				self.tasks[name] = task
Example #3
0
    def __init__(self):
        # Find Project Root
        path.current = os.getcwd()
        path.root = recurse_up(path.current, 'Cakefile')

        if path.root:
            os.chdir(path.root)
            sys.path.insert(0, '')

            # Print project path
            puts(fore.yellow('(in %s)' % path.root))
        else:
            raise CakeError('Cakefile not found')

        # Prepare environment
        self.env = {}
        self.tasks = {}

        # Read Cakefile
        with open('Cakefile') as f:
            exec(f.read(), self.env)

        # Load all tasks
        for name, task in self.env.items():
            if getattr(task, '_task', False):
                self.tasks[name] = task
Example #4
0
def api(modules):
    # ensure iterable
    if isinstance(modules, Socket):
        modules = [modules]

    # iterate list
    for module in modules:
        puts('= ' + fore.green(module.name))
        for obj in module.help():
            if isinstance(obj, list):
                # method
                puts('  * ' + fore.yellow(obj[0]) + ' ' + fore.white(obj[1]))
                if obj[2]:
                    puts('    ' + fore.blue(obj[2]))
Example #5
0
def api(modules):
	# ensure iterable
	if isinstance(modules, Socket):
		modules = [modules]
	
	# iterate list
	for module in modules:
		puts('= ' + fore.green(module.name))
		for obj in module.help():
			if isinstance(obj, list):
				# method
				puts('  * ' + fore.yellow(obj[0]) + ' ' + fore.white(obj[1]))
				if obj[2]:
					puts('    ' + fore.blue(obj[2]))
Example #6
0
def generate(modname):
	""" generate new module """

	# check for valid name
	if modname.lower() in pydoc.Helper.keywords.keys():
		raise PyscaleError('%s is a Python keyword.' % repr(modname.lower()))

	# go to project root
	root = find_project()
	if root != False:
		os.chdir(root)
	else:
		raise PyscaleError('Pyscale project not found (missing Cakefile?)')


	# create folder
	folder = 'app/%s' % modname
	if osp.isdir(folder):
		puts(fore.yellow(' exists ') + folder)
	else:
		puts(fore.green('  mkdir ') + folder)
		os.makedirs(folder)

	
	# create file
	modfile = 'app/%s/main' % modname
	tplfile = osp.join(pyscale.__path__[0], 'files', 'module')

	if osp.exists(modfile):
		raise PyscaleError('Module already exists. Aborting...')
	else:
		with open(tplfile) as f:
			tpl = jinja2.Template(f.read())
			tpl = tpl.render(module=modname.title())

		puts(fore.green(' create ') + modfile)
		with open(modfile, 'w') as f:
			f.write(tpl)
Example #7
0
def generate(modname):
    """ generate new module """

    # check for valid name
    if modname.lower() in pydoc.Helper.keywords.keys():
        raise PyscaleError('%s is a Python keyword.' % repr(modname.lower()))

    # go to project root
    root = find_project()
    if root != False:
        os.chdir(root)
    else:
        raise PyscaleError('Pyscale project not found (missing Cakefile?)')

    # create folder
    folder = 'app/%s' % modname
    if osp.isdir(folder):
        puts(fore.yellow(' exists ') + folder)
    else:
        puts(fore.green('  mkdir ') + folder)
        os.makedirs(folder)

    # create file
    modfile = 'app/%s/main' % modname
    tplfile = osp.join(pyscale.__path__[0], 'files', 'module')

    if osp.exists(modfile):
        raise PyscaleError('Module already exists. Aborting...')
    else:
        with open(tplfile) as f:
            tpl = jinja2.Template(f.read())
            tpl = tpl.render(module=modname.title())

        puts(fore.green(' create ') + modfile)
        with open(modfile, 'w') as f:
            f.write(tpl)
Example #8
0
def println(line):
    # blank line
    if re.match(r'\s*$', line):
        return puts(line)

    # logfile header
    mobj = re.match(r'==> (.*) <==$', line)
    if mobj:
        return puts(
            style.bright(
                fore.black('==> ') + fore.white(mobj.group(1)) +
                fore.black(' <==')))

    # exception line
    if re.match(EXCEPTION_PREFIX, line):
        return puts(fore.red(line))

    # standard log line
    basic = r'(.*?\s+)'

    date = basic * 3
    time = basic
    type = basic
    file = '(\[.*?\s+)\])'

    mobj = re.match(basic * 6 + r'(.*)', line)
    if not mobj:
        # non-conventional line
        return puts(line)
    else:
        groups = list(mobj.groups())

        groups.insert(0, str(fore.cyan))
        groups.insert(4, str(fore.blue))
        groups.insert(6, str(style.bright))
        groups.insert(8, str(style.reset_all))
        groups.insert(9, str(fore.cyan))
        groups.insert(11, str(style.reset_all))

        for idx, string in enumerate(groups):
            string = re.sub(r'(STATUS)', fore.white(r'\1'), string)
            string = re.sub(r'(DEBUG)', fore.white(r'\1'), string)
            string = re.sub(r'(INFO)', fore.green(r'\1'), string)
            string = re.sub(r'(WARNING)', fore.yellow(r'\1'), string)
            string = re.sub(r'(ERROR)', fore.red(r'\1'), string)
            string = re.sub(r'(EXCEPT)', fore.red(r'\1'), string)

            groups[idx] = string

        groups[-1] = re.sub(r'\[', fore.cyan(r'['), groups[-1])
        groups[-1] = re.sub(r'\]', fore.cyan(r']'), groups[-1])

        groups[-1] = re.sub(r'~>', fore.blue(r'~>'), groups[-1])
        groups[-1] = re.sub(r'<~', fore.yellow(r'<~'), groups[-1])

        groups[-1] = re.sub(r'\(', fore.cyan(r'('), groups[-1])
        groups[-1] = re.sub(r'\)', fore.cyan(r')'), groups[-1])

        groups[-1] = re.sub(r"'", fore.cyan(r"'"), groups[-1])
        groups[-1] = re.sub(r'"', fore.cyan(r'"'), groups[-1])

        return puts(''.join(groups))