Mercurial > kallithea
comparison rhodecode/lib/dbmigrate/schema/db_2_0_2.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 |
39 from beaker.cache import cache_region, region_invalidate | 39 from beaker.cache import cache_region, region_invalidate |
40 from webob.exc import HTTPNotFound | 40 from webob.exc import HTTPNotFound |
41 | 41 |
42 from pylons.i18n.translation import lazy_ugettext as _ | 42 from pylons.i18n.translation import lazy_ugettext as _ |
43 | 43 |
44 from rhodecode.lib.vcs import get_backend | 44 from kallithea.lib.vcs import get_backend |
45 from rhodecode.lib.vcs.utils.helpers import get_scm | 45 from kallithea.lib.vcs.utils.helpers import get_scm |
46 from rhodecode.lib.vcs.exceptions import VCSError | 46 from kallithea.lib.vcs.exceptions import VCSError |
47 from rhodecode.lib.vcs.utils.lazy import LazyProperty | 47 from kallithea.lib.vcs.utils.lazy import LazyProperty |
48 from rhodecode.lib.vcs.backends.base import EmptyChangeset | 48 from kallithea.lib.vcs.backends.base import EmptyChangeset |
49 | 49 |
50 from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \ | 50 from kallithea.lib.utils2 import str2bool, safe_str, get_changeset_safe, \ |
51 safe_unicode, remove_prefix, time_to_datetime, aslist, Optional, safe_int | 51 safe_unicode, remove_prefix, time_to_datetime, aslist, Optional, safe_int |
52 from rhodecode.lib.compat import json | 52 from kallithea.lib.compat import json |
53 from rhodecode.lib.caching_query import FromCache | 53 from kallithea.lib.caching_query import FromCache |
54 | 54 |
55 from rhodecode.model.meta import Base, Session | 55 from kallithea.model.meta import Base, Session |
56 | 56 |
57 URL_SEP = '/' | 57 URL_SEP = '/' |
58 log = logging.getLogger(__name__) | 58 log = logging.getLogger(__name__) |
59 | 59 |
60 #============================================================================== | 60 #============================================================================== |
301 | 301 |
302 @classmethod | 302 @classmethod |
303 def get_server_info(cls): | 303 def get_server_info(cls): |
304 import pkg_resources | 304 import pkg_resources |
305 import platform | 305 import platform |
306 import rhodecode | 306 import kallithea |
307 from rhodecode.lib.utils import check_git_version | 307 from kallithea.lib.utils import check_git_version |
308 mods = [(p.project_name, p.version) for p in pkg_resources.working_set] | 308 mods = [(p.project_name, p.version) for p in pkg_resources.working_set] |
309 info = { | 309 info = { |
310 'modules': sorted(mods, key=lambda k: k[0].lower()), | 310 'modules': sorted(mods, key=lambda k: k[0].lower()), |
311 'py_version': platform.python_version(), | 311 'py_version': platform.python_version(), |
312 'platform': safe_unicode(platform.platform()), | 312 'platform': safe_unicode(platform.platform()), |
313 'rhodecode_version': rhodecode.__version__, | 313 'rhodecode_version': kallithea.__version__, |
314 'git_version': safe_unicode(check_git_version()), | 314 'git_version': safe_unicode(check_git_version()), |
315 'git_path': rhodecode.CONFIG.get('git_path') | 315 'git_path': kallithea.CONFIG.get('git_path') |
316 } | 316 } |
317 return info | 317 return info |
318 | 318 |
319 | 319 |
320 class RhodeCodeUi(Base, BaseModel): | 320 class RhodeCodeUi(Base, BaseModel): |
480 @property | 480 @property |
481 def AuthUser(self): | 481 def AuthUser(self): |
482 """ | 482 """ |
483 Returns instance of AuthUser for this user | 483 Returns instance of AuthUser for this user |
484 """ | 484 """ |
485 from rhodecode.lib.auth import AuthUser | 485 from kallithea.lib.auth import AuthUser |
486 return AuthUser(user_id=self.user_id, api_key=self.api_key, | 486 return AuthUser(user_id=self.user_id, api_key=self.api_key, |
487 username=self.username) | 487 username=self.username) |
488 | 488 |
489 def __unicode__(self): | 489 def __unicode__(self): |
490 return u"<%s('id:%s:%s')>" % (self.__class__.__name__, | 490 return u"<%s('id:%s:%s')>" % (self.__class__.__name__, |
546 """ | 546 """ |
547 Tries to get User objects out of commit author string | 547 Tries to get User objects out of commit author string |
548 | 548 |
549 :param author: | 549 :param author: |
550 """ | 550 """ |
551 from rhodecode.lib.helpers import email, author_name | 551 from kallithea.lib.helpers import email, author_name |
552 # Valid email in the attribute passed, see if they're in the system | 552 # Valid email in the attribute passed, see if they're in the system |
553 _email = email(author) | 553 _email = email(author) |
554 if _email: | 554 if _email: |
555 user = cls.get_by_email(_email, case_insensitive=True) | 555 user = cls.get_by_email(_email, case_insensitive=True) |
556 if user: | 556 if user: |
661 active = Column("active", Boolean(), nullable=True, unique=None, default=True) | 661 active = Column("active", Boolean(), nullable=True, unique=None, default=True) |
662 user = relationship('User', lazy='joined') | 662 user = relationship('User', lazy='joined') |
663 | 663 |
664 @classmethod | 664 @classmethod |
665 def _get_ip_range(cls, ip_addr): | 665 def _get_ip_range(cls, ip_addr): |
666 from rhodecode.lib import ipaddr | 666 from kallithea.lib import ipaddr |
667 net = ipaddr.IPNetwork(address=ip_addr) | 667 net = ipaddr.IPNetwork(address=ip_addr) |
668 return [str(net.network), str(net.broadcast)] | 668 return [str(net.network), str(net.broadcast)] |
669 | 669 |
670 def __json__(self): | 670 def __json__(self): |
671 return dict( | 671 return dict( |
919 else: | 919 else: |
920 self._locked = None | 920 self._locked = None |
921 | 921 |
922 @hybrid_property | 922 @hybrid_property |
923 def changeset_cache(self): | 923 def changeset_cache(self): |
924 from rhodecode.lib.vcs.backends.base import EmptyChangeset | 924 from kallithea.lib.vcs.backends.base import EmptyChangeset |
925 dummy = EmptyChangeset().__json__() | 925 dummy = EmptyChangeset().__json__() |
926 if not self._changeset_cache: | 926 if not self._changeset_cache: |
927 return dummy | 927 return dummy |
928 try: | 928 try: |
929 return json.loads(self._changeset_cache) | 929 return json.loads(self._changeset_cache) |
1063 @property | 1063 @property |
1064 def _ui(self): | 1064 def _ui(self): |
1065 """ | 1065 """ |
1066 Creates an db based ui object for this repository | 1066 Creates an db based ui object for this repository |
1067 """ | 1067 """ |
1068 from rhodecode.lib.utils import make_ui | 1068 from kallithea.lib.utils import make_ui |
1069 return make_ui('db', clear_session=False) | 1069 return make_ui('db', clear_session=False) |
1070 | 1070 |
1071 @classmethod | 1071 @classmethod |
1072 def is_valid(cls, repo_name): | 1072 def is_valid(cls, repo_name): |
1073 """ | 1073 """ |
1074 returns True if given repo name is a valid filesystem repository | 1074 returns True if given repo name is a valid filesystem repository |
1075 | 1075 |
1076 :param cls: | 1076 :param cls: |
1077 :param repo_name: | 1077 :param repo_name: |
1078 """ | 1078 """ |
1079 from rhodecode.lib.utils import is_valid_repo | 1079 from kallithea.lib.utils import is_valid_repo |
1080 | 1080 |
1081 return is_valid_repo(repo_name, cls.base_path()) | 1081 return is_valid_repo(repo_name, cls.base_path()) |
1082 | 1082 |
1083 def get_api_data(self): | 1083 def get_api_data(self): |
1084 """ | 1084 """ |
1183 date | 1183 date |
1184 author | 1184 author |
1185 | 1185 |
1186 :param cs_cache: | 1186 :param cs_cache: |
1187 """ | 1187 """ |
1188 from rhodecode.lib.vcs.backends.base import BaseChangeset | 1188 from kallithea.lib.vcs.backends.base import BaseChangeset |
1189 if cs_cache is None: | 1189 if cs_cache is None: |
1190 cs_cache = EmptyChangeset() | 1190 cs_cache = EmptyChangeset() |
1191 # use no-cache version here | 1191 # use no-cache version here |
1192 scm_repo = self.scm_instance_no_cache() | 1192 scm_repo = self.scm_instance_no_cache() |
1193 if scm_repo: | 1193 if scm_repo: |
1267 grouped[stat.revision] = [str(stat.status), stat.status_lbl, | 1267 grouped[stat.revision] = [str(stat.status), stat.status_lbl, |
1268 pr_id, pr_repo] | 1268 pr_id, pr_repo] |
1269 return grouped | 1269 return grouped |
1270 | 1270 |
1271 def _repo_size(self): | 1271 def _repo_size(self): |
1272 from rhodecode.lib import helpers as h | 1272 from kallithea.lib import helpers as h |
1273 log.debug('calculating repository size...') | 1273 log.debug('calculating repository size...') |
1274 return h.format_byte_size(self.scm_instance.size) | 1274 return h.format_byte_size(self.scm_instance.size) |
1275 | 1275 |
1276 #========================================================================== | 1276 #========================================================================== |
1277 # SCM CACHE INSTANCE | 1277 # SCM CACHE INSTANCE |
1286 def scm_instance_no_cache(self): | 1286 def scm_instance_no_cache(self): |
1287 return self.__get_instance() | 1287 return self.__get_instance() |
1288 | 1288 |
1289 @property | 1289 @property |
1290 def scm_instance(self): | 1290 def scm_instance(self): |
1291 import rhodecode | 1291 import kallithea |
1292 full_cache = str2bool(rhodecode.CONFIG.get('vcs_full_cache')) | 1292 full_cache = str2bool(kallithea.CONFIG.get('vcs_full_cache')) |
1293 if full_cache: | 1293 if full_cache: |
1294 return self.scm_instance_cached() | 1294 return self.scm_instance_cached() |
1295 return self.__get_instance() | 1295 return self.__get_instance() |
1296 | 1296 |
1297 def scm_instance_cached(self, valid_cache_keys=None): | 1297 def scm_instance_cached(self, valid_cache_keys=None): |
1938 def _get_cache_key(cls, key): | 1938 def _get_cache_key(cls, key): |
1939 """ | 1939 """ |
1940 Wrapper for generating a unique cache key for this instance and "key". | 1940 Wrapper for generating a unique cache key for this instance and "key". |
1941 key must / will start with a repo_name which will be stored in .cache_args . | 1941 key must / will start with a repo_name which will be stored in .cache_args . |
1942 """ | 1942 """ |
1943 import rhodecode | 1943 import kallithea |
1944 prefix = rhodecode.CONFIG.get('instance_id', '') | 1944 prefix = kallithea.CONFIG.get('instance_id', '') |
1945 return "%s%s" % (prefix, key) | 1945 return "%s%s" % (prefix, key) |
1946 | 1946 |
1947 @classmethod | 1947 @classmethod |
1948 def set_invalidate(cls, repo_name, delete=False): | 1948 def set_invalidate(cls, repo_name, delete=False): |
1949 """ | 1949 """ |
2228 Session().add(notification) | 2228 Session().add(notification) |
2229 return notification | 2229 return notification |
2230 | 2230 |
2231 @property | 2231 @property |
2232 def description(self): | 2232 def description(self): |
2233 from rhodecode.model.notification import NotificationModel | 2233 from kallithea.model.notification import NotificationModel |
2234 return NotificationModel().make_description(self) | 2234 return NotificationModel().make_description(self) |
2235 | 2235 |
2236 | 2236 |
2237 class UserNotification(Base, BaseModel): | 2237 class UserNotification(Base, BaseModel): |
2238 __tablename__ = 'user_to_notification' | 2238 __tablename__ = 'user_to_notification' |
2287 @classmethod | 2287 @classmethod |
2288 def get_by_access_id(cls, gist_access_id): | 2288 def get_by_access_id(cls, gist_access_id): |
2289 return cls.query().filter(cls.gist_access_id == gist_access_id).scalar() | 2289 return cls.query().filter(cls.gist_access_id == gist_access_id).scalar() |
2290 | 2290 |
2291 def gist_url(self): | 2291 def gist_url(self): |
2292 import rhodecode | 2292 import kallithea |
2293 alias_url = rhodecode.CONFIG.get('gist_alias_url') | 2293 alias_url = kallithea.CONFIG.get('gist_alias_url') |
2294 if alias_url: | 2294 if alias_url: |
2295 return alias_url.replace('{gistid}', self.gist_access_id) | 2295 return alias_url.replace('{gistid}', self.gist_access_id) |
2296 | 2296 |
2297 from pylons import url | 2297 from pylons import url |
2298 return url('gist', gist_id=self.gist_access_id, qualified=True) | 2298 return url('gist', gist_id=self.gist_access_id, qualified=True) |
2302 """ | 2302 """ |
2303 Returns base path when all gists are stored | 2303 Returns base path when all gists are stored |
2304 | 2304 |
2305 :param cls: | 2305 :param cls: |
2306 """ | 2306 """ |
2307 from rhodecode.model.gist import GIST_STORE_LOC | 2307 from kallithea.model.gist import GIST_STORE_LOC |
2308 q = Session().query(RhodeCodeUi)\ | 2308 q = Session().query(RhodeCodeUi)\ |
2309 .filter(RhodeCodeUi.ui_key == URL_SEP) | 2309 .filter(RhodeCodeUi.ui_key == URL_SEP) |
2310 q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | 2310 q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
2311 return os.path.join(q.one().ui_value, GIST_STORE_LOC) | 2311 return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
2312 | 2312 |
2333 return data | 2333 return data |
2334 ## SCM functions | 2334 ## SCM functions |
2335 | 2335 |
2336 @property | 2336 @property |
2337 def scm_instance(self): | 2337 def scm_instance(self): |
2338 from rhodecode.lib.vcs import get_repo | 2338 from kallithea.lib.vcs import get_repo |
2339 base_path = self.base_path() | 2339 base_path = self.base_path() |
2340 return get_repo(os.path.join(*map(safe_str, | 2340 return get_repo(os.path.join(*map(safe_str, |
2341 [base_path, self.gist_access_id]))) | 2341 [base_path, self.gist_access_id]))) |
2342 | 2342 |
2343 | 2343 |