Skip to content

Commit

Permalink
fixing Desktop file update:
Browse files Browse the repository at this point in the history
  1. script fix_pyradio_desktop_file will no longer be downloaded
     from github; it will be installed in the "scripts" installation
     folder and copied to the cache folder and executed from there
  2. providing the PyRadio parameters will no longer have to be
     prefixed by a "_"; just put them at the end of the command line,
     enclosed in single or double quotes.
  • Loading branch information
s-n-g committed Jan 21, 2025
1 parent 864712e commit 3b90dad
Show file tree
Hide file tree
Showing 8 changed files with 409 additions and 54 deletions.
27 changes: 23 additions & 4 deletions devel/fix_pyradio_desktop_file
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Available options:
Use \"none\" to reset to the default terminal.
Use \"auto\" to reset to the auto-detected one.
-p PARAMETER
PyRadio parameter. Please replace hyphens with underscores.
So, \"-p 2 -t light\" would be passed as \"_p 2 _t light\").
A number of parameters to be passed to PyRadio, for example:
-p "-p3 -t light"
-d DISTRO_DESKTOP_FILE
If this is a distribution package, and the Desktop File is not
installed under /usr/share/applications, this parameter will
Expand All @@ -41,7 +41,7 @@ If your terminal of choise uses a different way to accept the command, please
include it in the TERMINAL value. For example, if the command parameter for
the terminal \"my_term\" is \"-S\", execute as follows:
./fix_pyradio_desktop_file -t 'my_term -S'
./fix_pyradio_desktop_file -t \"my_term -S\"
"
}

Expand Down Expand Up @@ -94,8 +94,16 @@ Comment=Curses based Radio Player" > "${DESKTOP_FILE}"
then
echo "$EXEC_LINE" >> "${DESKTOP_FILE}"
else
# set -x
# echo "EXEC_LINE = ${EXEC_LINE}"
# echo "PARAM = ${PARAM}"
PARAM=" ${PARAM//_/-}"
NEW_EXEC_LINE="${EXEC_LINE/ / $PARAM }"
# echo "PARAM = ${PARAM}"
NEW_EXEC_LINE="${EXEC_LINE} ${PARAM}"
# echo "NEW_EXEC_LINE = $NEW_EXEC_LINE"
NEW_EXEC_LINE=$(echo "${NEW_EXEC_LINE}" | sed "s|${PROGRAM}|'${PROGRAM}|")
NEW_EXEC_LINE="${NEW_EXEC_LINE}""'"
NEW_EXEC_LINE="$(echo "${NEW_EXEC_LINE}" | sed s/\'/\"/g)"
echo "$NEW_EXEC_LINE" >> "${DESKTOP_FILE}"
fi
echo "Icon=${DATA_DIR}/pyradio.png" >> "${DESKTOP_FILE}"
Expand Down Expand Up @@ -253,6 +261,12 @@ do
exit 1
else
echo " Auto-detecteted terminal: ${REQ_TERMINAL/ */}"
if [ "${REQ_TERMINAL}" = "gnome-terminal" ]
then
REQ_TERMINAL="${REQ_TERMINAL} --"
else
REQ_TERMINAL="${REQ_TERMINAL} -e"
fi
fi
else
if [ "${REQ_TERMINAL}" != "none" ]
Expand All @@ -279,6 +293,10 @@ do
}
shift
;;
-z)
ZERO=1
shift
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
Expand All @@ -290,6 +308,7 @@ set -- "${POSITIONAL[@]}" # restore positional parameters
get_data_dir
echo "Installing Desktop file ... "
DESKTOP_FILE=~/.local/share/applications/pyradio.desktop
[ -z ${ZERO} ] && rm ${DESKTOP_FILE}
# set -x
get_req_terminal
get_program
Expand Down
4 changes: 4 additions & 0 deletions devel/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ sed -i '/<li><a href="#requirements">Requirements/ a\
git add index.html
cd ..

