diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -27,6 +27,7 @@ import os import logging import datetime import traceback +import hashlib from collections import defaultdict from sqlalchemy import * @@ -43,9 +44,8 @@ from rhodecode.lib.utils2 import str2boo safe_unicode from rhodecode.lib.compat import json from rhodecode.lib.caching_query import FromCache +from rhodecode.model.meta import Base, Session -from rhodecode.model.meta import Base, Session -import hashlib URL_SEP = '/' log = logging.getLogger(__name__) @@ -152,11 +152,12 @@ class BaseModel(object): return safe_str(self.__unicode__()) return '' % (self.__class__.__name__) + class RhodeCodeSetting(Base, BaseModel): __tablename__ = 'rhodecode_settings' __table_args__ = ( UniqueConstraint('app_settings_name'), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} ) app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) @@ -222,7 +223,7 @@ class RhodeCodeSetting(Base, BaseModel): .filter(cls.app_settings_name.startswith('ldap_')).all() fd = {} for row in ret: - fd.update({row.app_settings_name:row.app_settings_value}) + fd.update({row.app_settings_name: row.app_settings_value}) return fd @@ -231,7 +232,7 @@ class RhodeCodeUi(Base, BaseModel): __tablename__ = 'rhodecode_ui' __table_args__ = ( UniqueConstraint('ui_key'), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} ) @@ -282,7 +283,7 @@ class User(Base, BaseModel): __tablename__ = 'users' __table_args__ = ( UniqueConstraint('username'), UniqueConstraint('email'), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} ) user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) @@ -404,7 +405,7 @@ class User(Base, BaseModel): class UserLog(Base, BaseModel): __tablename__ = 'user_logs' __table_args__ = ( - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}, ) user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) @@ -426,7 +427,7 @@ class UserLog(Base, BaseModel): class UsersGroup(Base, BaseModel): __tablename__ = 'users_groups' __table_args__ = ( - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}, ) @@ -468,7 +469,7 @@ class UsersGroup(Base, BaseModel): class UsersGroupMember(Base, BaseModel): __tablename__ = 'users_groups_members' __table_args__ = ( - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}, ) @@ -488,7 +489,7 @@ class Repository(Base, BaseModel): __tablename__ = 'repositories' __table_args__ = ( UniqueConstraint('repo_name'), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}, ) @@ -704,7 +705,7 @@ class Repository(Base, BaseModel): # get using prefilled cache_map invalidate_repo = cache_map[self.repo_name] if invalidate_repo: - invalidate_repo = (None if invalidate_repo.cache_active + invalidate_repo = (None if invalidate_repo.cache_active else invalidate_repo) else: # get from invalidate @@ -747,7 +748,7 @@ class RepoGroup(Base, BaseModel): __table_args__ = ( UniqueConstraint('group_name', 'group_parent_id'), CheckConstraint('group_id != group_parent_id'), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}, ) __mapper_args__ = {'order_by': 'group_name'} @@ -876,7 +877,7 @@ class RepoGroup(Base, BaseModel): class Permission(Base, BaseModel): __tablename__ = 'permissions' __table_args__ = ( - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}, ) permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) @@ -915,7 +916,7 @@ class UserRepoToPerm(Base, BaseModel): __tablename__ = 'repo_to_perm' __table_args__ = ( UniqueConstraint('user_id', 'repository_id', 'permission_id'), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} ) repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) @@ -944,7 +945,7 @@ class UserToPerm(Base, BaseModel): __tablename__ = 'user_to_perm' __table_args__ = ( UniqueConstraint('user_id', 'permission_id'), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} ) user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) @@ -959,7 +960,7 @@ class UsersGroupRepoToPerm(Base, BaseMod __tablename__ = 'users_group_repo_to_perm' __table_args__ = ( UniqueConstraint('repository_id', 'users_group_id', 'permission_id'), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} ) users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) @@ -988,7 +989,7 @@ class UsersGroupToPerm(Base, BaseModel): __tablename__ = 'users_group_to_perm' __table_args__ = ( UniqueConstraint('users_group_id', 'permission_id',), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} ) users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) @@ -1003,7 +1004,7 @@ class UserRepoGroupToPerm(Base, BaseMode __tablename__ = 'user_repo_group_to_perm' __table_args__ = ( UniqueConstraint('user_id', 'group_id', 'permission_id'), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} ) @@ -1021,7 +1022,7 @@ class UsersGroupRepoGroupToPerm(Base, Ba __tablename__ = 'users_group_repo_group_to_perm' __table_args__ = ( UniqueConstraint('users_group_id', 'group_id'), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} ) @@ -1039,7 +1040,7 @@ class Statistics(Base, BaseModel): __tablename__ = 'statistics' __table_args__ = ( UniqueConstraint('repository_id'), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} ) stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) @@ -1057,7 +1058,7 @@ class UserFollowing(Base, BaseModel): __table_args__ = ( UniqueConstraint('user_id', 'follows_repository_id'), UniqueConstraint('user_id', 'follows_user_id'), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} ) @@ -1082,7 +1083,7 @@ class CacheInvalidation(Base, BaseModel) __table_args__ = ( UniqueConstraint('cache_key'), Index('key_idx', 'cache_key'), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}, ) cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) @@ -1128,7 +1129,7 @@ class CacheInvalidation(Base, BaseModel) try: inv_obj = CacheInvalidation(key, org_key) Session.add(inv_obj) - #Session.commit() + Session.commit() except Exception: log.error(traceback.format_exc()) Session.rollback() @@ -1194,7 +1195,7 @@ class CacheInvalidation(Base, BaseModel) fixkey = kwargs.get('fixkey') if fixkey: del kwargs['fixkey'] - self.fixkey = fixkey + self.fixkey = fixkey super(cachemapdict, self).__init__(*args, **kwargs) def __getattr__(self, name): @@ -1223,7 +1224,7 @@ class CacheInvalidation(Base, BaseModel) class ChangesetComment(Base, BaseModel): __tablename__ = 'changeset_comments' __table_args__ = ( - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}, ) comment_id = Column('comment_id', Integer(), nullable=False, primary_key=True) @@ -1255,7 +1256,7 @@ class ChangesetComment(Base, BaseModel): class Notification(Base, BaseModel): __tablename__ = 'notifications' __table_args__ = ( - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}, ) @@ -1310,7 +1311,7 @@ class UserNotification(Base, BaseModel): __tablename__ = 'user_to_notification' __table_args__ = ( UniqueConstraint('user_id', 'notification_id'), - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} ) user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), primary_key=True) @@ -1330,7 +1331,7 @@ class UserNotification(Base, BaseModel): class DbMigrateVersion(Base, BaseModel): __tablename__ = 'db_migrate_version' __table_args__ = ( - {'extend_existing': True, 'mysql_engine':'InnoDB', + {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}, ) repository_id = Column('repository_id', String(250), primary_key=True)