Updates to scripts.

This commit is contained in:
Justin Emter
2017-08-13 11:48:29 -07:00
parent 8056c4b9ad
commit c903a1c6d7
3 changed files with 80 additions and 29 deletions

View File

@@ -59,6 +59,8 @@ class PseudoChannel():
DEBUG = config.debug_mode DEBUG = config.debug_mode
ROTATE_LOG = config.rotateLog
def __init__(self): def __init__(self):
logging.basicConfig(filename="pseudo-channel.log", level=logging.INFO) logging.basicConfig(filename="pseudo-channel.log", level=logging.INFO)
@@ -1008,6 +1010,18 @@ class PseudoChannel():
f.write(data) f.write(data)
def rotate_log(self):
try:
os.remove('../pseudo-channel.log')
except OSError:
pass
try:
os.remove('./pseudo-channel.log')
except OSError:
pass
def exit_app(self): def exit_app(self):
print " - Exiting Pseudo TV & cleaning up." print " - Exiting Pseudo TV & cleaning up."
@@ -1175,6 +1189,9 @@ if __name__ == '__main__':
see if it's midnight (or 23.59), if so then generate a new daily_schedule see if it's midnight (or 23.59), if so then generate a new daily_schedule
""" """
"""Every <user specified day> rotate log"""
dayToRotateLog = pseudo_channel.ROTATE_LOG.lower()
schedule.every().friday.at("00:00").do(pseudo_channel.rotate_log)
logging.info("+++++ Running PseudoChannel.py -r") logging.info("+++++ Running PseudoChannel.py -r")

View File

@@ -31,20 +31,6 @@
""" """
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# import ../plex_token.py
try:
import plex_token as plex_token
except ImportError as e:
print "+++++ Cannot find plex_token file. Make sure you create a plex_token.py file with the appropriate data."
raise e
baseurl = plex_token.baseurl
token = plex_token.token
gkey = plex_token.gkey
''' '''
* *
* List of plex clients to use (add multiple clients to control multiple TV's) * List of plex clients to use (add multiple clients to control multiple TV's)
@@ -83,8 +69,34 @@ useDailyOverlapCache = True
dailyUpdateTime = "12:00 AM" dailyUpdateTime = "12:00 AM"
"""Debug mode will give you more output in your terminal to help problem solve issues.s""" """Debug mode will give you more output in your terminal to help problem solve issues."""
debug_mode = True debug_mode = True
"""---""" """---"""
useGoogleCalendar = False useGoogleCalendar = False
"""When to delete / remake the pseudo-channel.log - right at midnight, (i.e. 'friday') """
rotateLog = "friday"
"""
##### Do not edit below this line.
Below is logic to grab your Plex 'token' & Plex 'baseurl'. If you are following along and have created a 'plex_token.py'
file as instructed, you do not need to edit below this line.
"""
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# import ../plex_token.py
try:
import plex_token as plex_token
except ImportError as e:
print "+++++ Cannot find plex_token file. Make sure you create a plex_token.py file with the appropriate data."
raise e
baseurl = plex_token.baseurl
token = plex_token.token
gkey = plex_token.gkey

View File

@@ -13,35 +13,57 @@
#----BEGIN EDITABLE VARS---- #----BEGIN EDITABLE VARS----
pid_file=running.pid SCRIPT_TO_EXECUTE_PLUS_ARGS='PseudoChannel.py -m -r'
output_pid_path=. OUTPUT_PID_FILE=running.pid
python_to_use="$(which python)" OUTPUT_PID_PATH=.
PYTHON_TO_USE="$(which python)"
# If using 'virtualenv' with python, specify the local virtualenv dir.
VIRTUAL_ENV_DIR="env"
#----END EDITABLE VARS------- #----END EDITABLE VARS-------
if [ ! -e $output_pid_path/$pid_file ]; then if [ -d "$VIRTUAL_ENV_DIR" ]; then
PYTHON_TO_USE="$VIRTUAL_ENV_DIR/bin/python"
fi
if [ ! -e "$OUTPUT_PID_PATH/$OUTPUT_PID_FILE" ]; then
# If the running.pid file doesn't exists, create it, start PseudoChannel.py and add the PID to it. # If the running.pid file doesn't exists, create it, start PseudoChannel.py and add the PID to it.
nohup $python_to_use ./PseudoChannel.py -m -r > /dev/null 2>&1 & echo $! > $output_pid_path/$pid_file "$PYTHON_TO_USE" ./$SCRIPT_TO_EXECUTE_PLUS_ARGS > /dev/null 2>&1 & echo $! > "$OUTPUT_PID_PATH/$OUTPUT_PID_FILE"
echo "Started $SCRIPT_TO_EXECUTE_PLUS_ARGS @ Process: $!"
echo "Started PseudoChannel.py @ Process: $!"
sleep .7 sleep .7
echo "Created $pid_file file in $output_pid_path dir"
echo "Created $OUTPUT_PID_FILE file in $OUTPUT_PID_PATH dir"
else else
# If the running.pid exists, read it & try to kill the process if it exists, then delete it. # If the running.pid exists, read it & try to kill the process if it exists, then delete it.
the_pid=$(<$output_pid_path/$pid_file) the_pid=$(<$OUTPUT_PID_PATH/$OUTPUT_PID_FILE)
rm $output_pid_path/$pid_file
echo "Deleted $pid_file file in $output_pid_path dir" rm "$OUTPUT_PID_PATH/$OUTPUT_PID_FILE"
kill $the_pid
echo "Deleted $OUTPUT_PID_FILE file in $OUTPUT_PID_PATH dir"
kill "$the_pid"
while [ -e /proc/$the_pid ] while [ -e /proc/$the_pid ]
do do
echo "PseudoChannel.py @: $the_pid is still running"
echo "$SCRIPT_TO_EXECUTE_PLUS_ARGS @: $the_pid is still running"
sleep .7 sleep .7
done done
echo "PseudoChannel.py @: $the_pid has finished"
echo "$SCRIPT_TO_EXECUTE_PLUS_ARGS @: $the_pid has finished"
fi fi