From 096d4b86e13688a24a7b3abecc46c2f625b57ae4 Mon Sep 17 00:00:00 2001 From: Alexander Burdeiny Date: Thu, 7 Jul 2016 12:43:56 +0300 Subject: [PATCH] =?UTF-8?q?1451:=20=D0=AD=D1=82=D0=B0=D0=BF=20=E2=84=965:?= =?UTF-8?q?=20=D0=90=D0=BC=D0=B8=D0=BD=D0=BA=D0=B0=20=D0=B1=D0=B0=D0=B3?= =?UTF-8?q?=D0=B8=20-=20=D0=A3=D1=80=D0=BB=20=D0=A2=D0=9E=D0=9F=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B7=D0=BC=D0=B5=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/commands/banner_log_update.py | 2 -- fabfile.py | 35 +++++++++++++++---- functions/custom_fields.py | 2 +- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/expobanner/management/commands/banner_log_update.py b/expobanner/management/commands/banner_log_update.py index 77a50cd1..f4e113d7 100644 --- a/expobanner/management/commands/banner_log_update.py +++ b/expobanner/management/commands/banner_log_update.py @@ -40,8 +40,6 @@ class Command(BaseCommand): unique_views = Log.objects.filter(type=1, **params).values('ip').distinct().count() unique_clicks = Log.objects.filter(type=2, **params).values('ip').distinct().count() - print(views, clicks, unique_views, unique_clicks) - logstat.click += clicks logstat.view += views logstat.unique_click += unique_clicks diff --git a/fabfile.py b/fabfile.py index 170fb7a9..089d81c6 100644 --- a/fabfile.py +++ b/fabfile.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from os.path import join, basename from collections import namedtuple, OrderedDict - +import re from fabric.api import * @@ -24,7 +24,7 @@ services = ['nginx', 'apache2'] stages = {} tickets = {} - +commands = {} def stage(stage_num): def ticket(func): @@ -35,19 +35,37 @@ def stage(stage_num): return func return ticket + +# command_pattern +# cp = re.compile('^python manage.py (?P\w+)$') +cp = re.compile('^(?P\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) @@ -109,9 +127,12 @@ def stage_init(stage_num): def t1451(): with cd(REMOTE_HOME_DIR): run('python manage.py migrate expobanner') - run('python manage.py migrate banner_log_update_old') - run('python manage.py migrate banner_log_update') + rc('banner_log_update_old') + rc('banner_log_update') + +register_command('banner_log_update_old') +register_command('banner_log_update') # def stage3_pre_final(): # with cd(REMOTE_HOME_DIR): diff --git a/functions/custom_fields.py b/functions/custom_fields.py index 991c9863..67a04834 100644 --- a/functions/custom_fields.py +++ b/functions/custom_fields.py @@ -281,7 +281,7 @@ class MonthMultiSelectField(models.CharField): @staticmethod def get_data_from_string(s): - pattern = re.compile('^(?P([1-9]|[1][0-2]))/(?P[0-9]{4})$') + p = re.compile('^(?P([1-9]|[1][0-2]))/(?P[0-9]{4})$') m = p.match(s) return m.group('month'), m.group('year')