Skip to content

Commit 8df625f

Browse files
committed
- fixing #233 (move .registers to state dir)
- fixing stations.csv (from erroneous PR) - updating headless.md
1 parent 226da73 commit 8df625f

File tree

9 files changed

+114
-95
lines changed

9 files changed

+114
-95
lines changed

docs/headless.html

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,12 @@ <h4 id="systemd">systemd</h4>
158158
touch ~/pyradio.log
159159
/usr/bin/tmux new-session -dA -s pyradio-session /home/spiros/.local/bin/pyradio --headless auto</pre>
160160
<p>Then create the stop file. Writhe this to <strong>~/.local/bin/stop-headless-pyradio.sh</strong></p>
161-
<p>Execute the following command:</p>
162-
<pre>pyradio -pc</pre>
163-
<p>and examine the value of the config parameter <strong>xdg_compliant</strong>.</p>
164-
<p>If <strong>xdg_compliant</strong> is <em>True</em>, write this code to the file:</p>
165161
<pre>#!/bin/bash
166162
[ -z &quot;$(/usr/bin/tmux ls | grep pyradio-session)&quot; ] || /usr/bin/tmux send-keys -t pyradio-session q
167163
sleep 2
168164
[ -z &quot;$(/usr/bin/tmux ls | grep pyradio-session)&quot; ] || /usr/bin/tmux send-keys -t pyradio-session q
165+
[ -e /home/spiros/.config/pyradio/data/server-headless.txt ] &amp;&amp; rm /home/spiros/.config/pyradio/data/server-headless.txt
169166
[ -e /home/spiros/.local/state/pyradio/server-headless.txt ] &amp;&amp; rm /home/spiros/.local/state/pyradio/server-headless.txt</pre>
170-
<p>If <strong>xdg_compliant</strong> is <em>False</em>, write this code to the file, instead:</p>
171-
<pre>#!/bin/bash
172-
[ -z &quot;$(/usr/bin/tmux ls | grep pyradio-session)&quot; ] || /usr/bin/tmux send-keys -t pyradio-session q
173-
sleep 2
174-
[ -z &quot;$(/usr/bin/tmux ls | grep pyradio-session)&quot; ] || /usr/bin/tmux send-keys -t pyradio-session q
175-
[ -e /home/spiros/.config/pyradio/data/server-headless.txt ] &amp;&amp; rm /home/spiros/.config/pyradio/data/server-headless.txt</pre>
176167
<p>Make both files executable:</p>
177168
<pre>chmod +x ~/.local/bin/start-headless-pyradio.sh
178169
chmod +x ~/.local/bin/stop-headless-pyradio.sh</pre>
@@ -192,22 +183,12 @@ <h4 id="systemd-1">systemd</h4>
192183
<pre>#!/bin/bash
193184
/usr/bin/screen -U -S pyradio-session -d -m /home/spiros/.local/bin/pyradio --headless auto</pre>
194185
<p>Then create the stop file. Writhe this to <strong>~/.local/bin/stop-headless-pyradio.sh</strong></p>
195-
<p>Execute the following command:</p>
196-
<pre>pyradio -pc</pre>
197-
<p>and examine the value of the config parameter <strong>xdg_compliant</strong>.</p>
198-
<p>If <strong>xdg_compliant</strong> is <em>True</em>, write this code to the file:</p>
199-
<pre>#!/bin/bash
200-
[ -z &quot;$(/usr/bin/screen -ls | grep pyradio-session)&quot; ] || /usr/bin/screen -S pyradio-session -p 0 -X stuff q
201-
sleep 2
202-
[ -z &quot;$(/usr/bin/screen -ls | grep pyradio-session)&quot; ] || /usr/bin/screen -S pyradio-session -p 0 -X stuff q
203-
[ -e /home/spiros/.local/state/pyradio/server-headless.txt ] &amp;&amp; rm /home/spiros/.local/state/pyradio/server-headless.txt
204-
</pre>
205-
<p>If <strong>xdg_compliant</strong> is <em>False</em>, write this code to the file, instead:</p>
206186
<pre>#!/bin/bash
207187
[ -z &quot;$(/usr/bin/screen -ls | grep pyradio-session)&quot; ] || /usr/bin/screen -S pyradio-session -p 0 -X stuff q
208188
sleep 2
209189
[ -z &quot;$(/usr/bin/screen -ls | grep pyradio-session)&quot; ] || /usr/bin/screen -S pyradio-session -p 0 -X stuff q
210190
[ -e /home/spiros/.config/pyradio/data/server-headless.txt ] &amp;&amp; rm /home/spiros/.config/pyradio/data/server-headless.txt
191+
[ -e /home/spiros/.local/state/pyradio/server-headless.txt ] &amp;&amp; rm /home/spiros/.local/state/pyradio/server-headless.txt
211192
</pre>
212193
<p>Make both files executable:</p>
213194
<pre>chmod +x ~/.local/bin/start-headless-pyradio.sh

