summaryrefslogtreecommitdiffstats
path: root/gitc_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'gitc_utils.py')
-rw-r--r--gitc_utils.py85
1 files changed, 11 insertions, 74 deletions
diff --git a/gitc_utils.py b/gitc_utils.py
index 04307a3c..d082c8d7 100644
--- a/gitc_utils.py
+++ b/gitc_utils.py
@@ -15,8 +15,6 @@
15 15
16from __future__ import print_function 16from __future__ import print_function
17import os 17import os
18import platform
19import re
20import sys 18import sys
21import time 19import time
22 20
@@ -24,7 +22,6 @@ import git_command
24import git_config 22import git_config
25import wrapper 23import wrapper
26 24
27from manifest_xml import GitcManifest
28 25
29GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' 26GITC_FS_ROOT_DIR = '/gitc/manifest-rw/'
30NUM_BATCH_RETRIEVE_REVISIONID = 300 27NUM_BATCH_RETRIEVE_REVISIONID = 300
@@ -68,86 +65,26 @@ def _set_project_revisions(projects):
68 sys.exit(1) 65 sys.exit(1)
69 proj.revisionExpr = gitcmd.stdout.split('\t')[0] 66 proj.revisionExpr = gitcmd.stdout.split('\t')[0]
70 67
71def _manifest_groups(manifest): 68def generate_gitc_manifest(client_dir, manifest, projects=None):
72 """Returns the manifest group string that should be synced
73
74 This is the same logic used by Command.GetProjects(), which is used during
75 repo sync
76
77 @param manifest: The XmlManifest object
78 """
79 mp = manifest.manifestProject
80 groups = mp.config.GetString('manifest.groups')
81 if not groups:
82 groups = 'default,platform-' + platform.system().lower()
83 return groups
84
85def generate_gitc_manifest(repodir, client_name, gitc_manifest, repo_manifest_file, paths=None):
86 """Generate a manifest for shafsd to use for this GITC client. 69 """Generate a manifest for shafsd to use for this GITC client.
87 70
88 @param repodir: The repo directory 71 @param client_dir: GITC client directory to install the .manifest file in.
89 @param client_name: The gitc client name 72 @param manifest: XmlManifest object representing the repo manifest.
90 @param gitc_manifest: Current gitc manifest, or None if there isn't one yet 73 @param projects: List of projects we want to update, this must be a sublist
91 @param repo_manifest_file: The file used by the main repo manifest 74 of manifest.projects to work properly. If not provided,
92 @param paths: List of project paths we want to update. 75 manifest.projects is used.
93 """ 76 """
94 manifest = GitcManifest(repodir, client_name)
95 manifest.Override(repo_manifest_file)
96
97 print('Generating GITC Manifest by fetching revision SHAs for each ' 77 print('Generating GITC Manifest by fetching revision SHAs for each '
98 'project.') 78 'project.')
99 if paths is None: 79 if projects is None:
100 paths = manifest.paths.keys() 80 projects = manifest.projects
101
102 groups = [x for x in re.split(r'[,\s]+', _manifest_groups(manifest)) if x]
103
104 # Convert the paths to projects, and filter them to the matched groups.
105 projects = [manifest.paths[p] for p in paths]
106 projects = [p for p in projects if p.MatchesGroups(groups)]
107
108 if gitc_manifest is not None:
109 for path, proj in manifest.paths.iteritems():
110 if not proj.MatchesGroups(groups):
111 continue
112
113 if not proj.upstream and not git_config.IsId(proj.revisionExpr):
114 proj.upstream = proj.revisionExpr
115
116 if not path in gitc_manifest.paths:
117 # Any new projects need their first revision, even if we weren't asked
118 # for them.
119 projects.append(proj)
120 elif not path in paths:
121 # And copy revisions from the previous manifest if we're not updating
122 # them now.
123 gitc_proj = gitc_manifest.paths[path]
124 if gitc_proj.old_revision:
125 proj.revisionExpr = None
126 proj.old_revision = gitc_proj.old_revision
127 else:
128 proj.revisionExpr = gitc_proj.revisionExpr
129
130 index = 0 81 index = 0
131 while index < len(projects): 82 while index < len(projects):
132 _set_project_revisions( 83 _set_project_revisions(
133 projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)]) 84 projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)])
134 index += NUM_BATCH_RETRIEVE_REVISIONID 85 index += NUM_BATCH_RETRIEVE_REVISIONID
135
136 if gitc_manifest is not None:
137 for path, proj in gitc_manifest.paths.iteritems():
138 if proj.old_revision and path in paths:
139 # If we updated a project that has been started, keep the old-revision
140 # updated.
141 repo_proj = manifest.paths[path]
142 repo_proj.old_revision = repo_proj.revisionExpr
143 repo_proj.revisionExpr = None
144
145 # Convert URLs from relative to absolute.
146 for name, remote in manifest.remotes.iteritems():
147 remote.fetchUrl = remote.resolvedFetchUrl
148
149 # Save the manifest. 86 # Save the manifest.
150 save_manifest(manifest) 87 save_manifest(manifest, client_dir=client_dir)
151 88
152def save_manifest(manifest, client_dir=None): 89def save_manifest(manifest, client_dir=None):
153 """Save the manifest file in the client_dir. 90 """Save the manifest file in the client_dir.
@@ -158,7 +95,7 @@ def save_manifest(manifest, client_dir=None):
158 if not client_dir: 95 if not client_dir:
159 client_dir = manifest.gitc_client_dir 96 client_dir = manifest.gitc_client_dir
160 with open(os.path.join(client_dir, '.manifest'), 'w') as f: 97 with open(os.path.join(client_dir, '.manifest'), 'w') as f:
161 manifest.Save(f, groups=_manifest_groups(manifest)) 98 manifest.Save(f)
162 # TODO(sbasi/jorg): Come up with a solution to remove the sleep below. 99 # TODO(sbasi/jorg): Come up with a solution to remove the sleep below.
163 # Give the GITC filesystem time to register the manifest changes. 100 # Give the GITC filesystem time to register the manifest changes.
164 time.sleep(3) 101 time.sleep(3) \ No newline at end of file