Show More
@@ -81,7 +81,7 b' class ChangelogController(BaseRepoContro' | |||||
81 | items_per_page=c.size, branch=branch_name) |
|
81 | items_per_page=c.size, branch=branch_name) | |
82 | collection = list(c.pagination) |
|
82 | collection = list(c.pagination) | |
83 | page_revisions = [x.raw_id for x in collection] |
|
83 | page_revisions = [x.raw_id for x in collection] | |
84 | c.comments = c.rhodecode_db_repo.comments(page_revisions) |
|
84 | c.comments = c.rhodecode_db_repo.get_comments(page_revisions) | |
85 | c.statuses = c.rhodecode_db_repo.statuses(page_revisions) |
|
85 | c.statuses = c.rhodecode_db_repo.statuses(page_revisions) | |
86 | except (RepositoryError, ChangesetDoesNotExistError, Exception), e: |
|
86 | except (RepositoryError, ChangesetDoesNotExistError, Exception), e: | |
87 | log.error(traceback.format_exc()) |
|
87 | log.error(traceback.format_exc()) |
@@ -51,8 +51,6 b' from rhodecode.lib.caching_query import ' | |||||
51 |
|
51 | |||
52 | from rhodecode.model.meta import Base, Session |
|
52 | from rhodecode.model.meta import Base, Session | |
53 |
|
53 | |||
54 |
|
||||
55 |
|
||||
56 | URL_SEP = '/' |
|
54 | URL_SEP = '/' | |
57 | log = logging.getLogger(__name__) |
|
55 | log = logging.getLogger(__name__) | |
58 |
|
56 | |||
@@ -136,7 +134,7 b' class BaseModel(object):' | |||||
136 |
|
134 | |||
137 | @classmethod |
|
135 | @classmethod | |
138 | def query(cls): |
|
136 | def query(cls): | |
139 | return Session.query(cls) |
|
137 | return Session().query(cls) | |
140 |
|
138 | |||
141 | @classmethod |
|
139 | @classmethod | |
142 | def get(cls, id_): |
|
140 | def get(cls, id_): | |
@@ -158,7 +156,7 b' class BaseModel(object):' | |||||
158 | @classmethod |
|
156 | @classmethod | |
159 | def delete(cls, id_): |
|
157 | def delete(cls, id_): | |
160 | obj = cls.query().get(id_) |
|
158 | obj = cls.query().get(id_) | |
161 | Session.delete(obj) |
|
159 | Session().delete(obj) | |
162 |
|
160 | |||
163 | def __repr__(self): |
|
161 | def __repr__(self): | |
164 | if hasattr(self, '__unicode__'): |
|
162 | if hasattr(self, '__unicode__'): | |
@@ -294,7 +292,7 b' class RhodeCodeUi(Base, BaseModel):' | |||||
294 | new_ui.ui_key = key |
|
292 | new_ui.ui_key = key | |
295 | new_ui.ui_value = val |
|
293 | new_ui.ui_value = val | |
296 |
|
294 | |||
297 | Session.add(new_ui) |
|
295 | Session().add(new_ui) | |
298 |
|
296 | |||
299 |
|
297 | |||
300 | class User(Base, BaseModel): |
|
298 | class User(Base, BaseModel): | |
@@ -424,7 +422,7 b' class User(Base, BaseModel):' | |||||
424 | def update_lastlogin(self): |
|
422 | def update_lastlogin(self): | |
425 | """Update user lastlogin""" |
|
423 | """Update user lastlogin""" | |
426 | self.last_login = datetime.datetime.now() |
|
424 | self.last_login = datetime.datetime.now() | |
427 | Session.add(self) |
|
425 | Session().add(self) | |
428 | log.debug('updated user %s lastlogin' % self.username) |
|
426 | log.debug('updated user %s lastlogin' % self.username) | |
429 |
|
427 | |||
430 | def get_api_data(self): |
|
428 | def get_api_data(self): | |
@@ -479,7 +477,7 b' class UserEmailMap(Base, BaseModel):' | |||||
479 | @validates('_email') |
|
477 | @validates('_email') | |
480 | def validate_email(self, key, email): |
|
478 | def validate_email(self, key, email): | |
481 | # check if this email is not main one |
|
479 | # check if this email is not main one | |
482 | main_email = Session.query(User).filter(User.email == email).scalar() |
|
480 | main_email = Session().query(User).filter(User.email == email).scalar() | |
483 | if main_email is not None: |
|
481 | if main_email is not None: | |
484 | raise AttributeError('email %s is present is user table' % email) |
|
482 | raise AttributeError('email %s is present is user table' % email) | |
485 | return email |
|
483 | return email | |
@@ -621,7 +619,7 b' class Repository(Base, BaseModel):' | |||||
621 |
|
619 | |||
622 | @classmethod |
|
620 | @classmethod | |
623 | def get_by_repo_name(cls, repo_name): |
|
621 | def get_by_repo_name(cls, repo_name): | |
624 | q = Session.query(cls).filter(cls.repo_name == repo_name) |
|
622 | q = Session().query(cls).filter(cls.repo_name == repo_name) | |
625 | q = q.options(joinedload(Repository.fork))\ |
|
623 | q = q.options(joinedload(Repository.fork))\ | |
626 | .options(joinedload(Repository.user))\ |
|
624 | .options(joinedload(Repository.user))\ | |
627 | .options(joinedload(Repository.group)) |
|
625 | .options(joinedload(Repository.group)) | |
@@ -643,7 +641,7 b' class Repository(Base, BaseModel):' | |||||
643 |
|
641 | |||
644 | :param cls: |
|
642 | :param cls: | |
645 | """ |
|
643 | """ | |
646 | q = Session.query(RhodeCodeUi)\ |
|
644 | q = Session().query(RhodeCodeUi)\ | |
647 | .filter(RhodeCodeUi.ui_key == cls.url_sep()) |
|
645 | .filter(RhodeCodeUi.ui_key == cls.url_sep()) | |
648 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
646 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
649 | return q.one().ui_value |
|
647 | return q.one().ui_value | |
@@ -693,7 +691,7 b' class Repository(Base, BaseModel):' | |||||
693 | Returns base full path for that repository means where it actually |
|
691 | Returns base full path for that repository means where it actually | |
694 | exists on a filesystem |
|
692 | exists on a filesystem | |
695 | """ |
|
693 | """ | |
696 | q = Session.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == |
|
694 | q = Session().query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == | |
697 | Repository.url_sep()) |
|
695 | Repository.url_sep()) | |
698 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
696 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
699 | return q.one().ui_value |
|
697 | return q.one().ui_value | |
@@ -743,6 +741,18 b' class Repository(Base, BaseModel):' | |||||
743 | return baseui |
|
741 | return baseui | |
744 |
|
742 | |||
745 | @classmethod |
|
743 | @classmethod | |
|
744 | def inject_ui(cls, repo, extras={}): | |||
|
745 | from rhodecode.lib.vcs.backends.hg import MercurialRepository | |||
|
746 | from rhodecode.lib.vcs.backends.git import GitRepository | |||
|
747 | required = (MercurialRepository, GitRepository) | |||
|
748 | if not isinstance(repo, required): | |||
|
749 | raise Exception('repo must be instance of %s' % required) | |||
|
750 | ||||
|
751 | # inject ui extra param to log this action via push logger | |||
|
752 | for k, v in extras.items(): | |||
|
753 | repo._repo.ui.setconfig('rhodecode_extras', k, v) | |||
|
754 | ||||
|
755 | @classmethod | |||
746 | def is_valid(cls, repo_name): |
|
756 | def is_valid(cls, repo_name): | |
747 | """ |
|
757 | """ | |
748 | returns True if given repo name is a valid filesystem repository |
|
758 | returns True if given repo name is a valid filesystem repository | |
@@ -794,7 +804,7 b' class Repository(Base, BaseModel):' | |||||
794 | def last_change(self): |
|
804 | def last_change(self): | |
795 | return self.scm_instance.last_change |
|
805 | return self.scm_instance.last_change | |
796 |
|
806 | |||
797 | def comments(self, revisions=None): |
|
807 | def get_comments(self, revisions=None): | |
798 | """ |
|
808 | """ | |
799 | Returns comments for this repository grouped by revisions |
|
809 | Returns comments for this repository grouped by revisions | |
800 |
|
810 | |||
@@ -1052,7 +1062,7 b' class Permission(Base, BaseModel):' | |||||
1052 |
|
1062 | |||
1053 | @classmethod |
|
1063 | @classmethod | |
1054 | def get_default_perms(cls, default_user_id): |
|
1064 | def get_default_perms(cls, default_user_id): | |
1055 | q = Session.query(UserRepoToPerm, Repository, cls)\ |
|
1065 | q = Session().query(UserRepoToPerm, Repository, cls)\ | |
1056 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
1066 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ | |
1057 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
1067 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ | |
1058 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
1068 | .filter(UserRepoToPerm.user_id == default_user_id) | |
@@ -1061,7 +1071,7 b' class Permission(Base, BaseModel):' | |||||
1061 |
|
1071 | |||
1062 | @classmethod |
|
1072 | @classmethod | |
1063 | def get_default_group_perms(cls, default_user_id): |
|
1073 | def get_default_group_perms(cls, default_user_id): | |
1064 | q = Session.query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
1074 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ | |
1065 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
1075 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ | |
1066 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
1076 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ | |
1067 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
1077 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
@@ -1091,7 +1101,7 b' class UserRepoToPerm(Base, BaseModel):' | |||||
1091 | n.user = user |
|
1101 | n.user = user | |
1092 | n.repository = repository |
|
1102 | n.repository = repository | |
1093 | n.permission = permission |
|
1103 | n.permission = permission | |
1094 | Session.add(n) |
|
1104 | Session().add(n) | |
1095 | return n |
|
1105 | return n | |
1096 |
|
1106 | |||
1097 | def __unicode__(self): |
|
1107 | def __unicode__(self): | |
@@ -1135,7 +1145,7 b' class UsersGroupRepoToPerm(Base, BaseMod' | |||||
1135 | n.users_group = users_group |
|
1145 | n.users_group = users_group | |
1136 | n.repository = repository |
|
1146 | n.repository = repository | |
1137 | n.permission = permission |
|
1147 | n.permission = permission | |
1138 | Session.add(n) |
|
1148 | Session().add(n) | |
1139 | return n |
|
1149 | return n | |
1140 |
|
1150 | |||
1141 | def __unicode__(self): |
|
1151 | def __unicode__(self): | |
@@ -1281,15 +1291,15 b' class CacheInvalidation(Base, BaseModel)' | |||||
1281 |
|
1291 | |||
1282 | @classmethod |
|
1292 | @classmethod | |
1283 | def _get_or_create_key(cls, key, prefix, org_key): |
|
1293 | def _get_or_create_key(cls, key, prefix, org_key): | |
1284 | inv_obj = Session.query(cls).filter(cls.cache_key == key).scalar() |
|
1294 | inv_obj = Session().query(cls).filter(cls.cache_key == key).scalar() | |
1285 | if not inv_obj: |
|
1295 | if not inv_obj: | |
1286 | try: |
|
1296 | try: | |
1287 | inv_obj = CacheInvalidation(key, org_key) |
|
1297 | inv_obj = CacheInvalidation(key, org_key) | |
1288 | Session.add(inv_obj) |
|
1298 | Session().add(inv_obj) | |
1289 | Session.commit() |
|
1299 | Session().commit() | |
1290 | except Exception: |
|
1300 | except Exception: | |
1291 | log.error(traceback.format_exc()) |
|
1301 | log.error(traceback.format_exc()) | |
1292 | Session.rollback() |
|
1302 | Session().rollback() | |
1293 | return inv_obj |
|
1303 | return inv_obj | |
1294 |
|
1304 | |||
1295 | @classmethod |
|
1305 | @classmethod | |
@@ -1317,7 +1327,7 b' class CacheInvalidation(Base, BaseModel)' | |||||
1317 | """ |
|
1327 | """ | |
1318 |
|
1328 | |||
1319 | key, _prefix, _org_key = cls._get_key(key) |
|
1329 | key, _prefix, _org_key = cls._get_key(key) | |
1320 | inv_objs = Session.query(cls).filter(cls.cache_args == _org_key).all() |
|
1330 | inv_objs = Session().query(cls).filter(cls.cache_args == _org_key).all() | |
1321 | log.debug('marking %s key[s] %s for invalidation' % (len(inv_objs), |
|
1331 | log.debug('marking %s key[s] %s for invalidation' % (len(inv_objs), | |
1322 | _org_key)) |
|
1332 | _org_key)) | |
1323 | try: |
|
1333 | try: | |
@@ -1325,11 +1335,11 b' class CacheInvalidation(Base, BaseModel)' | |||||
1325 | if inv_obj: |
|
1335 | if inv_obj: | |
1326 | inv_obj.cache_active = False |
|
1336 | inv_obj.cache_active = False | |
1327 |
|
1337 | |||
1328 | Session.add(inv_obj) |
|
1338 | Session().add(inv_obj) | |
1329 | Session.commit() |
|
1339 | Session().commit() | |
1330 | except Exception: |
|
1340 | except Exception: | |
1331 | log.error(traceback.format_exc()) |
|
1341 | log.error(traceback.format_exc()) | |
1332 | Session.rollback() |
|
1342 | Session().rollback() | |
1333 |
|
1343 | |||
1334 | @classmethod |
|
1344 | @classmethod | |
1335 | def set_valid(cls, key): |
|
1345 | def set_valid(cls, key): | |
@@ -1340,8 +1350,8 b' class CacheInvalidation(Base, BaseModel)' | |||||
1340 | """ |
|
1350 | """ | |
1341 | inv_obj = cls.get_by_key(key) |
|
1351 | inv_obj = cls.get_by_key(key) | |
1342 | inv_obj.cache_active = True |
|
1352 | inv_obj.cache_active = True | |
1343 | Session.add(inv_obj) |
|
1353 | Session().add(inv_obj) | |
1344 | Session.commit() |
|
1354 | Session().commit() | |
1345 |
|
1355 | |||
1346 | @classmethod |
|
1356 | @classmethod | |
1347 | def get_cache_map(cls): |
|
1357 | def get_cache_map(cls): | |
@@ -1409,7 +1419,7 b' class ChangesetComment(Base, BaseModel):' | |||||
1409 | :param cls: |
|
1419 | :param cls: | |
1410 | :param revision: |
|
1420 | :param revision: | |
1411 | """ |
|
1421 | """ | |
1412 | q = Session.query(User)\ |
|
1422 | q = Session().query(User)\ | |
1413 | .join(ChangesetComment.author) |
|
1423 | .join(ChangesetComment.author) | |
1414 | if revision: |
|
1424 | if revision: | |
1415 | q = q.filter(cls.revision == revision) |
|
1425 | q = q.filter(cls.revision == revision) | |
@@ -1573,7 +1583,7 b' class Notification(Base, BaseModel):' | |||||
1573 | assoc = UserNotification() |
|
1583 | assoc = UserNotification() | |
1574 | assoc.notification = notification |
|
1584 | assoc.notification = notification | |
1575 | u.notifications.append(assoc) |
|
1585 | u.notifications.append(assoc) | |
1576 | Session.add(notification) |
|
1586 | Session().add(notification) | |
1577 | return notification |
|
1587 | return notification | |
1578 |
|
1588 | |||
1579 | @property |
|
1589 | @property | |
@@ -1600,7 +1610,7 b' class UserNotification(Base, BaseModel):' | |||||
1600 |
|
1610 | |||
1601 | def mark_as_read(self): |
|
1611 | def mark_as_read(self): | |
1602 | self.read = True |
|
1612 | self.read = True | |
1603 | Session.add(self) |
|
1613 | Session().add(self) | |
1604 |
|
1614 | |||
1605 |
|
1615 | |||
1606 | class DbMigrateVersion(Base, BaseModel): |
|
1616 | class DbMigrateVersion(Base, BaseModel): |
@@ -356,18 +356,16 b' class ScmModel(BaseModel):' | |||||
356 | 'ip': '', |
|
356 | 'ip': '', | |
357 | 'username': username, |
|
357 | 'username': username, | |
358 | 'action': 'push_remote', |
|
358 | 'action': 'push_remote', | |
359 | 'repository': repo.repo_name, |
|
359 | 'repository': dbrepo.repo_name, | |
360 | 'scm': repo.alias, |
|
360 | 'scm': repo.alias, | |
361 | } |
|
361 | } | |
|
362 | Repository.inject_ui(repo, extras=extras) | |||
362 |
|
363 | |||
363 | # inject ui extra param to log this action via push logger |
|
|||
364 | for k, v in extras.items(): |
|
|||
365 | repo._repo.ui.setconfig('rhodecode_extras', k, v) |
|
|||
366 | if repo.alias == 'git': |
|
364 | if repo.alias == 'git': | |
367 | repo.fetch(clone_uri) |
|
365 | repo.fetch(clone_uri) | |
368 | else: |
|
366 | else: | |
369 | repo.pull(clone_uri) |
|
367 | repo.pull(clone_uri) | |
370 | self.mark_for_invalidation(repo.repo_name) |
|
368 | self.mark_for_invalidation(dbrepo.repo_name) | |
371 | except: |
|
369 | except: | |
372 | log.error(traceback.format_exc()) |
|
370 | log.error(traceback.format_exc()) | |
373 | raise |
|
371 | raise |
General Comments 0
You need to be logged in to leave comments.
Login now