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