Skip to content

Commit a560867

Browse files
committed
- starting 0.8.8-bate4
- build script will use Python 3 by default - using contextmanager to deal with the lock file
1 parent 3911adb commit a560867

File tree

9 files changed

+285
-179
lines changed

9 files changed

+285
-179
lines changed

Changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2020-11-05
2+
* Installation script will use Python 3 by default
3+
14
2020-10-30 s-n-g
25
* Version 0.8.8-beta3
36
* Re-implementing status bar output function

Makefile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@ SPHINXBUILD=sphinx-build
33
ALLSPHINXOPTS= -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
44
BUILDDIR=_build
55

6+
.PHONY: build
7+
build:
8+
python3 setup.py build
9+
10+
.PHONY: install
11+
install:
12+
devel/build_install_pyradio 3
13+
14+
.PHONY: uninstall
15+
uninstall:
16+
devel/build_install_pyradio -u
617

718
.PHONY: clean
819
clean:
9-
rm -rf build dist docs/_build
10-
find . -name "*.pyc" -delete
11-
find . -name "*.orig" -delete
12-
find . -name "*.log" -delete
20+
sudo rm -rf build dist docs/_build
21+
sudo find . -name "*.pyc" -delete
22+
sudo find . -name "*.orig" -delete
23+
sudo find . -name "*.log" -delete
24+
sudo find . -name "*.1.gz" -delete
1325

1426
.PHONY: register
1527
register:

