Esempio n. 1
0
File: Version.py Progetto: 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.')
Esempio n. 2
0
File: Find.py Progetto: rec/grit
def find(*args):
    root = GitRoot.ROOT
    if not root:
        raise ValueError('There is no git repository here.')
    args = list(args)
    is_forward = '-' not in args
    if not is_forward:
        args.remove('-')

    if not args:
        raise ValueError('No file specified for find')

    if len(args) < 2:
        args.append(os.getcwd())

    prefix, current = args
    settings = Project.settings('find')
    find_root = os.path.join(root, settings['find_root'])
    display_root = os.path.join(root, settings['display_root'])
    matches = sorted(list(_match(find_root, prefix)))

    if not matches:
        raise ValueError("Can't find files matching prefix " + prefix)
    try:
        index = matches.index(os.getcwd())
    except ValueError:
        _print_match(matches[0] if is_forward else matches[-1], display_root)
    else:
        _print_match(matches[(index + (1 if is_forward else -1)) % len(matches)],
                     display_root)
Esempio n. 3
0
File: Slack.py Progetto: rec/grit
def slack(days=2):
    days = int(days)
    inverse = Remote.inverse()
    slack_names = Project.settings('slack')
    def slack(user):
        return '@' + slack_names[user]

    label_names = dict((v, k) for (k, v) in Project.settings('labels').items())

    def labels_to_names(labels):
        return ' '.join(
            slack(label_names[i]) for i in labels if i in label_names)

    previous = get_previous_business_day(days)
    def match(issue):
        if issue['updated_at'] >= previous:
            # print('too new:', issue['number'], issue['updated_at'], previous)
            return False
        for label in issue['labels']:
            if label['name'] in ('Passed', 'Hold'):
                # print('passed:', issue['number'])
                return False
        # print('slack:', issue['number'])
        return True

    if False:
        import json
        json.dump(Git.issues(), open('/tmp/git-issues.json', 'w'),
                  sort_keys=True, indent=4, separators=(',', ': '))
    slackers = [i for i in Git.issues() if match(i)]
    if not slackers:
        return;
    print('\nPull requests that are over %d business day%s stale:' % (
          days, '' if days == 1 else 's'))

    labels = Git.labels()
    for issue in sorted(slackers, key=operator.itemgetter('updated_at')):
        try:
            user = slack(inverse[issue['user']['login']]) + ':'
            update = issue['updated_at'][:10]
            url = Open.get_url(str(issue['number']))
            lab = labels_to_names(labels[issue['number']])
            print('  %s (%s): %s (%s)' % (url, update, user, lab))
        except Exception as e:
            print('ERROR:', e)
            raise
    print()
Esempio n. 4
0
File: Version.py Progetto: 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)
Esempio n. 5
0
File: New.py Progetto: 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()
Esempio n. 6
0
File: Start.py Progetto: 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
Esempio n. 7
0
File: EFind.py Progetto: rec/grit
def efind(*args):
    args = list(args)
    is_forward = '-' not in args
    if not is_forward:
        args.remove('-')

    if '+' in args:
        args.remove('+')

    if not args:
        raise ValueError('No file specified for find')

    if len(args) < 2:
        args.append(os.getcwd())

    prefix, current = args
    current = current and os.path.abspath(current)

    root = GitRoot.root(current)
    if not root:
        raise ValueError('There is no git repository here.')

    settings = Project.settings('find')
    find_root = os.path.join(root, settings['find_root'])
    display_root = os.path.join(root, settings['display_root'])
    matches = match(find_root, prefix)

    if not matches:
        open('/tmp/error.txt', 'w').write('failed to find prefix ' + prefix + ' current ' + current)
        return

    if is_forward:
        index = bisect.bisect_right(matches, current)
    else:
        index = bisect.bisect_left(matches, current) - 1
    print(matches[index % len(matches)])
Esempio n. 8
0
File: Clone.py Progetto: rec/grit
def clone(branch="", directory=""):
    directory = Start.clone(directory)
    base_branch = Project.settings("clone").get("base_branch", "develop")
    if branch and branch != base_branch:
        Import.run_import(branch, cwd=directory)
    Test.run_test(directory)
Esempio n. 9
0
File: Release.py Progetto: rec/grit
def base_branch():
    return Project.settings('git').get('base_branch', 'develop')
Esempio n. 10
0
File: Release.py Progetto: rec/grit
    def branch(self, category):
        return '%s-%s' % (self.name, category)

    def update_pulls(self, base_commit):
        pulls = [p for p in Git.pulls().values() if self.accept(p)]
        pull_dict = dict((p.number, p.commit_id) for p in pulls)
        pull_dict['base_commit'] = base_commit
        if self.pull_dict != pull_dict:
            self.pull_dict = pull_dict
            _release(pulls, self.branch('working'), self.branch('next'),
                     self.name)
            return True


SETTINGS = Project.settings('release')
SELECTORS = [PullSelector(s) for s in SETTINGS.get('selectors', [])]

def release():
    previous_pulls = {}
    while True:
        base_commit = Git.commit_id(upstream=True, branch=base_branch())
        success = False
        for selector in SELECTORS:
            success = selector.update_pulls(base_commit) or success

        if success:
            Slack.slack()
        else:
            print(String.timestamp(short=True) + ': no change.')
        if ARGS.period:
Esempio n. 11
0
def filename():
    return Project.settings('version')['changelog']
Esempio n. 12
0
File: Remake.py Progetto: rec/grit
def remake():
    remake = Project.settings('remake').get('remake')
    if remake:
        Call.call(remake, cwd=GitRoot.ROOT)
        print('Project file remade.')