Skip to content

Commit

Permalink
feat: remove gettext call from TurboGears
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Styk <mart.styk@gmail.com>
  • Loading branch information
StykMartin committed Feb 8, 2025
1 parent 6f9d19e commit 1c71efb
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 106 deletions.
20 changes: 10 additions & 10 deletions Server/bkr/server/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ def login_password(self, username, password, proxy_user=None):
"""
user = User.by_user_name(username)
if user is None:
raise LoginException(_(u'Invalid username or password'))
raise LoginException(u'Invalid username or password')
if not user.can_log_in():
raise LoginException(_(u'Invalid username or password'))
raise LoginException(u'Invalid username or password')
if not user.check_password(password):
raise LoginException(_(u'Invalid username or password'))
raise LoginException(u'Invalid username or password')
if proxy_user:
if not user.has_permission(u'proxy_auth'):
raise LoginException(_(u'%s does not have proxy_auth permission') % user.user_name)
Expand Down Expand Up @@ -304,20 +304,20 @@ def login_oauth2(self, access_token, proxy_user=None):
token_info = token_info_resp.json()

if not token_info['active']:
raise LoginException(_(u'Invalid token'))
raise LoginException(u'Invalid token')

if not 'https://beaker-project.org/oidc/scope' in token_info.get('scope', '').split(' '):
raise LoginException(_(u'Token missing required scope'))
raise LoginException(u'Token missing required scope')

username = token_info.get('sub')
if not username:
raise LoginException(_(u'Token missing subject'))
raise LoginException(u'Token missing subject')

user = User.by_user_name(username)
if user is None:
raise LoginException(_(u'Invalid username'))
raise LoginException(u'Invalid username')
if not user.can_log_in():
raise LoginException(_(u'Invalid username'))
raise LoginException(u'Invalid username')
if proxy_user:
if not user.has_permission(u'proxy_auth'):
raise LoginException(_(u'%s does not have proxy_auth permission') % user.user_name)
Expand Down Expand Up @@ -371,9 +371,9 @@ def login_krbV(self, krb_request, proxy_user=None):
username = cprinc.name.split("@")[0]
user = User.by_user_name(username)
if user is None:
raise LoginException(_(u'Invalid username'))
raise LoginException(u'Invalid username')
if not user.can_log_in():
raise LoginException(_(u'Invalid username'))
raise LoginException(u'Invalid username')
if proxy_user:
if not user.has_permission(u'proxy_auth'):
raise LoginException(_(u'%s does not have proxy_auth permission') % user.user_name)
Expand Down
10 changes: 5 additions & 5 deletions Server/bkr/server/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def edit(self,**kw):
value = item.current_value()
)
else:
flash(_(u"Error: No item ID specified"))
flash(u"Error: No item ID specified")
raise redirect(".")

# Show all future values, and the previous five
Expand Down Expand Up @@ -100,24 +100,24 @@ def save(self, **kw):
if 'id' in kw and kw['id']:
item = ConfigItem.by_id(kw['id'])
else:
flash(_(u"Error: No item ID"))
flash(u"Error: No item ID")
raise redirect(".")
if kw['valid_from']:
try:
valid_from = datetime.strptime(kw['valid_from'], '%Y-%m-%d %H:%M')
except ValueError:
flash(_(u"Invalid date and time specification, use: YYYY-MM-DD HH:MM"))
flash(u"Invalid date and time specification, use: YYYY-MM-DD HH:MM")
raise redirect("/configuration/edit?id=%d" % item.id)
else:
valid_from = None

try:
item.set(kw['value'], valid_from, identity.current.user)
except Exception as msg:
flash(_(u"Failed to save setting: %s" % msg))
flash(u"Failed to save setting: %s" % msg)
raise redirect("/configuration/edit?id=%d" % item.id)

flash(_(u"%s saved" % item.name))
flash(u"%s saved" % item.name)
redirect(".")

@identity.require(identity.in_group("admin"))
Expand Down
12 changes: 6 additions & 6 deletions Server/bkr/server/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def view(self, id=None, *args, **kw):
try:
distro = Distro.by_id(id)
except InvalidRequestError:
flash(_(u"Invalid distro id %s" % id))
flash(u"Invalid distro id %s" % id)
redirect(".")
is_admin = identity.current.user and identity.current.user.is_admin() or False
task_form = TaskSearchForm(hidden=dict(distro=True, osmajor_id=True))
Expand Down Expand Up @@ -74,7 +74,7 @@ def get_osmajor(self, distro):
try:
osmajor = '%s' % Distro.by_name(distro).osversion.osmajor
except DatabaseLookupError:
raise BX(_('Invalid Distro: %s' % distro))
raise BX('Invalid Distro: %s' % distro)
return osmajor

get_family = get_osmajor
Expand Down Expand Up @@ -108,15 +108,15 @@ def save_tag(self, id=None, tag=None, *args, **kw):
try:
distro = Distro.by_id(id)
except InvalidRequestError:
flash(_(u"Invalid distro id %s" % id))
flash(u"Invalid distro id %s" % id)
redirect(".")
if tag['text']:
distro.tags.append(tag['text'])
distro.activity.append(DistroActivity(
user=identity.current.user, service=u'WEBUI',
action=u'Added', field_name=u'Tag',
old_value=None, new_value=tag['text']))
flash(_(u"Added Tag %s" % tag['text']))
flash(u"Added Tag %s" % tag['text'])
redirect("./view?id=%s" % id)

@cherrypy.expose
Expand All @@ -132,7 +132,7 @@ def tag_remove(self, id=None, tag=None, *args, **kw):
try:
distro = Distro.by_id(id)
except InvalidRequestError:
flash(_(u"Invalid distro id %s" % id))
flash(u"Invalid distro id %s" % id)
redirect(".")
if tag:
for dtag in distro.tags:
Expand All @@ -142,7 +142,7 @@ def tag_remove(self, id=None, tag=None, *args, **kw):
user=identity.current.user, service=u'WEBUI',
action=u'Removed', field_name=u'Tag',
old_value=tag, new_value=None))
flash(_(u"Removed Tag %s" % tag))
flash(u"Removed Tag %s" % tag)
redirect("./view?id=%s" % id)

def _distros(self,distro,**kw):
Expand Down
30 changes: 15 additions & 15 deletions Server/bkr/server/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ def create(self, kw):
password = kw.get('root_password')

if ldap and not identity.current.user.is_admin():
raise BX(_(u'Only admins can create LDAP groups'))
raise BX(u'Only admins can create LDAP groups')
if ldap and not config.get("identity.ldap.enabled", False):
raise BX(_(u'LDAP is not enabled'))
raise BX(u'LDAP is not enabled')
try:
group = Group.by_name(group_name)
except NoResultFound:
Expand All @@ -184,7 +184,7 @@ def create(self, kw):
service=u'XMLRPC', agent=identity.current.user)
return 'Group created: %s.' % group_name
else:
raise BX(_(u'Group already exists: %s.' % group_name))
raise BX(u'Group already exists: %s.' % group_name)

# XML-RPC method for modifying a group
@identity.require(identity.not_anonymous())
Expand Down Expand Up @@ -216,22 +216,22 @@ def modify(self, group_name, kw):
"""
# if not called from the bkr group-modify
if not kw:
raise BX(_('Please specify an attribute to modify.'))
raise BX('Please specify an attribute to modify.')

