Toggle navigation
Toggle navigation
This project
Loading...
Sign in
서승완
/
kappa
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Mitch Garnaat
2016-02-12 15:17:46 -0500
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
be2b9af5f68e312196c7b05ee1f5343a8ca5a7cf
be2b9af5
2 parents
d9c1d280
db491860
Merge branch 'samuel-soubeyran-python-refactor' into python-refactor
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
8 deletions
kappa/function.py
kappa/function.py
View file @
be2b9af
...
...
@@ -55,6 +55,10 @@ class Function(object):
return
self
.
_config
[
'handler'
]
@property
def
dependencies
(
self
):
return
self
.
_config
.
get
(
'dependencies'
,
list
())
@property
def
description
(
self
):
return
self
.
_config
[
'description'
]
...
...
@@ -148,7 +152,8 @@ class Function(object):
# changed and needs to be updated so return True.
changed
=
True
self
.
_copy_config_file
()
self
.
zip_lambda_function
(
self
.
zipfile_name
,
self
.
_context
.
source_dir
)
files
=
[]
+
self
.
dependencies
+
[
self
.
_context
.
source_dir
]
self
.
zip_lambda_function
(
self
.
zipfile_name
,
files
)
m
=
hashlib
.
md5
()
with
open
(
self
.
zipfile_name
,
'rb'
)
as
fp
:
m
.
update
(
fp
.
read
())
...
...
@@ -196,7 +201,7 @@ class Function(object):
LOG
.
debug
(
'_zip_lambda_dir: lambda_dir=
%
s'
,
lambda_dir
)
LOG
.
debug
(
'zipfile_name=
%
s'
,
zipfile_name
)
relroot
=
os
.
path
.
abspath
(
lambda_dir
)
with
zipfile
.
ZipFile
(
zipfile_name
,
'
w
'
,
with
zipfile
.
ZipFile
(
zipfile_name
,
'
a
'
,
compression
=
zipfile
.
ZIP_DEFLATED
)
as
zf
:
for
root
,
subdirs
,
files
in
os
.
walk
(
lambda_dir
):
excluded_dirs
=
[]
...
...
@@ -206,27 +211,49 @@ class Function(object):
excluded_dirs
.
append
(
subdir
)
for
excluded
in
excluded_dirs
:
subdirs
.
remove
(
excluded
)
zf
.
write
(
root
,
os
.
path
.
relpath
(
root
,
relroot
))
try
:
dir_path
=
os
.
path
.
relpath
(
root
,
relroot
)
dir_path
=
os
.
path
.
normpath
(
os
.
path
.
splitdrive
(
dir_path
)[
1
])
while
dir_path
[
0
]
in
(
os
.
sep
,
os
.
altsep
):
dir_path
=
dir_path
[
1
:]
dir_path
+=
'/'
zf
.
getinfo
(
dir_path
)
except
KeyError
:
zf
.
write
(
root
,
dir_path
)
for
filename
in
files
:
if
filename
not
in
self
.
excluded_files
:
filepath
=
os
.
path
.
join
(
root
,
filename
)
if
os
.
path
.
isfile
(
filepath
):
arcname
=
os
.
path
.
join
(
os
.
path
.
relpath
(
root
,
relroot
),
filename
)
try
:
zf
.
getinfo
(
arcname
)
except
KeyError
:
zf
.
write
(
filepath
,
arcname
)
def
_zip_lambda_file
(
self
,
zipfile_name
,
lambda_file
):
LOG
.
debug
(
'_zip_lambda_file: lambda_file=
%
s'
,
lambda_file
)
LOG
.
debug
(
'zipfile_name=
%
s'
,
zipfile_name
)
with
zipfile
.
ZipFile
(
zipfile_name
,
'
w
'
,
with
zipfile
.
ZipFile
(
zipfile_name
,
'
a
'
,
compression
=
zipfile
.
ZIP_DEFLATED
)
as
zf
:
try
:
zf
.
getinfo
(
lambda_file
)
except
KeyError
:
zf
.
write
(
lambda_file
)
def
zip_lambda_function
(
self
,
zipfile_name
,
lambda_fn
):
if
os
.
path
.
isdir
(
lambda_fn
):
self
.
_zip_lambda_dir
(
zipfile_name
,
lambda_fn
)
def
zip_lambda_function
(
self
,
zipfile_name
,
files
):
try
:
os
.
remove
(
zipfile_name
)
except
OSError
:
pass
for
f
in
files
:
LOG
.
debug
(
'adding file
%
s'
,
f
)
if
os
.
path
.
isdir
(
f
):
self
.
_zip_lambda_dir
(
zipfile_name
,
f
)
else
:
self
.
_zip_lambda_file
(
zipfile_name
,
lambda_fn
)
self
.
_zip_lambda_file
(
zipfile_name
,
f
)
def
exists
(
self
):
return
self
.
_get_response
()
...
...
Please
register
or
login
to post a comment