Exemplo n.º 1
0
def github_pull(user, project):
    g = get_github(user)
    repo_name = project.github_repo
    if repo_name is None:
        raise Exception("No GitHub repo defined.")
    repo = g.get_repo(repo_name)
    # If somehow we don't have a branch set, this will use the "master_branch"
    branch_name = project.github_branch or repo.master_branch
    try:
        branch = repo.get_branch(branch_name)
    except GithubException:
        raise Exception("Unable to get the branch.")

    if project.github_last_commit == branch.commit.sha:
        # Nothing to do.
        return False

    commit = repo.get_git_commit(branch.commit.sha)
    tree = repo.get_git_tree(commit.tree.sha, recursive=True)

    paths = {x.path: x for x in tree.tree}
    paths_notags = {get_root_path(x) for x in paths}
    root = find_project_root(paths)

    # First try finding the resource map so we don't fail out part-done later.
    # TODO: transaction support for file contents would be nice...

    resource_root = root + 'resources/'
    manifest_path = root + 'appinfo.json'
    if manifest_path in paths:
        manifest_sha = paths[manifest_path].sha
        manifest = json.loads(git_blob(repo, manifest_sha))
        media = manifest.get('resources', {}).get('media', [])
    else:
        raise Exception("appinfo.json not found")

    project_type = manifest.get('projectType', 'native')

    for resource in media:
        path = resource_root + resource['file']
        if project_type == 'pebblejs' and resource['name'] in {
            'MONO_FONT_14', 'IMAGE_MENU_ICON', 'IMAGE_LOGO_SPLASH', 'IMAGE_TILE_SPLASH'}:
            continue
        if path not in paths_notags:
            raise Exception("Resource %s not found in repo." % path)

    # Now we grab the zip.
    zip_url = repo.get_archive_link('zipball', branch_name)
    u = urllib2.urlopen(zip_url)

    # And wipe the project!
    project.source_files.all().delete()
    project.resources.all().delete()

    # This must happen before do_import_archive or we'll stamp on its results.
    project.github_last_commit = branch.commit.sha
    project.github_last_sync = now()
    project.save()

    import_result = do_import_archive(project.id, u.read())

    send_keen_event('cloudpebble', 'cloudpebble_github_pull', user=user, data={
        'data': {
            'repo': project.github_repo
        }
    })

    return import_result
Exemplo n.º 2
0
def github_pull(user, project):
    g = get_github(user)
    repo_name = project.github_repo
    if repo_name is None:
        raise Exception("No GitHub repo defined.")
    repo = g.get_repo(repo_name)
    # If somehow we don't have a branch set, this will use the "master_branch"
    branch_name = project.github_branch or repo.master_branch
    try:
        branch = repo.get_branch(branch_name)
    except GithubException:
        raise Exception("Unable to get the branch.")

    if project.github_last_commit == branch.commit.sha:
        # Nothing to do.
        return False

    commit = repo.get_git_commit(branch.commit.sha)
    tree = repo.get_git_tree(commit.tree.sha, recursive=True)

    paths = {x.path: x for x in tree.tree}

    root = find_project_root(paths)

    # First try finding the resource map so we don't fail out part-done later.
    # TODO: transaction support for file contents would be nice...

    resource_root = root + 'resources/'
    manifest_path = root + 'appinfo.json'
    if manifest_path in paths:
        manifest_sha = paths[manifest_path].sha
        manifest = json.loads(git_blob(repo, manifest_sha))
        media = manifest.get('resources', {}).get('media', [])
    else:
        raise Exception("appinfo.json not found")

    project_type = manifest.get('projectType', 'native')

    for resource in media:
        path = resource_root + resource['file']
        if project_type == 'pebblejs' and resource['name'] in {
                'MONO_FONT_14', 'IMAGE_MENU_ICON', 'IMAGE_LOGO_SPLASH',
                'IMAGE_TILE_SPLASH'
        }:
            continue
        if path not in paths:
            raise Exception("Resource %s not found in repo." % path)

    # Now we grab the zip.
    zip_url = repo.get_archive_link('zipball', branch_name)
    u = urllib2.urlopen(zip_url)

    # And wipe the project!
    project.source_files.all().delete()
    project.resources.all().delete()

    # This must happen before do_import_archive or we'll stamp on its results.
    project.github_last_commit = branch.commit.sha
    project.github_last_sync = now()
    project.save()

    import_result = do_import_archive(project.id, u.read())

    send_keen_event('cloudpebble',
                    'cloudpebble_github_pull',
                    user=user,
                    data={'data': {
                        'repo': project.github_repo
                    }})

    return import_result