try:
group = Group.by_name(group_name)
except NoResultFound:
raise BX(_(u'Group does not exist: %s.' % group_name))
raise BX(u'Group does not exist: %s.' % group_name)

if group.membership_type == GroupMembershipType.ldap:
if not identity.current.user.is_admin():
raise BX(_(u'Only admins can modify LDAP groups'))
raise BX(u'Only admins can modify LDAP groups')
if kw.get('add_member', None) or kw.get('remove_member', None):
raise BX(_(u'Cannot edit membership of an LDAP group'))
raise BX(u'Cannot edit membership of an LDAP group')

user = identity.current.user
if not group.can_edit(user):
raise BX(_('You are not an owner of group %s' % group_name))
raise BX('You are not an owner of group %s' % group_name)

group_name = kw.get('group_name', None)
if group_name:
Expand All @@ -258,9 +258,9 @@ def modify(self, group_name, kw):
username = kw.get('add_member')
user = User.by_user_name(username)
if user is None:
raise BX(_(u'User does not exist %s' % username))
raise BX(u'User does not exist %s' % username)
if user.removed:
raise BX(_(u'Cannot add deleted user %s to group' % user.user_name))
raise BX(u'Cannot add deleted user %s to group' % user.user_name)

if user not in group.users:
group.add_member(user, service=u'XMLRPC',
Expand All @@ -269,20 +269,20 @@ def modify(self, group_name, kw):
agent = identity.current.user,
action='Added')
else:
raise BX(_(u'User %s is already in group %s' % (username, group.group_name)))
raise BX(u'User %s is already in group %s' % (username, group.group_name))

if kw.get('remove_member', None):
username = kw.get('remove_member')
user = User.by_user_name(username)

if user is None:
raise BX(_(u'User does not exist %s' % username))
raise BX(u'User does not exist %s' % username)

if user not in group.users:
raise BX(_(u'No user %s in group %s' % (username, group.group_name)))
raise BX(u'No user %s in group %s' % (username, group.group_name))
else:
if not group.can_remove_member(identity.current.user, user.user_id):
raise BX(_(u'Cannot remove member'))
raise BX(u'Cannot remove member')

groupUsers = group.users
for usr in groupUsers:
Expand Down Expand Up @@ -315,7 +315,7 @@ def members(self, group_name):
try:
group = Group.by_name(group_name)
except NoResultFound:
raise BX(_(u'Group does not exist: %s.' % group_name))
raise BX(u'Group does not exist: %s.' % group_name)

users=[]
for u in group.users:
Expand Down
4 changes: 2 additions & 2 deletions Server/bkr/server/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class NotAnonymousPredicate(IdentityPredicate):

def check(self):
if current.anonymous:
raise IdentityFailure(_(u'Anonymous access denied'))
raise IdentityFailure(u'Anonymous access denied')

not_anonymous = NotAnonymousPredicate

Expand All @@ -265,7 +265,7 @@ def __init__(self, group_name):

def check(self):
if current.user is None:
raise IdentityFailure(_(u'Anonymous access denied'))
raise IdentityFailure(u'Anonymous access denied')
if not current.user.in_group([self.group_name]):
raise IdentityFailure(_(u'Not member of group: %s') % self.group_name)

Expand Down
2 changes: 1 addition & 1 deletion Server/bkr/server/job_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def index(self,**kw):
jobs = model.Job.by_whiteboard(kw.get('whiteboard')).filter(not_(model.Job.is_deleted))
job_count = jobs.count()
if job_count > model.Job.max_by_whiteboard:
flash(_('Your whiteboard contains %s jobs, only %s will be used' % (job_count, model.Job.max_by_whiteboard)))
flash('Your whiteboard contains %s jobs, only %s will be used' % (job_count, model.Job.max_by_whiteboard))
jobs = jobs.limit(model.Job.max_by_whiteboard)
job_ids = [str(j.id) for j in jobs]
self.job_ids = job_ids
Expand Down
Loading

0 comments on commit 1c71efb

Please sign in to comment.