Пример #1
0
Файл: New.py Проект: rec/grit
def new(*files):
    if not files:
        raise Exception('No files specified for "new" command.')
    existing_templates = _existing_templates()

    templates = []
    for f in files:
        if os.path.exists(f):
            raise Exception(f + ' already exists!')
        for t in existing_templates:
            if f.endswith(t):
                template = Project.data('new', '%s.template' % t)
                break
        else:
            raise ValueError('No template for ' + f)
        templates.append([f, template])

    settings = Project.settings('new')
    namespace = settings.get('namespace', Settings.PROJECT),
    root = GitRoot.ROOT
    include_root = os.path.join(root, settings['include_root'])
    for f, template in templates:
        body, extension = os.path.splitext(f)
        if extension.startswith('.'):
            extension = extension[1:]
        name = os.path.basename(body)
        fname = os.path.dirname(os.path.abspath(name))
        path_to_file = os.path.relpath(fname, include_root)
        output = template.format(
            guard=_get_guard(f),
            path_to_file=path_to_file,
            name=name,
            namespace=namespace)
        name = '%s.%s' % (body, extension)
        with open(name, 'w') as f:
            f.write(output)
        Call.call('git add ' + name)
        print(name, 'written and git added.')
    Remake.remake()
Пример #2
0
Файл: Open.py Проект: rec/grit
def open_url(url):
    Call.call('%s %s' % (_OPEN_COMMANDS[platform.system()], url))
Пример #3
0
Файл: Remake.py Проект: rec/grit
def remake():
    remake = Project.settings('remake').get('remake')
    if remake:
        Call.call(remake, cwd=GitRoot.ROOT)
        print('Project file remade.')
Пример #4
0
Файл: Amend.py Проект: rec/grit
def amend():
    Call.call(_AMEND)
    if ARGS.force:
        Call.call(_PUSH_F)