示例#1
0
文件: Project.py 项目: rec/grit
def settings(*names):
    names = File.add_suffix(names)
    settings = {}
    for p in reversed(PATH):
        settings.update(File.get_json(*(p + names)))

    return settings
示例#2
0
文件: Version.py 项目: rec/grit
def get_version():
    files = Project.settings('version')['files']
    for f in files:
        old_version = File.search(f, VERSION)
        if old_version:
            return old_version
    raise Exception('ERROR: no version number found.')
示例#3
0
文件: Version.py 项目: rec/grit
def version_commit(version_number=None, success=None, failure=None):
    root = GitRoot.root()
    files = Project.settings('version')['files']

    old_version = get_version()

    if version_number == old_version:
        raise Exception('Version number is already %s' % old_version)
    if not version_number:
        version_number = semver.increment_string(old_version)
    if not CommandList.confirm('update version %s to %s' %
                               (old_version, version_number)):
        return
    for f in files:
        File.subn(os.path.join(root, f), VERSION, version_number)

    if success or failure:
        ChangeLog.add_status_line(version_number, success, failure)
    Git.git('commit', '-am', 'Set version to %s' % version_number)
示例#4
0
文件: CD.py 项目: rec/grit
def _move_root(forward, prefix=''):
    root = GitRoot.ROOT
    container = GitRoot.root_container()
    roots = sorted(File.each(path=container, select=GitRoot.select(prefix)))

    if roots:
        try:
            index = roots.index(root)
        except ValueError:
            print(roots[0] if forward else roots[-1])
            return
        index += (1 if forward else -1)
        path = roots[index % len(roots)]
        sub = os.path.join(path, os.path.relpath(os.getcwd(), root))
        print((sub if os.path.exists(sub) else path) or '.')
    else:
        print('.')
示例#5
0
文件: Start.py 项目: rec/grit
def clone(directory):
    settings = Project.settings("clone")
    branch = settings.get("base_branch", "develop")

    root = GitRoot.root(os.getcwd())
    if root:
        directory = directory or os.path.basename(root)
        root = os.path.dirname(root)
    else:
        directory = directory or Settings.PROJECT
        root = os.getcwd()

    directory = File.next_version(os.path.join(root, directory))
    settings.update(branch=branch, directory=directory, project=Settings.PROJECT, user=Settings.USER)
    # Call git clone.
    if Git.git(*_CLONE.format(**settings).split(), cwd=root):
        raise ValueError("Failed to start new directory")

    Remote.remote("all", cwd=directory)
    Remote.remote("upstream", Settings.PROJECT, directory)
    Git.git("pull", "upstream", branch)
    banner("Created", branch + ", directory", directory)
    return directory
示例#6
0
文件: Call.py 项目: rec/grit
def for_each_directory(
        command, select=None, path=None, before=None, after=None, **kwds):
    for f in File.each(path=path, select=select):
        before and before(f)
        call(command, cwd=f, **kwds)
        after and after(f)
示例#7
0
文件: Project.py 项目: rec/grit
def data(*names):
    for p in PATH:
        r = File.try_read(*(p + names))
        if r:
            return r
示例#8
0
文件: Project.py 项目: rec/grit
from __future__ import absolute_import, division, print_function, unicode_literals

import os

from grit import File
from grit import Settings

ROOT = File.root_relative('projects')

PATH = (
    (File.HOME, '.grit', Settings.PROJECT),
    (ROOT, Settings.PROJECT),
    (File.HOME, '.grit', 'default'),
    (ROOT, 'default'),
)

def data(*names):
    for p in PATH:
        r = File.try_read(*(p + names))
        if r:
            return r

def settings(*names):
    names = File.add_suffix(names)
    settings = {}
    for p in reversed(PATH):
        settings.update(File.get_json(*(p + names)))

    return settings

def files(*names):