Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F11004
deploy.py
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
dereckson
Oct 21 2015, 21:24
2015-10-21 21:24:15 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
deploy.py
View Options
#!/usr/bin/env python3
import
json
import
os
import
sys
#
# Deployment methods
#
def
deployExperiments
(
deploys
,
wwwroot
):
for
deploy
in
deploys
:
if
not
"name"
in
deploy
:
raise
KeyError
(
"Name is missing from deploy."
)
if
"path"
in
deploy
:
path
=
deploy
[
"path"
]
else
:
path
=
deploy
[
"name"
]
path
=
os
.
path
.
join
(
wwwroot
,
path
)
if
"repo"
in
deploy
:
if
"branch"
in
deploy
:
branch
=
deploy
[
"branch"
]
else
:
branch
=
"master"
deployRepo
(
deploy
[
"repo"
],
branch
,
path
)
else
:
createEmptyWebDirectory
(
path
)
def
createEmptyWebDirectory
(
path
):
os
.
makedirs
(
path
)
def
deployRepo
(
repo
,
branch
,
path
):
print
(
"Deploy"
,
repo
,
"at"
,
branch
,
"to"
,
path
)
#
# Procedural code
#
# Parse argument
if
len
(
sys
.
argv
)
==
2
:
wwwroot
=
sys
.
argv
[
1
]
if
not
os
.
path
.
exists
(
wwwroot
):
createEmptyWebDirectory
(
wwwroot
)
if
not
os
.
path
.
isdir
(
wwwroot
):
print
(
"Not a directory: "
+
wwwroot
,
file
=
sys
.
stderr
)
sys
.
exit
(
2
)
else
:
print
(
"Usage:"
,
sys
.
argv
[
0
],
"<web root directory to deploy>"
)
sys
.
exit
(
1
)
# Reads deploy configuration file
with
open
(
"conf/deploy.json"
,
"r"
)
as
configDeployFile
:
data
=
configDeployFile
.
read
()
deploys
=
json
.
loads
(
data
)
# Deploy
deployExperiments
(
deploys
,
wwwroot
)
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
9918
Default Alt Text
deploy.py (1 KB)
Attached To
Mode
P116 deploy.py
Attached
Detach File
Event Timeline
Log In to Comment