def fixups(models, _SESSION): notify('Fixing existing GA code into new format') cur_code = get_by_name(models.RhodeCodeSetting, 'ga_code') val = ''' <script> // google analytics var _gaq_code = '_GACODE_'; var _gaq = _gaq || []; _gaq.push(['_setAccount', _gaq_code]); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); rhodecode_statechange_callback = function(url, data){ // ANALYTICS callback on html5 history state changed // triggered by file browser, url is the new url, // data is extra info passed from the State object if ( typeof window._gaq !== 'undefined' ) { _gaq.push(['_trackPageview', url]); } } </script>''' if cur_code and getattr(cur_code, 'app_settings_value', ''): cur_val = getattr(cur_code, 'app_settings_value', '') val = val.replace('_GACODE_', cur_val) notify('Found GA code %s, migrating' % cur_val) new = get_by_name_or_create(models.RhodeCodeSetting, 'pre_code', val) new.app_settings_value = val _SESSION().add(new) _SESSION().commit()
def fixups(models, _SESSION): notify('fixing new schema for landing_rev') for repo in models.Repository.get_all(): print u'repo %s old landing rev is: %s' % (repo, repo.landing_rev) _rev = repo.landing_rev[1] _rev_type = 'rev' # default if _rev in ['default', 'master']: _rev_type = 'branch' elif _rev in ['tip']: _rev_type = 'rev' else: try: scm = repo.scm_instance if scm: known_branches = scm.branches.keys() known_bookmarks = scm.bookmarks.keys() if _rev in known_branches: _rev_type = 'branch' elif _rev in known_bookmarks: _rev_type = 'book' except Exception as e: print e print 'continue...' #we don't want any error to break the process pass _new_landing_rev = '%s:%s' % (_rev_type, _rev) print u'setting to %s' % _new_landing_rev repo.landing_rev = _new_landing_rev _SESSION().add(repo) _SESSION().commit()
def fixups(models, _SESSION): notify('Upgrading repositories Caches') repositories = models.Repository.getAll() for repo in repositories: print repo repo.update_commit_cache() _SESSION().commit()
def fixups(models, _SESSION): notify('Setting default renderer to rst') for cs_comment in models.ChangesetComment.get_all(): print 'comment_id %s renderer rst' % (cs_comment.comment_id) cs_comment.renderer = 'rst' _SESSION().add(cs_comment) _SESSION().commit()
def fixups(models, _SESSION): Optional = models.Optional def get_by_name(cls, key): return cls.query().filter(cls.app_settings_name == key).scalar() def create_or_update(cls, key, val=Optional(''), type=Optional('unicode')): res = get_by_name(cls, key) if not res: val = Optional.extract(val) type = Optional.extract(type) res = cls(key, val, type) else: res.app_settings_name = key if not isinstance(val, Optional): # update if set res.app_settings_value = val if not isinstance(type, Optional): # update if set res.app_settings_type = type return res notify('Creating upgrade URL') sett = create_or_update(models.RhodeCodeSetting, 'update_url', models.RhodeCodeSetting.DEFAULT_UPDATE_URL, 'unicode') _SESSION().add(sett) _SESSION.commit()
def fixups(models, _SESSION): notify('Fixing auth tokens roles') _role = models.UserApiKeys.ROLE_ALL for token in models.UserApiKeys.get_all(): print 'setting key %s role to "%s"' % (token, _role) token.role = _role _SESSION().add(token) _SESSION().commit()
def fixups(models, _SESSION): notify('Creating repository states') _state = models.Repository.STATE_CREATED for repo in models.Repository.get_all(): print 'setting repo %s state to "%s"' % (repo, _state) repo.repo_state = _state _SESSION().add(repo) _SESSION().commit()
def fixups(models, _SESSION): from pylons import config from rhodecode.lib.utils2 import str2bool Optional = models.Optional def get_by_name(cls, key): return cls.query().filter(cls.app_settings_name == key).scalar() def create_or_update(cls, key, val=Optional(''), type=Optional('unicode')): res = get_by_name(cls, key) if not res: val = Optional.extract(val) type = Optional.extract(type) res = cls(key, val, type) else: res.app_settings_name = key if not isinstance(val, Optional): # update if set res.app_settings_value = val if not isinstance(type, Optional): # update if set res.app_settings_type = type return res notify('migrating options from .ini file') use_gravatar = str2bool(config.get('use_gravatar')) print('Setting gravatar use to: %s' % use_gravatar) sett = create_or_update(models.RhodeCodeSetting, 'use_gravatar', use_gravatar, 'bool') _SESSION().add(sett) _SESSION.commit() # set the new format of gravatar URL gravatar_url = models.User.DEFAULT_GRAVATAR_URL if config.get('alternative_gravatar_url'): gravatar_url = config.get('alternative_gravatar_url') print('Setting gravatar url to:%s' % gravatar_url) sett = create_or_update(models.RhodeCodeSetting, 'gravatar_url', gravatar_url, 'unicode') _SESSION().add(sett) _SESSION.commit() # now create new changed value of clone_url clone_uri_tmpl = models.Repository.DEFAULT_CLONE_URI print('settings new clone url template to %s' % clone_uri_tmpl) sett = create_or_update(models.RhodeCodeSetting, 'clone_uri_tmpl', clone_uri_tmpl, 'unicode') _SESSION().add(sett) _SESSION.commit()
def fixups(models, _SESSION): notify('Adding grid items options now...') settings = [ ('admin_grid_items', 25, 'int'), # old hardcoded value was 25 ] for name, default, type_ in settings: setting = get_by_name(models.RhodeCodeSetting, name) if not setting: # if we don't have this option create it setting = models.RhodeCodeSetting(name, default, type_) setting._app_settings_type = type_ _SESSION().add(setting) _SESSION().commit()
def fixups(models, _SESSION): notify('Adding revision look items options now...') settings = [ ('show_revision_number', True, 'bool'), ('show_sha_length', 12, 'int'), ] for name, default, type_ in settings: setting = get_by_name(models.RhodeCodeSetting, name) if not setting: # if we don't have this option create it setting = models.RhodeCodeSetting(name, default, type_) setting._app_settings_type = type_ _SESSION().add(setting) _SESSION().commit()
def fixups(models, _SESSION): notify('Fixing default auth modules') plugins = 'rhodecode.lib.auth_modules.auth_rhodecode' opts = [] ldap_enabled = str2bool( getattr(get_by_name(models.RhodeCodeSetting, 'ldap_active'), 'app_settings_value', False)) if ldap_enabled: plugins += ',rhodecode.lib.auth_modules.auth_ldap' opts.append(('auth_ldap_enabled', 'True', 'bool')) opts.append(('auth_plugins', plugins, 'list'), ) opts.append(('auth_rhodecode_enabled', 'True', 'bool')) for name, default, type_ in opts: setting = get_by_name(models.RhodeCodeSetting, name) if not setting: # if we don't have this option create it setting = models.RhodeCodeSetting(name, default, type_) _SESSION().add(setting) _SESSION().commit() #copy over the LDAP settings old_ldap = [ ('ldap_active', 'false', 'bool'), ('ldap_host', '', 'unicode'), ('ldap_port', '389', 'int'), ('ldap_tls_kind', 'PLAIN', 'unicode'), ('ldap_tls_reqcert', '', 'unicode'), ('ldap_dn_user', '', 'unicode'), ('ldap_dn_pass', '', 'unicode'), ('ldap_base_dn', '', 'unicode'), ('ldap_filter', '', 'unicode'), ('ldap_search_scope', '', 'unicode'), ('ldap_attr_login', '', 'unicode'), ('ldap_attr_firstname', '', 'unicode'), ('ldap_attr_lastname', '', 'unicode'), ('ldap_attr_email', '', 'unicode') ] for k, v, t in old_ldap: old_setting = get_by_name(models.RhodeCodeSetting, k) name = 'auth_%s' % k setting = get_by_name(models.RhodeCodeSetting, name) if not setting: # if we don't have this option create it setting = models.RhodeCodeSetting(name, old_setting.app_settings_value, t) _SESSION().add(setting) _SESSION().commit()
def fixups(models, _SESSION): notify('Fixing default created on') for usr in models.User.get_all(): usr.created_on = datetime.datetime.now() _SESSION().add(usr) _SESSION().commit() notify('Migrating LDAP attribute to extern') for usr in models.User.get_all(): ldap_dn = usr.ldap_dn if ldap_dn: usr.extern_name = ldap_dn usr.extern_type = 'ldap' else: usr.extern_name = 'rhodecode' usr.extern_type = 'rhodecode' _SESSION().add(usr) _SESSION().commit()
def fixups(models, _SESSION): notify('Fixing default options now...') settings = [ #general ('realm', '', 'unicode'), ('title', '', 'unicode'), ('ga_code', '', 'unicode'), ('show_public_icon', False, 'bool'), ('show_private_icon', True, 'bool'), ('stylify_metatags', True, 'bool'), # defaults ('default_repo_enable_locking', False, 'bool'), ('default_repo_enable_downloads', False, 'bool'), ('default_repo_enable_statistics', False, 'bool'), ('default_repo_private', False, 'bool'), ('default_repo_type', 'hg', 'unicode'), #other ('dashboard_items', 100, 'int'), ('show_version', True, 'bool') ] for name, default, type_ in settings: setting = get_by_name(models.RhodeCodeSetting, name) if not setting: # if we don't have this option create it setting = models.RhodeCodeSetting(name, default, type_) # fix certain key to new defaults if name in ['title', 'show_public_icon']: # change title if it's only the default if name == 'title' and setting.app_settings_value == 'RhodeCode': setting.app_settings_value = default else: setting.app_settings_value = default setting._app_settings_type = type_ _SESSION().add(setting) _SESSION().commit()
def fixups(models, _SESSION): notify('Fixing default created on for repo groups') for gr in models.RepoGroup.get_all(): gr.created_on = datetime.datetime.now() _SESSION().add(gr) _SESSION().commit() repo_store_path = get_repos_location(models.RhodeCodeUi) _store = os.path.join(repo_store_path, '.cache', 'largefiles') notify('Setting largefiles usercache') print _store if not models.RhodeCodeUi.query().filter( models.RhodeCodeUi.ui_key == 'usercache').scalar(): largefiles = models.RhodeCodeUi() largefiles.ui_section = 'largefiles' largefiles.ui_key = 'usercache' largefiles.ui_value = _store _SESSION().add(largefiles) _SESSION().commit()
def fixups(models, _SESSION): notify('Fixing default created on') for gr in models.UserGroup.get_all(): gr.created_on = datetime.datetime.now() _SESSION().commit()