FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
aws-cli/scripts/make-bundle at develop · jdnc/aws-cli · GitHub
jdnc
/
aws-cli
Public
forked from
aws/aws-cli
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
aws-cli
/
scripts
/
make-bundle
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
159 lines (131 loc) · 4.98 KB
Breadcrumbs
aws-cli
/
scripts
/
make-bundle
Copy path
File metadata and controls
executable file
·
159 lines (131 loc) · 4.98 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python
"""Script to create self contained install.
The goal of this script is simple:
* Create a self contained install of the CLI that
has requires no external resources during installation.
It does this by using all the normal python tooling
(virtualenv, pip) but provides a simple, easy to use
interface for those not familiar with the python
ecosystem.
"""
import
os
import
sys
import
time
import
subprocess
import
shutil
import
tempfile
import
zipfile
from
contextlib
import
contextmanager
# These are package versions that are needed to boostrap
# the installation process. It is *not* the deps required
# by awscli/botocore.
PACKAGE_VERSION
=
{
'virtualenv'
:
'1.10.1'
,
# These packages are included because they are required for
# python2.6, but our normal dependency downloading via pip
# only works if you use python2.6. To fix this issue, we're
# explicitly saying that we need to download these packages
# even if pip doesn't think we need them. That way we can
# run make-bundle in python versions besides 2.6.
'ordereddict'
:
'1.1'
,
'simplejson'
:
'3.3.0'
,
'argparse'
:
'1.2.1'
,
}
class
BadRCError
(
Exception
):
pass
@
contextmanager
def
cd
(
dirname
):
original
=
os
.
getcwd
()
os
.
chdir
(
dirname
)
try
:
yield
finally
:
os
.
chdir
(
original
)
def
run
(
cmd
):
sys
.
stdout
.
write
(
"Running cmd: %s
\n
"
%
cmd
)
p
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
stdout
,
stderr
=
p
.
communicate
()
rc
=
p
.
wait
()
if
p
.
returncode
!=
0
:
raise
BadRCError
(
"Bad rc (%s) for cmd '%s': %s"
%
(
rc
,
cmd
,
stderr
+
stdout
))
return
stdout
def
create_scratch_dir
():
# This creates the dir where all the bundling occurs.
# First we need a top level dir.
dirname
=
tempfile
.
mkdtemp
(
prefix
=
'bundle'
)
# Then we need to create a dir where all the packages
# will come from.
os
.
mkdir
(
os
.
path
.
join
(
dirname
,
'packages'
))
return
dirname
def
download_package_tarballs
(
dirname
,
packages
):
with
cd
(
dirname
):
for
package
in
packages
:
run
(
'pip install -d . %s==%s'
%
(
package
,
PACKAGE_VERSION
[
package
]))
def
download_cli_deps
(
scratch_dir
):
# As far as i can tell this is a bug in pip.
# Running 'pip intall -d . ~/clidir' does not work.
# Running 'pip install -d foo ~/clidir' results
# in python consuming 100% CPU.
# This problem is surprisingly hard, specifically that
# of downloading all the dependent python packages of
# the awscli as tarballs.
# So here's what we do.
# Step one create a virtualenv.
venv_dir
=
'/tmp/venv-%s'
%
str
(
int
(
time
.
time
()))
run
(
'virtualenv %s'
%
venv_dir
)
pip
=
os
.
path
.
join
(
venv_dir
,
'bin'
,
'pip'
)
assert
os
.
path
.
isfile
(
pip
)
awscli_dir
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
with
cd
(
scratch_dir
):
run
(
'%s install -d . -e %s'
%
(
pip
,
awscli_dir
))
# Remove the awscli package, we'll create our own sdist.
_remove_cli_zip
(
scratch_dir
)
def
_remove_cli_zip
(
scratch_dir
):
clidir
=
[
f
for
f
in
os
.
listdir
(
scratch_dir
)
if
f
.
startswith
(
'awscli'
)]
assert
len
(
clidir
)
==
1
os
.
remove
(
os
.
path
.
join
(
scratch_dir
,
clidir
[
0
]))
def
add_cli_sdist
(
scratch_dir
):
awscli_dir
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
if
os
.
path
.
exists
(
os
.
path
.
join
(
awscli_dir
,
'dist'
)):
shutil
.
rmtree
(
os
.
path
.
join
(
awscli_dir
,
'dist'
))
with
cd
(
awscli_dir
):
run
(
'python setup.py sdist'
)
filename
=
os
.
listdir
(
'dist'
)[
0
]
os
.
rename
(
os
.
path
.
join
(
'dist'
,
filename
),
os
.
path
.
join
(
scratch_dir
,
filename
))
def
create_bootstrap_script
(
scratch_dir
):
install_script
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
'install'
)
shutil
.
copy
(
install_script
,
os
.
path
.
join
(
scratch_dir
,
'install'
))
def
zip_dir
(
scratch_dir
):
basename
=
'awscli-bundle.zip'
dirname
,
tmpdir
=
os
.
path
.
split
(
scratch_dir
)
final_dir_name
=
os
.
path
.
join
(
dirname
,
'awscli-bundle'
)
if
os
.
path
.
isdir
(
final_dir_name
):
shutil
.
rmtree
(
final_dir_name
)
os
.
rename
(
scratch_dir
,
final_dir_name
)
with
cd
(
dirname
):
with
zipfile
.
ZipFile
(
basename
,
'w'
,
zipfile
.
ZIP_DEFLATED
)
as
zipped
:
for
root
,
dirnames
,
filenames
in
os
.
walk
(
'awscli-bundle'
):
for
filename
in
filenames
:
zipped
.
write
(
os
.
path
.
join
(
root
,
filename
))
return
os
.
path
.
join
(
dirname
,
basename
)
def
main
():
scratch_dir
=
create_scratch_dir
()
package_dir
=
os
.
path
.
join
(
scratch_dir
,
'packages'
)
print
(
"Bundle dir at: %s"
%
scratch_dir
)
download_package_tarballs
(
package_dir
,
packages
=
[
'virtualenv'
,
'ordereddict'
,
'simplejson'
,
'argparse'
])
download_cli_deps
(
package_dir
)
add_cli_sdist
(
package_dir
)
create_bootstrap_script
(
scratch_dir
)
zip_filename
=
zip_dir
(
scratch_dir
)
print
(
"Zipped bundle installer is at: %s"
%
zip_filename
)
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL