added media method to sync media files between branches
modified: modules/deploy.py
This commit is contained in:
parent
12ab59b33e
commit
90137fd692
1 changed files with 91 additions and 0 deletions
|
|
@ -321,6 +321,97 @@ def sync(full=True, extras=False):
|
|||
django_collectstatic()
|
||||
|
||||
|
||||
@task
|
||||
def media(destination_branch):
|
||||
"""
|
||||
sync media files from source branch to current branch
|
||||
|
||||
src - the source branch from which we are copying media files
|
||||
"""
|
||||
configuration = env.config
|
||||
|
||||
import initialize
|
||||
|
||||
print configuration.project.branch
|
||||
|
||||
configuration_dst = initialize.get_config(
|
||||
destination_branch)
|
||||
|
||||
configuration_src = configuration
|
||||
|
||||
print "branch_src: %s" % configuration_src.project.branch
|
||||
print "branch_dst: %s" % configuration_dst.project.branch
|
||||
|
||||
print "src - server_media_dynamic: %s" % \
|
||||
configuration_src.paths.server.media.dynamic
|
||||
print "dst - server_media_dynamic: %s" % \
|
||||
configuration_dst.paths.server.media.dynamic
|
||||
|
||||
# add a trailing slash to the directories
|
||||
dynamic_src = "%s/" % configuration_src.paths.server.media.dynamic
|
||||
dynamic_dst = "%s/" % configuration_dst.paths.server.media.dynamic
|
||||
|
||||
# rsync can only sync to one remote, so check and see if the dst or
|
||||
# src project.host is pointing to localhost
|
||||
if configuration_dst.project.host == 'localhost':
|
||||
cmd_rsync = "rsync -pthrvz --rsh='ssh -p 22' " \
|
||||
" {user_src}@{host_src}:{path_src} " \
|
||||
" {path_dst}".format(
|
||||
user_src=configuration_src.project.user,
|
||||
host_src=configuration_src.project.host,
|
||||
path_src=dynamic_src,
|
||||
user_dst=configuration_dst.project.user,
|
||||
host_dst=configuration_dst.project.host,
|
||||
path_dst=dynamic_dst,
|
||||
)
|
||||
else:
|
||||
cmd_rsync = "rsync -pthrvz --rsh='ssh -p 22' " \
|
||||
" {path_src} " \
|
||||
" {user_dst}@{host_dst}:{path_dst}".format(
|
||||
user_src=configuration_src.project.user,
|
||||
host_src=configuration_src.project.host,
|
||||
path_src=dynamic_src,
|
||||
user_dst=configuration_dst.project.user,
|
||||
host_dst=configuration_dst.project.host,
|
||||
path_dst=dynamic_dst,
|
||||
)
|
||||
|
||||
print cmd_rsync
|
||||
|
||||
upstream = True
|
||||
remote_dir = dynamic_dst
|
||||
local_dir = dynamic_src
|
||||
|
||||
if configuration_src.project.host == "localhost":
|
||||
remote_dir = dynamic_dst
|
||||
local_dir = dynamic_src
|
||||
upstream = True
|
||||
configuration_dst = initialize.environment(
|
||||
destination_branch)
|
||||
|
||||
print "\ncopy from {src} to {dst}\n".format(
|
||||
src=configuration_src.project.host,
|
||||
dst=configuration_dst.project.host)
|
||||
|
||||
elif configuration_dst.project.host == "localhost":
|
||||
remote_dir = dynamic_src
|
||||
local_dir = dynamic_dst
|
||||
upstream = False
|
||||
|
||||
print "upstream: %s" % upstream
|
||||
print "\ncopy from {src} to {dst}\n".format(
|
||||
src=configuration_src.project.host,
|
||||
dst=configuration_dst.project.host)
|
||||
else:
|
||||
print_console("no moving media files from staging to production")
|
||||
return
|
||||
|
||||
from fabric.contrib.project import rsync_project
|
||||
rsync_project(remote_dir=remote_dir,
|
||||
local_dir=local_dir,
|
||||
upload=upstream)
|
||||
|
||||
|
||||
@task
|
||||
def test():
|
||||
configuration = env.config
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue