comparison rhodecode/lib/dbmigrate/schema/db_2_1_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 48ad84558fb4
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 #==============================================================================
304 304
305 @classmethod 305 @classmethod
306 def get_server_info(cls): 306 def get_server_info(cls):
307 import pkg_resources 307 import pkg_resources
308 import platform 308 import platform
309 import rhodecode 309 import kallithea
310 from rhodecode.lib.utils import check_git_version 310 from kallithea.lib.utils import check_git_version
311 mods = [(p.project_name, p.version) for p in pkg_resources.working_set] 311 mods = [(p.project_name, p.version) for p in pkg_resources.working_set]
312 info = { 312 info = {
313 'modules': sorted(mods, key=lambda k: k[0].lower()), 313 'modules': sorted(mods, key=lambda k: k[0].lower()),
314 'py_version': platform.python_version(), 314 'py_version': platform.python_version(),
315 'platform': safe_unicode(platform.platform()), 315 'platform': safe_unicode(platform.platform()),
316 'rhodecode_version': rhodecode.__version__, 316 'rhodecode_version': kallithea.__version__,
317 'git_version': safe_unicode(check_git_version()), 317 'git_version': safe_unicode(check_git_version()),
318 'git_path': rhodecode.CONFIG.get('git_path') 318 'git_path': kallithea.CONFIG.get('git_path')
319 } 319 }
320 return info 320 return info
321 321
322 322
323 class RhodeCodeUi(Base, BaseModel): 323 class RhodeCodeUi(Base, BaseModel):
484 @property 484 @property
485 def AuthUser(self): 485 def AuthUser(self):
486 """ 486 """
487 Returns instance of AuthUser for this user 487 Returns instance of AuthUser for this user
488 """ 488 """
489 from rhodecode.lib.auth import AuthUser 489 from kallithea.lib.auth import AuthUser
490 return AuthUser(user_id=self.user_id, api_key=self.api_key, 490 return AuthUser(user_id=self.user_id, api_key=self.api_key,
491 username=self.username) 491 username=self.username)
492 492
493 def __unicode__(self): 493 def __unicode__(self):
494 return u"<%s('id:%s:%s')>" % (self.__class__.__name__, 494 return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
561 """ 561 """
562 Tries to get User objects out of commit author string 562 Tries to get User objects out of commit author string
563 563
564 :param author: 564 :param author:
565 """ 565 """
566 from rhodecode.lib.helpers import email, author_name 566 from kallithea.lib.helpers import email, author_name
567 # Valid email in the attribute passed, see if they're in the system 567 # Valid email in the attribute passed, see if they're in the system
568 _email = email(author) 568 _email = email(author)
569 if _email: 569 if _email:
570 user = cls.get_by_email(_email, case_insensitive=True) 570 user = cls.get_by_email(_email, case_insensitive=True)
571 if user: 571 if user:
696 active = Column("active", Boolean(), nullable=True, unique=None, default=True) 696 active = Column("active", Boolean(), nullable=True, unique=None, default=True)
697 user = relationship('User', lazy='joined') 697 user = relationship('User', lazy='joined')
698 698
699 @classmethod 699 @classmethod
700 def _get_ip_range(cls, ip_addr): 700 def _get_ip_range(cls, ip_addr):
701 from rhodecode.lib import ipaddr 701 from kallithea.lib import ipaddr
702 net = ipaddr.IPNetwork(address=ip_addr) 702 net = ipaddr.IPNetwork(address=ip_addr)
703 return [str(net.network), str(net.broadcast)] 703 return [str(net.network), str(net.broadcast)]
704 704
705 def __json__(self): 705 def __json__(self):
706 return dict( 706 return dict(
958 else: 958 else:
959 self._locked = None 959 self._locked = None
960 960
961 @hybrid_property 961 @hybrid_property
962 def changeset_cache(self): 962 def changeset_cache(self):
963 from rhodecode.lib.vcs.backends.base import EmptyChangeset 963 from kallithea.lib.vcs.backends.base import EmptyChangeset
964 dummy = EmptyChangeset().__json__() 964 dummy = EmptyChangeset().__json__()
965 if not self._changeset_cache: 965 if not self._changeset_cache:
966 return dummy 966 return dummy
967 try: 967 try:
968 return json.loads(self._changeset_cache) 968 return json.loads(self._changeset_cache)
1102 @property 1102 @property
1103 def _ui(self): 1103 def _ui(self):
1104 """ 1104 """
1105 Creates an db based ui object for this repository 1105 Creates an db based ui object for this repository
1106 """ 1106 """
1107 from rhodecode.lib.utils import make_ui 1107 from kallithea.lib.utils import make_ui
1108 return make_ui('db', clear_session=False) 1108 return make_ui('db', clear_session=False)
1109 1109
1110 @classmethod 1110 @classmethod
1111 def is_valid(cls, repo_name): 1111 def is_valid(cls, repo_name):
1112 """ 1112 """
1113 returns True if given repo name is a valid filesystem repository 1113 returns True if given repo name is a valid filesystem repository
1114 1114
1115 :param cls: 1115 :param cls:
1116 :param repo_name: 1116 :param repo_name:
1117 """ 1117 """
1118 from rhodecode.lib.utils import is_valid_repo 1118 from kallithea.lib.utils import is_valid_repo
1119 1119
1120 return is_valid_repo(repo_name, cls.base_path()) 1120 return is_valid_repo(repo_name, cls.base_path())
1121 1121
1122 def get_api_data(self): 1122 def get_api_data(self):
1123 """ 1123 """
1222 date 1222 date
1223 author 1223 author
1224 1224
1225 :param cs_cache: 1225 :param cs_cache:
1226 """ 1226 """
1227 from rhodecode.lib.vcs.backends.base import BaseChangeset 1227 from kallithea.lib.vcs.backends.base import BaseChangeset
1228 if cs_cache is None: 1228 if cs_cache is None:
1229 cs_cache = EmptyChangeset() 1229 cs_cache = EmptyChangeset()
1230 # use no-cache version here 1230 # use no-cache version here
1231 scm_repo = self.scm_instance_no_cache() 1231 scm_repo = self.scm_instance_no_cache()
1232 if scm_repo: 1232 if scm_repo:
1306 grouped[stat.revision] = [str(stat.status), stat.status_lbl, 1306 grouped[stat.revision] = [str(stat.status), stat.status_lbl,
1307 pr_id, pr_repo] 1307 pr_id, pr_repo]
1308 return grouped 1308 return grouped
1309 1309
1310 def _repo_size(self): 1310 def _repo_size(self):
1311 from rhodecode.lib import helpers as h 1311 from kallithea.lib import helpers as h
1312 log.debug('calculating repository size...') 1312 log.debug('calculating repository size...')
1313 return h.format_byte_size(self.scm_instance.size) 1313 return h.format_byte_size(self.scm_instance.size)
1314 1314
1315 #========================================================================== 1315 #==========================================================================
1316 # SCM CACHE INSTANCE 1316 # SCM CACHE INSTANCE
1325 def scm_instance_no_cache(self): 1325 def scm_instance_no_cache(self):
1326 return self.__get_instance() 1326 return self.__get_instance()
1327 1327
1328 @property 1328 @property
1329 def scm_instance(self): 1329 def scm_instance(self):
1330 import rhodecode 1330 import kallithea
1331 full_cache = str2bool(rhodecode.CONFIG.get('vcs_full_cache')) 1331 full_cache = str2bool(kallithea.CONFIG.get('vcs_full_cache'))
1332 if full_cache: 1332 if full_cache:
1333 return self.scm_instance_cached() 1333 return self.scm_instance_cached()
1334 return self.__get_instance() 1334 return self.__get_instance()
1335 1335
1336 def scm_instance_cached(self, valid_cache_keys=None): 1336 def scm_instance_cached(self, valid_cache_keys=None):
1977 def _get_cache_key(cls, key): 1977 def _get_cache_key(cls, key):
1978 """ 1978 """
1979 Wrapper for generating a unique cache key for this instance and "key". 1979 Wrapper for generating a unique cache key for this instance and "key".
1980 key must / will start with a repo_name which will be stored in .cache_args . 1980 key must / will start with a repo_name which will be stored in .cache_args .
1981 """ 1981 """
1982 import rhodecode 1982 import kallithea
1983 prefix = rhodecode.CONFIG.get('instance_id', '') 1983 prefix = kallithea.CONFIG.get('instance_id', '')
1984 return "%s%s" % (prefix, key) 1984 return "%s%s" % (prefix, key)
1985 1985
1986 @classmethod 1986 @classmethod
1987 def set_invalidate(cls, repo_name, delete=False): 1987 def set_invalidate(cls, repo_name, delete=False):
1988 """ 1988 """
2267 Session().add(notification) 2267 Session().add(notification)
2268 return notification 2268 return notification
2269 2269
2270 @property 2270 @property
2271 def description(self): 2271 def description(self):
2272 from rhodecode.model.notification import NotificationModel 2272 from kallithea.model.notification import NotificationModel
2273 return NotificationModel().make_description(self) 2273 return NotificationModel().make_description(self)
2274 2274
2275 2275
2276 class UserNotification(Base, BaseModel): 2276 class UserNotification(Base, BaseModel):
2277 __tablename__ = 'user_to_notification' 2277 __tablename__ = 'user_to_notification'
2326 @classmethod 2326 @classmethod
2327 def get_by_access_id(cls, gist_access_id): 2327 def get_by_access_id(cls, gist_access_id):
2328 return cls.query().filter(cls.gist_access_id == gist_access_id).scalar() 2328 return cls.query().filter(cls.gist_access_id == gist_access_id).scalar()
2329 2329
2330 def gist_url(self): 2330 def gist_url(self):
2331 import rhodecode 2331 import kallithea
2332 alias_url = rhodecode.CONFIG.get('gist_alias_url') 2332 alias_url = kallithea.CONFIG.get('gist_alias_url')
2333 if alias_url: 2333 if alias_url:
2334 return alias_url.replace('{gistid}', self.gist_access_id) 2334 return alias_url.replace('{gistid}', self.gist_access_id)
2335 2335
2336 from pylons import url 2336 from pylons import url
2337 return url('gist', gist_id=self.gist_access_id, qualified=True) 2337 return url('gist', gist_id=self.gist_access_id, qualified=True)
2341 """ 2341 """
2342 Returns base path when all gists are stored 2342 Returns base path when all gists are stored
2343 2343
2344 :param cls: 2344 :param cls:
2345 """ 2345 """
2346 from rhodecode.model.gist import GIST_STORE_LOC 2346 from kallithea.model.gist import GIST_STORE_LOC
2347 q = Session().query(RhodeCodeUi)\ 2347 q = Session().query(RhodeCodeUi)\
2348 .filter(RhodeCodeUi.ui_key == URL_SEP) 2348 .filter(RhodeCodeUi.ui_key == URL_SEP)
2349 q = q.options(FromCache("sql_cache_short", "repository_repo_path")) 2349 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
2350 return os.path.join(q.one().ui_value, GIST_STORE_LOC) 2350 return os.path.join(q.one().ui_value, GIST_STORE_LOC)
2351 2351
2372 return data 2372 return data
2373 ## SCM functions 2373 ## SCM functions
2374 2374
2375 @property 2375 @property
2376 def scm_instance(self): 2376 def scm_instance(self):
2377 from rhodecode.lib.vcs import get_repo 2377 from kallithea.lib.vcs import get_repo
2378 base_path = self.base_path() 2378 base_path = self.base_path()
2379 return get_repo(os.path.join(*map(safe_str, 2379 return get_repo(os.path.join(*map(safe_str,
2380 [base_path, self.gist_access_id]))) 2380 [base_path, self.gist_access_id])))
2381 2381
2382 2382