def connect(self): print('Connecting.......') self.exit = False self.fd = None self.child_pid = None self.accept() (child_pid, fd) = pty.fork() if child_pid == 0: env2 = os.environ.copy() env2['TERM'] = 'xterm' subprocess.run([get_executable(), "-m", "xonsh"], env=env2) else: self.fd = fd self.child_pid = child_pid self.thread = Thread(target=read_and_forward_pty_output, args=(self, )) self.thread.start()
def py_run(cmd): """run python script args: cmd - array of parameters returns: array: return code, return stdout data return stderr data example: py_run(["manage.py", "help"]) """ return run([ get_executable(), ] + cmd)
def run(param=None): if param: argv = param else: argv = sys.argv base_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(base_path) ext_lib_path = os.path.join(base_path, "ext_lib") if not ext_lib_path in sys.path: sys.path.append(ext_lib_path) os.environ['PYTIGON_ROOT_PATH'] = base_path if len(argv) > 1 and argv[1].startswith('manage'): if '_' in argv[1]: from pytigon.schserw.settings import ROOT_PATH, DATA_PATH, PRJ_PATH, \ STATIC_APP_ROOT, MEDIA_ROOT, UPLOAD_PATH x = argv[1].split('_', 1) app = x[1] if not os.path.exists(PRJ_PATH) or not os.path.exists(DATA_PATH): from pytigon_lib.schtools.install_init import init init(app, ROOT_PATH, DATA_PATH, PRJ_PATH, STATIC_APP_ROOT, [MEDIA_ROOT, UPLOAD_PATH]) path3 = os.path.join(PRJ_PATH, app) os.chdir(path3) subprocess.run([get_executable(), "manage.py"] + argv[2:]) os.chdir(base_path) else: subprocess.run([get_executable(), "manage.py"] + argv[2:]) elif len(argv) > 1 and argv[1].startswith('run_'): from pytigon.schserw.settings import ROOT_PATH, DATA_PATH, PRJ_PATH, \ STATIC_APP_ROOT, MEDIA_ROOT, UPLOAD_PATH x = argv[1].split('_', 1) if '/' in x[1]: x2 = x[1].split('/', 1) app = x2[0] script = x2[1] else: app = x[1] script = "run.py" path3 = os.path.join(PRJ_PATH, app) subprocess.run([ get_executable(), ] + [ os.path.join(path3, script), ] + argv[2:]) elif len(argv) > 1 and argv[1].startswith('runserver'): if '_' in argv[1]: from pytigon.schserw import ROOT_PATH, DATA_PATH, PRJ_PATH, \ STATIC_APP_ROOT, MEDIA_ROOT, UPLOAD_PATH x = argv[1].split('_', 1) app = x[1] if not os.path.exists(PRJ_PATH) or not os.path.exists(DATA_PATH): from pytigon_lib.schtools.install_init import init init(app, ROOT_PATH, DATA_PATH, PRJ_PATH, STATIC_APP_ROOT, [MEDIA_ROOT, UPLOAD_PATH]) path3 = os.path.join(PRJ_PATH, app) os.chdir(path3) options = [] if not '-b' in argv[2:]: options = [ '-b', '0.0.0.0:8000', ] options.append('asgi:application') tmp = sys.argv sys.argv = [ '', ] + argv[2:] + options if platform_name() == 'Android': from daphne.cli import CommandLineInterface CommandLineInterface.entrypoint() else: from hypercorn.__main__ import main main() sys.argv = tmp os.chdir(base_path) elif len(argv) > 1 and (argv[1].endswith('.py') or argv[1][-4:-1] == ".py"): subprocess.run([ get_executable(), ] + argv[1:]) else: help = False if len(argv) > 1 and argv[1] == '--help': help = True try: if help: print("First form:") print("===========") from pytigon_gui.pytigon import main main() except SystemExit: if help: print("Second form:") print("============") print( "Manage pytigon application: pytigon manage_{{project_name}} options" ) print( " to see all options run pytigon manage_{{project_name}} --help" ) print("") print("Third option:") print("=============") print( "Run web server: pytigon runserver_{{project_name}} options" ) print( " to see all options run pytigon runserver_{{project_name}} --help" ) print("") print("The fourth option:") print("==================") print("Run python script: pytigon {{script_name}}.py") print(" run python script in pytigon enviroment") print("") print("The fifth option:") print("=================") print( "Run python script in project directory: pytigon run_{{project_name}}/{{script_name}}.py" ) print(" run python script in pytigon enviroment") print("")
server = f"gunicorn -b 0.0.0.0:{port} -w {count} --access-logfile /var/log/pytigon-access.log --log-file /var/log/pytigon-err.log wsgi -t {TIMEOUT}" else: server1 = f"hypercorn -b 0.0.0.0:{port} -w {count} --access-log /var/log/pytigon-access.log --error-log /var/log/pytigon-err.log asgi:application" server2 = f"gunicorn -b 0.0.0.0:{port} -w {count} -k uvicorn.workers.UvicornWorker --access-logfile /var/log/pytigon-access.log --log-file /var/log/pytigon-err.log asgi:application -t {TIMEOUT}" server3 = f"daphne -b 0.0.0.0 -p {port} --proxy-headers --access-log /var/log/pytigon-access.log asgi:application" server = (server1, server2, server3)[ASGI_SERVER_ID] path = f"/var/www/pytigon/prj/{prj}" cmd = f"cd {path} && exec {server}" port += 1 print(cmd) ret_tab.append(subprocess.Popen(cmd, shell=True)) if not "NO_EXECUTE_TASKS" in environ: for prj in PRJS: cmd = "cd /var/www/pytigon && exec %s pytigon_task.py %s" % ( get_executable(), prj, ) print(cmd) ret_tab.append(subprocess.Popen(cmd, shell=True)) restart = subprocess.Popen("nginx -g 'daemon off;'", shell=True) restart.wait() for pos in ret_tab: pos.wait()
port = START_PORT ret_tab = [] if not "RUN_DJANGO" in environ or (environ["RUN_DJANGO"] and environ["RUN_DJANGO"] != "0"): for prj in PRJS: static_path = os.path.join(DATA_PATH, "static", prj) if not os.path.exists(static_path): os.makedirs(static_path) os.chown(static_path, uid, gid) cmd = ( f"cd /home/www-data/pytigon && su -m www-data -s /bin/sh -c 'cd /home/www-data/pytigon; exec %s -m pytigon.ptig manage_{prj} collectstatic --noinput'" % get_executable()) fnull = open(os.devnull, "w") collectstatic = subprocess.Popen(cmd, shell=True, stdout=fnull, stderr=subprocess.STDOUT) collectstatic.wait() if prj in NOWP: count = NOWP[prj] else: count = (NOWP["default-main"] if prj == MAIN_PRJ else NOWP["default-additional"]) server = f"gunicorn --preload -b 0.0.0.0:{port} --user www-data -w {count} {access_logfile} {error_logfile} wsgi -t {TIMEOUT}"