diff --git a/PseudoChannel.py b/PseudoChannel.py index b60872c..e3e1ef4 100644 --- a/PseudoChannel.py +++ b/PseudoChannel.py @@ -59,6 +59,8 @@ class PseudoChannel(): DEBUG = config.debug_mode + ROTATE_LOG = config.rotateLog + def __init__(self): logging.basicConfig(filename="pseudo-channel.log", level=logging.INFO) @@ -1008,6 +1010,18 @@ class PseudoChannel(): 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): 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 """ + """Every 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") diff --git a/pseudo_config.py b/pseudo_config.py index c07c8f9..4fc2be0 100644 --- a/pseudo_config.py +++ b/pseudo_config.py @@ -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) @@ -83,8 +69,34 @@ useDailyOverlapCache = True 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 """---""" -useGoogleCalendar = False \ No newline at end of file +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 \ No newline at end of file diff --git a/startstop.sh b/startstop.sh index 358be58..f125621 100755 --- a/startstop.sh +++ b/startstop.sh @@ -13,35 +13,57 @@ #----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------- -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. - 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 - echo "Created $pid_file file in $output_pid_path dir" + + echo "Created $OUTPUT_PID_FILE file in $OUTPUT_PID_PATH dir" else # 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) - rm $output_pid_path/$pid_file - echo "Deleted $pid_file file in $output_pid_path dir" - kill $the_pid + the_pid=$(<$OUTPUT_PID_PATH/$OUTPUT_PID_FILE) + + rm "$OUTPUT_PID_PATH/$OUTPUT_PID_FILE" + + echo "Deleted $OUTPUT_PID_FILE file in $OUTPUT_PID_PATH dir" + + kill "$the_pid" + while [ -e /proc/$the_pid ] + do - echo "PseudoChannel.py @: $the_pid is still running" + + echo "$SCRIPT_TO_EXECUTE_PLUS_ARGS @: $the_pid is still running" + sleep .7 + done - echo "PseudoChannel.py @: $the_pid has finished" + + echo "$SCRIPT_TO_EXECUTE_PLUS_ARGS @: $the_pid has finished" fi \ No newline at end of file