Skip to content

Commit

Permalink
Fixes KBNLresearch#16 - check for required executables
Browse files Browse the repository at this point in the history
This change will check if our required binaries are available. If not,
a more helpful error is thrown.
AFAIK, this works only on Linux/MacOS - but I see no limitations here
since we already targeting Linux only.
helge000 committed Jan 29, 2020
1 parent c22819d commit 7be2ec3
Showing 3 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tapeimgr/cli.py
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
import uuid
from .tape import Tape
from . import config
from . import shared


class tapeimgrCLI:
@@ -136,6 +137,12 @@ def process(self):
# Parse command line arguments
self.parseCommandLine()

# Check if required command line utils are available
for cmd in shared.REQUIRED_CMDS:
if not shared.checkCmd(cmd):
msg = ("Command '" + cmd + "' not found. Install required packge")
errorExit(msg)

# Validate input
self.tape.validateInput()

7 changes: 7 additions & 0 deletions tapeimgr/gui.py
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
from tkfilebrowser import askopendirname
from .tape import Tape
from . import config
from . import shared


class tapeimgrGUI(tk.Frame):
@@ -74,6 +75,12 @@ def on_submit(self, event=None):
self.tape.notes = self.notes_entry.get(1.0, tk.END).strip()
self.tape.fillBlocks = self.fBlocks.get()

# Check if required command line utils are available
for cmd in shared.REQUIRED_CMDS:
if not shared.checkCmd(cmd):
msg = ("Command '" + cmd + "' not found. Install required packge")
errorExit(msg)

# Validate input
self.tape.validateInput()

12 changes: 12 additions & 0 deletions tapeimgr/shared.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
import subprocess as sub
import pytz

REQUIRED_CMDS = ['mt', 'dd']

def launchSubProcess(args, writeLog=True):
"""Launch subprocess and return exit code, stdout and stderr"""
try:
@@ -102,3 +104,13 @@ def generateDateTime(timeZone):
dateTime = pst.localize(dateTime)
dateTimeFormatted = dateTime.isoformat()
return dateTimeFormatted

def checkCmd(cmd):
"""Check if executable is present in PATH"""
return sub.call(
"type " + cmd,
shell=True,
stdout=sub.PIPE,
stderr=sub.PIPE
) == 0

0 comments on commit 7be2ec3

Please sign in to comment.