def launch(*args, **options): "launch acts on the user specified action and options by executing Hedrix.run" action = args[0] if options['reload']: event_handler = Reload(options) observer = Observer() observer.schedule(event_handler, path='.', recursive=True) observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() pid = os.getpid() chalk.eraser() chalk.green('\nHendrix successfully closed.') os.kill(pid, 15) observer.join() exit('\n') else: try: deploy = HendrixDeploy(action, options) deploy.run() except Exception, e: if options.get('traceback'): tb = sys.exc_info()[2] msg = traceback.format_exc(tb) else: msg = str(e) chalk.red(msg, pipe=chalk.stderr) os._exit(1)
def on_any_event(self, event): if event.is_directory: return ext = os.path.splitext(event.src_path)[1] if ext == ".py": self.process = self.restart() chalk.eraser() chalk.yellow("Detected changes, restarting...")
def on_any_event(self, event): if event.is_directory: return ext = os.path.splitext(event.src_path)[1] if ext == '.py': self.schedule_restart() chalk.eraser() chalk.yellow("Detected changes in {}, restarting...".format(event.src_path))
def on_any_event(self, event): if event.is_directory: return ext = path(event.src_path).ext if ext == '.py': self.process = self.restart() chalk.eraser() chalk.yellow("Detected changes, restarting...")
def main(): "The function to execute when running hx" options, args = HendrixOptionParser.parse_args(sys.argv[1:]) options = vars(options) try: action = args[0] except IndexError: HendrixOptionParser.print_help() return exposeProject(options) options = djangoVsWsgi(options) options = devFriendly(options) redirect = noiseControl(options) try: if action == 'start' and not options['daemonize']: chalk.eraser() chalk.blue('Starting Hendrix...') elif action == 'stop': chalk.green('Stopping Hendrix...') if options['daemonize']: daemonize, _reload, opts = cleanOptions(options) process = subprocess.Popen( ['hx', action] + opts, stdout=redirect, stderr=redirect ) time.sleep(2) if process.poll(): raise RuntimeError else: launch(*args, **options) if action not in ['start_reload', 'restart']: chalk.eraser() chalk.green('\nHendrix successfully closed.') except Exception, e: msg = ( 'ERROR: %s\nCould not %s hendrix. Try again using the --traceback ' 'flag for more information.' ) chalk.red(msg % (str(e), action), pipe=chalk.stderr) if options['traceback']: raise else: os._exit(1)
def launch(*args, **options): """ launch acts on the user specified action and options by executing Hedrix.run """ action = args[0] if options["reload"]: event_handler = Reload(options) observer = Observer() observer.schedule(event_handler, path=".", recursive=True) observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() pid = os.getpid() chalk.eraser() chalk.green("\nHendrix successfully closed.") os.kill(pid, 15) observer.join() exit("\n") else: try: if options["key"] and options["cert"] and options["cache"]: from hendrix.deploy import hybrid HendrixDeploy = hybrid.HendrixDeployHybrid elif options["key"] and options["cert"]: from hendrix.deploy import ssl HendrixDeploy = ssl.HendrixDeploySSL elif options["cache"]: HendrixDeploy = cache.HendrixDeployCache else: HendrixDeploy = base.HendrixDeploy deploy = HendrixDeploy(action, options) deploy.run() except Exception, e: tb = sys.exc_info()[2] msg = traceback.format_exc(tb) chalk.red(msg, pipe=chalk.stderr) os._exit(1)
def logReload(options): """ encompasses all the logic for reloading observer. """ event_handler = Reload(options) observer = Observer() observer.schedule(event_handler, path='.', recursive=True) observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() pid = os.getpid() chalk.eraser() chalk.green('\nHendrix successfully closed.') os.kill(pid, 15) observer.join() exit('\n')
def main(): "The function to execute when running hx" options, args = HendrixOptionParser.parse_args(sys.argv[1:]) options = vars(options) action = args[0] exposeProject(options) options = djangoVsWsgi(options) options = devFriendly(options) redirect = noiseControl(options) try: if action == 'start' and not options['daemonize']: chalk.eraser() chalk.blue('Starting Hendrix...') elif action == 'stop': chalk.green('Stopping Hendrix...') if options['daemonize']: daemonize, _reload, opts = cleanOptions(options) process = subprocess.Popen(['hx', action] + opts, stdout=redirect, stderr=redirect) time.sleep(2) if process.poll(): raise RuntimeError else: launch(*args, **options) if action not in ['start_reload', 'restart']: chalk.eraser() chalk.green('\nHendrix successfully closed.') except Exception, e: msg = ( 'ERROR: %s\nCould not %s hendrix. Try again using the --traceback ' 'flag for more information.') chalk.red(msg % (str(e), action), pipe=chalk.stderr) if options['traceback']: raise else: os._exit(1)
def launch(*args, **options): """ launch acts on the user specified action and options by executing Hedrix.run """ action = args[0] if options['reload']: event_handler = Reload(options) observer = Observer() observer.schedule(event_handler, path='.', recursive=True) observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() pid = os.getpid() chalk.eraser() chalk.green('\nHendrix successfully closed.') os.kill(pid, 15) observer.join() exit('\n') else: try: if options['key'] and options['cert'] and options['cache']: HendrixDeploy = hybrid.HendrixDeployHybrid elif options['key'] and options['cert']: HendrixDeploy = ssl.HendrixDeploySSL elif options['cache']: HendrixDeploy = cache.HendrixDeployCache else: HendrixDeploy = base.HendrixDeploy deploy = HendrixDeploy(action, options) deploy.run() except Exception, e: if options.get('traceback'): tb = sys.exc_info()[2] msg = traceback.format_exc(tb) else: msg = str(e) chalk.red(msg, pipe=chalk.stderr) os._exit(1)
def start(self, fd=None): if fd is None: # anything in this block is only run once self.addGlobalServices() self.hendrix.startService() pids = [str(os.getpid())] # script pid if self.options['workers']: self.launchWorkers(pids) self.pid_file = self.openPidList(pids) else: fds = pickle.loads(fd) factories = {} for name in self.servers: factory = self.disownService(name) factories[name] = factory self.hendrix.startService() for name, factory in factories.iteritems(): self.addSubprocess(fds, name, factory) chalk.eraser() chalk.blue('Starting Hendrix...')
def main(): "The function to execute when running hx" options, args = HendrixOptionParser.parse_args(sys.argv[1:]) options = vars(options) try: action = args[0] except IndexError: HendrixOptionParser.print_help() return exposeProject(options) options = djangoVsWsgi(options) options = devFriendly(options) redirect = noiseControl(options) try: if action == "start" and not options["daemonize"]: chalk.eraser() chalk.blue("Starting Hendrix...") elif action == "stop": chalk.green("Stopping Hendrix...") if options["daemonize"]: daemonize, _reload, opts = cleanOptions(options) process = subprocess.Popen(["hx", action] + opts, stdout=redirect, stderr=redirect) time.sleep(2) if process.poll(): raise RuntimeError else: launch(*args, **options) if action not in ["start_reload", "restart"]: chalk.eraser() chalk.green("\nHendrix successfully closed.") except Exception, Argument: print Argument chalk.red("\n Could not %s hendrix.\n" % action, pipe=chalk.stderr)
def main(): "The function to execute when running hx" options, args = HendrixOptionParser.parse_args(sys.argv[1:]) options = vars(options) action = args[0] exposeProject(options) options = djangoVsWsgi(options) options = devFriendly(options) redirect = noiseControl(options) try: if action == "start" and not options["daemonize"]: chalk.eraser() chalk.blue("Starting Hendrix...") elif action == "stop": chalk.green("Stopping Hendrix...") if options["daemonize"]: daemonize, _reload, opts = cleanOptions(options) process = subprocess.Popen(["hx", action] + opts, stdout=redirect, stderr=redirect) time.sleep(2) if process.poll(): raise RuntimeError else: launch(*args, **options) if action not in ["start_reload", "restart"]: chalk.eraser() chalk.green("\nHendrix successfully closed.") except Exception, e: msg = "ERROR: %s\nCould not %s hendrix. Try again using the --traceback " "flag for more information." chalk.red(msg % (str(e), action), pipe=chalk.stderr) if options["traceback"]: raise else: os._exit(1)
def test_chalk_eraser_new_line(self): self.assertEqual(chalk.eraser(new_line=True), '\x1b[2J\x1b[0;0H\n')
def test_chalk_eraser(self): self.assertEqual(chalk.eraser(), '\x1b[2J\x1b[0;0H')