cp devel/fix_pyradio_desktop_file pyradio/scripts/
chmod -x pyradio/scripts/fix_pyradio_desktop_file
git add pyradio/scripts/fix_pyradio_desktop_file

# chmod +x devel/update_win_mplayer
# devel/update_win_mplayer && {
# git add pyradio/win.py
Expand Down
27 changes: 13 additions & 14 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1362,12 +1362,12 @@ <h2 id="command-line-options">Command line options <span style="padding-left: 10

Usage: pyradio [-h] [-c CONFIG_DIR] [-p [STATION_NUMBER]] [-x] [-u PLAYER]
[-l] [-lt] [-sds] [-sd] [-od] [-pc] [-d]
[--d-player-input D_PLAYER_INPUT] [-ul] [-us] [-U] [-R] [-V] [-ls]
[-s PLAYLIST] [-tlp] [-t THEME] [--show-themes] [--no-themes]
[--write-theme IN_THEME OUT_THEME,] [--terminal TERMINAL]
[--terminal-param TERMINAL_PARAM] [-oc] [-sc] [-cc] [-gc] [-r]
[-or] [-lr] [-mkv MKV_FILE] [-scv PNG_FILE] [-srt] [-ach]
[--headless IP_AND_PORT] [--address] [-fd]
[--d-player-input D_PLAYER_INPUT] [-ul] [-us] [-U] [-R] [-V]
[-ls] [-s PLAYLIST] [-tlp] [-t THEME] [--show-themes]
[--no-themes] [--write-theme IN_THEME OUT_THEME,]
[--terminal TERMINAL] [--terminal-param ...] [-oc] [-sc] [-cc]
[-gc] [-r] [-or] [-lr] [-mkv MKV_FILE] [-scv PNG_FILE] [-srt]
[-ach] [--headless IP_AND_PORT] [--address] [-fd]

Curses based Internet Radio Player

Expand Down Expand Up @@ -1429,11 +1429,10 @@ <h2 id="command-line-options">Command line options <span style="padding-left: 10
--terminal TERMINAL Use this terminal for Desktop file instead of the
auto-detected one. Use &quot;none&quot; to reset to the default
terminal or &quot;auto&quot; to reset to the auto-detected one.
--terminal-param TERMINAL_PARAM
Use this as PyRadio parameter in the Desktop File.
Please replace hyphens with underscores when passing
the parameter, for example: --terminal-param &quot;_p 3 _t
light&quot; (which will result to &quot;pyradio -p 3 -t light&quot;).
--terminal-param ... Use this as PyRadio parameter in the Desktop File.
Please make sure the parameters are at the end of the
command line. For example: pyradio --terminal kitty
--terminal-param &quot;-p3 -t light&quot;.

