Skip to content

Commit f321a49

Browse files
committed
Fix shellcheck warnings, pep 8 conformance, improved menu system, fix bug in call to get_zones, improved install/uninstall, bump minor version
1 parent cd7a007 commit f321a49

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1109
-844
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
May 16, 2023 :
6+
RoonCommandLine version 2.0.8 release 5
7+
8+
This is a bug fix release:
9+
* PEP 8 style guide conformance
10+
* Improved interactive menu system
11+
* Fix shellcheck warnings
12+
* Fix bug in call to get_zones in Get/Set Zone
13+
514
May 2, 2023 :
615
RoonCommandLine version 2.0.8 release 4
716

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ The Roon Command Line install creates two configuration files:
562562
and
563563

564564
`/usr/local/Roon/etc/roon_api.ini`
565-
565+
566566
These two configuration files are the first place to look when you encounter an issue.
567567
The /usr/local/Roon/etc/pyroonconf file contains 3 settings:
568568

@@ -622,7 +622,7 @@ interface. It accepts a wide variety of arguments and sends a command to the
622622
Python Roon API system which then communicates with the Roon Core.
623623

624624
If no arguments are provided to the `roon` command then an interactive dialog
625-
is presented from which the user can select commands and queries.
625+
is presented from which the user can select commands and queries.
626626

627627
Here is the current output of "roon -u" which displays a usage message.
628628

@@ -760,7 +760,7 @@ If multiple matches are found, the first match in the list is played.
760760
To narrow a search, exclusion filtering can be performed. Use the `-x string`
761761
argument to specify an exclusion substring for artist, composer, and playlist
762762
library searches. Use the `-X string` argument to specify an exclusion
763-
substring for album and genre library searches.
763+
substring for album and genre library searches.
764764

765765
In a large Roon library where multiple matches may be frequent and large,
766766
one approach is to first list the media you wish to play and based on the
@@ -793,7 +793,7 @@ would list the "Violin Concerto No. 1, Op. 26" by Mozart fist. Alternately,
793793
would also list the concerto first. Another search route for this album
794794
would be by searching albums by composer rather than albums by genre:
795795

796-
`roon -l comalbums -C Mozart -A "Violin Concerto"`
796+
`roon -l comalbums -C Mozart -A "Violin Concerto"`
797797

798798
Listing/playing media in the Roon Library "Composers" category searches the
799799
entire Roon database of available Composers rather than limiting the search
@@ -1036,13 +1036,11 @@ of this package will require little to no manual configuration.
10361036

10371037
[**NOTICE**](NOTICE) - Copyright notice
10381038

1039-
[**Install**](Install) - Installation script for Linux systems, Debian format install
1040-
1041-
[**Uninstall**](Uninstall) - Removal script for Linux systems, Debian format uninstall
1039+
[**Install**](Install) - Installation script
10421040

1043-
[**macInstall**](macInstall) - Installation script for Mac OS
1041+
[**Uninstall**](Uninstall) - Removal script
10441042

1045-
[**macUninstall**](macUninstall) - Removal script for Mac OS
1043+
[**macInstall**](macInstall) - Installation script for Mac OS (called from `Install`)
10461044

10471045
[**usage.txt**](usage.txt) - Frontend "roon" script usage documentation
10481046

Uninstall

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,88 @@
11
#!/bin/bash
2+
#
3+
# shellcheck disable=SC1090,SC2220,SC2207,SC2068,SC2001
24

