Mercurial > public > src > rhodecode
annotate pylons_app/lib/celerylib/tasks.py @ 530:5c376ac2d4c9 celery
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 18 Sep 2010 17:03:29 +0200 |
parents | a9e50dce3081 |
children | b12ea84fb906 |
rev | line source |
---|---|
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 from celery.decorators import task |
518
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
2 from celery.task.sets import subtask |
527
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
518
diff
changeset
|
3 from celeryconfig import PYLONS_CONFIG as config |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 from datetime import datetime, timedelta |
518
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
5 from pylons.i18n.translation import _ |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
6 from pylons_app.lib.celerylib import run_task |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 from pylons_app.lib.helpers import person |
518
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
8 from pylons_app.lib.smtp_mailer import SmtpMailer |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 from pylons_app.lib.utils import OrderedDict |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 from time import mktime |
518
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
11 from vcs.backends.hg import MercurialRepository |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 import calendar |
518
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
13 import traceback |
530
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
14 import json |
518
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
15 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
16 __all__ = ['whoosh_index', 'get_commits_stats', |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
17 'reset_user_password', 'send_email'] |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
18 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
19 def get_session(): |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
20 from sqlalchemy import engine_from_config |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
21 from sqlalchemy.orm import sessionmaker, scoped_session |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
22 engine = engine_from_config(dict(config.items('app:main')), 'sqlalchemy.db1.') |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
23 sa = scoped_session(sessionmaker(bind=engine)) |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
24 return sa |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 |
518
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
26 def get_hg_settings(): |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
27 from pylons_app.model.db import HgAppSettings |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
28 try: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
29 sa = get_session() |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
30 ret = sa.query(HgAppSettings).all() |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
31 finally: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
32 sa.remove() |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
33 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
34 if not ret: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
35 raise Exception('Could not get application settings !') |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
36 settings = {} |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
37 for each in ret: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
38 settings['hg_app_' + each.app_settings_name] = each.app_settings_value |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
39 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
40 return settings |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 |
518
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
42 def get_hg_ui_settings(): |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
43 from pylons_app.model.db import HgAppUi |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
44 try: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
45 sa = get_session() |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
46 ret = sa.query(HgAppUi).all() |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
47 finally: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
48 sa.remove() |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
49 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
50 if not ret: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
51 raise Exception('Could not get application ui settings !') |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
52 settings = {} |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
53 for each in ret: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
54 k = each.ui_key |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
55 v = each.ui_value |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
56 if k == '/': |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
57 k = 'root_path' |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
58 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
59 if k.find('.') != -1: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
60 k = k.replace('.', '_') |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
61 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
62 if each.ui_section == 'hooks': |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
63 v = each.ui_active |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
64 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
65 settings[each.ui_section + '_' + k] = v |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
66 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
67 return settings |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
68 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
69 @task |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
70 def whoosh_index(repo_location, full_index): |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
71 log = whoosh_index.get_logger() |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 from pylons_app.lib.indexers import DaemonLock |
518
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
73 from pylons_app.lib.indexers.daemon import WhooshIndexingDaemon, LockHeld |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 try: |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 l = DaemonLock() |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 WhooshIndexingDaemon(repo_location=repo_location)\ |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 .run(full_index=full_index) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 l.release() |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 return 'Done' |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 except LockHeld: |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 log.info('LockHeld') |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 return 'LockHeld' |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 |
518
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
84 @task |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 def get_commits_stats(repo): |
518
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
86 log = get_commits_stats.get_logger() |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 aggregate = OrderedDict() |
530
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
88 overview_aggregate = OrderedDict() |
527
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
518
diff
changeset
|
89 repos_path = get_hg_ui_settings()['paths_root_path'].replace('*', '') |
518
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
90 repo = MercurialRepository(repos_path + repo) |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 #graph range |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 td = datetime.today() + timedelta(days=1) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 y, m, d = td.year, td.month, td.day |
530
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
94 |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
95 ts_min_y = mktime((y - 1, (td - timedelta(days=calendar.mdays[m])).month, |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
96 d, 0, 0, 0, 0, 0, 0,)) |
530
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
97 ts_min_m = mktime((y, (td - timedelta(days=calendar.mdays[m])).month, |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
98 d, 0, 0, 0, 0, 0, 0,)) |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 |
530
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
100 ts_max_y = mktime((y, m, d, 0, 0, 0, 0, 0, 0,)) |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
101 |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 def author_key_cleaner(k): |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 k = person(k) |
530
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
104 k = k.replace('"', "") #for js data compatibilty |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 return k |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
106 |
530
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
107 for cs in repo[:1000]:#added limit 200 until fix #29 is made |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
108 k = '%s-%s-%s' % (cs.date.timetuple()[0], cs.date.timetuple()[1], |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
109 cs.date.timetuple()[2]) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
110 timetupple = [int(x) for x in k.split('-')] |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
111 timetupple.extend([0 for _ in xrange(6)]) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
112 k = mktime(timetupple) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
113 if aggregate.has_key(author_key_cleaner(cs.author)): |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
114 if aggregate[author_key_cleaner(cs.author)].has_key(k): |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
115 aggregate[author_key_cleaner(cs.author)][k]["commits"] += 1 |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
116 aggregate[author_key_cleaner(cs.author)][k]["added"] += len(cs.added) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
117 aggregate[author_key_cleaner(cs.author)][k]["changed"] += len(cs.changed) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
118 aggregate[author_key_cleaner(cs.author)][k]["removed"] += len(cs.removed) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
119 |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
120 else: |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
121 #aggregate[author_key_cleaner(cs.author)].update(dates_range) |
530
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
122 if k >= ts_min_y and k <= ts_max_y: |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 aggregate[author_key_cleaner(cs.author)][k] = {} |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
124 aggregate[author_key_cleaner(cs.author)][k]["commits"] = 1 |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
125 aggregate[author_key_cleaner(cs.author)][k]["added"] = len(cs.added) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 aggregate[author_key_cleaner(cs.author)][k]["changed"] = len(cs.changed) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
127 aggregate[author_key_cleaner(cs.author)][k]["removed"] = len(cs.removed) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
128 |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 else: |
530
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
130 if k >= ts_min_y and k <= ts_max_y: |
510
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
131 aggregate[author_key_cleaner(cs.author)] = OrderedDict() |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
132 #aggregate[author_key_cleaner(cs.author)].update(dates_range) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
133 aggregate[author_key_cleaner(cs.author)][k] = {} |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
134 aggregate[author_key_cleaner(cs.author)][k]["commits"] = 1 |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
135 aggregate[author_key_cleaner(cs.author)][k]["added"] = len(cs.added) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
136 aggregate[author_key_cleaner(cs.author)][k]["changed"] = len(cs.changed) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
137 aggregate[author_key_cleaner(cs.author)][k]["removed"] = len(cs.removed) |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
138 |
3fc3ce53659b
starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
139 |
530
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
140 if overview_aggregate.has_key(k): |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
141 overview_aggregate[k] += 1 |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
142 else: |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
143 overview_aggregate[k] = 1 |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
144 |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
145 overview_data = [] |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
146 for k, v in overview_aggregate.items(): |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
147 overview_data.append([k, v]) |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
148 data = {} |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
149 for author in aggregate: |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
150 data[author] = {"label":author, |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
151 "data":[{"time":x, |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
152 "commits":aggregate[author][x]['commits'], |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
153 "added":aggregate[author][x]['added'], |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
154 "changed":aggregate[author][x]['changed'], |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
155 "removed":aggregate[author][x]['removed'], |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
156 } for x in aggregate[author]], |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
157 "schema":["commits"] |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
158 } |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
159 |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
160 if not data: |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
161 data[author_key_cleaner(repo.contact)] = { |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
162 "label":author_key_cleaner(repo.contact), |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
163 "data":[0, 1], |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
164 "schema":["commits"], |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
165 } |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
166 |
5c376ac2d4c9
rewrote graph plotting, added zooming and json dump insted of stupid string formating.
Marcin Kuzminski <marcin@python-works.com>
parents:
527
diff
changeset
|
167 return (ts_min_m, ts_max_y, json.dumps(data), json.dumps(overview_data)) |
518
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
168 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
169 @task |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
170 def reset_user_password(user_email): |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
171 log = reset_user_password.get_logger() |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
172 from pylons_app.lib import auth |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
173 from pylons_app.model.db import User |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
174 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
175 try: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
176 try: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
177 sa = get_session() |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
178 user = sa.query(User).filter(User.email == user_email).scalar() |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
179 new_passwd = auth.PasswordGenerator().gen_password(8, |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
180 auth.PasswordGenerator.ALPHABETS_BIG_SMALL) |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
181 user.password = auth.get_crypt_password(new_passwd) |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
182 sa.add(user) |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
183 sa.commit() |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
184 log.info('change password for %s', user_email) |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
185 if new_passwd is None: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
186 raise Exception('unable to generate new password') |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
187 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
188 except: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
189 log.error(traceback.format_exc()) |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
190 sa.rollback() |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
191 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
192 run_task(send_email, user_email, |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
193 "Your new hg-app password", |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
194 'Your new hg-app password:%s' % (new_passwd)) |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
195 log.info('send new password mail to %s', user_email) |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
196 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
197 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
198 except: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
199 log.error('Failed to update user password') |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
200 log.error(traceback.format_exc()) |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
201 return True |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
202 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
203 @task |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
204 def send_email(recipients, subject, body): |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
205 log = send_email.get_logger() |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
206 email_config = dict(config.items('DEFAULT')) |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
207 mail_from = email_config.get('app_email_from') |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
208 user = email_config.get('smtp_username') |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
209 passwd = email_config.get('smtp_password') |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
210 mail_server = email_config.get('smtp_server') |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
211 mail_port = email_config.get('smtp_port') |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
212 tls = email_config.get('smtp_use_tls') |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
213 ssl = False |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
214 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
215 try: |
527
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
518
diff
changeset
|
216 m = SmtpMailer(mail_from, user, passwd, mail_server, |
518
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
217 mail_port, ssl, tls) |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
218 m.send(recipients, subject, body) |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
219 except: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
220 log.error('Mail sending failed') |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
221 log.error(traceback.format_exc()) |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
222 return False |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
510
diff
changeset
|
223 return True |