FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
aws-lambda-builders/aws_lambda_builders/actions.py at develop · QPC-database/aws-lambda-builders · GitHub
QPC-database
/
aws-lambda-builders
Public
forked from
aws/aws-lambda-builders
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
aws-lambda-builders
/
aws_lambda_builders
/
actions.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
101 lines (67 loc) · 2.67 KB
Breadcrumbs
aws-lambda-builders
/
aws_lambda_builders
/
actions.py
Copy path
File metadata and controls
101 lines (67 loc) · 2.67 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
"""
Definition of actions used in the workflow
"""
import
logging
import
shutil
import
six
from
aws_lambda_builders
.
utils
import
copytree
LOG
=
logging
.
getLogger
(
__name__
)
class
ActionFailedError
(
Exception
):
"""
Base class for exception raised when action failed to complete. Use this to express well-known failure scenarios.
"""
pass
class
Purpose
(
object
):
"""
Enum like object to describe the purpose of each action.
"""
# Action is identifying dependencies, downloading, compiling and resolving them
RESOLVE_DEPENDENCIES
=
"RESOLVE_DEPENDENCIES"
# Action is copying source code
COPY_SOURCE
=
"COPY_SOURCE"
# Action is compiling source code
COMPILE_SOURCE
=
"COMPILE_SOURCE"
@
staticmethod
def
has_value
(
item
):
return
item
in
Purpose
.
__dict__
.
values
()
class
_ActionMetaClass
(
type
):
def
__new__
(
mcs
,
name
,
bases
,
class_dict
):
cls
=
type
.
__new__
(
mcs
,
name
,
bases
,
class_dict
)
if
cls
.
__name__
==
"BaseAction"
:
return
cls
# Validate class variables
# All classes must provide a name
if
not
isinstance
(
cls
.
NAME
,
six
.
string_types
):
raise
ValueError
(
"Action must provide a valid name"
)
if
not
Purpose
.
has_value
(
cls
.
PURPOSE
):
raise
ValueError
(
"Action must provide a valid purpose"
)
return
cls
class
BaseAction
(
six
.
with_metaclass
(
_ActionMetaClass
,
object
)):
"""
Base class for all actions. It does not provide any implementation.
"""
# Every action must provide a name
NAME
=
None
# Optional description explaining what this action is about. Used to print help text
DESCRIPTION
=
""
# What is this action meant for? Must be a valid instance of `Purpose` class
PURPOSE
=
None
def
execute
(
self
):
"""
Runs the action. This method should complete the action, and if it fails raise appropriate exceptions.
:raises lambda_builders.actions.ActionFailedError: Instance of this class if something went wrong with the
action
"""
raise
NotImplementedError
(
"execute"
)
def
__repr__
(
self
):
return
"Name={}, Purpose={}, Description={}"
.
format
(
self
.
NAME
,
self
.
PURPOSE
,
self
.
DESCRIPTION
)
class
CopySourceAction
(
BaseAction
):
NAME
=
"CopySource"
DESCRIPTION
=
"Copying source code while skipping certain commonly excluded files"
PURPOSE
=
Purpose
.
COPY_SOURCE
def
__init__
(
self
,
source_dir
,
dest_dir
,
excludes
=
None
):
self
.
source_dir
=
source_dir
self
.
dest_dir
=
dest_dir
self
.
excludes
=
excludes
or
[]
def
execute
(
self
):
copytree
(
self
.
source_dir
,
self
.
dest_dir
,
ignore
=
shutil
.
ignore_patterns
(
*
self
.
excludes
))
Back
|
FazBrowse Home
|
New Git URL