Skip to content

Commit

Permalink
Merge pull request #428 from ultrabug/modfix-3.1-safe_format
Browse files Browse the repository at this point in the history
modules to use safe_format()
  • Loading branch information
ultrabug committed Sep 14, 2016
2 parents 95fdee8 + cb63abf commit 743d404
Show file tree
Hide file tree
Showing 32 changed files with 163 additions and 110 deletions.
8 changes: 5 additions & 3 deletions py3status/modules/arch_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ def check_updates(self):
pacman_updates = self._check_pacman_updates()
if self.include_aur:
aur_updates = self._check_aur_updates()
results = self.format.format(pacman=pacman_updates,
aur=aur_updates)
else:
results = self.format.format(pacman=str(pacman_updates))
aur_updates = ''

results = self.py3.safe_format(
self.format, {'pacman': pacman_updates, 'aur': aur_updates}
)

response = {
'full_text': results,
Expand Down
4 changes: 3 additions & 1 deletion py3status/modules/aws_bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def aws_bill(self):
elif bill_amount == 'conn_error':
response['full_text'] = 'Check your internet access'
elif bill_amount is not False:
response['full_text'] = self.format.format(bill_amount=bill_amount)
response['full_text'] = self.py3.safe_format(
self.format, {'bill_amount': bill_amount}
)
response['color'] = self.py3.COLOR_GOOD
else:
response['full_text'] = 'Global error - WTF exception'
Expand Down
18 changes: 11 additions & 7 deletions py3status/modules/battery_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ def on_click(self, event):
else:
format = self.format_notify_charging

message = format.format(ascii_bar=self.ascii_bar, icon=self.icon,
percent=self.percent_charged,
time_remaining=self.time_remaining)
message = self.py3.safe_format(format,
dict(ascii_bar=self.ascii_bar,
icon=self.icon,
percent=self.percent_charged,
time_remaining=self.time_remaining))

if message:
self._desktop_notification(message)
Expand Down Expand Up @@ -309,10 +311,12 @@ def _update_icon(self):
(len(self.blocks) - 1)))]

def _update_full_text(self):
self.full_text = self.format.format(ascii_bar=self.ascii_bar,
icon=self.icon,
percent=self.percent_charged,
time_remaining=self.time_remaining)
self.full_text = self.py3.safe_format(
self.format,
dict(ascii_bar=self.ascii_bar,
icon=self.icon,
percent=self.percent_charged,
time_remaining=self.time_remaining))

