Ejemplo n.º 1
0
def create_team(team_id):
    """Creates an institutional GitHub team.

    """
    # Post to GitHub API.
    payload = {
        'auto_init': True,
        'description': '{} team'.format(team_id.upper()),
        'maintainers': [GH_USER_NAME],
        'name': team_id,
        'privacy': 'secret'
    }

    r = requests.post(GH_API_ORG_TEAMS,
        data=json.dumps(payload),
        auth=GH_API_CREDENTIALS
        )

    # If created then log.
    if r.status_code == 201:
        pyessv.log("GH-team created: {}".format(team_id), app='GH')

    # If already exists then skip.
    elif r.status_code == 422:
        pyessv.log("GH-team already exists: {}".format(team_id), app='GH')

    # Otherwise log error.
    else:
        pyessv.log_error("GH-team creation failure: {} :: {}".format(team_id, r['errors'][0]['message']), app='GH')
Ejemplo n.º 2
0
def create_team(team_id):
    """Creates an institutional GitHub team.

    """
    # Post to GitHub API.
    payload = {
        'auto_init': True,
        'description': '{} team'.format(team_id.upper()),
        'maintainers': [GH_USER_NAME],
        'name': team_id,
        'privacy': 'secret'
    }

    r = requests.post(GH_API_ORG_TEAMS,
        data=json.dumps(payload),
        auth=GH_API_CREDENTIALS
        )

    # If created then log.
    if r.status_code == 201:
        pyessv.log("GH-team created: {}".format(team_id), app='GH')

    # If already exists then skip.
    elif r.status_code == 422:
        pyessv.log("GH-team already exists: {}".format(team_id), app='GH')

    # Otherwise log error.
    else:
        pyessv.log_error("GH-team creation failure: {} :: {}".format(team_id, r['errors'][0]['message']), app='GH')
Ejemplo n.º 3
0
def create_repo(institution_id):
    """Create a new institutional repo.

    """
    # Set payload.
    data = json.dumps({
        'auto_init': True,
        'name': institution_id,
        'description': '{} documentation archive'.format(institution_id.upper()),
        'homepage': 'https://github.com/ES-DOC-INSTITUTIONAL/{}'.format(institution_id),
        'private': False,
        'license_template': 'gpl-3.0',
        'has_issues': True,
        'has_projects': True,
        'has_wiki': True
    })

    # Post to Gh api.
    r = requests.post(GH_API_ORG_REPOS, data=data, auth=GH_API_CREDENTIALS)

    # If created then log.
    if r.status_code == 201:
        pyessv.log("GH-repo created: {}".format(institution_id))

    # If already exists then skip.
    elif r.status_code == 422:
        pyessv.log("GH-repo already exists: {}".format(institution_id))

    # Otherwise log error.
    else:
        pyessv.log_error("GH-repo creation failure: {} :: {}".format(institution_id, r['errors'][0]['message']))
Ejemplo n.º 4
0
def create_repo(institution_id):
    """Create a new institutional repo.

    """
    # Set payload.
    data = json.dumps({
        'auto_init': True,
        'name': institution_id,
        'description': '{} documentation archive'.format(institution_id.upper()),
        'homepage': 'https://github.com/ES-DOC-INSTITUTIONAL/{}'.format(institution_id),
        'private': False,
        'license_template': 'gpl-3.0',
        'has_issues': True,
        'has_projects': True,
        'has_wiki': True
    })

    # Post to Gh api.
    r = requests.post(GH_API_ORG_REPOS, data=data, auth=GH_API_CREDENTIALS)

    # If created then log.
    if r.status_code == 201:
        pyessv.log("GH-repo created: {}".format(institution_id))

    # If already exists then skip.
    elif r.status_code == 422:
        pyessv.log("GH-repo already exists: {}".format(institution_id))

    # Otherwise log error.
    else:
        pyessv.log_error("GH-repo creation failure: {} :: {}".format(institution_id, r['errors'][0]['message']))
Ejemplo n.º 5
0
def _main(args):
    """Main entry point.

    """
    # Initialise CMIP5 to CMIP6 mappings.
    mappings.init()

    # Write a JSON file for each CMIP6 institute | CMIP5 document combination.
    for institution_id in pyessv.WCRP.cmip6.get_institutes():
        if not args.institution_id in ["all", institution_id.canonical_name]:
            continue
        if not cmip5_documents.init(institution_id.canonical_name):
            continue
        for output in _yield_outputs(institution_id):
            output.save()
            pyessv.log('... {};'.format(output.fpath))