Cache:
-oc, --open-cache Open the Cache folder.
Expand Down Expand Up @@ -1622,7 +1621,7 @@ <h2 id="config-file">Config file <span style="padding-left: 10px;"><sup style="f
<p><strong>PyRadio</strong> upon its execution will first read its <em>package</em> configuration file and then will try to read the <em>user</em> configuration file. If an error occurs while parsing it, an error message will be displayed and <strong>PyRadio</strong> will terminate.</p>
<h3 id="the-package-config-file">The package config file</h3>
<p>The <em>package</em> configuration file contains the program’s <strong>default</strong> parameters. These are the player to use, the playlist to load etc.</p>
<p>It is heavily commented (as you can see <a href="pyradio/config">here</a>), so that it can be used as a template in order to manual create the <em>user</em> configuration file.</p>
<p>It is heavily commented (as you can see <a href="..//pyradio/config">here</a>), so that it can be used as a template in order to manual create the <em>user</em> configuration file.</p>
<p>One can also get the configuration file with the <strong>active parameter values</strong> (i.e. after changed by the <em>user</em> config file), by executing the command:</p>
<pre>pyradio -pc</pre>
<h3 id="the-user-config-file">The user config file</h3>
Expand Down Expand Up @@ -2215,8 +2214,8 @@ <h3 id="specifying-the-terminal-to-use">Specifying the terminal to use</h3>
<pre>pyradio --terminal none</pre>
<h4 id="specifying-pyradio-parameters">Specifying PyRadio parameters</h4>
<p>If a <strong>PyRadio</strong> parameter has to be present in the Desktop File, use the <strong>–terminal-param</strong> command line option:</p>
<pre>pyradio --terminal none --terminal-param &quot;_p 2&quot;</pre>
<p>This command will use no specific terminal and will pass the “<strong>-p 2</strong>” (play station No 2 automatically) parameter to <strong>PyRadio</strong>. To pass such a parameter, substitute all hyphens with underscores.</p>
<pre>pyradio --terminal none --terminal-param &quot;-p 3&quot;</pre>
<p>This command will use no specific terminal and will pass the “<strong>-p 3</strong>” (play station No 3 automatically) parameter to <strong>PyRadio</strong>. Just make sure that the parameter is at the end of the command line.</p>
<h2 id="session-locking">Session Locking <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></span></h2>
<p><strong>PyRadio</strong> uses session locking, which actually means that only the first instance executed within a given session will be able to write to the configuration file.</p>
<p>Subsequent instances will be “<em>locked</em>”. This means that the user can still play stations, load and edit playlists, load and test themes, but any changes will <strong>not</strong> be recorded in the configuration file.</p>
Expand Down
27 changes: 13 additions & 14 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ Furthermore, please refrain from using any third-party packaging methods, such a
Usage: pyradio [-h] [-c CONFIG_DIR] [-p [STATION_NUMBER]] [-x] [-u PLAYER]
[-l] [-lt] [-sds] [-sd] [-od] [-pc] [-d]
[--d-player-input D_PLAYER_INPUT] [-ul] [-us] [-U] [-R] [-V] [-ls]
[-s PLAYLIST] [-tlp] [-t THEME] [--show-themes] [--no-themes]
[--write-theme IN_THEME OUT_THEME,] [--terminal TERMINAL]
[--terminal-param TERMINAL_PARAM] [-oc] [-sc] [-cc] [-gc] [-r]
[-or] [-lr] [-mkv MKV_FILE] [-scv PNG_FILE] [-srt] [-ach]
[--headless IP_AND_PORT] [--address] [-fd]
[--d-player-input D_PLAYER_INPUT] [-ul] [-us] [-U] [-R] [-V]
[-ls] [-s PLAYLIST] [-tlp] [-t THEME] [--show-themes]
[--no-themes] [--write-theme IN_THEME OUT_THEME,]
[--terminal TERMINAL] [--terminal-param ...] [-oc] [-sc] [-cc]
[-gc] [-r] [-or] [-lr] [-mkv MKV_FILE] [-scv PNG_FILE] [-srt]
[-ach] [--headless IP_AND_PORT] [--address] [-fd]
Curses based Internet Radio Player
Expand Down Expand Up @@ -201,11 +201,10 @@ Terminal selection:
--terminal TERMINAL Use this terminal for Desktop file instead of the
auto-detected one. Use "none" to reset to the default
terminal or "auto" to reset to the auto-detected one.
--terminal-param TERMINAL_PARAM
Use this as PyRadio parameter in the Desktop File.
Please replace hyphens with underscores when passing
the parameter, for example: --terminal-param "_p 3 _t
light" (which will result to "pyradio -p 3 -t light").
--terminal-param ... Use this as PyRadio parameter in the Desktop File.
Please make sure the parameters are at the end of the
command line. For example: pyradio --terminal kitty
--terminal-param "-p3 -t light".
Cache:
-oc, --open-cache Open the Cache folder.
Expand Down Expand Up @@ -398,7 +397,7 @@ These modes are specifically designed to be used with tiling window managers, tr

