From 9758fa770e34bd01d15cc9e36efc1c6a1c3f7823 Mon Sep 17 00:00:00 2001 From: ZXGuesser Date: Sun, 15 Jan 2023 04:27:23 +0000 Subject: [PATCH] move new scripts into their own directory and start some migration code --- getvbit2 | 5 ++-- postupdate.sh | 30 +++++++++++++++++-- config.py => scripts/config.py | 4 ++- .../known_services.json | 26 ++++++++-------- runvbit2.py => scripts/runvbit2.py | 8 ++--- .../teletext-update.py | 0 vbit-config.py => scripts/vbit-config.py | 4 +-- teletext-update.service | 2 +- vbit2.service | 2 +- 9 files changed, 53 insertions(+), 28 deletions(-) rename config.py => scripts/config.py (97%) rename known_services.json => scripts/known_services.json (81%) rename runvbit2.py => scripts/runvbit2.py (95%) mode change 100644 => 100755 rename teletext-update.py => scripts/teletext-update.py (100%) mode change 100644 => 100755 rename vbit-config.py => scripts/vbit-config.py (98%) mode change 100644 => 100755 diff --git a/getvbit2 b/getvbit2 index 069d9a1..4588280 100755 --- a/getvbit2 +++ b/getvbit2 @@ -27,8 +27,9 @@ make # create links mkdir -p $HOME/.local/bin ln -s -f `pwd`/vbit2 $HOME/.local/bin/ -ln -s -f `pwd`/runvbit2.sh $HOME/.local/bin/ -ln -s -f `pwd`/vbit-config $HOME/.local/bin/ +ln -s -f `pwd`/scripts/runvbit2.py $HOME/.local/bin/runvbit2 +ln -s -f `pwd`/scripts/teletext-update.py $HOME/.local/bin/teletext-update +ln -s -f `pwd`/scripts/vbit-config.py $HOME/.local/bin/vbit-config # install systemd user scripts mkdir -p $HOME/.local/share/systemd/user diff --git a/postupdate.sh b/postupdate.sh index 348e20b..f70b89b 100755 --- a/postupdate.sh +++ b/postupdate.sh @@ -19,13 +19,17 @@ main(){ # recompile vbit2 make - sudo apt -y install python3-dialog + sudo apt -qq -y install python3-dialog + + # remove old symlink + rm $HOME/.local/bin/runvbit2.sh 2>/dev/null # create links mkdir -p $HOME/.local/bin ln -s -f `pwd`/vbit2 $HOME/.local/bin/ - ln -s -f `pwd`/runvbit2.sh $HOME/.local/bin/ - ln -s -f `pwd`/vbit-config $HOME/.local/bin/ + ln -s -f `pwd`/scripts/runvbit2.py $HOME/.local/bin/runvbit2 + ln -s -f `pwd`/scripts/teletext-update.py $HOME/.local/bin/teletext-update + ln -s -f `pwd`/scripts/vbit-config.py $HOME/.local/bin/vbit-config # install systemd user scripts mkdir -p $HOME/.local/share/systemd/user @@ -37,6 +41,9 @@ main(){ cleanoldunits + # warn about removing old services + migratejson + # restart vbit if service is active if [[ `systemctl --user is-active vbit2.service` == "active" ]]; then systemctl --user restart vbit2.service @@ -96,4 +103,21 @@ migrate(){ fi } +migratejson(){ + if [ -f $HOME/.teletext-services/config ]; then + printf 'This version of VBIT2 uses a new config format and directory scheme.\nServices will not be automatically migrated so must be reinstalled.\nThe following services were found:\n' + ls -d1 ~/.teletext-services/*/ + + read -n 1 -s -r -p "Do you wish to create a backup of these services? (y/N)" + if [[ $REPLY =~ ^[Yy]$ ]]; then + printf '\nbacking up old services to %s\n' "$HOME/teletext-services.bak" + mv $HOME/.teletext-services $HOME/teletext-services.bak + else + rm -rf $HOME/.teletext-services/ 2>/dev/null + fi + + vbit-config + fi +} + main; exit diff --git a/config.py b/scripts/config.py similarity index 97% rename from config.py rename to scripts/config.py index 2266c93..a71e318 100644 --- a/config.py +++ b/scripts/config.py @@ -88,7 +88,7 @@ def uninstallService(name): def installService(service): configData = load() - if not service.get("name") or not service.get("type") or not service.get("url") or not service.get("path"): + if not service.get("name") or not service.get("type") or not service.get("path"): raise RuntimeError("invalid service configuration data\n{0}".format(service)) installedNames = [] @@ -103,6 +103,8 @@ def installService(service): if not os.path.exists(service["path"]): raise RuntimeError("Directory does not exist") else: + if not service.get("url"): + raise RuntimeError("invalid service configuration data\n{0}".format(service)) doServiceInstall(service["type"], service["path"], service["url"]) serviceConfigObject = {"name":service["name"], "type":service["type"], "path":service["path"]} diff --git a/known_services.json b/scripts/known_services.json similarity index 81% rename from known_services.json rename to scripts/known_services.json index cc209b2..77bf0a7 100644 --- a/known_services.json +++ b/scripts/known_services.json @@ -2,21 +2,19 @@ "services":[ {"name":"Teefax","type":"svn","url":"http://teastop.plus.com/svn/teletext/","path":"Teefax"}, {"name":"Ceefax","type":"group","services":[ - {"name":"Ceefax (East)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/East","path":"CeefaxEast", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":"True"}]}, - {"name":"Ceefax (East Midlands)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/EastMidlands","path":"CeefaxEastMids", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":"True"}]}, - {"name":"Ceefax (London)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/London","path":"CeefaxLondon", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":"True"}]}, - {"name":"Ceefax (Northern Ireland)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/NorthernIreland","path":"CeefaxNI", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":"True"}]}, - {"name":"Ceefax (Scotland)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/Scotland","path":"CeefaxScotland", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":"True"}]}, - {"name":"Ceefax (South)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/South","path":"CeefaxSouth", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":"True"}]}, - {"name":"Ceefax (South West)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/SouthWest","path":"CeefaxSouthWest", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":"True"}]}, - {"name":"Ceefax (Wales)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/Wales","path":"CeefaxWales", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":"True"}]}, - {"name":"Ceefax (West)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/West","path":"CeefaxWest", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":"True"}]}, - {"name":"Ceefax (Worldwide)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/Worldwide","path":"CeefaxWorldwide", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":"True"}]}, - {"name":"Ceefax (Yorks and Lincs)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/Yorks&Lincs","path":"CeefaxYorksAndLincs", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":"True"}]} - ]}, - {"name":"Chunkytext","type":"git","url":"https://zxnet.co.uk/git/cf.git","path":"Chunkytext", "subservices":[ - {"name":"foo","path":"foo"} + {"name":"Ceefax (East)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/East","path":"CeefaxEast", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":true}]}, + {"name":"Ceefax (East Midlands)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/EastMidlands","path":"CeefaxEastMids", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":true}]}, + {"name":"Ceefax (London)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/London","path":"CeefaxLondon", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":true}]}, + {"name":"Ceefax (Northern Ireland)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/NorthernIreland","path":"CeefaxNI", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":true}]}, + {"name":"Ceefax (Scotland)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/Scotland","path":"CeefaxScotland", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":true}]}, + {"name":"Ceefax (South)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/South","path":"CeefaxSouth", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":true}]}, + {"name":"Ceefax (South West)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/SouthWest","path":"CeefaxSouthWest", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":true}]}, + {"name":"Ceefax (Wales)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/Wales","path":"CeefaxWales", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":true}]}, + {"name":"Ceefax (West)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/West","path":"CeefaxWest", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":true}]}, + {"name":"Ceefax (Worldwide)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/Worldwide","path":"CeefaxWorldwide", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":true}]}, + {"name":"Ceefax (Yorks and Lincs)","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/Yorks&Lincs","path":"CeefaxYorksAndLincs", "subservices":[{"name":"CeefaxCommon","type":"svn","url":"https://internal.nathanmediaservices.co.uk/svn/ceefax/national","path":"National","required":true}]} ]}, + {"name":"Chunkytext","type":"git","url":"https://zxnet.co.uk/git/cf.git","path":"Chunkytext"}, {"name":"SPARK","type":"git","url":"https://github.com/ZXGuesser/spark-teletext.git","path":"SPARK"} ] } \ No newline at end of file diff --git a/runvbit2.py b/scripts/runvbit2.py old mode 100644 new mode 100755 similarity index 95% rename from runvbit2.py rename to scripts/runvbit2.py index ca0b3f6..7697b1a --- a/runvbit2.py +++ b/scripts/runvbit2.py @@ -12,10 +12,10 @@ def signalHandler(_signo, _stack_frame): configData = config.load() -try: - service = config.getSelectedService(configData) -except Exception as e: - print(e) +service = config.getSelectedService() + +if not service: + print("No service selected") quit() linesPerField = 16 # vbit2 defaults to 16 lpf diff --git a/teletext-update.py b/scripts/teletext-update.py old mode 100644 new mode 100755 similarity index 100% rename from teletext-update.py rename to scripts/teletext-update.py diff --git a/vbit-config.py b/scripts/vbit-config.py old mode 100644 new mode 100755 similarity index 98% rename from vbit-config.py rename to scripts/vbit-config.py index c98634d..8b199f0 --- a/vbit-config.py +++ b/scripts/vbit-config.py @@ -9,7 +9,7 @@ import re from dialog import Dialog -# get absolute path of vbit2 install +# get absolute path of vbit2 scripts directory SCRIPTDIR = os.path.dirname(os.path.realpath(__file__)) # absolute path of known services file @@ -279,7 +279,7 @@ def mainMenu(): subprocess.run(["systemctl", "--user", command, "vbit2.service"]) elif tag == "U": os.system('clear') - subprocess.run(os.path.join(SCRIPTDIR,"update.sh")) # run the update script + subprocess.run(os.path.join(SCRIPTDIR,"../update.sh")) # run the update script break # exit vbit-config else: diff --git a/teletext-update.service b/teletext-update.service index 6f1dd94..70d4f93 100644 --- a/teletext-update.service +++ b/teletext-update.service @@ -3,4 +3,4 @@ Description=Automatically check active teletext service for updates [Service] Type=oneshot -ExecStart=%h/vbit2/teletext-update.sh +ExecStart=%h/.local/bin/teletext-update diff --git a/vbit2.service b/vbit2.service index 063b52c..da19b75 100644 --- a/vbit2.service +++ b/vbit2.service @@ -3,7 +3,7 @@ Description=VBIT2 [Service] Type=simple -ExecStart=%h/.local/bin/runvbit2.sh +ExecStart=%h/.local/bin/runvbit2 Restart=always [Install]