From d725de6949a7028da234db7c90b2048556f48bae Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Thu, 23 Jul 2015 12:36:25 -0600 Subject: [PATCH] Initial commit, got popularity scanner working --- .gitignore | 2 + README.md | 0 bin/popular-repositories | 20 +++++++++ setup.py | 92 ++++++++++++++++++++++++++++++++++++++++ teamanalysis/__init__.py | 0 teamanalysis/git.py | 14 ++++++ teamanalysis/repos.py | 26 ++++++++++++ teamanalysis/version.py | 1 + 8 files changed, 155 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 bin/popular-repositories create mode 100644 setup.py create mode 100644 teamanalysis/__init__.py create mode 100644 teamanalysis/git.py create mode 100644 teamanalysis/repos.py create mode 100644 teamanalysis/version.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7fdea58 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +*.egg-info diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/bin/popular-repositories b/bin/popular-repositories new file mode 100755 index 0000000..b4f585b --- /dev/null +++ b/bin/popular-repositories @@ -0,0 +1,20 @@ +#!/usr/bin/env python +import argparse +import teamanalysis.git +import teamanalysis.repos + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('name', help='The name of the person to look up') + args = parser.parse_args() + + for repo in teamanalysis.repos.REPOSITORIES: + print(repo) + abspath = '/Users/eliribble/src/{}/'.format(repo) + entries = teamanalysis.git.shortlog(abspath) + matching_entries = [entry for entry in entries if args.name in entry[1]] + for entry in matching_entries: + print("\t{} {}".format(*entry)) + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..ad19f57 --- /dev/null +++ b/setup.py @@ -0,0 +1,92 @@ +from setuptools import setup +import contextlib +import imp +import os +import re +import subprocess + +DATA_ROOTS = [] +PROJECT = 'teamanalysis' +VERSION_FILE = 'teamanalysis/version.py' + +def _get_output_or_none(args): + try: + return subprocess.check_output(args).decode('utf-8').strip() + except subprocess.CalledProcessError: + return None + +def _get_git_description(): + return _get_output_or_none(['git', 'describe']) + +def _get_git_branches_for_this_commit(): + branches = _get_output_or_none(['git', 'branch', '-r', '--contains', 'HEAD']) + split = branches.split('\n') if branches else [] + return [branch.strip() for branch in split] + +def _is_on_releasable_branch(branches): + return any(['origin/master' == branch or branch.startswith('origin/hotfix') for branch in branches]) + +def _git_to_version(git): + match = re.match(r'(?P[\d\.]+)-(?P[\d]+)-(?P\w{8})', git) + if not match: + version = git + else: + version = "{tag}.post0.dev{offset}".format(**match.groupdict()) + print("Calculated {} version '{}' from git description '{}'".format(PROJECT, version, git)) + return version + +@contextlib.contextmanager +def write_version(): + git_description = _get_git_description() + git_branches = _get_git_branches_for_this_commit() + version = _git_to_version(git_description) if git_description else None + if git_branches and not _is_on_releasable_branch(git_branches): + print("Forcing version to 0.0.1 because this commit is on branches {} and not a whitelisted branch".format(git_branches)) + version = '0.0.1' + if version: + with open(VERSION_FILE, 'r') as version_file: + old_contents = version_file.read() + with open(VERSION_FILE, 'w') as version_file: + version_file.write('VERSION = "{}"\n'.format(version)) + yield + if version: + with open(VERSION_FILE, 'w') as version_file: + version_file.write(old_contents) + +def get_version(): + basedir = os.path.abspath(os.path.dirname(__file__)) + version = imp.load_source('version', os.path.join(basedir, PROJECT, 'version.py')) + return version.VERSION + +def get_data_files(): + data_files = [] + for data_root in DATA_ROOTS: + for root, _, files in os.walk(data_root): + data_files.append((os.path.join(PROJECT, root), [os.path.join(root, f) for f in files])) + return data_files + +def main(): + with write_version(): + setup( + name = "teamanalysis", + version = get_version(), + description = "A project for analyzing what a team is doing", + url = "https://github.com/EliRibble/teamanlysis", + long_description = open("README.md").read(), + author = "Eli Ribble", + author_email = "eli@theribbles.org", + install_requires = [ + ], + packages = ['teamanalysis'], + package_data = { + "teamanalysis" : ["teamanalysis/*"], + }, + data_files = get_data_files(), + scripts = [ + "bin/popular-repositories", + ], + include_package_data = True, + ) + +if __name__ == "__main__": + main() diff --git a/teamanalysis/__init__.py b/teamanalysis/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/teamanalysis/git.py b/teamanalysis/git.py new file mode 100644 index 0000000..11e5dbd --- /dev/null +++ b/teamanalysis/git.py @@ -0,0 +1,14 @@ +import os +import re +import subprocess + +SHORTLOG_PATTERN = re.compile(r'\s+(?P\d+)\s+(?P[\w \-]+)\s*') +def shortlog(abspath): + os.chdir(abspath) + output = subprocess.check_output(['git', 'shortlog', '-s', '-n']) + lines = output.split('\n') + matches = [SHORTLOG_PATTERN.match(line) for line in lines] + matches = [match for match in matches if match] + entries = [(match.group('lines'), match.group('name')) for match in matches] + return entries + diff --git a/teamanalysis/repos.py b/teamanalysis/repos.py new file mode 100644 index 0000000..21ea3ca --- /dev/null +++ b/teamanalysis/repos.py @@ -0,0 +1,26 @@ + +REPOSITORIES = [ + '3diax', + 'archer', + 'authentise.com', + 'blue-whale', + 'chelido', + 'deployment', + 'docs', + 'eventbus', + #'gigas', + 'hoth', + 'lowes', + 'lowes-scanner', + 'marketing-website', + 'musicbot', + 'pao', + 'partner.authentise.com', + 'quickslice', + 'scylla', + 'sepiida', + 'sirenia', + 'streamus', + 'vision', +] + diff --git a/teamanalysis/version.py b/teamanalysis/version.py new file mode 100644 index 0000000..3c53fed --- /dev/null +++ b/teamanalysis/version.py @@ -0,0 +1 @@ +VERSION = 'development'