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 |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 21 | from subcmds import init |
| 22 | |
| 23 | |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 24 | class GitcInit(init.Init): |
| 25 | common = True |
| 26 | helpSummary = "Initialize a GITC Client." |
| 27 | helpUsage = """ |
| 28 | %prog [options] [client name] |
| 29 | """ |
| 30 | helpDescription = """ |
| 31 | The '%prog' command is ran to initialize a new GITC client for use |
| 32 | with the GITC file system. |
| 33 | |
| 34 | This command will setup the client directory, initialize repo, just |
| 35 | like repo init does, and then downloads the manifest collection |
| 36 | and installs in in the .repo/directory of the GITC client. |
| 37 | |
| 38 | Once this is done, a GITC manifest is generated by pulling the HEAD |
| 39 | SHA for each project and generates the properly formatted XML file |
| 40 | and installs it as .manifest in the GITC client directory. |
| 41 | |
| 42 | The -c argument is required to specify the GITC client name. |
| 43 | |
| 44 | The optional -f argument can be used to specify the manifest file to |
| 45 | use for this GITC client. |
| 46 | """ |
| 47 | |
| 48 | def _Options(self, p): |
| 49 | super(GitcInit, self)._Options(p) |
| 50 | g = p.add_option_group('GITC options') |
| 51 | g.add_option('-f', '--manifest-file', |
| 52 | dest='manifest_file', |
| 53 | help='Optional manifest file to use for this GITC client.') |
| 54 | g.add_option('-c', '--gitc-client', |
| 55 | dest='gitc_client', |
| 56 | help='The name for the new gitc_client instance.') |
| 57 | |
| 58 | def Execute(self, opt, args): |
| 59 | if not opt.gitc_client: |
| 60 | print('fatal: gitc client (-c) is required', file=sys.stderr) |
| 61 | sys.exit(1) |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame^] | 62 | self.client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(), |
Simran Basi | bdb5271 | 2015-08-10 13:23:23 -0700 | [diff] [blame] | 63 | opt.gitc_client) |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame^] | 64 | if not os.path.exists(gitc_utils.get_gitc_manifest_dir()): |
| 65 | os.makedirs(gitc_utils.get_gitc_manifest_dir()) |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 66 | if not os.path.exists(self.client_dir): |
| 67 | os.mkdir(self.client_dir) |
| 68 | super(GitcInit, self).Execute(opt, args) |
Simran Basi | f7a5189 | 2015-08-27 11:44:42 -0700 | [diff] [blame] | 69 | |
| 70 | for name, remote in self.manifest.remotes.iteritems(): |
| 71 | remote.fetchUrl = remote.resolvedFetchUrl |
| 72 | |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 73 | if opt.manifest_file: |
| 74 | if not os.path.exists(opt.manifest_file): |
| 75 | print('fatal: Specified manifest file %s does not exist.' % |
| 76 | opt.manifest_file) |
| 77 | sys.exit(1) |
Simran Basi | bdb5271 | 2015-08-10 13:23:23 -0700 | [diff] [blame] | 78 | self.manifest.Override(opt.manifest_file) |
| 79 | gitc_utils.generate_gitc_manifest(self.client_dir, self.manifest) |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 80 | print('Please run `cd %s` to view your GITC client.' % |
David Pursehouse | f4599a2 | 2015-08-20 16:45:39 +0900 | [diff] [blame] | 81 | os.path.join(gitc_utils.GITC_FS_ROOT_DIR, opt.gitc_client)) |