Beispiel #1
0
Datei: New.py Projekt: 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()
Beispiel #2
0
Datei: Test.py Projekt: rec/grit
def run_test(cwd=None):
    test = Project.data('test.sh').strip()
    if not test:
        raise ValueError('No test!')
    Call.for_each(test.format(project=Settings.PROJECT), cwd=cwd)