Mercurial > kallithea
comparison rhodecode/lib/celerylib/tasks.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
This imports changes between changesets 21af6c4eab3d and 6177597791c2 in
RhodeCode's original repository, including only changes to Python files and HTML.
RhodeCode clearly licensed its changes to these files under GPLv3
in their /LICENSE file, which states the following:
The Python code and integrated HTML are licensed under the GPLv3 license.
(See:
https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE
or
http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE
for an online copy of that LICENSE file)
Conservancy reviewed these changes and confirmed that they can be licensed as
a whole to the Kallithea project under GPLv3-only.
While some of the contents committed herein are clearly licensed
GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the
statement above from RhodeCode indicates that they intend GPLv3-only as their
license, per GPLv3ยง14 and other relevant sections of GPLv3.
author | Bradley M. Kuhn <bkuhn@sfconservancy.org> |
---|---|
date | Wed, 02 Jul 2014 19:03:13 -0400 |
parents | 3563bb7b4b82 |
children | 7e5f8c12a3fc |
comparison
equal
deleted
inserted
replaced
4115:8b7294a804a0 | 4116:ffd45b185016 |
---|---|
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """ | |
3 rhodecode.lib.celerylib.tasks | |
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
5 | |
6 RhodeCode task modules, containing all task that suppose to be run | |
7 by celery daemon | |
8 | |
9 :created_on: Oct 6, 2010 | |
10 :author: marcink | |
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> | |
12 :license: GPLv3, see COPYING for more details. | |
13 """ | |
14 # This program is free software: you can redistribute it and/or modify | 2 # This program is free software: you can redistribute it and/or modify |
15 # it under the terms of the GNU General Public License as published by | 3 # it under the terms of the GNU General Public License as published by |
16 # the Free Software Foundation, either version 3 of the License, or | 4 # the Free Software Foundation, either version 3 of the License, or |
17 # (at your option) any later version. | 5 # (at your option) any later version. |
18 # | 6 # |
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 # GNU General Public License for more details. | 10 # GNU General Public License for more details. |
23 # | 11 # |
24 # You should have received a copy of the GNU General Public License | 12 # You should have received a copy of the GNU General Public License |
25 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
14 """ | |
15 rhodecode.lib.celerylib.tasks | |
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
17 | |
18 RhodeCode task modules, containing all task that suppose to be run | |
19 by celery daemon | |
20 | |
21 :created_on: Oct 6, 2010 | |
22 :author: marcink | |
23 :copyright: (c) 2013 RhodeCode GmbH. | |
24 :license: GPLv3, see LICENSE for more details. | |
25 """ | |
26 | |
26 from celery.decorators import task | 27 from celery.decorators import task |
27 | 28 |
28 import os | 29 import os |
29 import traceback | 30 import traceback |
30 import logging | 31 import logging |
51 | 52 |
52 from rhodecode.model.db import Statistics, Repository, User | 53 from rhodecode.model.db import Statistics, Repository, User |
53 from rhodecode.model.scm import ScmModel | 54 from rhodecode.model.scm import ScmModel |
54 | 55 |
55 | 56 |
56 add_cache(config) | 57 add_cache(config) # pragma: no cover |
57 | 58 |
58 __all__ = ['whoosh_index', 'get_commits_stats', | 59 __all__ = ['whoosh_index', 'get_commits_stats', |
59 'reset_user_password', 'send_email'] | 60 'reset_user_password', 'send_email'] |
60 | 61 |
61 | 62 |
62 def get_logger(cls): | 63 def get_logger(cls): |
63 if CELERY_ON: | 64 if CELERY_ON: |
64 try: | 65 try: |
65 log = cls.get_logger() | 66 log = cls.get_logger() |
66 except: | 67 except Exception: |
67 log = logging.getLogger(__name__) | 68 log = logging.getLogger(__name__) |
68 else: | 69 else: |
69 log = logging.getLogger(__name__) | 70 log = logging.getLogger(__name__) |
70 | 71 |
71 return log | 72 return log |
297 log.error('Mail sending failed') | 298 log.error('Mail sending failed') |
298 log.error(traceback.format_exc()) | 299 log.error(traceback.format_exc()) |
299 return False | 300 return False |
300 return True | 301 return True |
301 | 302 |
302 | 303 @task(ignore_result=False) |
303 @task(ignore_result=True) | 304 @dbsession |
305 def create_repo(form_data, cur_user): | |
306 from rhodecode.model.repo import RepoModel | |
307 from rhodecode.model.user import UserModel | |
308 from rhodecode.model.db import RhodeCodeSetting | |
309 | |
310 log = get_logger(create_repo) | |
311 DBS = get_session() | |
312 | |
313 cur_user = UserModel(DBS)._get_user(cur_user) | |
314 | |
315 owner = cur_user | |
316 repo_name = form_data['repo_name'] | |
317 repo_name_full = form_data['repo_name_full'] | |
318 repo_type = form_data['repo_type'] | |
319 description = form_data['repo_description'] | |
320 private = form_data['repo_private'] | |
321 clone_uri = form_data.get('clone_uri') | |
322 repo_group = form_data['repo_group'] | |
323 landing_rev = form_data['repo_landing_rev'] | |
324 copy_fork_permissions = form_data.get('copy_permissions') | |
325 copy_group_permissions = form_data.get('repo_copy_permissions') | |
326 fork_of = form_data.get('fork_parent_id') | |
327 state = form_data.get('repo_state', Repository.STATE_PENDING) | |
328 | |
329 # repo creation defaults, private and repo_type are filled in form | |
330 defs = RhodeCodeSetting.get_default_repo_settings(strip_prefix=True) | |
331 enable_statistics = defs.get('repo_enable_statistics') | |
332 enable_locking = defs.get('repo_enable_locking') | |
333 enable_downloads = defs.get('repo_enable_downloads') | |
334 | |
335 try: | |
336 repo = RepoModel(DBS)._create_repo( | |
337 repo_name=repo_name_full, | |
338 repo_type=repo_type, | |
339 description=description, | |
340 owner=owner, | |
341 private=private, | |
342 clone_uri=clone_uri, | |
343 repo_group=repo_group, | |
344 landing_rev=landing_rev, | |
345 fork_of=fork_of, | |
346 copy_fork_permissions=copy_fork_permissions, | |
347 copy_group_permissions=copy_group_permissions, | |
348 enable_statistics=enable_statistics, | |
349 enable_locking=enable_locking, | |
350 enable_downloads=enable_downloads, | |
351 state=state | |
352 ) | |
353 | |
354 action_logger(cur_user, 'user_created_repo', | |
355 form_data['repo_name_full'], '', DBS) | |
356 | |
357 DBS.commit() | |
358 # now create this repo on Filesystem | |
359 RepoModel(DBS)._create_filesystem_repo( | |
360 repo_name=repo_name, | |
361 repo_type=repo_type, | |
362 repo_group=RepoModel(DBS)._get_repo_group(repo_group), | |
363 clone_uri=clone_uri, | |
364 ) | |
365 repo = Repository.get_by_repo_name(repo_name_full) | |
366 log_create_repository(repo.get_dict(), created_by=owner.username) | |
367 | |
368 # update repo changeset caches initially | |
369 repo.update_changeset_cache() | |
370 | |
371 # set new created state | |
372 repo.set_state(Repository.STATE_CREATED) | |
373 DBS.commit() | |
374 except Exception, e: | |
375 log.warning('Exception %s occured when forking repository, ' | |
376 'doing cleanup...' % e) | |
377 # rollback things manually ! | |
378 repo = Repository.get_by_repo_name(repo_name_full) | |
379 if repo: | |
380 Repository.delete(repo.repo_id) | |
381 DBS.commit() | |
382 RepoModel(DBS)._delete_filesystem_repo(repo) | |
383 raise | |
384 | |
385 # it's an odd fix to make celery fail task when exception occurs | |
386 def on_failure(self, *args, **kwargs): | |
387 pass | |
388 | |
389 return True | |
390 | |
391 | |
392 @task(ignore_result=False) | |
304 @dbsession | 393 @dbsession |
305 def create_repo_fork(form_data, cur_user): | 394 def create_repo_fork(form_data, cur_user): |
306 """ | 395 """ |
307 Creates a fork of repository using interval VCS methods | 396 Creates a fork of repository using interval VCS methods |
308 | 397 |
316 DBS = get_session() | 405 DBS = get_session() |
317 | 406 |
318 base_path = Repository.base_path() | 407 base_path = Repository.base_path() |
319 cur_user = UserModel(DBS)._get_user(cur_user) | 408 cur_user = UserModel(DBS)._get_user(cur_user) |
320 | 409 |
321 fork_name = form_data['repo_name_full'] | 410 repo_name = form_data['repo_name'] # fork in this case |
411 repo_name_full = form_data['repo_name_full'] | |
412 | |
322 repo_type = form_data['repo_type'] | 413 repo_type = form_data['repo_type'] |
323 description = form_data['description'] | |
324 owner = cur_user | 414 owner = cur_user |
325 private = form_data['private'] | 415 private = form_data['private'] |
326 clone_uri = form_data.get('clone_uri') | 416 clone_uri = form_data.get('clone_uri') |
327 repos_group = form_data['repo_group'] | 417 repo_group = form_data['repo_group'] |
328 landing_rev = form_data['landing_rev'] | 418 landing_rev = form_data['landing_rev'] |
329 copy_fork_permissions = form_data.get('copy_permissions') | 419 copy_fork_permissions = form_data.get('copy_permissions') |
330 fork_of = RepoModel(DBS)._get_repo(form_data.get('fork_parent_id')) | 420 |
331 | 421 try: |
332 fork_repo = RepoModel(DBS).create_repo( | 422 fork_of = RepoModel(DBS)._get_repo(form_data.get('fork_parent_id')) |
333 fork_name, repo_type, description, owner, private, clone_uri, | 423 |
334 repos_group, landing_rev, just_db=True, fork_of=fork_of, | 424 fork_repo = RepoModel(DBS)._create_repo( |
335 copy_fork_permissions=copy_fork_permissions | 425 repo_name=repo_name_full, |
336 ) | 426 repo_type=repo_type, |
337 | 427 description=form_data['description'], |
338 update_after_clone = form_data['update_after_clone'] | 428 owner=owner, |
339 | 429 private=private, |
340 source_repo_path = os.path.join(base_path, fork_of.repo_name) | 430 clone_uri=clone_uri, |
341 destination_fork_path = os.path.join(base_path, fork_name) | 431 repo_group=repo_group, |
342 | 432 landing_rev=landing_rev, |
343 log.info('creating fork of %s as %s', source_repo_path, | 433 fork_of=fork_of, |
344 destination_fork_path) | 434 copy_fork_permissions=copy_fork_permissions |
345 backend = get_backend(repo_type) | 435 ) |
346 | 436 action_logger(cur_user, 'user_forked_repo:%s' % repo_name_full, |
347 if repo_type == 'git': | 437 fork_of.repo_name, '', DBS) |
348 r = backend(safe_str(destination_fork_path), create=True, | 438 DBS.commit() |
349 src_url=safe_str(source_repo_path), | 439 |
350 update_after_clone=update_after_clone, | 440 update_after_clone = form_data['update_after_clone'] |
351 bare=True) | 441 source_repo_path = os.path.join(base_path, fork_of.repo_name) |
352 # add rhodecode hook into this repo | 442 |
353 ScmModel().install_git_hook(repo=r) | 443 # now create this repo on Filesystem |
354 elif repo_type == 'hg': | 444 RepoModel(DBS)._create_filesystem_repo( |
355 r = backend(safe_str(destination_fork_path), create=True, | 445 repo_name=repo_name, |
356 src_url=safe_str(source_repo_path), | 446 repo_type=repo_type, |
357 update_after_clone=update_after_clone) | 447 repo_group=RepoModel(DBS)._get_repo_group(repo_group), |
358 else: | 448 clone_uri=source_repo_path, |
359 raise Exception('Unknown backend type %s' % repo_type) | 449 ) |
360 | 450 repo = Repository.get_by_repo_name(repo_name_full) |
361 log_create_repository(fork_repo.get_dict(), created_by=cur_user.username) | 451 log_create_repository(repo.get_dict(), created_by=owner.username) |
362 | 452 |
363 action_logger(cur_user, 'user_forked_repo:%s' % fork_name, | 453 # update repo changeset caches initially |
364 fork_of.repo_name, '', DBS) | 454 repo.update_changeset_cache() |
365 | 455 |
366 action_logger(cur_user, 'user_created_fork:%s' % fork_name, | 456 # set new created state |
367 fork_name, '', DBS) | 457 repo.set_state(Repository.STATE_CREATED) |
368 # finally commit at latest possible stage | 458 DBS.commit() |
369 DBS.commit() | 459 except Exception, e: |
370 fork_repo.update_changeset_cache() | 460 log.warning('Exception %s occured when forking repository, ' |
461 'doing cleanup...' % e) | |
462 #rollback things manually ! | |
463 repo = Repository.get_by_repo_name(repo_name_full) | |
464 if repo: | |
465 Repository.delete(repo.repo_id) | |
466 DBS.commit() | |
467 RepoModel(DBS)._delete_filesystem_repo(repo) | |
468 raise | |
469 | |
470 # it's an odd fix to make celery fail task when exception occurs | |
471 def on_failure(self, *args, **kwargs): | |
472 pass | |
473 | |
474 return True | |
371 | 475 |
372 | 476 |
373 def __get_codes_stats(repo_name): | 477 def __get_codes_stats(repo_name): |
374 from rhodecode.config.conf import LANGUAGES_EXTENSIONS_MAP | 478 from rhodecode.config.conf import LANGUAGES_EXTENSIONS_MAP |
375 repo = Repository.get_by_repo_name(repo_name).scm_instance | 479 repo = Repository.get_by_repo_name(repo_name).scm_instance |
376 | 480 |
377 tip = repo.get_changeset() | 481 tip = repo.get_changeset() |
378 code_stats = {} | 482 code_stats = {} |
379 | 483 |