Exemplo n.º 3
0
def github_pull(user, project):
    g = get_github(user)
    repo_name = project.github_repo
    if repo_name is None:
        raise Exception("No GitHub repo defined.")
    repo = g.get_repo(repo_name)
    # If somehow we don't have a branch set, this will use the "master_branch"
    branch_name = project.github_branch or repo.master_branch
    try:
        branch = repo.get_branch(branch_name)
    except GithubException:
        raise Exception("Unable to get the branch.")

    if project.github_last_commit == branch.commit.sha:
        # Nothing to do.
        return False

    commit = repo.get_git_commit(branch.commit.sha)
    tree = repo.get_git_tree(commit.tree.sha, recursive=True)

    paths = {x.path: x for x in tree.tree}

    version, root = find_project_root(paths)

    # First try finding the resource map so we don't fail out part-done later.
    # TODO: transaction support for file contents would be nice...
    # SDK2
    resource_root = None
    media = {}
    if version == '2':
        resource_root = root + 'resources/'
        manifest_path = root + 'appinfo.json'
        if manifest_path in paths:
            manifest_sha = paths[manifest_path].sha
            manifest = json.loads(git_blob(repo, manifest_sha))
            media = manifest.get('resources', {}).get('media', [])
        else:
            raise Exception("appinfo.json not found")
    else:
        # SDK1
        resource_root = root + 'resources/src/'
        remote_map_path = resource_root + 'resource_map.json'
        if remote_map_path in paths:
            remote_map_sha = paths[remote_map_path].sha
            remote_map = json.loads(git_blob(repo, remote_map_sha))
            media = remote_map['media']
        else:
            raise Exception("resource_map.json not found.")

    for resource in media:
        path = resource_root + resource['file']
        if path not in paths:
            raise Exception("Resource %s not found in repo." % path)

    # Now we grab the zip.
    zip_url = repo.get_archive_link('zipball', branch_name)
    u = urllib2.urlopen(zip_url)
    with tempfile.NamedTemporaryFile(suffix='.zip') as temp:
        shutil.copyfileobj(u, temp)
        temp.flush()
        # And wipe the project!
        project.source_files.all().delete()
        project.resources.all().delete()
        import_result = do_import_archive(project.id, temp.name)
        project.github_last_commit = branch.commit.sha
        project.github_last_sync = now()
        project.save()
        return import_result
Exemplo n.º 4
0
def github_pull(user, project):
    g = get_github(user)
    repo_name = project.github_repo
    if repo_name is None:
        raise Exception("No GitHub repo defined.")
    repo = g.get_repo(repo_name)
    # If somehow we don't have a branch set, this will use the "master_branch"
    branch_name = project.github_branch or repo.master_branch
    try:
        branch = repo.get_branch(branch_name)
    except GithubException:
        raise Exception("Unable to get the branch.")

    if project.github_last_commit == branch.commit.sha:
        # Nothing to do.
        return False

    commit = repo.get_git_commit(branch.commit.sha)
    tree = repo.get_git_tree(commit.tree.sha, recursive=True)

    paths = {x.path: x for x in tree.tree}
    paths_notags = {get_root_path(x) for x in paths}

    # First try finding the resource map so we don't fail out part-done later.
    try:
        root, manifest_item = find_project_root_and_manifest([GitProjectItem(repo, x) for x in tree.tree])
    except ValueError as e:
        raise ValueError("In manifest file: %s" % str(e))
    resource_root = root + project.resources_path + "/"
    manifest = json.loads(manifest_item.read())

    media = manifest.get("resources", {}).get("media", [])
    project_type = manifest.get("projectType", "native")

    for resource in media:
        path = resource_root + resource["file"]
        if project_type == "pebblejs" and resource["name"] in {
            "MONO_FONT_14",
            "IMAGE_MENU_ICON",
            "IMAGE_LOGO_SPLASH",
            "IMAGE_TILE_SPLASH",
        }:
            continue
        if path not in paths_notags:
            raise Exception("Resource %s not found in repo." % path)

    # Now we grab the zip.
    zip_url = repo.get_archive_link("zipball", branch_name)
    u = urllib2.urlopen(zip_url)

    # And wipe the project!
    # TODO: transaction support for file contents would be nice...
    project.source_files.all().delete()
    project.resources.all().delete()

    # This must happen before do_import_archive or we'll stamp on its results.
    project.github_last_commit = branch.commit.sha
    project.github_last_sync = now()
    project.save()

    import_result = do_import_archive(project.id, u.read())

    send_td_event("cloudpebble_github_pull", data={"data": {"repo": project.github_repo}}, user=user)

    return import_result