# Path: ghtools/cli.py
# def catch_api_errors():
# def fail(message, exit_code=1):
# def get_client(nickname):
# def parse_identifier(identifier, require_repo=False):
# 
# Path: ghtools/github/organisation.py
# class Organisation(object):
# 
#     def __init__(self, org, client=None):
#         self._ident = Identifier.from_string(org)
#         self.org = self._ident.org
#         self.client = client or make_client(self._ident)
# 
#     def add_team_member(self, team, login):
#         self.client.put('/teams/{0}/members/{1}'.format(team['id'], login), data=' ')
# 
#     def add_team_repo(self, team, repo_name):
#         self.client.put('/teams/{0}/repos/{1}/{2}'.format(team['id'], self.org, repo_name), data=' ')
# 
#     def create_repo(self, repo):
#         keys = [
#             'name',
#             'description',
#             'homepage',
#             'private',
#             'has_issues',
#             'has_wiki',
#             'has_downloads'
#         ]
#         payload = dict((k, repo[k]) for k in keys)
#         res = self.client.post('/orgs/{0}/repos'.format(self.org), data=payload)
#         return res.json()
# 
#     def create_team(self, team):
#         res = self.client.post('/orgs/{0}/teams'.format(self.org), data=team)
#         return res.json()
# 
#     def get_repo(self, repo):
#         url = '/repos/{0}/{1}'.format(self.org, repo)
#         res = self.client.get(url)
#         return res.json()
# 
#     def list_members(self):
#         return self.client.paged_get('/orgs/{0}/members'.format(self.org))
# 
#     def list_repos(self):
#         return self.client.paged_get('/orgs/{0}/repos'.format(self.org))
# 
#     def list_teams(self):
#         return self.client.paged_get('/orgs/{0}/teams'.format(self.org))
# 
#     def list_team_members(self, team):
#         return self.client.paged_get('/teams/{0}/members'.format(team['id']))
# 
#     def list_team_repos(self, team):
#         return self.client.paged_get('/teams/{0}/repos'.format(team['id']))
# 
# 
#     def __str__(self):
#         return '<Organisation {0}>'.format(self._ident)
# 
# Path: ghtools/migrators/teams.py
# class TeamMigrator(object):
#     def __init__(self, src, dst, mapping_path):
#     def migrate(self):
#     def _create_team(self, team):
#     def _migrate_members(self, team):
#     def _migrate_repos(self, team):
#     def _load_members_mapping(self, mapping_path):
# def migrate(src, dst, mapping_path):


import logging
from argh import arg, dispatch_command
from ghtools import cli
from ghtools.github import Organisation
from ghtools.migrators import teams


log = logging.getLogger(__name__)


@arg('src', help='Migration source')
@arg('dst', help='Migration destination')
@arg('mapping', help='Mapping file for user accounts from src to dst')
def migrate_teams(args):
    with cli.catch_api_errors():
        src = Organisation(args.src)

# Path: ghtools/cli.py
# def catch_api_errors():
# def fail(message, exit_code=1):
# def get_client(nickname):
# def parse_identifier(identifier, require_repo=False):
# 
# Path: ghtools/github/organisation.py
# class Organisation(object):
# 
#     def __init__(self, org, client=None):
#         self._ident = Identifier.from_string(org)
#         self.org = self._ident.org
#         self.client = client or make_client(self._ident)
# 
#     def add_team_member(self, team, login):
#         self.client.put('/teams/{0}/members/{1}'.format(team['id'], login), data=' ')
# 
#     def add_team_repo(self, team, repo_name):
#         self.client.put('/teams/{0}/repos/{1}/{2}'.format(team['id'], self.org, repo_name), data=' ')
# 
#     def create_repo(self, repo):
#         keys = [
#             'name',
#             'description',
#             'homepage',
#             'private',
#             'has_issues',
#             'has_wiki',
#             'has_downloads'
#         ]
#         payload = dict((k, repo[k]) for k in keys)
#         res = self.client.post('/orgs/{0}/repos'.format(self.org), data=payload)
#         return res.json()
# 
#     def create_team(self, team):
#         res = self.client.post('/orgs/{0}/teams'.format(self.org), data=team)
#         return res.json()
# 
#     def get_repo(self, repo):
#         url = '/repos/{0}/{1}'.format(self.org, repo)
#         res = self.client.get(url)
#         return res.json()
# 
#     def list_members(self):
#         return self.client.paged_get('/orgs/{0}/members'.format(self.org))
# 
#     def list_repos(self):
#         return self.client.paged_get('/orgs/{0}/repos'.format(self.org))
# 
#     def list_teams(self):
#         return self.client.paged_get('/orgs/{0}/teams'.format(self.org))
# 
#     def list_team_members(self, team):
#         return self.client.paged_get('/teams/{0}/members'.format(team['id']))
# 
#     def list_team_repos(self, team):
#         return self.client.paged_get('/teams/{0}/repos'.format(team['id']))
# 
# 
#     def __str__(self):
#         return '<Organisation {0}>'.format(self._ident)
# 
# Path: ghtools/migrators/teams.py
# class TeamMigrator(object):
#     def __init__(self, src, dst, mapping_path):
#     def migrate(self):
#     def _create_team(self, team):
#     def _migrate_members(self, team):
#     def _migrate_repos(self, team):
#     def _load_members_mapping(self, mapping_path):
# def migrate(src, dst, mapping_path):


# Path: ghtools/command/migrate_teams.py
import logging
from argh import arg, dispatch_command
from ghtools import cli
from ghtools.github import Organisation
from ghtools.migrators import teams



log = logging.getLogger(__name__)


@arg('src', help='Migration source')
@arg('dst', help='Migration destination')
@arg('mapping', help='Mapping file for user accounts from src to dst')
def migrate_teams(args):
    with cli.catch_api_errors():
        src = Organisation(args.src)

        dst = Organisation(args.dst)