diff options
Diffstat (limited to 'repo')
| -rwxr-xr-x | repo | 45 |
1 files changed, 42 insertions, 3 deletions
| @@ -108,7 +108,7 @@ S_repo = 'repo' # special repo repository | |||
| 108 | S_manifests = 'manifests' # special manifest repository | 108 | S_manifests = 'manifests' # special manifest repository |
| 109 | REPO_MAIN = S_repo + '/main.py' # main script | 109 | REPO_MAIN = S_repo + '/main.py' # main script |
| 110 | MIN_PYTHON_VERSION = (2, 6) # minimum supported python version | 110 | MIN_PYTHON_VERSION = (2, 6) # minimum supported python version |
| 111 | GITC_MANIFEST_DIR = '/usr/local/google/gitc' | 111 | GITC_CONFIG_FILE = '/gitc/.config' |
| 112 | 112 | ||
| 113 | 113 | ||
| 114 | import errno | 114 | import errno |
| @@ -214,6 +214,7 @@ group.add_option('--config-name', | |||
| 214 | help='Always prompt for name/e-mail') | 214 | help='Always prompt for name/e-mail') |
| 215 | 215 | ||
| 216 | def _GitcInitOptions(init_optparse): | 216 | def _GitcInitOptions(init_optparse): |
| 217 | init_optparse.set_usage("repo gitc-init -u url -c client [options]") | ||
| 217 | g = init_optparse.add_option_group('GITC options') | 218 | g = init_optparse.add_option_group('GITC options') |
| 218 | g.add_option('-f', '--manifest-file', | 219 | g.add_option('-f', '--manifest-file', |
| 219 | dest='manifest_file', | 220 | dest='manifest_file', |
| @@ -222,6 +223,21 @@ def _GitcInitOptions(init_optparse): | |||
| 222 | dest='gitc_client', | 223 | dest='gitc_client', |
| 223 | help='The name for the new gitc_client instance.') | 224 | help='The name for the new gitc_client instance.') |
| 224 | 225 | ||
| 226 | _gitc_manifest_dir = None | ||
| 227 | def get_gitc_manifest_dir(): | ||
| 228 | global _gitc_manifest_dir | ||
| 229 | if _gitc_manifest_dir is None: | ||
| 230 | _gitc_manifest_dir = '' | ||
| 231 | try: | ||
| 232 | with open(GITC_CONFIG_FILE, 'r') as gitc_config: | ||
| 233 | for line in gitc_config: | ||
| 234 | match = re.match('gitc_dir=(?P<gitc_manifest_dir>.*)', line) | ||
| 235 | if match: | ||
| 236 | _gitc_manifest_dir = match.group('gitc_manifest_dir') | ||
| 237 | except IOError: | ||
| 238 | pass | ||
| 239 | return _gitc_manifest_dir | ||
| 240 | |||
| 225 | class CloneFailure(Exception): | 241 | class CloneFailure(Exception): |
| 226 | """Indicate the remote clone of repo itself failed. | 242 | """Indicate the remote clone of repo itself failed. |
| 227 | """ | 243 | """ |
| @@ -255,7 +271,15 @@ def _Init(args, gitc_init=False): | |||
| 255 | 271 | ||
| 256 | try: | 272 | try: |
| 257 | if gitc_init: | 273 | if gitc_init: |
| 258 | client_dir = os.path.join(GITC_MANIFEST_DIR, opt.gitc_client) | 274 | gitc_manifest_dir = get_gitc_manifest_dir() |
| 275 | if not gitc_manifest_dir: | ||
| 276 | _print('fatal: GITC filesystem is not available. Exiting...', | ||
| 277 | file=sys.stderr) | ||
| 278 | sys.exit(1) | ||
| 279 | if not opt.gitc_client: | ||
| 280 | _print('fatal: GITC client (-c) is required.', file=sys.stderr) | ||
| 281 | sys.exit(1) | ||
| 282 | client_dir = os.path.join(gitc_manifest_dir, opt.gitc_client) | ||
| 259 | if not os.path.exists(client_dir): | 283 | if not os.path.exists(client_dir): |
| 260 | os.makedirs(client_dir) | 284 | os.makedirs(client_dir) |
| 261 | os.chdir(client_dir) | 285 | os.chdir(client_dir) |
| @@ -661,6 +685,10 @@ def _ParseArguments(args): | |||
| 661 | 685 | ||
| 662 | 686 | ||
| 663 | def _Usage(): | 687 | def _Usage(): |
| 688 | gitc_usage = "" | ||
| 689 | if get_gitc_manifest_dir(): | ||
| 690 | gitc_usage = " gitc-init Initialize a GITC Client.\n" | ||
| 691 | |||
| 664 | _print( | 692 | _print( |
| 665 | """usage: repo COMMAND [ARGS] | 693 | """usage: repo COMMAND [ARGS] |
| 666 | 694 | ||
| @@ -669,7 +697,8 @@ repo is not yet installed. Use "repo init" to install it here. | |||
| 669 | The most commonly used repo commands are: | 697 | The most commonly used repo commands are: |
| 670 | 698 | ||
| 671 | init Install repo in the current working directory | 699 | init Install repo in the current working directory |
| 672 | help Display detailed help on a command | 700 | """ + gitc_usage + |
| 701 | """ help Display detailed help on a command | ||
| 673 | 702 | ||
| 674 | For access to the full online help, install repo ("repo init"). | 703 | For access to the full online help, install repo ("repo init"). |
| 675 | """, file=sys.stderr) | 704 | """, file=sys.stderr) |
| @@ -681,6 +710,10 @@ def _Help(args): | |||
| 681 | if args[0] == 'init': | 710 | if args[0] == 'init': |
| 682 | init_optparse.print_help() | 711 | init_optparse.print_help() |
| 683 | sys.exit(0) | 712 | sys.exit(0) |
| 713 | elif args[0] == 'gitc-init': | ||
| 714 | _GitcInitOptions(init_optparse) | ||
| 715 | init_optparse.print_help() | ||
| 716 | sys.exit(0) | ||
| 684 | else: | 717 | else: |
| 685 | _print("error: '%s' is not a bootstrap command.\n" | 718 | _print("error: '%s' is not a bootstrap command.\n" |
| 686 | ' For access to online help, install repo ("repo init").' | 719 | ' For access to online help, install repo ("repo init").' |
| @@ -746,6 +779,12 @@ def main(orig_args): | |||
| 746 | wrapper_path = os.path.abspath(__file__) | 779 | wrapper_path = os.path.abspath(__file__) |
| 747 | my_main, my_git = _RunSelf(wrapper_path) | 780 | my_main, my_git = _RunSelf(wrapper_path) |
| 748 | 781 | ||
| 782 | cwd = os.getcwd() | ||
| 783 | if get_gitc_manifest_dir() and cwd.startswith(get_gitc_manifest_dir()): | ||
| 784 | _print('error: repo cannot be used in the GITC local manifest directory.' | ||
| 785 | '\nIf you want to work on this GITC client please rerun this ' | ||
| 786 | 'command from the corresponding client under /gitc/', file=sys.stderr) | ||
| 787 | sys.exit(1) | ||
| 749 | if not repo_main: | 788 | if not repo_main: |
| 750 | if opt.help: | 789 | if opt.help: |
| 751 | _Usage() | 790 | _Usage() |
