def PopulateRepos(self):
     shared.EnsureRunningInTask()  # gives us automatic retries
     repos = []
     template_dir = self.repo_collection.key.id()  # repo_collection_url
     for dirname in os.listdir(template_dir):
         # skip github submodule templates in production
         if not common.IsDevMode() and '-' in dirname:
             continue
         dirpath = os.path.join(template_dir, dirname)
         if not os.path.isdir(dirpath):
             continue
         try:
             with open(os.path.join(dirpath,
                                    _PLAYGROUND_SETTINGS_FILENAME)) as f:
                 data = json.loads(f.read())
             name = data.get('template_name')
             description = data.get('template_description')
             open_files = data.get('open_files', [])
         except IOError:
             name = dirpath
             description = dirname
             open_files = []
         url = os.path.join(template_dir, dirname)
         html_url = (
             'https://code.google.com/p/cloud-playground/source/browse/'
             '?repo=bliss#git%2F{}'.format(urllib.quote(url)))
         model.CreateRepoAsync(repo_url=url,
                               html_url=html_url,
                               name=name,
                               description=description,
                               open_files=open_files)
Exemple #2
0
 def post(self):
     """Handles HTTP POST requests."""
     if not users.is_current_user_admin():
         self.response.set_status(httplib.UNAUTHORIZED)
         return
     project_id = self.request.data['project_id']
     if not project_id:
         Abort(httplib.BAD_REQUEST, 'project_id required')
     project = model.GetProject(project_id)
     if not project:
         Abort(httplib.NOT_FOUND,
               'failed to retrieve project {}'.format(project_id))
     repo_url = project.template_url
     repo = model.GetRepo(repo_url)
     model.CreateRepoAsync(repo.key.id(), repo.html_url, repo.name,
                           repo.description, repo.open_files)
    def PopulateRepos(self):
        shared.EnsureRunningInTask()  # gives us automatic retries
        baseurl = self.repo_collection.key.id()
        fetched = fetcher.Fetcher(baseurl, follow_redirects=True)
        page = fetched.content
        candidate_repos = self._GetChildPaths(page)
        fetches = []

        # we found a project in the root directory
        if 'app.yaml' in candidate_repos:
            candidate_repos.insert(0, '')

        if common.IsDevMode():
            # fetch fewer repos during development
            candidate_repos = candidate_repos[:1]

        for c in candidate_repos:
            if c and not c.endswith('/'):
                continue
            project_url = '{0}{1}'.format(baseurl, c)
            app_yaml_url = '{0}app.yaml'.format(project_url)
            fetched = fetcher.Fetcher(app_yaml_url, follow_redirects=True)
            fetches.append((c, project_url, app_yaml_url, fetched))

        repos = []
        for c, project_url, app_yaml_url, fetched in fetches:
            try:
                content = fetched.content
                shared.i('found app.yaml: {}'.format(app_yaml_url))
                name = c.rstrip('/') or project_url
                description = 'Sample code from {0}'.format(project_url)
                model.CreateRepoAsync(repo_url=project_url,
                                      html_url=project_url,
                                      name=name,
                                      description=description,
                                      open_files=[])
            except urlfetch_errors.Error:
                exc_info = sys.exc_info()
                formatted_exception = traceback.format_exception(
                    exc_info[0], exc_info[1], exc_info[2])
                shared.w('skipping {0}'.format(project_url))
                for line in [line for line in formatted_exception if line]:
                    shared.w(line)
  def PopulateRepos(self):
    shared.EnsureRunningInTask()  # gives us automatic retries
    repo_collection_url = self.repo_collection.key.id()
    info = GetInfo(repo_collection_url)
    # e.g. https://api.github.com/users/GoogleCloudPlatform/repos
    url = 'https://api.github.com/users/{0}/repos'.format(info.user)
    fetched = FetchAsyncWithAuth(url, follow_redirects=True)
    repos = self._GetAppEnginePythonRepos(fetched.json_content)

    credential = model.GetOAuth2Credential('github')
    if (not credential or not credential.client_id
        or not credential.client_secret):
      # fetch fewer when we're not authenticated
      repos = repos[:1]

    repo_entities = []
    for repo in repos:
      name = repo['name']
      description=repo['description'] or repo['html_url']
      model.CreateRepoAsync(repo_url=repo['html_url'],
                            html_url=repo['html_url'],
                            name=name, description=description, open_files=[])
Exemple #5
0
 def post(self):
     """Handles HTTP POST requests."""
     repo_url = self.request.data.get('repo_url')
     if not repo_url:
         Abort(httplib.BAD_REQUEST, 'repo_id required')
     repo = model.GetRepo(repo_url)
     if not repo:
         html_url = name = description = repo_url
         repo = model.CreateRepoAsync(repo_url=repo_url,
                                      html_url=html_url,
                                      name=name,
                                      description=description,
                                      open_files=[])
     project = repo.project.get()
     if not project or project.in_progress_task_name:
         Abort(
             httplib.REQUEST_TIMEOUT,
             'Requested template is not yet available. '
             'Please try again in 30  seconds.')
     r = self.DictOfProject(project)
     self.response.headers['Content-Type'] = _JSON_MIME_TYPE
     self.response.write(tojson(r))