blob: 89472edbae4d2cda103200d090b0cc2da9052d01 [file] [log] [blame]
Simran Basi1efc2b42015-08-05 15:04:22 -07001# Copyright (C) 2015 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Simran Basi1efc2b42015-08-05 15:04:22 -070015import os
Simran Basi1efc2b42015-08-05 15:04:22 -070016import sys
17
Simran Basibdb52712015-08-10 13:23:23 -070018import gitc_utils
Dan Willemsen79360642015-08-31 15:45:06 -070019from command import GitcAvailableCommand
Dan Willemsen5ea32d12015-09-08 13:27:20 -070020from manifest_xml import GitcManifest
Simran Basi1efc2b42015-08-05 15:04:22 -070021from subcmds import init
Dan Willemsen745b4ad2015-10-06 15:23:19 -070022import wrapper
Simran Basi1efc2b42015-08-05 15:04:22 -070023
24
Dan Willemsen79360642015-08-31 15:45:06 -070025class GitcInit(init.Init, GitcAvailableCommand):
Simran Basi1efc2b42015-08-05 15:04:22 -070026 common = True
27 helpSummary = "Initialize a GITC Client."
28 helpUsage = """
29%prog [options] [client name]
30"""
31 helpDescription = """
32The '%prog' command is ran to initialize a new GITC client for use
33with the GITC file system.
34
35This command will setup the client directory, initialize repo, just
36like repo init does, and then downloads the manifest collection
Alexander Bird3c035802015-09-11 13:48:10 -040037and installs it in the .repo/directory of the GITC client.
Simran Basi1efc2b42015-08-05 15:04:22 -070038
39Once this is done, a GITC manifest is generated by pulling the HEAD
40SHA for each project and generates the properly formatted XML file
41and installs it as .manifest in the GITC client directory.
42
43The -c argument is required to specify the GITC client name.
44
45The optional -f argument can be used to specify the manifest file to
46use for this GITC client.
47"""
48
49 def _Options(self, p):
Mike Frysinger5d9c4972021-02-19 13:34:09 -050050 super()._Options(p, gitc_init=True)
Simran Basi1efc2b42015-08-05 15:04:22 -070051 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',
Dan Willemsen745b4ad2015-10-06 15:23:19 -070057 help='The name of the gitc_client instance to create or modify.')
Simran Basi1efc2b42015-08-05 15:04:22 -070058
59 def Execute(self, opt, args):
Dan Willemsen745b4ad2015-10-06 15:23:19 -070060 gitc_client = gitc_utils.parse_clientdir(os.getcwd())
61 if not gitc_client or (opt.gitc_client and gitc_client != opt.gitc_client):
David Pursehouse3cda50a2020-02-13 13:17:03 +090062 print('fatal: Please update your repo command. See go/gitc for instructions.',
63 file=sys.stderr)
Simran Basi1efc2b42015-08-05 15:04:22 -070064 sys.exit(1)
Simran Basi8ce50412015-08-28 14:25:44 -070065 self.client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(),
Dan Willemsen745b4ad2015-10-06 15:23:19 -070066 gitc_client)
Mike Frysinger5d9c4972021-02-19 13:34:09 -050067 super().Execute(opt, args)
Simran Basif7a51892015-08-27 11:44:42 -070068
Dan Willemsen5ea32d12015-09-08 13:27:20 -070069 manifest_file = self.manifest.manifestFile
Simran Basi1efc2b42015-08-05 15:04:22 -070070 if opt.manifest_file:
71 if not os.path.exists(opt.manifest_file):
72 print('fatal: Specified manifest file %s does not exist.' %
73 opt.manifest_file)
74 sys.exit(1)
Dan Willemsen5ea32d12015-09-08 13:27:20 -070075 manifest_file = opt.manifest_file
76
Dan Willemsen745b4ad2015-10-06 15:23:19 -070077 manifest = GitcManifest(self.repodir, gitc_client)
Dan Willemsen5ea32d12015-09-08 13:27:20 -070078 manifest.Override(manifest_file)
79 gitc_utils.generate_gitc_manifest(None, manifest)
Simran Basi1efc2b42015-08-05 15:04:22 -070080 print('Please run `cd %s` to view your GITC client.' %
Dan Willemsen745b4ad2015-10-06 15:23:19 -070081 os.path.join(wrapper.Wrapper().GITC_FS_ROOT_DIR, gitc_client))