Ejemplo n.º 6
0
def init(ctx):
    """Write topic workbook.

    """
    path = os.path.join(os.getenv('ESDOC_HOME'), 'repos/institutional')
    path = os.path.join(path, ctx.institution_id)
    path = os.path.join(path, ctx.MIP_ERA)
    path = os.path.join(path, 'models')
    path = os.path.join(path, ctx.source_id)
    if not os.path.isdir(path):
        os.makedirs(path)
    fname = '_'.join([ctx.MIP_ERA, ctx.institution_id, ctx.source_id])
    fname += '_coupling.xlsx'
    path = os.path.join(path, fname)

    pyessv.log('generating --> {}'.format(fname), app='SH')
    ctx.wb = xlsxwriter.Workbook(path)
Ejemplo n.º 7
0
def _main():
    """Main entry point.

    """
    institutes = _get_institutes()
    repos = utils.get_repos()

    repos_to_create = set(institutes).difference(set(repos.keys()))
    repos_to_delete = set(repos.keys()).difference(set(institutes))

    if len(repos_to_create) == 0 and len(repos_to_delete) == 0:
        pyessv.log("Repos are in sync - nothing todo")
        return

    for institution_id in repos_to_create:
        utils.create_repo(institution_id)

    for repo in [i for i in repos.values() if i.name in repos_to_delete]:
        print(repo)
Ejemplo n.º 8
0
def _main():
    """Main entry point.

    """
    institutes = _get_institutes()
    repos = utils.get_repos()

    repos_to_create = set(institutes).difference(set(repos.keys()))
    repos_to_delete = set(repos.keys()).difference(set(institutes))

    if len(repos_to_create) == 0 and len(repos_to_delete) == 0:
        pyessv.log("Repos are in sync - nothing todo")
        return

    for institution_id in repos_to_create:
        utils.create_repo(institution_id)

    for repo in [i for i in repos.values() if i.name in repos_to_delete]:
        utils.delete_repo(repo)
Ejemplo n.º 9
0
def _sync_fs(i, s, settings):
    """Syncs an institute's model documentation upon the file system.
    This results in either an updated document or a deleted document.

    """
    # Get file content.
    content = _get_content(i, s, settings)

    # Get file path.
    path = _get_cim_fpath(i, s)

    # Delete if content is null.
    if content is None:
        pass
        # if os.path.exists(path):
        #     pyessv.log('deleting --> {}'.format(path.split('/')[-1]), app='SH')
        #     os.remove(path)

    # Write otherwise.
    else:
        pyessv.log('writing --> {}'.format(path.split('/')[-1]), app='SH')
        with open(path, 'w') as fstream:
            fstream.write(content)
Ejemplo n.º 10
0
def _main():
    """Main entry point.

    """
    # Set canonical institutes & actual GH teams.
    institutes = [i.canonical_name.split(':')[-1] for i in pyessv.load('wcrp:cmip6:institution-id')]
    teams = utils.get_teams(lambda i: i['name'].startswith('cmip6-'))

    # Set teams to be created.
    to_create = ['cmip6-{}'.format(i) for i in institutes if 'cmip6-{}'.format(i) not in teams]

    # Set teams to be deleted.
    to_delete = [i for i in teams.values() if i.name.startswith('cmip6') and  i.institution_id not in institutes]

    # Escape when nothing to do.
    if len(to_create) == 0 and len(to_delete) == 0:
        pyessv.log("Teams are in sync - nothing todo")
        return

    # Update GH.
    for team_id in to_create:
        utils.create_team(team_id)
    for team in to_delete:
        utils.delete_team(team)
Ejemplo n.º 11
0
def delete_team(team):
    """Informs user of required deltions to be manually performed.

    """
    pyessv.log("TODO: manually delete GitHub team: {}".format(team.name))
Ejemplo n.º 12
0
def delete_repo(repo):
    """Informs user of required deltions to be manually performed.

    """
    pyessv.log("TODO: manually delete GitHub repo: {}".format(repo.name))
Ejemplo n.º 13
0
def delete_team(team):
    """Informs user of required deltions to be manually performed.

    """
    pyessv.log("TODO: manually delete GitHub team: {}".format(team.name))
Ejemplo n.º 14
0
def delete_repo(repo):
    """Informs user of required deltions to be manually performed.

    """
    pyessv.log("TODO: manually delete GitHub repo: {}".format(repo.name))