3-
have_fade=`type -p roon_fade`
5+
uninstall() {
6+
LOCAL="/usr/local"
7+
APPL=${LOCAL}/share/applications
8+
DOC=${LOCAL}/share/doc
9+
ROON=${LOCAL}/Roon
10+
ROONBIN=${ROON}/bin
11+
12+
[ -d /usr/local/bin ] && {
13+
cd /usr/local/bin || exit 1
14+
for command in "${ROONBIN}"/*
15+
do
16+
[ "${command}" == "${ROONBIN}/*" ] && continue
17+
b=$(basename "${command}")
18+
[ -L "$b" ] && {
19+
/bin/ls -l "$b" | grep ${ROON} > /dev/null && sudo rm -f "$b"
20+
}
21+
done
22+
}
23+
24+
sudo rm -rf ${ROON}
25+
sudo rm -rf ${DOC}/RoonCommandLine
26+
sudo rm -f ${APPL}/rooncommand.desktop
27+
28+
ROON_SITE_DIR=
29+
# Check the global site directories
30+
have_python3=$(type -p python3)
31+
if [ "${have_python3}" ]
32+
then
33+
SITES=($(sudo python3 -c 'import site; print(site.getsitepackages())' | tr -d '[],'))
34+
else
35+
SITES=($(sudo python -c 'import site; print(site.getsitepackages())' | tr -d '[],'))
36+
fi
37+
for site in ${SITES[@]}
38+
do
39+
site=$(echo "$site" | sed -e "s/'//g")
40+
[ -d "${site}"/roonapi ] && {
41+
ROON_SITE_DIR=${site}/roonapi
42+
break
43+
}
44+
done
45+
46+
if [ "$ROON_SITE_DIR" ]
47+
then
48+
# Roll back the Python Roon API patch if it was applied
49+
cd "$ROON_SITE_DIR" || exit 1
50+
for i in *.orig
51+
do
52+
[ "$i" == "*.orig" ] && continue
53+
j=$(echo "$i" | sed -e "s/.orig//")
54+
sudo mv "$i" "$j"
55+
done
56+
else
57+
echo "Could not locate the roonapi Python module installation directory"
58+
echo "Python Roon API patch not reversed."
59+
fi
60+
61+
# Don't uninstall roonapi Python module, they might be using it for something else
62+
# if [ "${have_python3}" ]
63+
# then
64+
# sudo python3 -m pip uninstall roonapi -y
65+
# else
66+
# sudo python -m pip uninstall roonapi -y
67+
# fi
68+
69+
echo ""
70+
echo "RoonCommandLine uninstalled"
71+
}
72+
73+
have_fade=$(type -p roon_fade)
474
[ "${have_fade}" ] && roon_fade off
575

6-
plat=`uname -s`
76+
plat=$(uname -s)
777
if [ "$plat" == "Darwin" ]
878
then
9-
./macUninstall
79+
uninstall
1080
else
1181
debian=
12-
have_apt=`type -p apt`
13-
have_dpkg=`type -p dpkg`
14-
have_rpm=`type -p rpm`
15-
have_yum=`type -p yum`
82+
have_apt=$(type -p apt)
83+
have_dpkg=$(type -p dpkg)
84+
have_rpm=$(type -p rpm)
85+
have_yum=$(type -p yum)
1686
[ -f /etc/os-release ] && . /etc/os-release
1787
[ "${ID_LIKE}" == "debian" ] && debian=1
1888
[ "${debian}" ] || [ -f /etc/debian_version ] && debian=1
@@ -24,26 +94,27 @@ else
2494
then
2595
if [ "${have_apt}" ]
2696
then
27-
sudo apt remove "${PKG}" -y
97+
sudo apt remove "${PKG}" -y > /dev/null 2>&1
2898
else
2999
if [ "${have_dpkg}" ]
30100
then
31-
sudo dpkg -r "${PKG}"
101+
sudo dpkg -r "${PKG}" > /dev/null 2>&1
32102
else
33103
echo "Cannot locate either apt or dpkg to remove. Skipping."
34104
fi
35105
fi
36106
else
37107
if [ "${have_yum}" ]
38108
then
39-
sudo yum remove "${PKG}"
109+
sudo yum remove "${PKG}" > /dev/null 2>&1
40110
else
41111
if [ "${have_rpm}" ]
42112
then
43-
sudo rpm -e "${PKG}"
113+
sudo rpm -e "${PKG}" > /dev/null 2>&1
44114
else
45115
echo "Cannot locate either yum or rpm to remove. Skipping."
46116
fi
47117
fi
48118
fi
119+
uninstall
49120
fi

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
VERSION=2.0.8
2-
RELEASE=4
2+
RELEASE=5

api/get_core_ip.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
release = config['DEFAULT']['RoonCommandLineRelease']
1111
fullver = version + "-" + release
1212

13-
appinfo = {
13+
app = {
1414
"extension_id": "roon_command_line",
1515
"display_name": "Python library for Roon",
1616
"display_version": fullver,
@@ -21,11 +21,12 @@
2121

2222
discover = RoonDiscovery(None)
2323
servers = discover.all()
24-
apis = [RoonApi(appinfo, None, server[0], server[1], False) for server in servers]
24+
apis = [RoonApi(app, None, server[0], server[1], False) for server in servers]
2525

2626
auth_api = []
2727
while len(auth_api) == 0:
28-
print("\nWaiting for authorization - in Roon, click \033[1mSettings -> Extensions -> Enable\033[0m\n", flush=True)
28+
print("\nWaiting for authorization - in Roon, \
29+
click \033[1mSettings -> Extensions -> Enable\033[0m\n", flush=True)
2930
time.sleep(15)
3031
auth_api = [api for api in apis if api.token is not None]
3132

api/get_zone_attributes.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
from os import path
55
import sys
6+
from roonapi import RoonApi
67
#
78
# Get the volume of a zone's outputs
89
#
@@ -18,7 +19,8 @@
1819
tokenfile = config['DEFAULT']['TokenFileName']
1920

2021
parser = argparse.ArgumentParser()
21-
parser.add_argument("-g", "--grouped", default=False, action='store_true', help="return attributes for all zones in a grouped zone")
22+
parser.add_argument("-g", "--grouped", default=False, action='store_true',
23+
help="return attributes for all zones in a grouped zone")
2224
parser.add_argument("-z", "--zone", help="zone selection")
2325
args = parser.parse_args()
2426

@@ -37,7 +39,6 @@
3739
release = config['DEFAULT']['RoonCommandLineRelease']
3840
fullver = version + "-" + release
3941

40-
from roonapi import RoonApi
4142
appinfo = {
4243
"extension_id": "roon_command_line",
4344
"display_name": "Python library for Roon",
@@ -75,19 +76,19 @@
7576
result = []
7677
is_grouped = False
7778
if group is not None:
78-
is_grouped = roonapi.is_grouped(output_id)
79+
is_grouped = roonapi.is_grouped(output_id)
7980
if is_grouped:
80-
# Get the attributes for all zones in a zone grouping
81-
grouped_zone_names = roonapi.grouped_zone_names(output_id)
82-
if grouped_zone_names is not None:
83-
for zone_name in grouped_zone_names:
84-
for (k, v) in outputs.items():
85-
if zone_name in v["display_name"]:
86-
result.append(v)
81+
# Get the attributes for all zones in a zone grouping
82+
grouped_zone_names = roonapi.grouped_zone_names(output_id)
83+
if grouped_zone_names is not None:
84+
for zone_name in grouped_zone_names:
85+
for (k, v) in outputs.items():
86+
if zone_name in v["display_name"]:
87+
result.append(v)
8788
else:
88-
# Get the attributes of the specified zone with the specified method
89-
for (k, v) in outputs.items():
90-
if zone_name in v["display_name"]:
91-
result.append(v)
89+
# Get the attributes of the specified zone with the specified method
90+
for (k, v) in outputs.items():
91+
if zone_name in v["display_name"]:
92+
result.append(v)
9293

9394
print(json.dumps(result))

api/get_zone_remaining.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import configparser
33
from os import path
44
import sys
5+
from roonapi import RoonApi
56
#
67
# Get the volume of a zone's outputs
78
#
@@ -31,7 +32,6 @@
3132
release = config['DEFAULT']['RoonCommandLineRelease']
3233
fullver = version + "-" + release
3334

34-
from roonapi import RoonApi
3535
appinfo = {
3636
"extension_id": "roon_command_line",
3737
"display_name": "Python library for Roon",
@@ -70,14 +70,15 @@
7070
else:
7171
zone = roonapi.zone_by_output_id(output_id)
7272
if zone is not None:
73-
state = zone["state"]
74-
length = zone["now_playing"]["length"]
75-
position = zone["now_playing"]["seek_position"]
76-
if length is not None:
77-
if position is not None:
78-
remaining = length - position
73+
state = zone["state"]
74+
length = zone["now_playing"]["length"]
75+
position = zone["now_playing"]["seek_position"]
76+
if length is not None:
77+
if position is not None:
78+
remaining = length - position
7979

8080
if remaining is not None:
81-
print(zone_name + ": Time remaining = " + str(remaining) + " seconds, State = " + state)
81+
print(zone_name + ": Time remaining = " + str(remaining) +
82+
" seconds, State = " + state)
8283
else:
8384
print(zone_name + ": State = " + state)

api/list_albums.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import configparser
33
from os import path
44
import sys
5+
from roonapi import RoonApi
56

67
config = configparser.ConfigParser()
78
config.read('/usr/local/Roon/etc/roon_api.ini')
@@ -36,7 +37,6 @@
3637
release = config['DEFAULT']['RoonCommandLineRelease']
3738
fullver = version + "-" + release
3839

39-
from roonapi import RoonApi
4040
appinfo = {
4141
"extension_id": "roon_command_line",
4242
"display_name": "Python library for Roon",
@@ -73,12 +73,12 @@
7373
# List matching albums
7474
albums = roonapi.list_media(output_id, ["Library", "Albums", albumsearch])
7575
if exalbumsearch is not None and albums:
76-
albums = [chkalbum for chkalbum in albums if not exalbumsearch in chkalbum]
76+
albums = [chkalbum for chkalbum in albums if exalbumsearch not in chkalbum]
7777
if albums:
7878
if albumsearch == "__all__":
7979
print("\nAll Albums in Library:\n")
8080
else:
8181
print("\nAlbums with", albumsearch, "in title", ":\n")
82-
print(*albums, sep = "\n")
82+
print(*albums, sep="\n")
8383
else:
8484
print("No albums found matching ", albumsearch)

0 commit comments

Comments
 (0)