Ver Fonte

Allow executing commands instead of only .py files

notcammy há 7 anos atrás
pai
commit
276c7d770a
2 ficheiros alterados com 13 adições e 36 exclusões
  1. 9 11
      pyinstalive/downloader.py
  2. 4 25
      pyinstalive/initialize.py

+ 9 - 11
pyinstalive/downloader.py

@@ -5,6 +5,7 @@ import subprocess
 import sys
 import threading
 import time
+import shlex
 
 from glob import glob
 from tqdm import tqdm
@@ -32,13 +33,10 @@ def main(instagram_api_arg, record_arg, settings_arg):
 
 
 
-def run_script(file):
+def run_command(command):
 	try:
 		FNULL = open(os.devnull, 'w')
-		if sys.version.split(' ')[0].startswith('2'):
-			subprocess.call(["python", file], stdout=FNULL, stderr=subprocess.STDOUT)
-		else:
-			subprocess.call(["python3", file], stdout=FNULL, stderr=subprocess.STDOUT)
+		subprocess.Popen(shlex.split(command), stdout=FNULL, stderr=subprocess.STDOUT)
 	except OSError as e:
 		pass
 
@@ -128,12 +126,12 @@ def download_livestream(broadcast):
 
 		if (settings.run_at_start is not "None"):
 			try:
-				thread = threading.Thread(target=run_script, args=(settings.run_at_start,))
+				thread = threading.Thread(target=run_command, args=(settings.run_at_start,))
 				thread.daemon = True
 				thread.start()
-				log("[I] Executed file to run at start.", "GREEN")
+				log("[I] Command executed: \033[94m{:s}".format(settings.run_at_start), "GREEN")
 			except Exception as e:
-				log('[W] Could not run file: {:s}'.format(str(e)), "YELLOW")
+				log('[W] Could not execute command: {:s}'.format(str(e)), "YELLOW")
 
 
 		comment_thread_worker = None
@@ -177,12 +175,12 @@ def stitch_video(broadcast_downloader, broadcast, comment_thread_worker):
 
 		if (settings.run_at_finish is not "None"):
 			try:
-				thread = threading.Thread(target=run_script, args=(settings.run_at_finish,))
+				thread = threading.Thread(target=run_command, args=(settings.run_at_finish,))
 				thread.daemon = True
 				thread.start()
-				log("[I] Executed file to run at finish.", "GREEN")
+				log("[I] Command executed: \033[94m{:s}".format(settings.run_at_finish), "GREEN")
 			except Exception as e:
-				log('[W] Could not run file: {:s}'.format(str(e)), "YELLOW")
+				log('[W] Could not execute command: {:s}'.format(str(e)), "YELLOW")
 
 		log('[I] Stitching downloaded files into video...', "GREEN")		
 

+ 4 - 25
pyinstalive/initialize.py

@@ -72,18 +72,8 @@ def check_config_validity(config):
 
 
 		try:
-			settings.run_at_start = config.get('pyinstalive', 'run_at_start')
-			if (settings.run_at_start):
-				if not os.path.isfile(settings.run_at_start):
-					log("[W] Path to file given for 'run_at_start' does not exist, using default value (None)", "YELLOW")
-					settings.run_at_start = "None"
-					has_thrown_errors = True
-				else:
-					if not settings.run_at_start.split('.')[-1] == 'py':
-						log("[W] File given for 'run_at_start' is not a Python script, using default value (None)", "YELLOW")
-						settings.run_at_start = "None"
-						has_thrown_errors = True
-			else:
+			settings.run_at_start = config.get('pyinstalive', 'run_at_start').replace("\\", "\\\\")
+			if not settings.run_at_start:
 				settings.run_at_start = "None"
 		except:
 			log("[W] Invalid or missing settings detected for 'run_at_start', using default value (None)", "YELLOW")
@@ -93,20 +83,9 @@ def check_config_validity(config):
 
 
 		try:
-			settings.run_at_finish = config.get('pyinstalive', 'run_at_finish')
-			if (settings.run_at_finish):
-				if not os.path.isfile(settings.run_at_finish):
-					log("[W] Path to file given for 'run_at_finish' does not exist, using default value (None)", "YELLOW")
-					settings.run_at_finish = "None"
-					has_thrown_errors = True
-				else:
-					if not settings.run_at_finish.split('.')[-1] == 'py':
-						log("[W] File given for 'run_at_finish' is not a Python script, using default value (None)", "YELLOW")
-						settings.run_at_finish = "None"
-						has_thrown_errors = True
-			else:
+			settings.run_at_finish = config.get('pyinstalive', 'run_at_finish').replace("\\", "\\\\")
+			if not settings.run_at_finish:
 				settings.run_at_finish = "None"
-
 		except:
 			log("[W] Invalid or missing settings detected for 'run_at_finish', using default value (None)", "YELLOW")
 			settings.run_at_finish = "None"