Skip to content

Commit

Permalink
- Fixing player_params_file and schedule_file when XDG compliance is ON
Browse files Browse the repository at this point in the history
- Updating docs broken links
  • Loading branch information
s-n-g committed Aug 23, 2024
1 parent 9ea7a80 commit 5a618d1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Finally, include the file produced in your report.

## Packaging PyRadio

If you are a packager and would like to produce a package for your distribution please do follow [this mini guide](docs/packagers-info.md).
If you are a packager and would like to produce a package for your distribution please do follow [this mini guide](docs/packaging.md).

## TODO

Expand Down
2 changes: 1 addition & 1 deletion docs/packaging.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ <h3 id="pyradio__pycache__">pyradio/__pycache__</h3>
<h2 id="recordings-directory">Recordings Directory <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>Parameter <strong>recording_dir</strong> in the config will point to the directory to save recorded files.</p>
<p>It may seem like a good idea to change it to something meaningful but there is a catch.</p>
<p><strong>PyRadio 0.9.3</strong> (and newer) will nornaly use the <em>default</em> location, which is <em><sub>/pyradio-recordings<em>. Furthermore, it will move the pre-0.9.3 default recordings dir (~/.config/pyradio/recordings) and titles log (from </em></sub>/.config/pyradio</em>) to this new default location.</p>
<p><strong>PyRadio 0.9.3</strong> (and newer) will nornaly use the <em>default</em> location, which is <em><sub>/pyradio-recordings<em>. Furthermore, it will move the pre-0.9.3 default recordings dir, i.e. </em></sub>/.config/pyradio/recordings</em> and titles log(from <em>~/.config/pyradio</em>, to this new default location.</p>
<p>If you, the packager, provide a different default <strong>recording_dir</strong> in the package config file, your users will probably end up in the following situation:</p>
<ol type="1">
<li><p>Pro existing recordings and titles logs will end up in <em>~/pyradio-recordings</em>.</p></li>
Expand Down
2 changes: 1 addition & 1 deletion docs/packaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Parameter **recording_dir** in the config will point to the directory to save re

It may seem like a good idea to change it to something meaningful but there is a catch.

**PyRadio 0.9.3** (and newer) will nornaly use the *default* location, which is *~/pyradio-recordings*. Furthermore, it will move the pre-0.9.3 default recordings dir (~/.config/pyradio/recordings) and titles log (from *~/.config/pyradio*) to this new default location.
**PyRadio 0.9.3** (and newer) will nornaly use the *default* location, which is *~/pyradio-recordings*. Furthermore, it will move the pre-0.9.3 default recordings dir, i.e. *~/.config/pyradio/recordings* and titles log(from *~/.config/pyradio*, to this new default location.

If you, the packager, provide a different default **recording_dir** in the package config file, your users will probably end up in the following situation:

Expand Down
35 changes: 20 additions & 15 deletions pyradio/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ def __init__(self, stationFile='', user_config_dir=None):
self.xdg.build_paths()
self.xdg.ensure_paths_exist()
self.root_path = path.join(path.dirname(__file__), 'stations.csv')
self.player_params_file = path.join(self.data_dir, 'player-params.json')
self.schedule_file = path.join(self.data_dir, 'schedule.json')
self.themes_dir = path.join(self.stations_dir, 'themes')
self.favorites_path = path.join(self.stations_dir, 'favorites.csv')
try:
Expand Down Expand Up @@ -2393,6 +2391,22 @@ def _read_config(self, distro_config=False):
self.opts['dirty_config'][1] = True

self._make_sure_dirs_exist()
''' detect previous XDG Base installation '''
if not platform.startswith('win') and \
self._user_config_dir is None and \
not self.xdg_compliant and \
distro_config:
# d_dir = path.join(XdgDirs.get_xdg_dir('XDG_DATA_HOME'), 'pyradio')
# s_dir = path.join(XdgDirs.get_xdg_dir('XDG_STATE_HOME'), 'pyradio')
d_dir = XdgDirs.get_xdg_dir('XDG_DATA_HOME')
s_dir = XdgDirs.get_xdg_dir('XDG_STATE_HOME')
if path.exists(d_dir) and path.exists(s_dir):
print('[magenta]XDG Dirs[/magenta] found; enabling [magenta]XDG Base compliant[/magenta] operation')
self.xdg_compliant = True
self.need_to_fix_desktop_file_icon = True

# do this here to get proper extra parameters config filepath if XDG is on
self.player_params_file = path.join(self.data_dir, 'player-params.json')
if not distro_config:
if path.exists(self.player_params_file + '.restore'):
try:
Expand All @@ -2406,20 +2420,11 @@ def _read_config(self, distro_config=False):
except:
pass
self._first_read = False
logger.error('\n\nfile = {0}\nplayer extra params = {1}\n\n'.format(self.player_params_file, self.params))

# do this here to get proper schedule config filepath if XDG is on
self.schedule_file = path.join(self.data_dir, 'schedule.json')

''' detect previous XDG Base installation '''
if not platform.startswith('win') and \
self._user_config_dir is None and \
not self.xdg_compliant and \
distro_config:
# d_dir = path.join(XdgDirs.get_xdg_dir('XDG_DATA_HOME'), 'pyradio')
# s_dir = path.join(XdgDirs.get_xdg_dir('XDG_STATE_HOME'), 'pyradio')
d_dir = XdgDirs.get_xdg_dir('XDG_DATA_HOME')
s_dir = XdgDirs.get_xdg_dir('XDG_STATE_HOME')
if path.exists(d_dir) and path.exists(s_dir):
print('[magenta]XDG Dirs[/magenta] found; enabling [magenta]XDG Base compliant[/magenta] operation')
self.xdg_compliant = True
self.need_to_fix_desktop_file_icon = True

def _make_sure_dirs_exist(self):
if self.opts['recording_dir'][1] == '':
Expand Down

0 comments on commit 5a618d1

Please sign in to comment.