docs/headless.md

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -171,30 +171,13 @@ touch ~/pyradio.log
171171

172172
Then create the stop file. Writhe this to **~/.local/bin/stop-headless-pyradio.sh**
173173

174-
Execute the following command:
175-
176-
pyradio -pc
177-
178-
and examine the value of the config parameter **xdg_compliant**.
179-
180-
If **xdg_compliant** is *True*, write this code to the file:
181-
182-
```
183-
#!/bin/bash
184-
[ -z "$(/usr/bin/tmux ls | grep pyradio-session)" ] || /usr/bin/tmux send-keys -t pyradio-session q
185-
sleep 2
186-
[ -z "$(/usr/bin/tmux ls | grep pyradio-session)" ] || /usr/bin/tmux send-keys -t pyradio-session q
187-
[ -e /home/spiros/.local/state/pyradio/server-headless.txt ] && rm /home/spiros/.local/state/pyradio/server-headless.txt
188-
```
189-
190-
If **xdg_compliant** is *False*, write this code to the file, instead:
191-
192174
```
193175
#!/bin/bash
194176
[ -z "$(/usr/bin/tmux ls | grep pyradio-session)" ] || /usr/bin/tmux send-keys -t pyradio-session q
195177
sleep 2
196178
[ -z "$(/usr/bin/tmux ls | grep pyradio-session)" ] || /usr/bin/tmux send-keys -t pyradio-session q
197179
[ -e /home/spiros/.config/pyradio/data/server-headless.txt ] && rm /home/spiros/.config/pyradio/data/server-headless.txt
180+
[ -e /home/spiros/.local/state/pyradio/server-headless.txt ] && rm /home/spiros/.local/state/pyradio/server-headless.txt
198181
```
199182

200183
Make both files executable:
@@ -236,31 +219,13 @@ Then create the start file. Write this to **~/.local/bin/start-headless-pyradio.
236219

237220
Then create the stop file. Writhe this to **~/.local/bin/stop-headless-pyradio.sh**
238221

239-
Execute the following command:
240-
241-
pyradio -pc
242-
243-
and examine the value of the config parameter **xdg_compliant**.
244-
245-
If **xdg_compliant** is *True*, write this code to the file:
246-
247-
```
248-
#!/bin/bash
249-
[ -z "$(/usr/bin/screen -ls | grep pyradio-session)" ] || /usr/bin/screen -S pyradio-session -p 0 -X stuff q
250-
sleep 2
251-
[ -z "$(/usr/bin/screen -ls | grep pyradio-session)" ] || /usr/bin/screen -S pyradio-session -p 0 -X stuff q
252-
[ -e /home/spiros/.local/state/pyradio/server-headless.txt ] && rm /home/spiros/.local/state/pyradio/server-headless.txt
253-
254-
```
255-
256-
If **xdg_compliant** is *False*, write this code to the file, instead:
257-
258222
```
259223
#!/bin/bash
260224
[ -z "$(/usr/bin/screen -ls | grep pyradio-session)" ] || /usr/bin/screen -S pyradio-session -p 0 -X stuff q
261225
sleep 2
262226
[ -z "$(/usr/bin/screen -ls | grep pyradio-session)" ] || /usr/bin/screen -S pyradio-session -p 0 -X stuff q
263227
[ -e /home/spiros/.config/pyradio/data/server-headless.txt ] && rm /home/spiros/.config/pyradio/data/server-headless.txt
228+
[ -e /home/spiros/.local/state/pyradio/server-headless.txt ] && rm /home/spiros/.local/state/pyradio/server-headless.txt
264229
265230
```
266231

pyradio/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ remote_control_server_auto_start = False
174174
# Packagers should set this paramater as resired!
175175
#
176176
# Default value: False
177-
xdg_compliant = False
177+
xdg_compliant = True
178178

179179
# The name of the distribution providing the package. If this parameter is set
180180
# to anything other than "None" PyRadio will not permit updating (-U command

pyradio/config.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,6 @@ def __init__(self, stationFile='', user_config_dir=None):
167167
if platform.startswith('win'):
168168
self._open_string_id = 1
169169

