diff options
Diffstat (limited to 'subcmds/gitc_init.py')
| -rw-r--r-- | subcmds/gitc_init.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/subcmds/gitc_init.py b/subcmds/gitc_init.py new file mode 100644 index 00000000..03d8cc30 --- /dev/null +++ b/subcmds/gitc_init.py | |||
| @@ -0,0 +1,80 @@ | |||
| 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 | ||
| 18 | import shutil | ||
| 19 | import sys | ||
| 20 | |||
| 21 | import gitc_utils | ||
| 22 | from subcmds import init | ||
| 23 | |||
| 24 | |||
| 25 | class GitcInit(init.Init): | ||
| 26 | common = True | ||
| 27 | helpSummary = "Initialize a GITC Client." | ||
| 28 | helpUsage = """ | ||
| 29 | %prog [options] [client name] | ||
| 30 | """ | ||
| 31 | helpDescription = """ | ||
| 32 | The '%prog' command is ran to initialize a new GITC client for use | ||
| 33 | with the GITC file system. | ||
| 34 | |||
| 35 | This command will setup the client directory, initialize repo, just | ||
| 36 | like repo init does, and then downloads the manifest collection | ||
| 37 | and installs in in the .repo/directory of the GITC client. | ||
| 38 | |||
| 39 | Once this is done, a GITC manifest is generated by pulling the HEAD | ||
| 40 | SHA for each project and generates the properly formatted XML file | ||
| 41 | and installs it as .manifest in the GITC client directory. | ||
| 42 | |||
| 43 | The -c argument is required to specify the GITC client name. | ||
| 44 | |||
| 45 | The optional -f argument can be used to specify the manifest file to | ||
| 46 | use for this GITC client. | ||
| 47 | """ | ||
| 48 | |||
| 49 | def _Options(self, p): | ||
| 50 | super(GitcInit, self)._Options(p) | ||
| 51 | g = p.add_option_group('GITC options') | ||
| 52 | g.add_option('-f', '--manifest-file', | ||
| 53 | dest='manifest_file', | ||
| 54 | help='Optional manifest file to use for this GITC client.') | ||
| 55 | g.add_option('-c', '--gitc-client', | ||
| 56 | dest='gitc_client', | ||
| 57 | help='The name for the new gitc_client instance.') | ||
| 58 | |||
| 59 | def Execute(self, opt, args): | ||
| 60 | if not opt.gitc_client: | ||
| 61 | print('fatal: gitc client (-c) is required', file=sys.stderr) | ||
| 62 | sys.exit(1) | ||
| 63 | self.client_dir = os.path.join(gitc_utils.GITC_MANIFEST_DIR, | ||
| 64 | opt.gitc_client) | ||
| 65 | if not os.path.exists(gitc_utils.GITC_MANIFEST_DIR): | ||
| 66 | os.makedirs(gitc_utils.GITC_MANIFEST_DIR) | ||
| 67 | if not os.path.exists(self.client_dir): | ||
| 68 | os.mkdir(self.client_dir) | ||
| 69 | super(GitcInit, self).Execute(opt, args) | ||
| 70 | # Make the destination manifest file a symlink to repo's so both repo and | ||
| 71 | # GITC refer to the same manifest. | ||
| 72 | if opt.manifest_file: | ||
| 73 | if not os.path.exists(opt.manifest_file): | ||
| 74 | print('fatal: Specified manifest file %s does not exist.' % | ||
| 75 | opt.manifest_file) | ||
| 76 | sys.exit(1) | ||
| 77 | self.manifest.Override(opt.manifest_file) | ||
| 78 | gitc_utils.generate_gitc_manifest(self.client_dir, self.manifest) | ||
| 79 | print('Please run `cd %s` to view your GITC client.' % | ||
| 80 | os.path.join(gitc_utils.GITC_FS_ROOT_DIR, opt.gitc_client)) \ No newline at end of file | ||
