blob: 30a9f7a560682d7fceaa503a30c389ea39f49ab5 [file] [log] [blame]
Mike Frysingerf6013762019-06-13 02:30:51 -04001# -*- coding:utf-8 -*-
Simran Basi1efc2b42015-08-05 15:04:22 -07002#
3# Copyright (C) 2015 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17from __future__ import print_function
18import os
Simran Basi1efc2b42015-08-05 15:04:22 -070019import sys
20
Simran Basibdb52712015-08-10 13:23:23 -070021import gitc_utils
Dan Willemsen79360642015-08-31 15:45:06 -070022from command import GitcAvailableCommand
Dan Willemsen5ea32d12015-09-08 13:27:20 -070023from manifest_xml import GitcManifest
Simran Basi1efc2b42015-08-05 15:04:22 -070024from subcmds import init
Dan Willemsen745b4ad2015-10-06 15:23:19 -070025import wrapper
Simran Basi1efc2b42015-08-05 15:04:22 -070026
27
Dan Willemsen79360642015-08-31 15:45:06 -070028class GitcInit(init.Init, GitcAvailableCommand):
Simran Basi1efc2b42015-08-05 15:04:22 -070029 common = True
30 helpSummary = "Initialize a GITC Client."
31 helpUsage = """
32%prog [options] [client name]
33"""
34 helpDescription = """
35The '%prog' command is ran to initialize a new GITC client for use
36with the GITC file system.
37
38This command will setup the client directory, initialize repo, just
39like repo init does, and then downloads the manifest collection
Alexander Bird3c035802015-09-11 13:48:10 -040040and installs it in the .repo/directory of the GITC client.
Simran Basi1efc2b42015-08-05 15:04:22 -070041
42Once this is done, a GITC manifest is generated by pulling the HEAD
43SHA for each project and generates the properly formatted XML file
44and installs it as .manifest in the GITC client directory.
45
46The -c argument is required to specify the GITC client name.
47
48The optional -f argument can be used to specify the manifest file to
49use for this GITC client.
50"""
51
52 def _Options(self, p):
Mike Frysinger66098f72020-02-05 00:01:59 -050053 super(GitcInit, self)._Options(p, gitc_init=True)
Simran Basi1efc2b42015-08-05 15:04:22 -070054 g = p.add_option_group('GITC options')
55 g.add_option('-f', '--manifest-file',
56 dest='manifest_file',
57 help='Optional manifest file to use for this GITC client.')
58 g.add_option('-c', '--gitc-client',
59 dest='gitc_client',
Dan Willemsen745b4ad2015-10-06 15:23:19 -070060 help='The name of the gitc_client instance to create or modify.')
Simran Basi1efc2b42015-08-05 15:04:22 -070061
62 def Execute(self, opt, args):
Dan Willemsen745b4ad2015-10-06 15:23:19 -070063 gitc_client = gitc_utils.parse_clientdir(os.getcwd())
64 if not gitc_client or (opt.gitc_client and gitc_client != opt.gitc_client):
David Pursehouse3cda50a2020-02-13 13:17:03 +090065 print('fatal: Please update your repo command. See go/gitc for instructions.',
66 file=sys.stderr)
Simran Basi1efc2b42015-08-05 15:04:22 -070067 sys.exit(1)
Simran Basi8ce50412015-08-28 14:25:44 -070068 self.client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(),
Dan Willemsen745b4ad2015-10-06 15:23:19 -070069 gitc_client)
Simran Basi1efc2b42015-08-05 15:04:22 -070070 super(GitcInit, self).Execute(opt, args)
Simran Basif7a51892015-08-27 11:44:42 -070071
Dan Willemsen5ea32d12015-09-08 13:27:20 -070072 manifest_file = self.manifest.manifestFile
Simran Basi1efc2b42015-08-05 15:04:22 -070073 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)
Dan Willemsen5ea32d12015-09-08 13:27:20 -070078 manifest_file = opt.manifest_file
79
Dan Willemsen745b4ad2015-10-06 15:23:19 -070080 manifest = GitcManifest(self.repodir, gitc_client)
Dan Willemsen5ea32d12015-09-08 13:27:20 -070081 manifest.Override(manifest_file)
82 gitc_utils.generate_gitc_manifest(None, manifest)
Simran Basi1efc2b42015-08-05 15:04:22 -070083 print('Please run `cd %s` to view your GITC client.' %
Dan Willemsen745b4ad2015-10-06 15:23:19 -070084 os.path.join(wrapper.Wrapper().GITC_FS_ROOT_DIR, gitc_client))