Example #1
0
 def api_versions(self):
     from readthedocs.builds.models import APIVersion
     ret = []
     for version_data in api.project(self.pk).active_versions.get()['versions']:
         version = APIVersion(**version_data)
         ret.append(version)
     return sort_version_aware(ret)
Example #2
0
 def get_version(project, version_pk):
     """Ensure we're using a sane version"""
     if version_pk:
         version_data = api_v2.version(version_pk).get()
     else:
         version_data = (api_v2.version(
             project.slug).get(slug=LATEST)['objects'][0])
     return APIVersion(**version_data)
Example #3
0
def version_from_slug(slug, version):
    from readthedocs.builds.models import Version, APIVersion
    from readthedocs.restapi.client import api
    if getattr(settings, 'DONT_HIT_DB', True):
        version_data = api.version().get(project=slug,
                                         slug=version)['results'][0]
        v = APIVersion(**version_data)
    else:
        v = Version.objects.get(project__slug=slug, slug=version)
    return v
Example #4
0
    def get_version(version_pk):
        """
        Retrieve version data from the API.

        :param version_pk: version pk to sync
        :type version_pk: int
        :returns: a data-complete version object
        :rtype: builds.models.APIVersion
        """
        version_data = api_v2.version(version_pk).get()
        return APIVersion(**version_data)
Example #5
0
    def get_version(project=None, version_pk=None):
        """
        Retrieve version data from the API.

        :param project: project object to sync
        :type project: projects.models.Project
        :param version_pk: version pk to sync
        :type version_pk: int
        :returns: a data-complete version object
        :rtype: builds.models.APIVersion
        """
        assert (project or version_pk), 'project or version_pk is needed'
        if version_pk:
            version_data = api_v2.version(version_pk).get()
        else:
            version_data = (api_v2.version(
                project.slug).get(slug=LATEST)['objects'][0])
        return APIVersion(**version_data)
Example #6
0
def update_imported_docs(version_pk):
    """
    Check out or update the given project's repository.

    :param version_pk: Version id to update
    """
    version_data = api_v2.version(version_pk).get()
    version = APIVersion(**version_data)
    project = version.project
    ret_dict = {}

    # Make Dirs
    if not os.path.exists(project.doc_path):
        os.makedirs(project.doc_path)

    if not project.vcs_repo():
        raise RepositoryError(
            _('Repository type "{repo_type}" unknown').format(
                repo_type=project.repo_type
            )
        )

    with project.repo_nonblockinglock(
            version=version,
            max_lock_age=getattr(settings, 'REPO_LOCK_SECONDS', 30)):

        # Get the actual code on disk
        try:
            before_vcs.send(sender=version)
            if version:
                log.info(
                    LOG_TEMPLATE.format(
                        project=project.slug,
                        version=version.slug,
                        msg='Checking out version {slug}: {identifier}'.format(
                            slug=version.slug,
                            identifier=version.identifier
                        )
                    )
                )
                version_slug = version.slug
                version_repo = project.vcs_repo(version_slug)

                ret_dict['checkout'] = version_repo.checkout(version.identifier)
            else:
                # Does this ever get called?
                log.info(LOG_TEMPLATE.format(
                    project=project.slug, version=version.slug, msg='Updating to latest revision'))
                version_slug = LATEST
                version_repo = project.vcs_repo(version_slug)
                ret_dict['checkout'] = version_repo.update()
        finally:
            after_vcs.send(sender=version)

        # Update tags/version

        version_post_data = {'repo': version_repo.repo_url}

        if version_repo.supports_tags:
            version_post_data['tags'] = [
                {'identifier': v.identifier,
                 'verbose_name': v.verbose_name,
                 } for v in version_repo.tags
            ]

        if version_repo.supports_branches:
            version_post_data['branches'] = [
                {'identifier': v.identifier,
                 'verbose_name': v.verbose_name,
                 } for v in version_repo.branches
            ]

        try:
            api_v2.project(project.pk).sync_versions.post(version_post_data)
        except HttpClientError:
            log.exception("Sync Versions Exception")
        except Exception:
            log.exception("Unknown Sync Versions Exception")
    return ret_dict