devel/build_install_pyradio

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
#!/bin/bash
22
function help(){
33
if [[ $(uname -s) = "Darwin" ]] || [[ $(uname -s) = "darwin" ]]; then
4-
echo "Usage: $0 [2/3/-u]"
4+
echo "Usage: $0 [2/-u]"
55
else
6-
echo "Usage: $0 [2/3/-u/--user]"
6+
echo "Usage: $0 [2/-u/--user]"
77
fi
88
echo "
99
Available options:
10-
2 build using python v. 2.x
11-
3 build using python v. 3.x
12-
-u uninstall pyradio
13-
--user user install (in ~/.local)
10+
2 build using python v. 2.x
11+
-u uninstall pyradio
12+
--user user install (in ~/.local)
1413
15-
If no option is used, will build using system default
14+
If no option is used, will build using Python 3
1615
1716
Checking python availability:"
1817

19-
for n in "" 2 3;do
18+
for n in 2 3 "";do
2019
echo -n " python${n}"
2120
[ -z "$n" ] && echo -n " "
2221
echo -n " ... "
@@ -97,6 +96,69 @@ function uninstall(){
9796
echo "PyRadio successfully uninstalled"
9897
}
9998

99+
function create_bdist(){
100+
rm -rf build pyradio.egg-info dist debian 2>/dev/null
101+
python3 setup.py bdist || {
102+
echo "Error creating bdist"
103+
exit 1
104+
}
105+
106+
}
107+
108+
function get_cur_version(){
109+
cur_version=$(grep 'version_info = ' pyradio/__init__.py | sed 's/version_info = (//;s/, /./g;s/)//')
110+
cur_state=$(grep 'app_state = ' pyradio/__init__.py | sed "s/app_state = //;s/'//g")
111+
[[ -z "$cur_state" ]] || cur_version="$cur_version"-"$cur_state"
112+
#echo "$cur_version"
113+
}
114+
115+
function do_debian(){
116+
get_cur_version
117+
outfile=pyradio-${cur_version}_all.deb
118+
create_bdist
119+
mkdir -p debian/DEBIAN
120+
cat <<END >debian/DEBIAN/control
121+
Source: pyradio
122+
Version: |version|
123+
Priority: optional
124+
Build-Depends: debhelper-compat (= 9) python3-setuptools
125+
Maintainer: Spiros Georgaras <[email protected]>
126+
Package: pyradio
127+
Section: Multimedia
128+
Architecture: all
129+
Description: Command line internet radio player
130+
131+
END
132+
133+
134+
cd debian
135+
tar xzf ../dist/*z
136+
mkdir -p usr/local/share/doc
137+
cp ../*md usr/local/share/doc
138+
cp ../*html usr/local/share/doc
139+
cp ../LICENCE usr/local/share/doc/copyright
140+
mkdir -p usr/local/share/man/man1
141+
cp ../pyradio.1 usr/local/share/man/man1/
142+
gzip usr/local/share/man/man1/pyradio.1
143+
sed -i "s/|version|/$cur_version/" DEBIAN/control
144+
cd ..
145+
146+
dpkg-deb -b debian $outfile
147+
# clean up
148+
rm -rf build pyradio.egg-info dist debian 2>/dev/null
149+
echo
150+
echo "=============================================================================="
151+
echo "File created: $outfile
152+
You can install it by executing
153+
sudo dpkg -i ./$outfile
154+
or
155+
sudo apt install ./$outfile
156+
"
157+
echo "=============================================================================="
158+
159+
}
160+
161+
TO_PYTHON=3
100162
while [[ $# -gt 0 ]]
101163
do
102164
key="$1"
@@ -105,6 +167,10 @@ do
105167
help
106168
exit
107169
;;
170+
-d)
171+
do_debian
172+
exit
173+
;;
108174
-u)
109175
uninstall
110176
exit
@@ -121,10 +187,6 @@ do
121187
TO_PYTHON=2
122188
shift
123189
;;
124-
3)
125-
TO_PYTHON=3
126-
shift
127-
;;
128190
*) # unknown option
129191
POSITIONAL+=("$1") # save it in an array for later
130192
shift # past argument

devel/what_tag

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ When ready to push, type
4141
To delete a this tag, type
4242
(local) ${cRed}git tag --delete $final_version${cReset}
4343
(remote) ${cRed}git push --delete origin $final_version${cReset}
44+
45+
To update ${cYellow}coderholic${cReset}, type:
46+
${cGreen}git push upstream master${cReset}
47+
48+
Finally, got to ${cRed}~/projects/my-gits/aur/pyragio-git${cReset}
49+
and execute ${cRed}./add-pkgver${cReset} to get AUR package
50+
ready for update.
4451
"
4552

4653

pyradio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# New stable version: ''
77
# Beta version: 'betax', x=1,2,3...
88
# RC version: 'RCx', x=1,23...
9-
app_state = 'beta3'
9+
app_state = 'beta4'
1010

1111
__version__ = version = '.'.join(map(str, version_info))
1212
__project__ = __name__

pyradio/config.py

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ class PyRadioStations(object):
6666

6767
playlist_recovery_result = 0
6868

69-
locked = False
70-
7169
_open_string = [ "open(stationFile, 'r')", "open(stationFile, 'r', encoding='utf-8')" ]
7270
_open_string_id = 0
7371

@@ -101,15 +99,6 @@ def __init__(self, stationFile=''):
10199
sys.exit(1)
102100
self.root_path = path.join(path.dirname(__file__), 'stations.csv')
103101

104-
if path.exists(self._session_lock_file):
105-
self.locked = True
106-
else:
107-
try:
108-
with open(self._session_lock_file, 'w') as f:
109-
pass
110-
except:
111-
pass
112-
113102
self._ps = PyRadioPlaylistStack()
114103

115104
if not self.locked:
@@ -371,7 +360,7 @@ def _get_playlist_abspath_from_data(self, stationFile=''):
371360
else:
372361
n, f = self.read_playlists()
373362
if sel <= n-1:
374-
stationFile=self.playlists[sel][-1]
363+
stationFile = self.playlists[sel][-1]
375364
return stationFile, 0
376365
else:
377366
""" playlist number sel does not exit """
@@ -921,6 +910,9 @@ class PyRadioConfig(PyRadioStations):
921910
theme_has_error = False
922911
theme_not_supported_notification_shown = False
923912

913+
# True if lock file exists
914+
locked = False
915+
924916
opts = collections.OrderedDict()
925917
opts[ 'general_title' ] = [ 'General Options', '' ]
926918
opts[ 'player' ] = [ 'Player: ', '' ]
@@ -964,6 +956,7 @@ def __init__(self):
964956

965957
self._check_config_file(self.stations_dir)
966958
self.config_file = path.join(self.stations_dir, 'config')
959+
self.force_to_remove_lock_file = False
967960

968961
@property
969962
def requested_player(self):
@@ -1083,9 +1076,13 @@ def session_lock_file(self, val):
10831076
return
10841077

10851078
def _get_lock_file(self):
1079+
''' Populate self._session_lock_file
1080+
If it exists, locked becomes True
1081+
Otherwise, the file is created
1082+
'''
10861083
if path.exists('/run/user'):
10871084
from os import geteuid
1088-
self._session_lock_file = path.join('/run/user', str(geteuid()), 'pyradio.lock')
1085+
self._session_lock_file = path.join('/run/user', str(geteuid()), 'pyradio.lock')
10891086
# remove old style session lock file (if it exists)
10901087
if path.exists(path.join(self.stations_dir, '.lock')):
10911088
try:
@@ -1095,22 +1092,35 @@ def _get_lock_file(self):
10951092
else:
10961093
self._session_lock_file = path.join(self.stations_dir, 'pyradio.lock')
10971094

1098-
def remove_session_lock_file(self):
1099-
#print(self._session_lock_file)
11001095
if path.exists(self._session_lock_file):
1096+
self.locked = True
1097+
else:
11011098
try:
1102-
remove(self._session_lock_file)
1103-
if logger.isEnabledFor(logging.INFO):
1104-
logger.info('Lock file removed...')
1105-
return 0, self._session_lock_file
1099+
with open(self._session_lock_file, 'w') as f:
1100+
pass
11061101
except:
1107-
if logger.isEnabledFor(logging.INFO):
1108-
logger.info('Failed to remove Lock file...')
1109-
return 1, self._session_lock_file
1110-
else:
1102+
pass
1103+
1104+
def remove_session_lock_file(self):
1105+
''' remove session lock file, if session is not locked '''
1106+
if self.locked:
11111107
if logger.isEnabledFor(logging.INFO):
1112-
logger.info('Lock file not found...')
1113-
return -1, self._session_lock_file
1108+
logger.info('Not removing lock file; session is locked...')
1109+
else:
1110+
if path.exists(self._session_lock_file):
1111+
try:
1112+
remove(self._session_lock_file)
1113+
if logger.isEnabledFor(logging.INFO):
1114+
logger.info('Lock file removed...')
1115+
return 0, self._session_lock_file
1116+
except:
1117+
if logger.isEnabledFor(logging.INFO):
1118+
logger.info('Failed to remove Lock file...')
1119+
return 1, self._session_lock_file
1120+
else:
1121+
if logger.isEnabledFor(logging.INFO):
1122+
logger.info('Lock file not found...')
1123+
return -1, self._session_lock_file
11141124

11151125
def _check_config_file(self, usr):
11161126
''' Make sure a config file exists in the config dir '''

0 commit comments

Comments
 (0)