forked from googlearchive/cloud-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollection.py
More file actions
69 lines (53 loc) · 2 KB
/
Copy pathcollection.py
File metadata and controls
69 lines (53 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""Class representing a code repository."""
import json
from .. import model
from .. import shared
from mimic.__mimic import common
_PLAYGROUND_SETTINGS_FILENAME = '.playground'
class RepoCollection(object):
"""An abstract base class for accessing a collection of code repositories."""
def __init__(self, repo_collection):
"""Constructor.
Args:
repo_collection: The repo collection entity.
"""
self.repo_collection = repo_collection
def CreateTemplateProject(self, repo):
shared.EnsureRunningInTask() # gives us automatic retries
task_name = shared.GetCurrentTaskName()
template_project = model.SetProjectOwningTask(repo.project, task_name)
tree = common.config.CREATE_TREE_FUNC(str(template_project.key.id()))
tree.Clear()
self.CreateProjectTreeFromRepo(tree, repo)
self.ParseAndApplyProjectSettings(tree, template_project)
template_project = model.SetProjectOwningTask(repo.project, None)
repo.in_progress_task_name = None
repo.put()
def ParseAndApplyProjectSettings(self, tree, project):
try:
json_text = tree.GetFileContents(_PLAYGROUND_SETTINGS_FILENAME)
except IOError:
shared.i('No {} file found for project {} based on {}'
.format(_PLAYGROUND_SETTINGS_FILENAME, project.key.id(),
project.template_url))
return
if not json_text:
return
try:
data = json.loads(json_text)
except Exception, e:
shared.w('Failed to parse JSON in {} for project {} based on {} due to {}'
.format(_PLAYGROUND_SETTINGS_FILENAME, project.key.id(),
project.template_url, e))
return
model.UpdateProject(project.key.id(), data)
def PopulateRepos(self):
"""Populate repos for this collection."""
raise NotImplementedError
def CreateProjectTreeFromRepo(self, tree, repo):
"""Populate project from code repository.
Args:
tree: The Tree to populate.
repo: The Repo entity.
"""
raise NotImplementedError