Changeset - 260a7a01b054
[Not reviewed]
beta
0 23 0
Mads Kiilerich - 13 years ago 2013-03-28 01:10:45
madski@unity3d.com
follow Python conventions for boolean values

True and False might be singletons and the "default" values for "boolean"
expressions, but "all" values in Python has a boolean value and should be
evaluated as such. Checking with 'is True' and 'is False' is thus confusing,
error prone and unnessarily complex.

If we anywhere rely and nullable boolean fields from the database layer and
don't want the null value to be treated as False then we should check
explicitly for null with 'is None'.
23 files changed with 37 insertions and 37 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/admin/notifications.py
Show inline comments
 
@@ -159,7 +159,7 @@ class NotificationsController(BaseContro
 
            # if this association to user is not valid, we don't want to show
 
            # this message
 
            if unotification:
 
                if unotification.read is False:
 
                if not unotification.read:
 
                    unotification.mark_as_read()
 
                    Session().commit()
 
                c.notification = no
rhodecode/controllers/admin/repos_groups.py
Show inline comments
 
@@ -348,7 +348,7 @@ class ReposGroupsController(BaseControll
 
            .filter(RepoGroup.group_parent_id == c.group.group_id).all()
 
        c.groups = self.scm_model.get_repos_groups(groups)
 

	
 
        if c.visual.lightweight_dashboard is False:
 
        if not c.visual.lightweight_dashboard:
 
            c.repos_list = self.scm_model.get_repos(all_repos=gr_filter)
 
        ## lightweight version of dashboard
 
        else:
rhodecode/controllers/files.py
Show inline comments
 
@@ -416,7 +416,7 @@ class FilesController(BaseRepoController
 

	
 
        try:
 
            dbrepo = RepoModel().get_by_repo_name(repo_name)
 
            if dbrepo.enable_downloads is False:
 
            if not dbrepo.enable_downloads:
 
                return _('downloads disabled')
 

	
 
            if c.rhodecode_repo.alias == 'hg':
rhodecode/controllers/home.py
Show inline comments
 
@@ -52,7 +52,7 @@ class HomeController(BaseController):
 
        c.groups = self.scm_model.get_repos_groups()
 
        c.group = None
 

	
 
        if c.visual.lightweight_dashboard is False:
 
        if not c.visual.lightweight_dashboard:
 
            c.repos_list = self.scm_model.get_repos()
 
        ## lightweight version of dashboard
 
        else:
rhodecode/controllers/login.py
Show inline comments
 
@@ -76,7 +76,7 @@ class LoginController(BaseController):
 
                Session().commit()
 

	
 
                # If they want to be remembered, update the cookie
 
                if c.form_result['remember'] is not False:
 
                if c.form_result['remember']:
 
                    _year = (datetime.datetime.now() +
 
                             datetime.timedelta(seconds=60 * 60 * 24 * 365))
 
                    session._set_cookie_expires(_year)
rhodecode/lib/auth.py
Show inline comments
 
@@ -381,7 +381,7 @@ class  AuthUser(object):
 

	
 
        if not is_user_loaded:
 
            # if we cannot authenticate user try anonymous
 
            if self.anonymous_user.active is True:
 
            if self.anonymous_user.active:
 
                user_model.fill_data(self, user_id=self.anonymous_user.user_id)
 
                # then we set this user is logged in
 
                self.is_authenticated = True
rhodecode/lib/celerylib/__init__.py
Show inline comments
 
@@ -124,7 +124,7 @@ def dbsession(func):
 
            ret = func(*fargs, **fkwargs)
 
            return ret
 
        finally:
 
            if CELERY_ON and CELERY_EAGER is False:
 
            if CELERY_ON and not CELERY_EAGER:
 
                meta.Session.remove()
 

	
 
    return decorator(__wrapper, func)
rhodecode/lib/db_manage.py
Show inline comments
 
@@ -69,9 +69,9 @@ class DbManage(object):
 
        self.init_db()
 
        global ask_ok
 

	
 
        if self.cli_args.get('force_ask') is True:
 
        if self.cli_args.get('force_ask'):
 
            ask_ok = lambda *args, **kwargs: True
 
        elif self.cli_args.get('force_ask') is False:
 
        elif not self.cli_args.get('force_ask'):
 
            ask_ok = lambda *args, **kwargs: False
 

	
 
    def init_db(self):
 
@@ -589,7 +589,7 @@ class DbManage(object):
 

	
 
        if retries == 0:
 
            sys.exit('max retries reached')
 
        if path_ok is False:
 
        if not path_ok:
 
            retries -= 1
 
            return self.config_prompt(test_repo_path, retries)
 

	
rhodecode/lib/diffs.py
Show inline comments
 
@@ -421,7 +421,7 @@ class DiffProcessor(object):
 

	
 
        sorter = lambda info: {'A': 0, 'M': 1, 'D': 2}.get(info['operation'])
 

	
 
        if inline_diff is False:
 
        if not inline_diff:
 
            return diff_container(sorted(_files, key=sorter))
 

	
 
        # highlight inline changes
rhodecode/lib/hooks.py
Show inline comments
 
@@ -143,7 +143,7 @@ def log_pull_action(ui, repo, **kwargs):
 
        kw.update(ex)
 
        callback(**kw)
 

	
 
    if ex.make_lock is True:
 
    if ex.make_lock:
 
        Repository.lock(Repository.get_by_repo_name(ex.repository), user.user_id)
 
        #msg = 'Made lock on repo `%s`' % repository
 
        #sys.stdout.write(msg)
 
@@ -202,7 +202,7 @@ def log_push_action(ui, repo, **kwargs):
 
        kw.update(ex)
 
        callback(**kw)
 

	
 
    if ex.make_lock is False:
 
    if not ex.make_lock:
 
        Repository.unlock(Repository.get_by_repo_name(ex.repository))
 
        msg = 'Released lock on repo `%s`\n' % ex.repository
 
        sys.stdout.write(msg)
rhodecode/lib/middleware/simplegit.py
Show inline comments
 
@@ -126,7 +126,7 @@ class SimpleGit(BaseVCSController):
 
            return HTTPInternalServerError()(environ, start_response)
 

	
 
        # quick check if that dir exists...
 
        if is_valid_repo(repo_name, self.basepath, 'git') is False:
 
        if not is_valid_repo(repo_name, self.basepath, 'git'):
 
            return HTTPNotFound()(environ, start_response)
 

	
 
        #======================================================================
 
@@ -143,11 +143,11 @@ class SimpleGit(BaseVCSController):
 
            anonymous_perm = self._check_permission(action, anonymous_user,
 
                                                    repo_name, ip_addr)
 

	
 
            if anonymous_perm is not True or anonymous_user.active is False:
 
                if anonymous_perm is not True:
 
            if not anonymous_perm or not anonymous_user.active:
 
                if not anonymous_perm:
 
                    log.debug('Not enough credentials to access this '
 
                              'repository as anonymous user')
 
                if anonymous_user.active is False:
 
                if not anonymous_user.active:
 
                    log.debug('Anonymous access is disabled, running '
 
                              'authentication')
 
                #==============================================================
 
@@ -184,7 +184,7 @@ class SimpleGit(BaseVCSController):
 

	
 
                #check permissions for this repository
 
                perm = self._check_permission(action, user, repo_name, ip_addr)
 
                if perm is not True:
 
                if not perm:
 
                    return HTTPForbidden()(environ, start_response)
 

	
 
        # extras are injected into UI object and later available
rhodecode/lib/middleware/simplehg.py
Show inline comments
 
@@ -89,7 +89,7 @@ class SimpleHg(BaseVCSController):
 
            return HTTPInternalServerError()(environ, start_response)
 

	
 
        # quick check if that dir exists...
 
        if is_valid_repo(repo_name, self.basepath, 'hg') is False:
 
        if not is_valid_repo(repo_name, self.basepath, 'hg'):
 
            return HTTPNotFound()(environ, start_response)
 

	
 
        #======================================================================
 
@@ -106,11 +106,11 @@ class SimpleHg(BaseVCSController):
 
            anonymous_perm = self._check_permission(action, anonymous_user,
 
                                                    repo_name, ip_addr)
 

	
 
            if anonymous_perm is not True or anonymous_user.active is False:
 
                if anonymous_perm is not True:
 
            if not anonymous_perm or not anonymous_user.active:
 
                if not anonymous_perm:
 
                    log.debug('Not enough credentials to access this '
 
                              'repository as anonymous user')
 
                if anonymous_user.active is False:
 
                if not anonymous_user.active:
 
                    log.debug('Anonymous access is disabled, running '
 
                              'authentication')
 
                #==============================================================
 
@@ -147,7 +147,7 @@ class SimpleHg(BaseVCSController):
 

	
 
                #check permissions for this repository
 
                perm = self._check_permission(action, user, repo_name, ip_addr)
 
                if perm is not True:
 
                if not perm:
 
                    return HTTPForbidden()(environ, start_response)
 

	
 
        # extras are injected into mercurial UI object and later available
rhodecode/lib/rcmail/response.py
Show inline comments
 
@@ -444,7 +444,7 @@ def properly_encode_header(value, encode
 
    try:
 
        return value.encode("ascii")
 
    except UnicodeEncodeError:
 
        if not_email is False and VALUE_IS_EMAIL_ADDRESS(value):
 
        if not not_email and VALUE_IS_EMAIL_ADDRESS(value):
 
            # this could have an email address, make sure we don't screw it up
 
            name, address = parseaddr(value)
 
            return '"%s" <%s>' % (
rhodecode/model/db.py
Show inline comments
 
@@ -1698,7 +1698,7 @@ class CacheInvalidation(Base, BaseModel)
 
        cache_key = cls._get_cache_key(key)
 
        inv = cls._get_or_create_inv_obj(cache_key, repo_name)
 

	
 
        if inv and inv.cache_active is False:
 
        if inv and not inv.cache_active:
 
            return inv
 

	
 
    @classmethod
rhodecode/model/notification.py
Show inline comments
 
@@ -100,7 +100,7 @@ class NotificationModel(BaseModel):
 
            body=body, recipients=recipients_objs, type_=type_
 
        )
 

	
 
        if with_email is False:
 
        if not with_email:
 
            return notif
 

	
 
        #don't send email to person who created this comment
rhodecode/model/permission.py
Show inline comments
 
@@ -120,7 +120,7 @@ class PermissionModel(BaseModel):
 
                               .all():
 

	
 
                    #don't reset PRIVATE repositories
 
                    if r2p.repository.private is False:
 
                    if not r2p.repository.private:
 
                        r2p.permission = _def
 
                        self.sa.add(r2p)
 

	
rhodecode/model/user.py
Show inline comments
 
@@ -132,7 +132,7 @@ class UserModel(BaseModel):
 
            new_user.username = username
 
            new_user.admin = admin
 
            # set password only if creating an user or password is changed
 
            if edit is False or user.password != password:
 
            if not edit or user.password != password:
 
                new_user.password = get_crypt_password(password)
 
                new_user.api_key = generate_api_key(username)
 
            new_user.email = email
rhodecode/model/users_group.py
Show inline comments
 
@@ -102,7 +102,7 @@ class UserGroupModel(BaseModel):
 
            assigned_groups = UserGroupRepoToPerm.query()\
 
                .filter(UserGroupRepoToPerm.users_group == users_group).all()
 

	
 
            if assigned_groups and force is False:
 
            if assigned_groups and not force:
 
                raise UserGroupsAssignedException('RepoGroup assigned to %s' %
 
                                                   assigned_groups)
 

	
rhodecode/model/validators.py
Show inline comments
 
@@ -280,7 +280,7 @@ def ValidAuth():
 

	
 
            if not authenticate(username, password):
 
                user = User.get_by_username(username)
 
                if user and user.active is False:
 
                if user and not user.active:
 
                    log.warning('user %s is disabled' % username)
 
                    msg = M(self, 'disabled_account', state)
 
                    raise formencode.Invalid(msg, value, state,
 
@@ -503,7 +503,7 @@ def CanWriteGroup(old_data=None):
 
                        error_dict=dict(repo_type=msg)
 
                    )
 
                ## check if we can write to root location !
 
                elif gr is None and can_create_repos() is False:
 
                elif gr is None and not can_create_repos():
 
                    msg = M(self, 'permission_denied_root', state)
 
                    raise formencode.Invalid(msg, value, state,
 
                        error_dict=dict(repo_type=msg)
 
@@ -533,7 +533,7 @@ def CanCreateGroup(can_create_in_root=Fa
 
                #we can create in root, we're fine no validations required
 
                return
 

	
 
            forbidden_in_root = gr is None and can_create_in_root is False
 
            forbidden_in_root = gr is None and not can_create_in_root
 
            val = HasReposGroupPermissionAny('group.admin')
 
            forbidden = not val(gr_name, 'can create group validator')
 
            if forbidden_in_root or forbidden:
rhodecode/templates/files/files_source.html
Show inline comments
 
@@ -25,7 +25,7 @@
 
              ${h.link_to(_('show as raw'),h.url('files_raw_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path),class_="ui-btn")}
 
              ${h.link_to(_('download as raw'),h.url('files_rawfile_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path),class_="ui-btn")}
 
              % if h.HasRepoPermissionAny('repository.write','repository.admin')(c.repo_name):
 
               % if c.on_branch_head and c.changeset.branch and c.file.is_binary is False:
 
               % if c.on_branch_head and c.changeset.branch and not c.file.is_binary:
 
                ${h.link_to(_('edit on branch:%s') % c.changeset.branch,h.url('files_edit_home',repo_name=c.repo_name,revision=c.changeset.branch,f_path=c.f_path),class_="ui-btn")}
 
               %else:
 
                ${h.link_to(_('edit on branch:?'), '#', class_="ui-btn disabled tooltip", title=_('Editing files allowed only when on branch head revision'))}
rhodecode/templates/index_base.html
Show inline comments
 
@@ -72,7 +72,7 @@
 
            </div>
 
             <%cnt=0%>
 
             <%namespace name="dt" file="/data_table/_dt_elements.html"/>
 
            % if c.visual.lightweight_dashboard is False:
 
            % if not c.visual.lightweight_dashboard:
 
              ## old full detailed version
 
            <div id='repos_list_wrap' class="yui-skin-sam">
 
            <table id="repos_list">
 
@@ -131,7 +131,7 @@
 
            % endif
 
        </div>
 
    </div>
 
    % if c.visual.lightweight_dashboard is False:
 
    % if not c.visual.lightweight_dashboard:
 
    <script>
 
      YUD.get('repo_count').innerHTML = ${cnt+1 if cnt else 0};
 

	
rhodecode/templates/summary/summary.html
Show inline comments
 
@@ -146,7 +146,7 @@ ${self.context_bar('summary')}
 
              <div class="input ${summary(c.show_stats)}">
 
                %if len(c.rhodecode_repo.revisions) == 0:
 
                  ${_('There are no downloads yet')}
 
                %elif c.enable_downloads is False:
 
                %elif not c.enable_downloads:
 
                  ${_('Downloads are disabled for this repository')}
 
                    %if h.HasPermissionAll('hg.admin')('enable downloads on from summary'):
 
                        ${h.link_to(_('enable'),h.url('edit_repo',repo_name=c.repo_name),class_="ui-btn")}
rhodecode/tests/scripts/test_concurency.py
Show inline comments
 
@@ -183,7 +183,7 @@ def test_clone_with_credentials(no_error
 
    else:
 
        stdout, stderr = Command(cwd).execute(backend, method, clone_url, dest)
 
        print stdout,'sdasdsadsa'
 
        if no_errors is False:
 
        if not no_errors:
 
            if backend == 'hg':
 
                assert """adding file changes""" in stdout, 'no messages about cloning'
 
                assert """abort""" not in stderr , 'got error from clone'
0 comments (0 inline, 0 general)