From b6d8f6430310b6bb868e71652ee1301db366d65a Mon Sep 17 00:00:00 2001 From: Rok Garbas Date: Sat, 2 Jul 2011 22:26:52 +0200 Subject: [PATCH] lots of beutification of getting ready for first release --- README.rst | 54 ++++++++++++++++++++++++++++++++++-- githubcollective/__init__.py | 24 +++++++++++----- githubcollective/github.py | 5 ++-- githubcollective/sync.py | 24 ---------------- 4 files changed, 71 insertions(+), 36 deletions(-) diff --git a/README.rst b/README.rst index 737fc66..a4889ca 100644 --- a/README.rst +++ b/README.rst @@ -9,6 +9,9 @@ Approach that ``github-collective`` tool takes is that you edit central configuration (for now only ini-like file) from where configuration is read and updated respectivly. +Initially purposo of this scrip is to manage Plone's collective organisation on +github: https://collective.github.com + .. contents @@ -35,6 +38,32 @@ name. :: % bin/github-collective --help + usage: github-collective [-h] -c CONFIG [-M MAILER] [-C CACHE] -o GITHUB_ORG + -u GITHUB_USERNAME -P GITHUB_PASSWORD [-v] [-p] + + This tool will let you automate tedious tasks of creating teams granting + permission and creating repositories. + + optional arguments: + -h, --help show this help message and exit + -c CONFIG, --config CONFIG + path to configuration file (could also be remote + location). eg. + http://collective.github.com/permissions.cfg (default: + None) + -M MAILER, --mailer MAILER + TODO (default: None) + -C CACHE, --cache CACHE + path to file where to cache results from github. + (default: None) + -o GITHUB_ORG, --github-org GITHUB_ORG + github organisation. (default: None) + -u GITHUB_USERNAME, --github-username GITHUB_USERNAME + github account username. (default: None) + -P GITHUB_PASSWORD, --github-password GITHUB_PASSWORD + github account password. (default: None) + -v, --verbose + -p, --pretend Example of configuration stored locally @@ -43,8 +72,8 @@ Example of configuration stored locally :: % bin/github-collective \ - -c example.cfg \ # path to configuration file - -o collective \ # organization that we are + -c example.cfg \ # path to configuration file + -o vim-addons \ # organization that we are -u garbas \ # account that has management right for organization -P PASSWORD # account password @@ -60,6 +89,27 @@ Example of configuration stored on github -u garbas \ # account that has management right for organization -P PASSWORD # account password +Example of cached configuration +------------------------------- + +:: + + % bin/github-collective \ + -c https://raw.github.com/garbas/github-collective/master/example.cfg \ + # url to configuration file + -C .cache # file where store and read cached results from github + -o collective \ # organization that we are + -u garbas \ # account that has management right for organization + -P PASSWORD # account password + + +Todo +==== + + - Send emails to owners about removing repos + - better logging mechanism (eg. logbook) + + Credits ======= diff --git a/githubcollective/__init__.py b/githubcollective/__init__.py index 048d863..e3dc742 100644 --- a/githubcollective/__init__.py +++ b/githubcollective/__init__.py @@ -29,16 +29,26 @@ def send(self, to, msg): def run(): parser = argparse.ArgumentParser( - prog=Sync.__name__, + prog='github-collective', + description='This tool will let you automate tedious tasks of ' + 'creating teams granting permission and creating ' + 'repositories.', formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) - parser.add_argument('-c', '--config', type=select_config, required=True) - parser.add_argument('-M', '--mailer', type=lambda x: Mailer(x)) - parser.add_argument('-C', '--cache', type=str) - parser.add_argument('-o', '--github-org', type=str, required=True) - parser.add_argument('-u', '--github-username', type=str, required=True) - parser.add_argument('-P', '--github-password', type=str, required=True) + parser.add_argument('-c', '--config', type=select_config, required=True, + help="path to configuration file (could also be remote location). " + "eg. http://collective.github.com/permissions.cfg") + parser.add_argument('-M', '--mailer', type=lambda x: Mailer(x), + help="TODO") + parser.add_argument('-C', '--cache', type=str, + help="path to file where to cache results from github.") + parser.add_argument('-o', '--github-org', type=str, required=True, + help="github organisation.") + parser.add_argument('-u', '--github-username', type=str, required=True, + help="github account username.") + parser.add_argument('-P', '--github-password', type=str, required=True, + help="github account password.") parser.add_argument('-v', '--verbose', action='store_true') parser.add_argument('-p', '--pretend', action='store_true') diff --git a/githubcollective/github.py b/githubcollective/github.py index 94a2388..b67b2ff 100644 --- a/githubcollective/github.py +++ b/githubcollective/github.py @@ -7,10 +7,7 @@ import base64 import requests -from githubcollective.team import Team -from githubcollective.repo import Repo from githubcollective.config import BASE_URL -from githubcollective.config import TEAM_PREFIX class Github(object): @@ -36,6 +33,8 @@ def __init__(self, organization, username, password, verbose, pretend): # requests library helpers def _request(self, method, url, data=None): + if self.pretend: + return kw = {'url': BASE_URL+url+'?per_page=10000', 'headers': self.headers} if data: diff --git a/githubcollective/sync.py b/githubcollective/sync.py index 20d73c0..8c09b6d 100644 --- a/githubcollective/sync.py +++ b/githubcollective/sync.py @@ -3,10 +3,6 @@ class Sync(object): - """ - """ - - __name__ = 'githubcollective-sync' def __init__(self, github, mailer=None, verbose=False, pretend=False): self.github = github @@ -127,27 +123,19 @@ def run(self, new, old): def add_repo(self, config, repo): config._repos[repo.name] = repo - if self.pretend: - return return self.github._gh_org_create_repo(repo.name) def remove_repo(self, config, repo): del config._repos[repo.name] - if self.pretend: - return if self.mailer: raise NotImplemented def fork_repo(self, config, fork_url, repo): config._repos[repo.name] = repo - if self.pretend: - return return self._gh_org_fork_repo(fork_url) def add_team(self, config, team): config._teams[team.name] = Team(team.name, team.permission) - if self.pretend: - return return self._gh_org_create_team( name=team.name, permission=team.permission, @@ -156,8 +144,6 @@ def add_team(self, config, team): def edit_team(self, config, team): config._teams[team.name].name = team.name config._teams[team.name].permission = team.permission - if self.pretend: - return return self._gh_org_edit_team( id=team.id, name=team.name, @@ -166,34 +152,24 @@ def edit_team(self, config, team): def remove_team(self, config, team): del config._teams[team.name] - if self.pretend: - return return self._gh_org_delete_team(team.id) def add_team_member(self, config, team, member): team = config.get_team(team.name) team.members.update([member]) - if self.pretend: - return return self._gh_org_add_team_member(team.id, member) def remove_team_member(self, config, team, member): team = config.get_team(team.name) team.members.remove(member) - if self.pretend: - return return self._gh_org_remove_team_member(team.id, member) def add_team_repo(self, config, team, repo): team = config.get_team(team.name) team.repos.update([repo]) - if self.pretend: - return return self._gh_org_add_team_repo(team.id, repo) def remove_team_repo(self, config, team, repo): team = config.get_team(team.name) team.repos.remove(repo) - if self.pretend: - return return self._gh_org_remove_team_repo(team.id, repo)