diff options
Diffstat (limited to 'gitc_utils.py')
-rw-r--r-- | gitc_utils.py | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/gitc_utils.py b/gitc_utils.py index ef028b08..4d8d5366 100644 --- a/gitc_utils.py +++ b/gitc_utils.py | |||
@@ -16,6 +16,7 @@ | |||
16 | from __future__ import print_function | 16 | from __future__ import print_function |
17 | import os | 17 | import os |
18 | import sys | 18 | import sys |
19 | import time | ||
19 | 20 | ||
20 | import git_command | 21 | import git_command |
21 | import git_config | 22 | import git_config |
@@ -26,6 +27,18 @@ GITC_MANIFEST_DIR = '/usr/local/google/gitc/' | |||
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 | ||
30 | def parse_clientdir(gitc_fs_path): | ||
31 | """Parse a path in the GITC FS and return its client name. | ||
32 | |||
33 | @param gitc_fs_path: A subdirectory path within the GITC_FS_ROOT_DIR. | ||
34 | |||
35 | @returns: The GITC client name | ||
36 | """ | ||
37 | if (gitc_fs_path == GITC_FS_ROOT_DIR or | ||
38 | not gitc_fs_path.startswith(GITC_FS_ROOT_DIR)): | ||
39 | return None | ||
40 | return gitc_fs_path.split(GITC_FS_ROOT_DIR)[1].split('/')[0] | ||
41 | |||
29 | def _set_project_revisions(projects): | 42 | def _set_project_revisions(projects): |
30 | """Sets the revisionExpr for a list of projects. | 43 | """Sets the revisionExpr for a list of projects. |
31 | 44 | ||
@@ -50,19 +63,37 @@ def _set_project_revisions(projects): | |||
50 | sys.exit(1) | 63 | sys.exit(1) |
51 | proj.revisionExpr = gitcmd.stdout.split('\t')[0] | 64 | proj.revisionExpr = gitcmd.stdout.split('\t')[0] |
52 | 65 | ||
53 | def generate_gitc_manifest(client_dir, manifest): | 66 | def generate_gitc_manifest(client_dir, manifest, projects=None): |
54 | """Generate a manifest for shafsd to use for this GITC client. | 67 | """Generate a manifest for shafsd to use for this GITC client. |
55 | 68 | ||
56 | @param client_dir: GITC client directory to install the .manifest file in. | 69 | @param client_dir: GITC client directory to install the .manifest file in. |
57 | @param manifest: XmlManifest object representing the repo manifest. | 70 | @param manifest: XmlManifest object representing the repo manifest. |
71 | @param projects: List of projects we want to update, this must be a sublist | ||
72 | of manifest.projects to work properly. If not provided, | ||
73 | manifest.projects is used. | ||
58 | """ | 74 | """ |
59 | print('Generating GITC Manifest by fetching revision SHAs for each ' | 75 | print('Generating GITC Manifest by fetching revision SHAs for each ' |
60 | 'project.') | 76 | 'project.') |
77 | if projects is None: | ||
78 | projects = manifest.projects | ||
61 | index = 0 | 79 | index = 0 |
62 | while index < len(manifest.projects): | 80 | while index < len(projects): |
63 | _set_project_revisions( | 81 | _set_project_revisions( |
64 | manifest.projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)]) | 82 | projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)]) |
65 | index += NUM_BATCH_RETRIEVE_REVISIONID | 83 | index += NUM_BATCH_RETRIEVE_REVISIONID |
66 | # Save the manifest. | 84 | # Save the manifest. |
85 | save_manifest(manifest, client_dir=client_dir) | ||
86 | |||
87 | def save_manifest(manifest, client_dir=None): | ||
88 | """Save the manifest file in the client_dir. | ||
89 | |||
90 | @param client_dir: Client directory to save the manifest in. | ||
91 | @param manifest: Manifest object to save. | ||
92 | """ | ||
93 | if not client_dir: | ||
94 | client_dir = manifest.gitc_client_dir | ||
67 | with open(os.path.join(client_dir, '.manifest'), 'w') as f: | 95 | with open(os.path.join(client_dir, '.manifest'), 'w') as f: |
68 | manifest.Save(f) | 96 | manifest.Save(f) |
97 | # TODO(sbasi/jorg): Come up with a solution to remove the sleep below. | ||
98 | # Give the GITC filesystem time to register the manifest changes. | ||
99 | time.sleep(3) \ No newline at end of file | ||