The *package* configuration file contains the program's **default** parameters. These are the player to use, the playlist to load etc.

It is heavily commented (as you can see [here](pyradio/config)), so that it can be used as a template in order to manual create the *user* configuration file.
It is heavily commented (as you can see [here](..//pyradio/config)), so that it can be used as a template in order to manual create the *user* configuration file.

One can also get the configuration file with the **active parameter values** (i.e. after changed by the *user* config file), by executing the command:

Expand Down Expand Up @@ -1184,9 +1183,9 @@ To restore the original functionality (specifying no terminal):

If a **PyRadio** parameter has to be present in the Desktop File, use the **--terminal-param** command line option:

pyradio --terminal none --terminal-param "_p 2"
pyradio --terminal none --terminal-param "-p 3"

This command will use no specific terminal and will pass the "**-p 2**" (play station No 2 automatically) parameter to **PyRadio**. To pass such a parameter, substitute all hyphens with underscores.
This command will use no specific terminal and will pass the "**-p 3**" (play station No 3 automatically) parameter to **PyRadio**. Just make sure that the parameter is at the end of the command line.

## Session Locking

Expand Down
8 changes: 4 additions & 4 deletions docs/pyradio.1
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ Write an Internal or System Theme to themes directory.
Use this terminal for Desktop file instead of the
auto-detected one. Use "\fInone\fR" to reset to the default
terminal or "\fIauto\fR" to reset to the auto-detected one.
.IP\ \fB--terminal-param\fR\ \fITERMINAL_PARAM\fR
.IP\ \fB--terminal-param\fR\ \fI...\fR
Use this as PyRadio parameter in the Desktop File.
Please replace hyphens with underscores when passing
the parameter, for example: \fB--terminal-param\fR \fI"_p 3 _t
light"\fR (which will result to "\fBpyradio \fI-p 3 -t light\fR").
Please make sure that the argument is at the end of the command line,
for example: \fB--terminal-param\fR \fI"-p 3 -t
light"\fR.

.PP
\fICache:\fR
Expand Down
42 changes: 24 additions & 18 deletions pyradio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import logging.handlers
import shutil
from argparse import ArgumentParser, SUPPRESS as SUPPRESS
from argparse import ArgumentParser, SUPPRESS as SUPPRESS, REMAINDER
from os import path, getenv, environ, remove, chmod, makedirs, rmdir
from sys import platform
from contextlib import contextmanager
Expand Down Expand Up @@ -315,8 +315,7 @@ def shell():
not system().lower().startswith('win'):
term_group = parser.add_argument_group('• Terminal selection')
term_group.add_argument('--terminal', help='Use this terminal for Desktop file instead of the auto-detected one. Use "none" to reset to the default terminal or "auto" to reset to the auto-detected one.')
term_group.add_argument('--terminal-param', help='Use this as PyRadio parameter in the Desktop File. Please replace hyphens with underscores when passing the parameter, for example: --terminal-param "_p 3 _t light" (which will result to "pyradio -p 3 -t light").')

term_group.add_argument('--terminal-param', nargs=REMAINDER, help='Use this as PyRadio parameter in the Desktop File. Please make sure the parameters are at the end of the command line. For example: pyradio --terminal kitty --terminal-param "-p3 -t light".')

if HAS_PIPX:
cache_group = parser.add_argument_group('• Cache')
Expand Down Expand Up @@ -405,26 +404,33 @@ def shell():
script = None
# script = '/home/spiros/projects/my-gits/pyradio/devel/fix_pyradio_desktop_file'
if script is None:
package_file = path.join(path.dirname(__file__), 'scripts', 'fix_pyradio_desktop_file')
script = path.join(pyradio_config.cache_dir, 'fix_pyradio_desktop_file')
try:
from urllib.request import urlretrieve
except:
from urllib import urlretrieve
try:
r = urlretrieve('https://raw.githubusercontent.com/coderholic/pyradio/master/devel/fix_pyradio_desktop_file')
except:
print('Cannot contact github...')
sys.exit(1)
if int(r[1]['content-length']) < 1000:
print('Cannot contact github...')
shutil.copy(package_file, script)
except Exception as e:
print('Error copying file: "{}"'.format(e))
sys.exit(1)
script = r[0]
# try:
# from urllib.request import urlretrieve
# except:
# from urllib import urlretrieve
# try:
# r = urlretrieve('https://raw.githubusercontent.com/coderholic/pyradio/master/devel/fix_pyradio_desktop_file')
# except:
# print('Cannot contact github...')
# sys.exit(1)
# if int(r[1]['content-length']) < 1000:
# print('Cannot contact github...')
# sys.exit(1)
# script = r[0]
# script = '/home/spiros/projects/my-gits/pyradio/devel/fix_pyradio_desktop_file'
chmod(script , 0o766)
if args.terminal_param:
command = 'bash -c "' + script + ' -t ' + args.terminal + " -p '-" + args.terminal_param + "'" + '"'
command = 'bash -c "' + script + ' -t ' + args.terminal + " -p '" + args.terminal_param.replace('\\', '') + "'" + '"'
subprocess.call(command, shell=True)
command = 'bash -c "' + script + ' -t ' + args.terminal + " -p '" + ' '.join(args.terminal_param) + "'" + '"'
else:
subprocess.call('bash -c "' + script + ' -t ' + args.terminal + '"', shell=True)
command = 'bash -c "' + script + ' -t ' + args.terminal + '"'
subprocess.call(command, shell=True)
if r is not None:
remove(r[0])
sys.exit()
Expand Down
12 changes: 12 additions & 0 deletions pyradio/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@ def ctrl_c_handler(self, signum, frame, save_playlist=True):
If that causes problems, uncomment lines
'''
while self._remote_control_server is not None:
logger.error('\n\nclose_server\n\n')
ret, _ = self._remote_control_server.close_server()
if ret:
self._remote_control_server = None
Expand Down Expand Up @@ -10864,7 +10865,9 @@ def _linux_signal_handler(self, a_signal, a_frame):
logger.info('My terminal got closed... Terminating...')
self.log.stop_timer()
if self._remote_control_server is not None:
logger.error('\n\nclose_server\n\n')
self._remote_control_server.close_server()
self._remote_control_server = None
self._force_exit = True
self.stop_update_notification_thread = True
self.player.stop_timeout_counter_thread = True
Expand All @@ -10887,10 +10890,15 @@ def _linux_signal_handler(self, a_signal, a_frame):
)
except:
pass
# if self._remote_control_server is not None:
# logger.error('\n\nclose_server\n\n')
# ret, _ = self._remote_control_server.close_server()
while self._remote_control_server is not None:
logger.error('\n\nclose_server\n\n')
ret, _ = self._remote_control_server.close_server()
if ret:
self._remote_control_server = None
self._remote_control_server = None
self._wait_for_threads()

def _windows_signal_handler(self, event):
Expand Down Expand Up @@ -10919,7 +10927,9 @@ def _windows_signal_handler(self, event):
logger.info('My console window got closed... Terminating...')
self.log.stop_timer()
if self._remote_control_server is not None:
logger.error('\n\nclose_server\n\n')
self._remote_control_server.close_server()
self._remote_control_server = None
self._force_exit = True
self.player.close_from_windows()
self._cnf.save_config()
Expand Down Expand Up @@ -11197,9 +11207,11 @@ def _start_remote_control_server(self):

def _stop_remote_control_server(self):
if self._remote_control_server:
logger.error('\n\nclose_server\n\n')
ret = self._remote_control_server.close_server()
while not ret:
sleep(.15)
logger.error('\n\nclose_server\n\n')
ret = self._remote_control_server.close_server()
self._remote_control_server = self._remote_control_server_thread = None

Expand Down
Loading

0 comments on commit 3b90dad

Please sign in to comment.