Skip to content

Commit

Permalink
Merge pull request #21 from bpennypacker/work
Browse files Browse the repository at this point in the history
Work
  • Loading branch information
bpennypacker authored Feb 27, 2021
2 parents 34ec6dd + f64e0ca commit 2feb4d1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
35 changes: 23 additions & 12 deletions phad
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ from socket import error as socket_error
from subprocess import Popen, PIPE
from threading import Timer

VERSION = "0.4.1"
VERSION = "0.4.2"

current_template_id = 0
display_timeout = 0
Expand Down Expand Up @@ -107,11 +107,13 @@ Ctl = {

EOM = "---EOM---" # All FTL responses end with this

args = None

#############################################################################

def Warning(msg):
print ("{}Warning:{} {}".format(Fore['Bright_Red'], Ctl['Reset'], msg))
if args.verbose:
print ("{}Warning:{} {}".format(Fore['Bright_Red'], Ctl['Reset'], msg))

#############################################################################

Expand Down Expand Up @@ -683,11 +685,14 @@ def get_host_data(cfg):

data['pid'] = os.getpid()

results = run('grep -c "model name" /proc/cpuinfo')
results = run('nproc')
if len(results):
data['numprocs'] = int(results)
else:
data['numprocs'] = 0
msg = "Unexpected result from nproc [{}]. Assuming 1 processor.".format(results)
Warning(msg)
Devug(msg)
data['numprocs'] = 1

data['cpuload'] = data['loadavg'][0] / data['numprocs'] * 100

Expand Down Expand Up @@ -914,13 +919,6 @@ def display_power(val):
#############################################################################

if __name__ == '__main__':
try:
from evdev import ecodes, InputDevice, categorize
evdevInstalled = True
except:
Warning('Module evdev not found. Touch screen support is disabled.')
time.sleep(10)

parser = argparse.ArgumentParser(description="Pi-Hole Alternate Display")
parser.add_argument('-c', '--config',
help="Config file",
Expand Down Expand Up @@ -953,9 +951,21 @@ if __name__ == '__main__':
help="Write debugging information to debug.log",
required=False,
action="store_true")
parser.add_argument('-v', '--verbose',
help="Display warning messages on stdout",
required=False,
action="store_true")

args = parser.parse_args()

try:
from evdev import ecodes, InputDevice, categorize
evdevInstalled = True
except:
Warning('Module evdev not found. Touch screen support is disabled.')
if args.verbose:
time.sleep(10)

if args.debug:
Ctl['Clear_Screen'] = '' # Disable clearing the screen & moving home so debug statement are seen
Ctl['Home'] = ''
Expand Down Expand Up @@ -1051,7 +1061,8 @@ if __name__ == '__main__':
os.path.isfile(backlight_file) == False:
Warning("LCD backlight file {} not found".format(backlight_file))
Warning("Disabling backlight toggling of display.")
time.sleep(10)
if args.verbose:
time.sleep(10)
backlight_enabled = False

signal.signal(signal.SIGHUP, signal_handler)
Expand Down
25 changes: 19 additions & 6 deletions phad-simple-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ PYTHON3=$(/usr/bin/env python3 -c 'import sys; print(sys.version_info[0])')

if [[ "$PYTHON3" != "3" ]] ; then
printf " %b %s\\n" "${CROSS}" "Python 3 not found\\n"
printf " %b %bPi-hole requires version 3 of Python to run.%b\\n" "${INFO}" "${COL_LIGHT_RED}" "${COL_NC}"
printf " %b %bPhad requires version 3 of Python to run.%b\\n" "${INFO}" "${COL_LIGHT_RED}" "${COL_NC}"
printf " Please ensure Python 3 is installed and that the following command\\n"
printf " launches the Python 3 interpreter:\\n"
printf "\\n %b/usr/bin/env python3%b\\n" "${COL_LIGHT_GREEN}" "${COL_NC}"
Expand All @@ -117,9 +117,22 @@ for i in ${PIHOLE_FILES} ; do
fi
done

printf " %b %bChecking Python 3 for pip%b\\n" "${INFO}" "${COL_LIGHT_RED}" "${COL_NC}"
/usr/bin/env python3 -m pip --version > /dev/null 2>&1
if [[ $? -ne 0 ]] ; then
printf " %b %bInstalling python3-pip package%b\\n" "${INFO}" "${COL_LIGHT_RED}" "${COL_NC}"
sudo apt-get install python3-pip > /dev/null 2>&1
if [[ $? -ne 0 ]] ; then
printf " %b %s\\n" "${CROSS}" "Unable to install python3-pip\\n"
printf " %b %bThe python3-pip package is required to allow python to install other packages.%b\\n" "${INFO}" "${COL_LIGHT_RED}" "${COL_NC}"
printf " Please ensure the Python3 pip module is installed then re-run this installer.\\n"
exit 1
fi
fi

if [[ "$1" == "--upgrade" ]] ; then
printf " %b %bChecking Python and installing Python 3 dependencies%b\\n" "${INFO}" "${COL_LIGHT_RED}" "${COL_NC}"
EVDEV=$(/usr/bin/env python2 -m pip list | grep evdev)
printf " %b %bInstalling Python 3 dependencies%b\\n" "${INFO}" "${COL_LIGHT_RED}" "${COL_NC}"
EVDEV=$(/usr/bin/env python3 -m pip list | grep evdev)
if [[ "$EVDEV" != "" ]] ; then
REQUIREMENTS="$REQUIREMENTS evdev>==1.0.0"
fi
Expand Down Expand Up @@ -166,7 +179,7 @@ cd $PHAD_DIR

for i in ${PHAD_FILES} ; do
if [ -f "$i" ] ; then
printf " %b %s\\n" "${CROSS}" "phad file $i exists"
printf " %b %s\\n" "${CROSS}" "file ${PHAD_DIR}/${i} exists"
printf " %b %bphad appears to already be installed in $PHAD_DIR. Aborting.%b\\n" "${INFO}" "${COL_LIGHT_RED}" "${COL_NC}"
exit 1
fi
Expand Down Expand Up @@ -230,13 +243,13 @@ fi
if [[ "$TOUCHSCREEN_DEV" == "" ]] ; then
T="x"
while ! [[ $T =~ $RE ]] ; do
T=$(whiptail --title "Display cycle time" --inputbox "How many seconds shold phad wait between switching its display?" ${r} ${c} 20 3>&1 1>&2 2>&3)
T=$(whiptail --title "Display cycle time" --inputbox "No touchscreen interface was found, so touch support will be disabled. Instead, phad will be configured to cycle between displays automatically. How many seconds shold phad wait between switching its display?" ${r} ${c} 20 3>&1 1>&2 2>&3)
done
[ "$T" != "" ] && TEMPLATE_TIMEOUT="-s $T"
fi

declare -a TEMPLATE_LIST=()
if [[ "TOUCHSCREEN_DEV" != "" && "$BACKLIGHT_FILE" == "" ]] ; then
if [[ "$TOUCHSCREEN_DEV" != "" && "$BACKLIGHT_FILE" == "" ]] ; then
TEMPLATE_LIST+=("blank.j2" "A blank screen to simulate turning off the display" ON)
fi

Expand Down

0 comments on commit 2feb4d1

Please sign in to comment.