def _build_response(self):
self.response = {}
Expand Down
20 changes: 11 additions & 9 deletions py3status/modules/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,24 @@ def bluetooth(self):
data = []
for mac in macs:
out = check_output(shlex.split('hcitool name %s' % mac))
fmt_str = self.format.format(
name=out.strip().decode('utf-8'),
mac=mac
fmt_str = self.py3.safe_format(
self.format,
{'name': out.strip().decode('utf-8'), 'mac': mac}
)
data.append(fmt_str)

output = '{format_prefix}{data}'.format(
format_prefix=self.format_prefix,
data=self.device_separator.join(data)
output = self.py3.safe_format(
'{format_prefix}{data}',
{'format_prefix': self.format_prefix,
'data': self.device_separator.join(data)}
)

color = self.py3.COLOR_GOOD
else:
output = '{format_prefix}{format}'.format(
format_prefix=self.format_no_conn_prefix,
format=self.format_no_conn
output = self.py3.safe_format(
'{format_prefix}{format}',
dict(format_prefix=self.format_no_conn_prefix,
format=self.format_no_conn)
)

response = {
Expand Down
14 changes: 8 additions & 6 deletions py3status/modules/deadbeef.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ def get_status(self):

response = {
'cached_until': self.py3.time_in(self.cache_timeout),
'full_text': self.format.format(artist=artist,
title=title,
length=length,
elapsed=elapsed,
year=year,
tracknum=tracknum)
'full_text': self.py3.safe_format(self.format,
dict(artist=artist,
title=title,
length=length,
elapsed=elapsed,
year=year,
tracknum=tracknum)
)
}
return response
except:
Expand Down
3 changes: 2 additions & 1 deletion py3status/modules/external_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def external_script(self):

response = {
'cached_until': self.py3.time_in(self.cache_timeout),
'full_text': self.format.format(output=return_value)
'full_text': self.py3.safe_format(self.format,
{'output': return_value})
}
else:
response = {
Expand Down
4 changes: 2 additions & 2 deletions py3status/modules/fedora_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def check_updates(self):
self._first = False
response = {
'cached_until': self.py3.time_in(),
'full_text': self.format.format(updates='?')
'full_text': self.py3.safe_format(self.format, {'updates': '?'})
}
return response

Expand Down Expand Up @@ -77,7 +77,7 @@ def check_updates(self):
response = {
'cached_until': self.py3.time_in(self.cache_timeout),
'color': color,
'full_text': self.format.format(updates=updates)
'full_text': self.py3.safe_format(self.format, {'updates': updates})
}
return response

Expand Down
2 changes: 1 addition & 1 deletion py3status/modules/gpmdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def gpmdp(self):
if '{%s}' % cmd in self.format:
data[cmd] = self._run_cmd(cmd)

result = self.format.format(**data)
result = self.py3.safe_format(self.format, data)

response = {
'cached_until': self.py3.time_in(self.cache_timeout),
Expand Down
2 changes: 1 addition & 1 deletion py3status/modules/graphite.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def graphite(self):
response = {
'cached_until': self.py3.time_in(self.cache_timeout),
'color': getattr(self.py3, 'COLOR_{}'.format(color_key.upper())),
'full_text': self.format.format(**r_json)
'full_text': self.py3.safe_format(self.format, r_json)
}
return response

Expand Down
3 changes: 2 additions & 1 deletion py3status/modules/hamster.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def hamster(self):

response = {}
response['cached_until'] = self.py3.time_in(self.cache_timeout)
response['full_text'] = self.format.format(current=cur_task)
response['full_text'] = self.py3.safe_format(self.format,
{'current': cur_task})
return response


Expand Down
8 changes: 5 additions & 3 deletions py3status/modules/icinga2.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ def get_status(self):
response = {
'color': self.color,
'cached_until': self.py3.time_in(self.cache_timeout),
'full_text': self.format.format(
status_name=STATUS_NAMES.get(self.status, "INVALID STATUS"),
count=self._query_service_count(self.status))
'full_text': self.py3.safe_format(
self.format,
dict(
status_name=STATUS_NAMES.get(self.status, "INVALID STATUS"),
count=self._query_service_count(self.status)))
}
return response

Expand Down
8 changes: 6 additions & 2 deletions py3status/modules/imap.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ def check_mail(self):
response['full_text'] = mail_count
elif mail_count != 0:
response['color'] = self.new_mail_color
response['full_text'] = self.format.format(unseen=mail_count)
response['full_text'] = self.py3.safe_format(
self.format, {'unseen': mail_count}
)
else:
if self.hide_if_zero:
response['full_text'] = ''
else:
response['full_text'] = self.format.format(unseen=mail_count)
response['full_text'] = self.py3.safe_format(
self.format, {'unseen': mail_count}
)

return response

Expand Down
4 changes: 3 additions & 1 deletion py3status/modules/insync.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def check_insync(self):
else:
queued = ""

results = self.format.format(status=status, queued=queued)
results = self.py3.safe_format(
self.format, {'status': status, 'queued': queued}
)

response = {
'cached_until': self.py3.time_in(self.cache_timeout),
Expand Down
15 changes: 9 additions & 6 deletions py3status/modules/kdeconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ def _get_text(self):
return (UNKNOWN_DEVICE, self.py3.COLOR_BAD)

if not device['isReachable'] or not device['isPaired']():
return (self.format_disconnected.format(name=device['name']),
return (self.py3.safe_format(self.format_disconnected,
{'name': device['name']}),
self.py3.COLOR_BAD)

battery = self._get_battery()
Expand All @@ -213,11 +214,13 @@ def _get_text(self):
notif = self._get_notifications()
(notif_size, notif_status) = self._get_notifications_status(notif)

return (self.format.format(name=device['name'],
charge=charge,
bat_status=bat_status,
notif_size=notif_size,
notif_status=notif_status), color)
return (self.py3.safe_format(self.format,
dict(name=device['name'],
charge=charge,
bat_status=bat_status,
notif_size=notif_size,
notif_status=notif_status)),
color)

def kdeconnector(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion py3status/modules/keyboard_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def keyboard_layout(self):
if lang_color:
response['color'] = lang_color

response['full_text'] = self.format.format(layout=lang)
response['full_text'] = self.py3.safe_format(self.format, {'layout': lang})
return response

def _get_layouts(self):
Expand Down
12 changes: 6 additions & 6 deletions py3status/modules/net_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ def currentSpeed(self):
return {
'cached_until': self.py3.time_in(self.cache_timeout),
'full_text': "" if hide else
self.format.format(
total=self._divide_and_format(delta['total']),
up=self._divide_and_format(delta['up']),
down=self._divide_and_format(delta['down']),
interface=interface[:-1],
) if interface else self.format_no_connection
self.py3.safe_format(self.format,
dict(total=self._divide_and_format(delta['total']),
up=self._divide_and_format(delta['up']),
down=self._divide_and_format(delta['down']),
interface=interface[:-1])
) if interface else self.format_no_connection
}

def _get_stat(self):
Expand Down
2 changes: 1 addition & 1 deletion py3status/modules/rt.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def rt_tickets(self):
'color' not in response):
response.update({'color': self.py3.COLOR_DEGRADED})
if has_one_queue_formatted:
response['full_text'] = self.format.format(**tickets)
response['full_text'] = self.py3.safe_format(self.format, tickets)
else:
response['full_text'] = 'queue(s) not found ({})'.format(
self.format)
Expand Down
2 changes: 1 addition & 1 deletion py3status/modules/selinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def selinux_status(self):

response = {
'cached_until': self.py3.time_in(self.cache_timeout),
'full_text': self.format.format(state=selinuxstring),
'full_text': self.py3.safe_format(self.format, {'state': selinuxstring}),
'color': color,
}

Expand Down
11 changes: 7 additions & 4 deletions py3status/modules/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,13 @@ def _get_text(self):
self.py3.COLOR_PAUSED or self.py3.COLOR_DEGRADED)

return (
self.format.format(title=title,
artist=artist,
album=album,
time=rtime), color)
self.py3.safe_format(
self.format,
dict(title=title,
artist=artist,
album=album,
time=rtime)
), color)
except Exception:
return (
self.format_down,
Expand Down
15 changes: 9 additions & 6 deletions py3status/modules/sysdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,15 @@ def sysData(self):

response = {
'cached_until': self.py3.time_in(self.cache_timeout),
'full_text': self.format.format(
cpu_usage='%.2f' % (cpu_usage),
cpu_temp=cpu_temp,
mem_used='%.2f' % mem_used,
mem_total='%.2f' % mem_total,
mem_used_percent='%.2f' % mem_used_percent,
'full_text': self.py3.safe_format(
self.format,
dict(
cpu_usage='%.2f' % (cpu_usage),
cpu_temp=cpu_temp,
mem_used='%.2f' % mem_used,
mem_total='%.2f' % mem_total,
mem_used_percent='%.2f' % mem_used_percent,
)
)
}

Expand Down
14 changes: 10 additions & 4 deletions py3status/modules/twitch_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,22 @@ def is_streaming(self):
self._get_display_name()
if 'error' in r.json():
colour = self.py3.COLOR_BAD
full_text = self.format_invalid.format(stream_name=self.stream_name)
format = self.format_invalid
stream_name = self.stream_name
elif r.json().get('stream') is None:
colour = self.py3.COLOR_BAD
full_text = self.format_offline.format(stream_name=self._display_name)
format = self.format_offline
stream_name = self._display_name
elif r.json().get('stream') is not None:
colour = self.py3.COLOR_GOOD
full_text = self.format.format(stream_name=self._display_name)
format = self.format
stream_name = self._display_name
else:
colour = self.py3.COLOR_BAD
full_text = "An unknown error has occurred."
format = "An unknown error has occurred."
stream_name = None

full_text = self.py3.safe_format(format, {'stream_name': stream_name})

response = {
'cached_until': self.py3.time_in(self.cache_timeout),
Expand Down
14 changes: 8 additions & 6 deletions py3status/modules/uname.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ def show_uname(self):
system, node, release, version, machine, processor = uname()
response = {
'cached_until': self.py3.time_in(self.cache_timeout),
'full_text': self.format.format(system=system,
node=node,
release=release,
version=version,
machine=machine,
processor=processor)
'full_text': self.py3.safe_format(
self.format,
dict(system=system,
node=node,
release=release,
version=version,
machine=machine,
processor=processor))
}
return response

Expand Down
9 changes: 5 additions & 4 deletions py3status/modules/vnstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ def currentSpeed(self):

response = {
'cached_until': self.py3.time_in(self.cache_timeout),
'full_text': self.format.format(
total=self._divide_and_format(stat['total']),
up=self._divide_and_format(stat['up']),
down=self._divide_and_format(stat['down']),
'full_text': self.py3.safe_format(
self.format,
dict(total=self._divide_and_format(stat['total']),
up=self._divide_and_format(stat['up']),
down=self._divide_and_format(stat['down'])),
),
'transformed': True
}
Expand Down
Loading

0 comments on commit 743d404

Please sign in to comment.