Mercurial > kallithea
comparison rhodecode/lib/dbmigrate/schema/db_1_7_0.py @ 4186:7e5f8c12a3fc kallithea-2.2.5-rebrand
First step in two-part process to rename directories to kallithea.
This first step is to change all references in the files where they refer
to the old directory name.
author | Bradley M. Kuhn <bkuhn@sfconservancy.org> |
---|---|
date | Wed, 02 Jul 2014 19:04:28 -0400 |
parents | ffd45b185016 |
children |
comparison
equal
deleted
inserted
replaced
4185:aaa7c3331186 | 4186:7e5f8c12a3fc |
---|---|
10 # GNU General Public License for more details. | 10 # GNU General Public License for more details. |
11 # | 11 # |
12 # 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 |
13 # 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 """ | 14 """ |
15 rhodecode.model.db | 15 kallithea.model.db |
16 ~~~~~~~~~~~~~~~~~~ | 16 ~~~~~~~~~~~~~~~~~~ |
17 | 17 |
18 Database Models for RhodeCode | 18 Database Models for RhodeCode |
19 | 19 |
20 :created_on: Apr 08, 2010 | 20 :created_on: Apr 08, 2010 |
38 from beaker.cache import cache_region, region_invalidate | 38 from beaker.cache import cache_region, region_invalidate |
39 from webob.exc import HTTPNotFound | 39 from webob.exc import HTTPNotFound |
40 | 40 |
41 from pylons.i18n.translation import lazy_ugettext as _ | 41 from pylons.i18n.translation import lazy_ugettext as _ |
42 | 42 |
43 from rhodecode.lib.vcs import get_backend | 43 from kallithea.lib.vcs import get_backend |
44 from rhodecode.lib.vcs.utils.helpers import get_scm | 44 from kallithea.lib.vcs.utils.helpers import get_scm |
45 from rhodecode.lib.vcs.exceptions import VCSError | 45 from kallithea.lib.vcs.exceptions import VCSError |
46 from rhodecode.lib.vcs.utils.lazy import LazyProperty | 46 from kallithea.lib.vcs.utils.lazy import LazyProperty |
47 from rhodecode.lib.vcs.backends.base import EmptyChangeset | 47 from kallithea.lib.vcs.backends.base import EmptyChangeset |
48 | 48 |
49 from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \ | 49 from kallithea.lib.utils2 import str2bool, safe_str, get_changeset_safe, \ |
50 safe_unicode, remove_suffix, remove_prefix, time_to_datetime, _set_extras | 50 safe_unicode, remove_suffix, remove_prefix, time_to_datetime, _set_extras |
51 from rhodecode.lib.compat import json | 51 from kallithea.lib.compat import json |
52 from rhodecode.lib.caching_query import FromCache | 52 from kallithea.lib.caching_query import FromCache |
53 | 53 |
54 from rhodecode.model.meta import Base, Session | 54 from kallithea.model.meta import Base, Session |
55 | 55 |
56 URL_SEP = '/' | 56 URL_SEP = '/' |
57 log = logging.getLogger(__name__) | 57 log = logging.getLogger(__name__) |
58 | 58 |
59 #============================================================================== | 59 #============================================================================== |
405 @property | 405 @property |
406 def AuthUser(self): | 406 def AuthUser(self): |
407 """ | 407 """ |
408 Returns instance of AuthUser for this user | 408 Returns instance of AuthUser for this user |
409 """ | 409 """ |
410 from rhodecode.lib.auth import AuthUser | 410 from kallithea.lib.auth import AuthUser |
411 return AuthUser(user_id=self.user_id, api_key=self.api_key, | 411 return AuthUser(user_id=self.user_id, api_key=self.api_key, |
412 username=self.username) | 412 username=self.username) |
413 | 413 |
414 def __unicode__(self): | 414 def __unicode__(self): |
415 return u"<%s('id:%s:%s')>" % (self.__class__.__name__, | 415 return u"<%s('id:%s:%s')>" % (self.__class__.__name__, |
471 """ | 471 """ |
472 Tries to get User objects out of commit author string | 472 Tries to get User objects out of commit author string |
473 | 473 |
474 :param author: | 474 :param author: |
475 """ | 475 """ |
476 from rhodecode.lib.helpers import email, author_name | 476 from kallithea.lib.helpers import email, author_name |
477 # Valid email in the attribute passed, see if they're in the system | 477 # Valid email in the attribute passed, see if they're in the system |
478 _email = email(author) | 478 _email = email(author) |
479 if _email: | 479 if _email: |
480 user = cls.get_by_email(_email, case_insensitive=True) | 480 user = cls.get_by_email(_email, case_insensitive=True) |
481 if user: | 481 if user: |
585 active = Column("active", Boolean(), nullable=True, unique=None, default=True) | 585 active = Column("active", Boolean(), nullable=True, unique=None, default=True) |
586 user = relationship('User', lazy='joined') | 586 user = relationship('User', lazy='joined') |
587 | 587 |
588 @classmethod | 588 @classmethod |
589 def _get_ip_range(cls, ip_addr): | 589 def _get_ip_range(cls, ip_addr): |
590 from rhodecode.lib import ipaddr | 590 from kallithea.lib import ipaddr |
591 net = ipaddr.IPNetwork(address=ip_addr) | 591 net = ipaddr.IPNetwork(address=ip_addr) |
592 return [str(net.network), str(net.broadcast)] | 592 return [str(net.network), str(net.broadcast)] |
593 | 593 |
594 def __json__(self): | 594 def __json__(self): |
595 return dict( | 595 return dict( |
816 else: | 816 else: |
817 self._locked = None | 817 self._locked = None |
818 | 818 |
819 @hybrid_property | 819 @hybrid_property |
820 def changeset_cache(self): | 820 def changeset_cache(self): |
821 from rhodecode.lib.vcs.backends.base import EmptyChangeset | 821 from kallithea.lib.vcs.backends.base import EmptyChangeset |
822 dummy = EmptyChangeset().__json__() | 822 dummy = EmptyChangeset().__json__() |
823 if not self._changeset_cache: | 823 if not self._changeset_cache: |
824 return dummy | 824 return dummy |
825 try: | 825 try: |
826 return json.loads(self._changeset_cache) | 826 return json.loads(self._changeset_cache) |
960 @property | 960 @property |
961 def _ui(self): | 961 def _ui(self): |
962 """ | 962 """ |
963 Creates an db based ui object for this repository | 963 Creates an db based ui object for this repository |
964 """ | 964 """ |
965 from rhodecode.lib.utils import make_ui | 965 from kallithea.lib.utils import make_ui |
966 return make_ui('db', clear_session=False) | 966 return make_ui('db', clear_session=False) |
967 | 967 |
968 @classmethod | 968 @classmethod |
969 def is_valid(cls, repo_name): | 969 def is_valid(cls, repo_name): |
970 """ | 970 """ |
971 returns True if given repo name is a valid filesystem repository | 971 returns True if given repo name is a valid filesystem repository |
972 | 972 |
973 :param cls: | 973 :param cls: |
974 :param repo_name: | 974 :param repo_name: |
975 """ | 975 """ |
976 from rhodecode.lib.utils import is_valid_repo | 976 from kallithea.lib.utils import is_valid_repo |
977 | 977 |
978 return is_valid_repo(repo_name, cls.base_path()) | 978 return is_valid_repo(repo_name, cls.base_path()) |
979 | 979 |
980 def get_api_data(self): | 980 def get_api_data(self): |
981 """ | 981 """ |
1077 date | 1077 date |
1078 author | 1078 author |
1079 | 1079 |
1080 :param cs_cache: | 1080 :param cs_cache: |
1081 """ | 1081 """ |
1082 from rhodecode.lib.vcs.backends.base import BaseChangeset | 1082 from kallithea.lib.vcs.backends.base import BaseChangeset |
1083 if cs_cache is None: | 1083 if cs_cache is None: |
1084 cs_cache = EmptyChangeset() | 1084 cs_cache = EmptyChangeset() |
1085 # use no-cache version here | 1085 # use no-cache version here |
1086 scm_repo = self.scm_instance_no_cache() | 1086 scm_repo = self.scm_instance_no_cache() |
1087 if scm_repo: | 1087 if scm_repo: |
1161 grouped[stat.revision] = [str(stat.status), stat.status_lbl, | 1161 grouped[stat.revision] = [str(stat.status), stat.status_lbl, |
1162 pr_id, pr_repo] | 1162 pr_id, pr_repo] |
1163 return grouped | 1163 return grouped |
1164 | 1164 |
1165 def _repo_size(self): | 1165 def _repo_size(self): |
1166 from rhodecode.lib import helpers as h | 1166 from kallithea.lib import helpers as h |
1167 log.debug('calculating repository size...') | 1167 log.debug('calculating repository size...') |
1168 return h.format_byte_size(self.scm_instance.size) | 1168 return h.format_byte_size(self.scm_instance.size) |
1169 | 1169 |
1170 #========================================================================== | 1170 #========================================================================== |
1171 # SCM CACHE INSTANCE | 1171 # SCM CACHE INSTANCE |
1180 def scm_instance_no_cache(self): | 1180 def scm_instance_no_cache(self): |
1181 return self.__get_instance() | 1181 return self.__get_instance() |
1182 | 1182 |
1183 @property | 1183 @property |
1184 def scm_instance(self): | 1184 def scm_instance(self): |
1185 import rhodecode | 1185 import kallithea |
1186 full_cache = str2bool(rhodecode.CONFIG.get('vcs_full_cache')) | 1186 full_cache = str2bool(kallithea.CONFIG.get('vcs_full_cache')) |
1187 if full_cache: | 1187 if full_cache: |
1188 return self.scm_instance_cached() | 1188 return self.scm_instance_cached() |
1189 return self.__get_instance() | 1189 return self.__get_instance() |
1190 | 1190 |
1191 def scm_instance_cached(self, valid_cache_keys=None): | 1191 def scm_instance_cached(self, valid_cache_keys=None): |
1813 def _get_cache_key(cls, key): | 1813 def _get_cache_key(cls, key): |
1814 """ | 1814 """ |
1815 Wrapper for generating a unique cache key for this instance and "key". | 1815 Wrapper for generating a unique cache key for this instance and "key". |
1816 key must / will start with a repo_name which will be stored in .cache_args . | 1816 key must / will start with a repo_name which will be stored in .cache_args . |
1817 """ | 1817 """ |
1818 import rhodecode | 1818 import kallithea |
1819 prefix = rhodecode.CONFIG.get('instance_id', '') | 1819 prefix = kallithea.CONFIG.get('instance_id', '') |
1820 return "%s%s" % (prefix, key) | 1820 return "%s%s" % (prefix, key) |
1821 | 1821 |
1822 @classmethod | 1822 @classmethod |
1823 def set_invalidate(cls, repo_name): | 1823 def set_invalidate(cls, repo_name): |
1824 """ | 1824 """ |
2099 Session().add(notification) | 2099 Session().add(notification) |
2100 return notification | 2100 return notification |
2101 | 2101 |
2102 @property | 2102 @property |
2103 def description(self): | 2103 def description(self): |
2104 from rhodecode.model.notification import NotificationModel | 2104 from kallithea.model.notification import NotificationModel |
2105 return NotificationModel().make_description(self) | 2105 return NotificationModel().make_description(self) |
2106 | 2106 |
2107 | 2107 |
2108 class UserNotification(Base, BaseModel): | 2108 class UserNotification(Base, BaseModel): |
2109 __tablename__ = 'user_to_notification' | 2109 __tablename__ = 'user_to_notification' |
2158 @classmethod | 2158 @classmethod |
2159 def get_by_access_id(cls, gist_access_id): | 2159 def get_by_access_id(cls, gist_access_id): |
2160 return cls.query().filter(cls.gist_access_id == gist_access_id).scalar() | 2160 return cls.query().filter(cls.gist_access_id == gist_access_id).scalar() |
2161 | 2161 |
2162 def gist_url(self): | 2162 def gist_url(self): |
2163 import rhodecode | 2163 import kallithea |
2164 alias_url = rhodecode.CONFIG.get('gist_alias_url') | 2164 alias_url = kallithea.CONFIG.get('gist_alias_url') |
2165 if alias_url: | 2165 if alias_url: |
2166 return alias_url.replace('{gistid}', self.gist_access_id) | 2166 return alias_url.replace('{gistid}', self.gist_access_id) |
2167 | 2167 |
2168 from pylons import url | 2168 from pylons import url |
2169 return url('gist', gist_id=self.gist_access_id, qualified=True) | 2169 return url('gist', gist_id=self.gist_access_id, qualified=True) |
2173 """ | 2173 """ |
2174 Returns base path when all gists are stored | 2174 Returns base path when all gists are stored |
2175 | 2175 |
2176 :param cls: | 2176 :param cls: |
2177 """ | 2177 """ |
2178 from rhodecode.model.gist import GIST_STORE_LOC | 2178 from kallithea.model.gist import GIST_STORE_LOC |
2179 q = Session().query(RhodeCodeUi)\ | 2179 q = Session().query(RhodeCodeUi)\ |
2180 .filter(RhodeCodeUi.ui_key == URL_SEP) | 2180 .filter(RhodeCodeUi.ui_key == URL_SEP) |
2181 q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | 2181 q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
2182 return os.path.join(q.one().ui_value, GIST_STORE_LOC) | 2182 return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
2183 | 2183 |
2204 return data | 2204 return data |
2205 ## SCM functions | 2205 ## SCM functions |
2206 | 2206 |
2207 @property | 2207 @property |
2208 def scm_instance(self): | 2208 def scm_instance(self): |
2209 from rhodecode.lib.vcs import get_repo | 2209 from kallithea.lib.vcs import get_repo |
2210 base_path = self.base_path() | 2210 base_path = self.base_path() |
2211 return get_repo(os.path.join(*map(safe_str, | 2211 return get_repo(os.path.join(*map(safe_str, |
2212 [base_path, self.gist_access_id]))) | 2212 [base_path, self.gist_access_id]))) |
2213 | 2213 |
2214 | 2214 |