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')