Exemplo n.º 1
0
def process_rename(renames, data):
    if not renames:
        return

    c = color.cyan
    for k, v in renames.items():
        t = Template(v)
        v = t.render(**data)
        if '{{' in v:
            log.error('error renaming', c(k), 'to', c(v))
        elif os.path.exists(v):
            log.warn('rewriting', c(v))
            shutil.rmtree(v)
            shutil.move(k, v)
        else:
            log.info('renaming', c(k), 'to', c(v))
            shutil.move(k, v)
Exemplo n.º 2
0
def test_log():
    log.info('hello test')

    log.start('start a level')
    log.info('info in a level')
    log.warn('warn in a level')
    log.error('error in a level')
    log.debug('debug info')
    log.verbose.info('will not print this')
    log.config(verbose=True)
    log.verbose.info('will print this')

    log.start('start second level')
    log.verbose.debug('hello debug')
    log.end()
    log.config(quiet=True)
    log.info('will not print')
    log.end('close a level')
    log.message('foo', 'bar')
Exemplo n.º 3
0
Arquivo: git.py Projeto: lepture/init
def shell(argv, cwd=None, input=None):
    """
    Run a shell command, get the response from stdout.
    """

    if not isinstance(argv, (list, tuple)):
        argv = argv.split()

    try:
        p = Popen(argv, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=cwd)
    except OSError as e:
        if e.errno == os.errno.ENOENT:
            log.error("Maybe you haven't installed", argv[0])
        else:
            log.error(e)
        return None

    stdout, stderr = p.communicate(input=input)
    if stderr:
        # log.error(stderr.decode())
        return None

    return stdout.decode()
Exemplo n.º 4
0
def shell(argv, cwd=None, input=None):
    """
    Run a shell command, get the response from stdout.
    """

    if not isinstance(argv, (list, tuple)):
        argv = argv.split()

    try:
        p = Popen(argv, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=cwd)
    except OSError as e:
        if e.errno == os.errno.ENOENT:
            log.error("Maybe you haven't installed", argv[0])
        else:
            log.error(e)
        return None

    stdout, stderr = p.communicate(input=input)
    if stderr:
        # log.error(stderr.decode())
        return None

    return stdout.decode()
Exemplo n.º 5
0
from terminal.builtin import log

log.start('terminal build')
log.info('build foo')
log.debug('read file foo.py')
log.warn('not found foo.py')
log.info('build bar')
log.debug('read file bar.py')
log.start('sub read')
log.info('parse bar.py')
log.info('bar is python')
log.end('parse end')
log.error('syntax error')
log.end('end build')
Exemplo n.º 6
0
from terminal.builtin import log

log.start("terminal build")
log.info("build foo")
log.debug("read file foo.py")
log.warn("not found foo.py")
log.info("build bar")
log.debug("read file bar.py")
log.start("sub read")
log.info("parse bar.py")
log.info("bar is python")
log.end("parse end")
log.error("syntax error")
log.end("end build")
Exemplo n.º 7
0
def init(name):
    """
    The main interface for this program.

    Define a template yourself, the folder structure of a template::

        template.py
        config.json (optional)
        root/

    In your ``template.py``, define a ``prompt`` function to collect
    information::

        def main():
            # prompt for user, and get data from user
            # return data
    """
    folder = os.path.join(TEMPLATE_DIR, name)
    if not os.path.exists(folder):
        install(name)

    log.info('loading', color.cyan(name))

    template = None
    for name in ['template.yml', 'template.yaml', 'template']:
        template = os.path.join(folder, name)
        if os.path.exists(template):
            break

    if not template:
        log.error('template not found.')
        return

    config = _get_config(template)

    if 'register' in config and os.path.exists(config['register']):
        q = confirm(
            'This is not an empty directory, do you want to rewrite it')
        if not q:
            return sys.exit(2)

    # a blank line for seprating the logs and prompts
    print('')
    data = process_prompts(config)
    print('')

    # write from templates
    process_write(os.path.join(folder, 'root'), data)

    # create license
    if 'license' in data:
        process_license(data['license'], data)

    process_rename(config.get('rename', {}), data)

    footer = config.get('footer')
    if isinstance(footer, (list, tuple)):
        footer = '\n'.join(footer)

    if footer:
        print('\n%s\n' % footer)
    return