You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
379 lines
10 KiB
379 lines
10 KiB
# -*- coding: utf-8 -*-
|
|
from os.path import join, basename
|
|
from collections import namedtuple, OrderedDict
|
|
import re
|
|
from fabric.api import *
|
|
|
|
|
|
env.roledefs = {
|
|
'dev': ['root@176.121.11.165'],
|
|
'prod': ['root@176.121.11.162'],
|
|
}
|
|
env.passwords = {
|
|
'root@176.121.11.165:22': 'ue6R287QZfMc',
|
|
'root@176.121.11.162:22': 'XcS2jx5e8k6n',
|
|
}
|
|
|
|
REMOTE_HOME_DIR = '/home/www/expomap/'
|
|
LOCAL_HOME_DIR = '/home/alexander/projects/expomap/'
|
|
|
|
nginx_conf_tech = '/etc/nginx/sites-available/tech_work_hit.expomap.ru'
|
|
nginx_conf = '/etc/nginx/sites-available/hit.expomap.ru'
|
|
apache2_conf = '/etc/apache2/sites-available/proj.com'
|
|
settings_conf = join(REMOTE_HOME_DIR, 'proj/settings.py')
|
|
services = ['nginx', 'apache2']
|
|
|
|
stages = {}
|
|
tickets = {}
|
|
commands = {}
|
|
|
|
def stage(stage_num):
|
|
def add_func(func):
|
|
if not callable(func):
|
|
raise NotImplementedError('func must be a callable')
|
|
func = ticket(func)
|
|
stages.setdefault(stage_num, OrderedDict()).update({func.__name__: func})
|
|
return func
|
|
return add_func
|
|
|
|
|
|
def ticket(func):
|
|
if not callable(func):
|
|
raise NotImplementedError('func must be a callable')
|
|
# stages.setdefault(stage_num, OrderedDict()).update({func.__name__: func})
|
|
tickets.update({func.__name__: func})
|
|
return func
|
|
|
|
|
|
# command_pattern
|
|
# cp = re.compile('^python manage.py (?P<command>\w+)$')
|
|
cp = re.compile('^(?P<command>\w+)$')
|
|
|
|
def register_command(command_string):
|
|
command = cp.match(command_string).group('command')
|
|
if not command:
|
|
raise ValueError('Invalid command string {command_string}'.format(command_string=command_string))
|
|
def func():
|
|
with cd(REMOTE_HOME_DIR):
|
|
run('python manage.py ' + command)
|
|
commands.update({command: func})
|
|
|
|
# run command
|
|
def rc(command):
|
|
if command in commands and callable(commands[command]):
|
|
commands[command]()
|
|
else:
|
|
raise ValueError('Command {command} is not callable'.format(command=command))
|
|
|
|
def set_host(host):
|
|
env.hosts = env.roledefs.get(host)
|
|
env.role = host
|
|
|
|
def dev():
|
|
set_host('dev')
|
|
|
|
def prod():
|
|
set_host('prod')
|
|
|
|
def get_configs():
|
|
localdir = join(LOCAL_HOME_DIR, 'support/', env.role)
|
|
get(nginx_conf, localdir)
|
|
get(apache2_conf, localdir)
|
|
get(join(REMOTE_HOME_DIR, 'schema.xml'), localdir)
|
|
get(settings_conf, localdir)
|
|
|
|
|
|
def put_configs():
|
|
localdir = join(LOCAL_HOME_DIR, 'support/', env.role)
|
|
# nginx
|
|
put(join(localdir, basename(nginx_conf)),
|
|
nginx_conf)
|
|
# # apache2
|
|
# put(join(localdir, basename(apache2_conf)),
|
|
# apache2_conf)
|
|
# settings
|
|
# put(join(localdir, basename(settings_conf)),
|
|
# settings_conf)
|
|
|
|
|
|
def newsletters_media():
|
|
with cd(join(REMOTE_HOME_DIR, 'media')):
|
|
run('mkdir -p newsletter')
|
|
put(
|
|
join(LOCAL_HOME_DIR, 'media/newsletter'),
|
|
join(REMOTE_HOME_DIR, 'media')
|
|
)
|
|
|
|
|
|
def call_state(state, only=None):
|
|
if only is not None and only in services:
|
|
run('service {only} {state}'.format(only=only, state=state))
|
|
return
|
|
for service in services:
|
|
run('service {service} {state}'.format(service=service, state=state))
|
|
|
|
|
|
def chown():
|
|
with cd(REMOTE_HOME_DIR):
|
|
run('chown -Rv www-data:www-data .')
|
|
|
|
|
|
def pull(with_configs=False, func=None):
|
|
with cd(REMOTE_HOME_DIR):
|
|
call_state('stop', only='apache2')
|
|
run('git pull')
|
|
if with_configs:
|
|
put_configs()
|
|
if func is not None and func in tickets and callable(tickets[func]):
|
|
tickets[func]()
|
|
call_state('start', only='apache2')
|
|
|
|
|
|
def stage_init(stage_num):
|
|
with cd(REMOTE_HOME_DIR):
|
|
call_state('stop', only='apache2')
|
|
run('git fetch')
|
|
run('git checkout stage{stage_num}'.format(stage_num=stage_num))
|
|
run('git pull')
|
|
# stage_num = int(stage_num)
|
|
# if stage_num in stages and isinstance(stages[stage_num], dict):
|
|
# for func_name, func in stages[stage_num].iteritems():
|
|
# func()
|
|
# call_state('start', only='apache2')
|
|
|
|
|
|
def migrate(app_name):
|
|
with cd(REMOTE_HOME_DIR):
|
|
run('python manage.py migrate {app_name}'.format(app_name=app_name))
|
|
|
|
|
|
def devmode(state=True):
|
|
localdir = join(LOCAL_HOME_DIR, 'support/', env.role)
|
|
# nginx
|
|
conf = nginx_conf_tech if state == True else nginx_conf
|
|
put(join(localdir, basename(conf)), nginx_conf)
|
|
run('/etc/init.d/nginx reload')
|
|
|
|
|
|
@stage(5)
|
|
def t1451():
|
|
with cd(REMOTE_HOME_DIR):
|
|
run('python manage.py migrate expobanner')
|
|
|
|
# temporary
|
|
register_command('banner_log_update_old')
|
|
register_command('banner_log_update')
|
|
#
|
|
|
|
@stage(5)
|
|
def t1458():
|
|
with cd(REMOTE_HOME_DIR):
|
|
run('python manage.py migrate service 0001 --fake')
|
|
run('python manage.py migrate service')
|
|
run('python manage.py set_events_services')
|
|
|
|
register_command('set_events_services')
|
|
|
|
|
|
@stage(5)
|
|
def t1456():
|
|
with cd(REMOTE_HOME_DIR):
|
|
run('python manage.py migrate expobanner')
|
|
|
|
|
|
@stage(5)
|
|
def t1463():
|
|
with cd(REMOTE_HOME_DIR):
|
|
run('python manage.py migrate newsletter')
|
|
run('pip install pymorphy2[fast]')
|
|
run('pip install -U pymorphy2-dicts-ru')
|
|
|
|
|
|
@stage(5)
|
|
def t1460():
|
|
with cd(REMOTE_HOME_DIR):
|
|
run('python manage.py migrate newsletter')
|
|
|
|
|
|
@ticket
|
|
def update_crontab():
|
|
with cd(REMOTE_HOME_DIR):
|
|
run('python manage.py crontab remove')
|
|
run('python manage.py crontab add')
|
|
|
|
|
|
@stage(5)
|
|
def t1461():
|
|
with cd(REMOTE_HOME_DIR):
|
|
run('pip install chainmap==1.0.2')
|
|
run('pip install suds==0.4')
|
|
run('python manage.py migrate conference')
|
|
run('python manage.py migrate exposition')
|
|
run('python manage.py update_events_filter_fields')
|
|
|
|
|
|
@ticket
|
|
def switch_to_stage4():
|
|
with cd(REMOTE_HOME_DIR):
|
|
call_state('stop', only='apache2')
|
|
run('git fetch')
|
|
run('git checkout stage4')
|
|
run('git pull')
|
|
call_state('start', only='apache2')
|
|
|
|
@ticket
|
|
def switch_to_stage5():
|
|
with cd(REMOTE_HOME_DIR):
|
|
call_state('stop', only='apache2')
|
|
run('git fetch')
|
|
run('git checkout staget5')
|
|
run('git pull')
|
|
call_state('start', only='apache2')
|
|
|
|
@ticket
|
|
def t1580():
|
|
with cd(REMOTE_HOME_DIR):
|
|
run('python manage.py migrate')
|
|
run('python manage.py users_to_mailinglist')
|
|
|
|
@ticket
|
|
def mailing():
|
|
with cd(REMOTE_HOME_DIR):
|
|
run('python manage.py migrate newsletter 0010')
|
|
run('python manage.py migrate newsletter 0011 --fake')
|
|
run('python manage.py migrate newsletter')
|
|
run('python manage.py migrate newsletter 0010 --fake')
|
|
run('python manage.py migrate newsletter 0011')
|
|
run('python manage.py migrate newsletter --fake')
|
|
run('python manage.py migrate')
|
|
run('python manage.py newsletter_create_dailymail')
|
|
|
|
@ticket
|
|
def mailing2():
|
|
with cd(REMOTE_HOME_DIR):
|
|
run('python manage.py migrate newsletter 0010 --fake')
|
|
run('python manage.py migrate newsletter 0011')
|
|
run('python manage.py migrate newsletter --fake')
|
|
|
|
@ticket
|
|
def t1609():
|
|
with cd(REMOTE_HOME_DIR):
|
|
files = ['media/cache/3b/8e/3b8ee5e07a982562d873a69550dd47c9.jpg']
|
|
for file in files:
|
|
put(
|
|
join(LOCAL_HOME_DIR, file),
|
|
join(REMOTE_HOME_DIR, file)
|
|
)
|
|
|
|
# def stage3_pre_final():
|
|
# with cd(REMOTE_HOME_DIR):
|
|
# run('pip install pandas')
|
|
# run('pip install django-rosetta==0.7.6')
|
|
# run('git checkout master')
|
|
# run('git pull')
|
|
# call_state('stop')
|
|
# put_configs()
|
|
# run('python manage.py migrate conference 0001 --fake')
|
|
# run('python manage.py migrate conference')
|
|
# run('python manage.py migrate expobanner')
|
|
# run('python manage.py migrate theme 0001 --fake')
|
|
# run('python manage.py migrate theme 0002')
|
|
# run('python manage.py migrate article 0001 --fake')
|
|
# run('python manage.py migrate article 0002')
|
|
# run('python manage.py migrate stats_collector')
|
|
# run('python manage.py crontab remove')
|
|
# run('python manage.py crontab add')
|
|
# chown()
|
|
# call_state('start')
|
|
|
|
|
|
# def stage3_release():
|
|
# call_state('stop')
|
|
# with cd(REMOTE_HOME_DIR):
|
|
# # run('python manage.py themeblog_to_blog')
|
|
# run('git fetch')
|
|
# run('git checkout stage3_release')
|
|
# run('git pull')
|
|
# # run('python manage.py migrate settings 0002 --fake')
|
|
# run('python manage.py migrate settings')
|
|
# run('python manage.py migrate article 0003')
|
|
# chown()
|
|
# call_state('start')
|
|
|
|
|
|
# def c_fix():
|
|
# with cd(REMOTE_HOME_DIR):
|
|
# call_state('stop', only='apache2')
|
|
# run('git pull')
|
|
# run('python manage.py migrate expobanner')
|
|
# call_state('start', only='apache2')
|
|
|
|
|
|
# def stage4_firstrun():
|
|
# with cd(REMOTE_HOME_DIR):
|
|
# call_state('stop')
|
|
# run('git fetch')
|
|
# run('git checkout stage4')
|
|
# # run('git checkout -- proj/settings.py')
|
|
# pull(with_configs=True)
|
|
# run('python manage.py syncdb')
|
|
# ticket1374()
|
|
# ticket1393()
|
|
# ticket1392()
|
|
# ticket1384()
|
|
# ticket1395()
|
|
# ticket1384_p1()
|
|
# ticket1384_p2()
|
|
# t1443()
|
|
# call_state('start')
|
|
|
|
|
|
# @ticket
|
|
# def ticket1395():
|
|
# with cd(REMOTE_HOME_DIR):
|
|
# run('python manage.py accounts_check_url')
|
|
|
|
|
|
# @ticket
|
|
# def ticket1374():
|
|
# with cd(REMOTE_HOME_DIR):
|
|
# run('python manage.py migrate theme')
|
|
|
|
|
|
# @ticket
|
|
# def ticket1393():
|
|
# with cd(REMOTE_HOME_DIR):
|
|
# run('python manage.py migrate newsletter 0001 --fake')
|
|
# run('python manage.py migrate newsletter')
|
|
|
|
|
|
# @ticket
|
|
# def ticket1392():
|
|
# with cd(REMOTE_HOME_DIR):
|
|
# run('python manage.py migrate newsletter')
|
|
|
|
|
|
# @ticket
|
|
# def ticket1384():
|
|
# with cd(REMOTE_HOME_DIR):
|
|
# run('python manage.py migrate exposition 0001 --fake')
|
|
# run('python manage.py migrate exposition')
|
|
# run('python manage.py migrate conference')
|
|
|
|
|
|
# @ticket
|
|
# def ticket1384_p1():
|
|
# with cd(REMOTE_HOME_DIR):
|
|
# run('python manage.py check_url')
|
|
|
|
|
|
# @ticket
|
|
# def ticket1384_p2():
|
|
# with cd(REMOTE_HOME_DIR):
|
|
# run('python manage.py check_translation')
|
|
|
|
|
|
# @ticket
|
|
# def t1443():
|
|
# with cd(REMOTE_HOME_DIR):
|
|
# run('chown -Rv www-data:www-data locale')
|
|
|