170-
# if sys.platform.startswith('win'):
171-
# self.stations_dir = path.join(getenv('APPDATA'), 'pyradio')
172-
# self.registers_dir = path.join(self.stations_dir, '_registers')
173-
# else:
174-
# if user_config_dir is None:
175-
# self.stations_dir = path.join(getenv('HOME', '~'), '.config', 'pyradio')
176-
# else:
177-
# self.stations_dir = user_config_dir
178-
# self.registers_dir = path.join(self.stations_dir, '.registers')
179-
# self.data_dir = path.join(self.stations_dir, 'data')
180-
# self.state_dir = self.data_dir
181-
182170
if user_config_dir is not None:
183171
self.stations_dir = user_config_dir
184172
self.xdg.build_paths()

pyradio/config_window.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,6 +2677,7 @@ class PyRadioSelectPlaylist(object):
26772677
def __init__(self,
26782678
parent,
26792679
config_path,
2680+
registers_path,
26802681
default_playlist,
26812682
include_registers=False,
26822683
global_functions=None):
@@ -2700,6 +2701,7 @@ def __init__(self,
27002701
''' revert to old behavior '''
27012702
self._parent_Y = 1
27022703
self._config_path = config_path
2704+
self._registers_path = registers_path
27032705
self.playlist = default_playlist
27042706
self._orig_playlist = default_playlist
27052707
self._selected_playlist = default_playlist
@@ -2802,9 +2804,9 @@ def _read_items(self):
28022804
if len(self._items) > 0:
28032805
self._items.sort()
28042806
if self._include_registers:
2805-
self._registers_path = path.join(self._config_path, '.registers')
2806-
if platform == 'win32':
2807-
self._registers_path.replace('.reg', '_reg')
2807+
# self._registers_path = path.join(self._config_path, '.registers')
2808+
# if platform == 'win32':
2809+
# self._registers_path.replace('.reg', '_reg')
28082810
r_items = glob.glob(path.join(self._registers_path, '*.csv'))
28092811
if r_items:
28102812
r_items.sort()
@@ -2869,11 +2871,13 @@ def _get_result(self):
28692871
if self._include_registers:
28702872
if self._items[self._selected_playlist_id].startswith('Register: '):
28712873
ret = self._items[self._selected_playlist_id].replace('Register: ', 'register_')
2872-
ret = path.join(self._config_path, '.registers', ret + '.csv')
2874+
ret = path.join(self._registers_path, ret + '.csv')
2875+
logger.error(f'ret 1: {ret = }')
28732876
else:
2874-
ret = path.join(self._config_path, self._items[self._selected_playlist_id] + '.csv')
2875-
if platform == 'win32':
2876-
ret.replace('.registers', '_registers')
2877+
ret = path.join(self._registers_path, self._items[self._selected_playlist_id] + '.csv')
2878+
logger.error(f'ret 2: {ret = }')
2879+
# if platform == 'win32':
2880+
# ret.replace('.registers', '_registers')
28772881
return 0, ret
28782882

28792883
stationFile = path.join(self._config_path, self._items[self._selected_playlist_id] + '.csv')
@@ -3086,7 +3090,7 @@ class PyRadioSelectStation(PyRadioSelectPlaylist):
30863090

30873091
_default_playlist = ''
30883092

3089-
def __init__(self, parent, config_path, default_playlist, default_station,
3093+
def __init__(self, parent, config_path, registers_dir, default_playlist, default_station,
30903094
global_functions=None, is_from_schedule=False):
30913095
self._default_playlist = default_playlist
30923096
self._orig_default_playlist = default_playlist
@@ -3098,7 +3102,7 @@ def __init__(self, parent, config_path, default_playlist, default_station,
30983102
if self._is_from_schedule:
30993103
self._config_path = config_path
31003104
default_station = self._read_items(a_station=default_station)
3101-
PyRadioSelectPlaylist.__init__(self, parent, config_path, default_station)
3105+
PyRadioSelectPlaylist.__init__(self, parent, config_path, registers_dir, default_station)
31023106
self._global_functions = set_global_functions(global_functions)
31033107
self._title = ' Station Selection '
31043108
''' adding 2 to padding calculation

pyradio/main.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ def _win_python_3_12():
177177
setattr(curses, key, value)
178178
return stdscr
179179

180+
def create_systemd_service_files():
181+
file_names = ('start-headless-pyradio.sh', 'stop-headless-pyradio.sh', 'pyradio.service')
182+
if program == 'tmux':
183+
files = (
184+
r'''#!|SHELL|
185+
touch |HOME|/pyradio.log
186+
|PROGRAM| new-session -dA -s pyradio-session |PYRADIO| --headless auto
187+
''',
188+
r'''#!|SHELL|
189+
[ -z "$(|PROGRAM| ls | grep pyradio-session)" ] || |PROGRAM| send-keys -t pyradio-session q
190+
sleep 2
191+
[ -z "$(|PROGRAM| ls | grep pyradio-session)" ] || |PROGRAM| sennd-keys -t pyradio-session q
192+
[ -e |HOME|/.config/pyradio/data/server-headless.txt ] && rm |HOME|/.config/pyradio/data/server-headless.txt
193+
[ -e |HOME|/.local/state/pyradio/server-headless.txt ] && rm |HOME|/.local/state/pyradio/server-headless.txt
194+
'''
195+
)
196+
pass
197+
else:
198+
pass
199+
180200
def shell():
181201
version_too_old = False
182202
if sys.version_info[0] == 2:
@@ -337,6 +357,8 @@ def shell():
337357
help='Show remote control server address.')
338358
gr_headless.add_argument('-fd', '--free-dead-headless-server', action='store_true',
339359
help='Use this if your headless server has terminated unexpectedly, and you cannot start a new one (you get a message that it is already running).')
360+
# gr_headless.add_argument('-gss', '--generate-systemd-service-files', action='store_true',
361+
help='Create systemd service files to enable / disable headless operation using tmux or screen.')
340362
args = parser.parse_args()
341363
sys.stdout.flush()
342364

@@ -353,6 +375,10 @@ def shell():
353375

354376
if not system().lower().startswith('darwin') and \
355377
not system().lower().startswith('win'):
378+
# if args.generate_systemd_service_files:
379+
# create_systemd_service_files()
380+
# sys.exit()
381+
# elif args.terminal:
356382
if args.terminal:
357383
try:
358384
from urllib.request import urlretrieve

pyradio/radio.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,8 +1991,8 @@ def ctrl_c_handler(self, signum, frame, save_playlist=True):
19911991
# ok
19921992
if self._cnf.titles_log.titles_handler:
19931993
logger.critical('=== Logging stopped')
1994-
logger.error('signum = {}'.format(signum))
1995-
logger.error('frame = {}'.format(frame))
1994+
# logger.error('signum = {}'.format(signum))
1995+
# logger.error('frame = {}'.format(frame))
19961996
search_cls = [x for x in self._search_classes if x is not None]
19971997
for n in range(len(search_cls)):
19981998
search_cls[n].save_search_history()
@@ -6203,6 +6203,7 @@ def keypress(self, char):
62036203
self._playlist_select_win = PyRadioSelectPlaylist(
62046204
self.bodyWin,
62056205
self._cnf.stations_dir,
6206+
self._cnf.registers_dir,
62066207
self._cnf.station_title,
62076208
include_registers=True,
62086209
global_functions=self._global_functions
@@ -6636,6 +6637,7 @@ def keypress(self, char):
66366637
self._schedule_playlist_select_win = PyRadioSelectPlaylist(
66376638
self.bodyWin,
66386639
self._cnf.stations_dir,
6640+
self._cnf.registers_dir,
66396641
self._simple_schedule.playlist,
66406642
global_functions=self._global_functions
66416643
)
@@ -6746,6 +6748,7 @@ def keypress(self, char):
67466748
self._playlist_select_win = PyRadioSelectPlaylist(
67476749
self.bodyWin,
67486750
self._cnf.stations_dir,
6751+
self._cnf.registers_dir,
67496752
self._config_win._config_options['default_playlist'][1],
67506753
global_functions=self._global_functions
67516754
)

pyradio/stations.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ Echoes of Bluemars - Cryosleep,http://streams.echoesofbluemars.org:8000/cryoslee
4242
Echoes of Bluemars - Voices from Within,http://streams.echoesofbluemars.org:8000/voicesfromwithin.m3u
4343
Synphaera Radio (Space Music),https://somafm.com/synphaera.pls
4444
Radio Levač (Serbian Folk & Country),http://213.239.205.210:8046/stream
45-
Radio 35 (Serbian and English Pop, Folk, Country & Hits),http://stream.radio035.net:8010/listen.pls
45+
"Radio 35 (Serbian and English Pop, Folk, Country & Hits)",http://stream.radio035.net:8010/listen.pls

0 commit comments

Comments
 (0)