forked from cask/cask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go
executable file
·100 lines (74 loc) · 2.83 KB
/
go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
# -*- coding: utf-8; -*-
# Copyright (C) 2012, 2013, 2014 Johan Andersson
# Copyright (C) 2013, 2014 Sebastian Wiesner
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with GNU Emacs; see the file COPYING. If not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
"""
Install Cask
"""
from __future__ import unicode_literals, print_function
import os
import sys
import errno
from subprocess import CalledProcessError, check_call
HOME = os.path.expanduser('~')
TARGET_DIRECTORY = os.path.join(HOME, '.cask')
REPOSITORY = 'https://github.com/cask/cask.git'
ISSUE_TRACKER = 'https://github.com/cask/cask/issues'
class CaskGoError(Exception):
pass
OKGREEN = '\033[32m'
FAIL = '\033[31m'
ENDC = '\033[0m'
def success(s):
print(OKGREEN + s + ENDC)
sys.exit(0)
def fail(s):
print(FAIL + s + ENDC, file=sys.stderr)
sys.exit(1)
def bootstrap_cask(target_directory):
cask = os.path.join(target_directory, 'bin', 'cask')
try:
check_call([sys.executable, cask, 'upgrade-cask'])
except CalledProcessError:
raise CaskGoError('Cask could not be bootstrapped. Try again later, '
'or report an issue at {0}'.format(ISSUE_TRACKER))
def install_cask(target_directory):
if os.path.isdir(target_directory):
raise CaskGoError(
'Directory {0} exists. Is Cask already installed?'.format(
target_directory))
else:
try:
check_call(['git', 'clone', REPOSITORY, target_directory])
except CalledProcessError:
raise CaskGoError('Cask could not be installed. Try again '
'later, or report an issue at {0}'.format(
ISSUE_TRACKER))
except OSError as error:
if error.errno == errno.ENOENT:
raise CaskGoError('git executable not found. Please install Git')
else:
raise
def main():
try:
install_cask(TARGET_DIRECTORY)
bootstrap_cask(TARGET_DIRECTORY)
success("""\
Successfully installed Cask! Now, add the cask binary to your $PATH:
export PATH="{0}/bin:$PATH\"""".format(TARGET_DIRECTORY))
except CaskGoError as error:
fail('{0!s}'.format(error))
if __name__ == '__main__':
sys.exit(main())