<commit_before>#!/usr/bin/env python
"""Create Google Cloud Platform projects."""

# import standard libraries
import glob
import re
import sys
import time
import yaml

# update path
# sys.path.insert(0, 'lib')

from lib.args import create_arg_parser
from lib.google import Google

google = Google()


def get_parent(settings):
    """

    Function: get_parent.

    description

    Args:

      project_id - [type/description]
      settings   - [type/description]

    Returns:

      return description
    """
    organization = settings['organization']
    folder = settings['folder']
    parent = None

    if organization:
        parent = {
            'id': str(organization).replace('organizations/', ''),
            'type': 'organization',
        }
    elif folder:
        parent = {
            'id': str(folder).replace('folders/', ''),
            'type': 'folder',
        }
    return parent


def create_project(project_id, settings):
    """

    Function: create_project.

    description

    Args:

      project_id - [type/description]
      settings   - [type/description]

    Returns:

      return description
    """
    organization = settings['organization']
    folder = settings['folder']

    # labels = settings['labels']

    project = {
        'projectId': project_id,
        'name': project_id,
    }

    project['parent'] = get_parent(settings)

    # if labels:
    #   project['labels'] = labels

    sys.stdout.write('   * creating project: %s...' % project_id)
    sys.stdout.flush()

    result = google.create_project(project)
    if result:
        time.sleep(1)
        print 'successful.'
    return result
<commit_msg>Now waits until project is really created before proceeding.<commit_after>#!/usr/bin/env python
"""Create Google Cloud Platform projects."""

# import standard libraries
import glob
import re
import sys
import time
import yaml

# update path
# sys.path.insert(0, 'lib')

from lib.args import create_arg_parser
from lib.google import Google

google = Google()


def get_parent(settings):
    """

    Function: get_parent.

    description

    Args:

      project_id - [type/description]
      settings   - [type/description]

    Returns:

      return description
    """
    organization = settings['organization']
    folder = settings['folder']
    parent = None

    if organization:
        parent = {
            'id': str(organization).replace('organizations/', ''),
            'type': 'organization',
        }
    elif folder:
        parent = {
            'id': str(folder).replace('folders/', ''),
            'type': 'folder',
        }
    return parent


def create_project(project_id, settings):
    """

    Function: create_project.

    description

    Args:

      project_id - [type/description]
      settings   - [type/description]

    Returns:

      return description
    """
    organization = settings['organization']
    folder = settings['folder']

    # labels = settings['labels']

    project = {
        'projectId': project_id,
        'name': project_id,
    }

    project['parent'] = get_parent(settings)

    # if labels:
    #   project['labels'] = labels

    sys.stdout.write('   * creating project: %s...' % project_id)
    sys.stdout.flush()

    result = google.create_project(project)
    if result:
        created = False
        while not created:
            try:
                project = google.get_project(project_id)
                created = True
            except:
                created = False
        print 'successful.'

    return result

{'fraction_non_alphanumeric': 0.11620111731843576, 'fraction_numerical': 0.0008379888268156424, 'mean_word_length': 2.288337924701561, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6567609', 'n_tokens_mistral': 1018, 'n_tokens_neox': 959, 'n_words': 250}