Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

additional import try/except clauses for examples #40

Merged
merged 7 commits into from
Nov 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/dot3k/advanced/animations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import datetime
import math
import time
from sys import exit

try:
import psutil
Expand Down
1 change: 1 addition & 0 deletions examples/dot3k/basic/mouse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

import signal
from sys import exit

try:
import uinput
Expand Down
1 change: 1 addition & 0 deletions examples/plugins/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import struct
import subprocess
import time
from sys import exit

try:
import psutil
Expand Down
8 changes: 4 additions & 4 deletions examples/plugins/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import re
import socket
import subprocess
import sys
import time
from sys import version_info

from dot3k.menu import MenuOption

Expand Down Expand Up @@ -169,7 +169,7 @@ def kill(self):

def send(self, command):
try:
if sys.version_info[0] >= 3:
if version_info[0] >= 3:
self.socket.send((command + "\n").encode('utf-8'))
else:
self.socket.send(command + "\n")
Expand All @@ -179,7 +179,7 @@ def send(self, command):
def get_current_stream(self):
self.send("status")
status = self.socket.recv(8192)
if sys.version_info[0] >= 3:
if version_info[0] >= 3:
status = status.decode('utf-8')
result = re.search('input:\ (.*)\ ', status)
state = re.search('state\ (.*)\ ', status)
Expand Down Expand Up @@ -210,7 +210,7 @@ def start(self):
if self.pid is None:
try:
return_value = subprocess.check_output(['pidof', 'vlc'])
if sys.version_info[0] >= 3:
if version_info[0] >= 3:
self.pid = int(return_value.decode('utf-8').split(' ')[0])
else:
self.pid = int(return_value.decode('utf-8').split(' ')[0])
Expand Down
4 changes: 2 additions & 2 deletions examples/plugins/volume.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import subprocess
import sys
import time
from sys import version_info

import dot3k.backlight
from dot3k.menu import MenuIcon
Expand Down Expand Up @@ -80,7 +80,7 @@ def set_mode(self):

def get_volume(self):
actual_volume = subprocess.check_output("amixer get 'PCM' | awk '$0~/%/{print $4}' | tr -d '[]%'", shell=True)
if sys.version_info[0] >= 3:
if version_info[0] >= 3:
return actual_volume.strip().decode('utf-8')
else:
return actual_volume.strip()
Expand Down
1 change: 1 addition & 0 deletions examples/plugins/wlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import subprocess
import threading
from sys import exit

try:
import wifi
Expand Down
10 changes: 8 additions & 2 deletions examples/radio_utils/control
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/usr/bin/env python

import socket
import sys
import ConfigParser

try:
import ConfigParser
except ImportError:
import configparser as ConfigParser


config = ConfigParser.ConfigParser()
config.read(['../dot3k.cfg', 'dot3k.cfg'])
Expand Down Expand Up @@ -31,4 +37,4 @@ if command is not None:
sck.connect((host, port))
sck.send(command + '\n')
except socket.error:
exit('Unable to connect to server: ' + host + ':' + str(port))
sys.exit('Unable to connect to server: ' + host + ':' + str(port))
4 changes: 3 additions & 1 deletion examples/radio_utils/playshoutcast
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python

import socket
import sys
import urllib


to_play = None
host = '127.0.0.1'
port = 9393
Expand Down Expand Up @@ -38,4 +40,4 @@ if to_play is not None:
sck.send('add ' + to_play + '\n')
sck.send('play\n')
except socket.error:
exit('Unable to connect to server: ' + host + ':' + str(port))
sys.exit('Unable to connect to server: ' + host + ':' + str(port))
9 changes: 7 additions & 2 deletions examples/radio_utils/playstream
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/usr/bin/env python
import socket
import sys
import ConfigParser

try:
import ConfigParser
except ImportError:
import configparser as ConfigParser


config = ConfigParser.ConfigParser()
config.read(['../dot3k.cfg', 'dot3k.cfg'])
Expand Down Expand Up @@ -42,4 +47,4 @@ if to_play is not None:
sck.send('add ' + to_play + '\n')
sck.send('play\n')
except socket.error:
exit('Unable to connect to server: ' + host + ':' + str(port))
sys.exit('Unable to connect to server: ' + host + ':' + str(port))
15 changes: 12 additions & 3 deletions examples/radio_utils/podcast
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
#!/usr/bin/env python

import podcastparser
import urllib
import socket
import sys
import ConfigParser
import urllib

try:
import ConfigParser
except ImportError:
import configparser as ConfigParser

try:
import podcastparser
except ImportError:
sys.exit("This script requires the podcastparser module\nInstall with: sudo pip install podcastparser")


feedurl = "http://crankygamersuk.libsyn.com/rss"
episode_idx = 0
Expand Down
1 change: 1 addition & 0 deletions examples/radio_utils/volume
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/usr/bin/env bash

amixer sset 'PCM' $1%
8 changes: 6 additions & 2 deletions examples/utils/usbkeyboard.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import threading
from sys import exit

import usb.core
import usb.util
try:
import usb.core
import usb.util
except ImportError:
exit("This script requires the pyusb module\nInstall with: sudo pip install pyusb")


class StoppableThread(threading.Thread):
Expand Down
6 changes: 3 additions & 3 deletions packaging/makelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ inform "pypi changelog generated"

if [ -n $(grep version "$libdir/setup.py" &> /dev/null) ]; then
inform "touched up version in setup.py"
sed -i "s/[0-9].[0-9].[0-9]/$version/" "$libdir/setup.py"
sed -i "s/'[0-9].[0-9].[0-9]'/'$version'/" "$libdir/setup.py"
else
warning "couldn't touch up version in setup, no match found"
fi
Expand All @@ -69,10 +69,10 @@ fi

for sibling in ${sibname[@]}; do
if grep -e "__version__" "$libdir/$sibling.py" &> /dev/null; then
sed -i "s/__version__ = '[0-9].[0-9].[0-9]/__version__ = '$version/" "$libdir/$sibling.py"
sed -i "s/__version__ = '[0-9].[0-9].[0-9]'/__version__ = '$version'/" "$libdir/$sibling.py"
inform "touched up version in $sibling.py"
elif grep -e "__version__" "$libdir/$sibling/__init__.py" &> /dev/null; then
sed -i "s/__version__ = '[0-9].[0-9].[0-9]/__version__ = '$version/" "$libdir/$sibling/__init__.py"
sed -i "s/__version__ = '[0-9].[0-9].[0-9]'/__version__ = '$version'/" "$libdir/$sibling/__init__.py"
inform "touched up version in $sibling/__init__.py"
elif [ "$versionwarn" == "yes" ]; then
warning "couldn't touch up __version__ in $sibling, no match found"
Expand Down