Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2015 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | from __future__ import print_function |
| 17 | import os |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 18 | import sys |
| 19 | |
Simran Basi | bdb5271 | 2015-08-10 13:23:23 -0700 | [diff] [blame] | 20 | import gitc_utils |
Dan Willemsen | 7936064 | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 21 | from command import GitcAvailableCommand |
Dan Willemsen | 5ea32d1 | 2015-09-08 13:27:20 -0700 | [diff] [blame] | 22 | from manifest_xml import GitcManifest |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 23 | from subcmds import init |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 24 | import wrapper |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 25 | |
| 26 | |
Dan Willemsen | 7936064 | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 27 | class GitcInit(init.Init, GitcAvailableCommand): |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 28 | common = True |
| 29 | helpSummary = "Initialize a GITC Client." |
| 30 | helpUsage = """ |
| 31 | %prog [options] [client name] |
| 32 | """ |
| 33 | helpDescription = """ |
| 34 | The '%prog' command is ran to initialize a new GITC client for use |
| 35 | with the GITC file system. |
| 36 | |
| 37 | This command will setup the client directory, initialize repo, just |
| 38 | like repo init does, and then downloads the manifest collection |
Alexander Bird | 3c03580 | 2015-09-11 13:48:10 -0400 | [diff] [blame] | 39 | and installs it in the .repo/directory of the GITC client. |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 40 | |
| 41 | Once this is done, a GITC manifest is generated by pulling the HEAD |
| 42 | SHA for each project and generates the properly formatted XML file |
| 43 | and installs it as .manifest in the GITC client directory. |
| 44 | |
| 45 | The -c argument is required to specify the GITC client name. |
| 46 | |
| 47 | The optional -f argument can be used to specify the manifest file to |
| 48 | use for this GITC client. |
| 49 | """ |
| 50 | |
| 51 | def _Options(self, p): |
| 52 | super(GitcInit, self)._Options(p) |
| 53 | g = p.add_option_group('GITC options') |
| 54 | g.add_option('-f', '--manifest-file', |
| 55 | dest='manifest_file', |
| 56 | help='Optional manifest file to use for this GITC client.') |
| 57 | g.add_option('-c', '--gitc-client', |
| 58 | dest='gitc_client', |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 59 | help='The name of the gitc_client instance to create or modify.') |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 60 | |
| 61 | def Execute(self, opt, args): |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 62 | gitc_client = gitc_utils.parse_clientdir(os.getcwd()) |
| 63 | if not gitc_client or (opt.gitc_client and gitc_client != opt.gitc_client): |
| 64 | print('fatal: Please update your repo command. See go/gitc for instructions.', file=sys.stderr) |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 65 | sys.exit(1) |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 66 | self.client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(), |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 67 | gitc_client) |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 68 | super(GitcInit, self).Execute(opt, args) |
Simran Basi | f7a5189 | 2015-08-27 11:44:42 -0700 | [diff] [blame] | 69 | |
Dan Willemsen | 5ea32d1 | 2015-09-08 13:27:20 -0700 | [diff] [blame] | 70 | manifest_file = self.manifest.manifestFile |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 71 | if opt.manifest_file: |
| 72 | if not os.path.exists(opt.manifest_file): |
| 73 | print('fatal: Specified manifest file %s does not exist.' % |
| 74 | opt.manifest_file) |
| 75 | sys.exit(1) |
Dan Willemsen | 5ea32d1 | 2015-09-08 13:27:20 -0700 | [diff] [blame] | 76 | manifest_file = opt.manifest_file |
| 77 | |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 78 | manifest = GitcManifest(self.repodir, gitc_client) |
Dan Willemsen | 5ea32d1 | 2015-09-08 13:27:20 -0700 | [diff] [blame] | 79 | manifest.Override(manifest_file) |
| 80 | gitc_utils.generate_gitc_manifest(None, manifest) |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 81 | print('Please run `cd %s` to view your GITC client.' % |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 82 | os.path.join(wrapper.Wrapper().GITC_FS_ROOT_DIR, gitc_client)) |